Change createTimetrackAccount to use axios
This commit is contained in:
parent
bd9eae2dff
commit
24240164ad
@ -1,12 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-container id="createAccountListen">
|
<v-container @keyup.enter.prevent="addAccount">
|
||||||
<v-card align-center>
|
<v-card align-center>
|
||||||
<p class="text-center logowhite--text" style="font-size:30pt">Details</p>
|
<p class="text-center logowhite--text" style="font-size:30pt">Details</p>
|
||||||
|
|
||||||
<v-form>
|
<v-form>
|
||||||
<v-text-field
|
<v-text-field
|
||||||
label="name"
|
label="name"
|
||||||
v-model="newname"
|
v-model="accountData.name"
|
||||||
name="name"
|
name="name"
|
||||||
prepend-icon="mdi-account-tie"
|
prepend-icon="mdi-account-tie"
|
||||||
type="text"
|
type="text"
|
||||||
@ -14,7 +13,7 @@
|
|||||||
/>
|
/>
|
||||||
<v-text-field
|
<v-text-field
|
||||||
label="revenue"
|
label="revenue"
|
||||||
v-model="newrevenue"
|
v-model="accountData.revenue"
|
||||||
name="revenue"
|
name="revenue"
|
||||||
prepend-icon="mdi-currency-usd"
|
prepend-icon="mdi-currency-usd"
|
||||||
type="text"
|
type="text"
|
||||||
@ -22,73 +21,50 @@
|
|||||||
/>
|
/>
|
||||||
<v-text-field
|
<v-text-field
|
||||||
label="description"
|
label="description"
|
||||||
v-model="newdescription"
|
v-model="accountData.description"
|
||||||
name="description"
|
name="description"
|
||||||
prepend-icon="mdi-information-variant"
|
prepend-icon="mdi-information-variant"
|
||||||
type="text"
|
type="text"
|
||||||
color="primary"
|
color="primary"
|
||||||
/>
|
/>
|
||||||
</v-form>
|
</v-form>
|
||||||
|
|
||||||
<div class="text-center ma-3">
|
<div class="text-center ma-3">
|
||||||
<v-btn rounded color="logowhite" outlined dark v-on:click="addAccount()">Add</v-btn>
|
<v-btn rounded color="logowhite" outlined dark @click="addAccount">Add</v-btn>
|
||||||
</div>
|
</div>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-container>
|
</v-container>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import {BASE_URI} from "../globals";
|
import {BASE_URI} from "../globals";
|
||||||
|
import axios from "axios"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "CreateTimeTrackAccount",
|
name: "CreateTimeTrackAccount",
|
||||||
data: () => ({
|
data: () => ({
|
||||||
user: sessionStorage.getItem("timeTrackAccountListUserId"),
|
user: sessionStorage.getItem("timeTrackAccountListUserId"),
|
||||||
newname: "",
|
accountData: {name: "", revenue: "", description: ""}
|
||||||
newrevenue: "",
|
|
||||||
newdescription: "",
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
addAccount() {
|
addAccount() {
|
||||||
if (this.newname != "" || this.newrevenue != "" || this.newdescription != "") {
|
if (Object.values(this.accountData).every(data => data)) {
|
||||||
var xhttp = new XMLHttpRequest();
|
let postData = {
|
||||||
var suc;
|
user: this.user,
|
||||||
xhttp.onreadystatechange = function () {
|
...this.accountData
|
||||||
if ((this.status == 201) & (this.readyState == 4)) {
|
|
||||||
suc = true;
|
|
||||||
}
|
}
|
||||||
};
|
let config = {
|
||||||
xhttp.open("POST", BASE_URI + "/accounts", false);
|
headers: {
|
||||||
xhttp.setRequestHeader("Content-Type", "application/json");
|
'Authorization': sessionStorage.getItem("jwt")
|
||||||
|
|
||||||
xhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt"));
|
|
||||||
xhttp.send(
|
|
||||||
"{" +
|
|
||||||
'"user": "' +
|
|
||||||
this.user +
|
|
||||||
'", "revenue": "' +
|
|
||||||
this.newrevenue +
|
|
||||||
'", "name": "' +
|
|
||||||
this.newname +
|
|
||||||
'", "description": "' +
|
|
||||||
this.newdescription +
|
|
||||||
'"}'
|
|
||||||
);
|
|
||||||
if (suc == true) {
|
|
||||||
this.$router.push("/timetrackaccounts");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
axios.post(BASE_URI + "/accounts", postData, config)
|
||||||
|
.then(() => {
|
||||||
|
this.$router.push("/timetrackaccounts")
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log("Error " + err)
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
var listen = document.getElementById('createAccountListen');
|
|
||||||
listen.addEventListener("keyup", e => {
|
|
||||||
if (e.keyCode === 13) {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
this.addAccount();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user