Commit eb3870a2 authored by TTS Kieu Tuan Anh's avatar TTS Kieu Tuan Anh

add update user

parent b0f0ef05
...@@ -17,7 +17,7 @@ import axios from "axios"; ...@@ -17,7 +17,7 @@ import axios from "axios";
import VueAxios from "vue-axios"; import VueAxios from "vue-axios";
import Nav from "@/components/Nav"; import Nav from "@/components/Nav";
import Footer from "@/components/footer"; import Footer from "@/components/Footer";
export default { export default {
components: { Nav }, components: { Nav },
......
...@@ -167,7 +167,7 @@ ...@@ -167,7 +167,7 @@
import Nav from "@/components/Nav"; import Nav from "@/components/Nav";
import Navigation from "@/components/Navigation"; import Navigation from "@/components/Navigation";
import axios from "axios"; import axios from "axios";
import notification from "@/components/notification"; import notification from "@/components/Notification";
import Toasted from 'vue-toasted'; import Toasted from 'vue-toasted';
import { ModalPlugin } from 'bootstrap-vue'; import { ModalPlugin } from 'bootstrap-vue';
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</b-breadcrumb> </b-breadcrumb>
<div style="float: right"> <div style="float: right">
<b-button v-b-modal.modal-login >New User</b-button> <b-button v-b-modal.modal-login >New User</b-button>
<!-- modal create user -->
<b-modal id="modal-login" title="Create User" class="modal fade" > <b-modal id="modal-login" title="Create User" class="modal fade" >
<Notification :message="error" v-if="error" /> <Notification :message="error" v-if="error" />
<p class="my-4"> <p class="my-4">
...@@ -44,11 +44,7 @@ ...@@ -44,11 +44,7 @@
v-model="password" v-model="password"
required required
/> />
<!-- <div class="button">
<button class="w-30 btn btn-sm btn-primary" type="submit">
Create
</button>
</div> -->
</form> </form>
</p> </p>
<template #modal-footer> <template #modal-footer>
...@@ -56,6 +52,44 @@ ...@@ -56,6 +52,44 @@
<button @click="createUser" v-b-modal.modal-close_visit class="btn btn-success btn-sm m-1">Submit</button> <button @click="createUser" v-b-modal.modal-close_visit class="btn btn-success btn-sm m-1">Submit</button>
</template> </template>
</b-modal> </b-modal>
<!-- modal edit user -->
<b-modal id="modal-edit" title="Edit User" class="modal fade" >
<p class="my-4">
<form @submit.prevent="" >
<label>Name :</label>
<input
type="text"
class="form-control mb-2"
placeholder="name"
v-model="eName"
max="255"
min="1"
required
/>
<label>Email :</label>
<input
type="email"
class="form-control mb-2"
placeholder="Email"
v-model="eEmail"
required
/>
<label>Password :</label>
<input
type="password"
class="form-control mb-2"
placeholder="password"
v-model="ePassword"
required
/>
</form>
</p>
<template #modal-footer>
<button v-b-modal.modal-close_visit @click="$bvModal.hide('modal-edit')" class="btn btn-danger btn-sm m-1">Close</button>
<button @click="updateUser(this?.eID)" v-b-modal.modal-close_visit class="btn btn-success btn-sm m-1">Submit</button>
</template>
</b-modal>
</div> </div>
<v-data-table <v-data-table
:headers="headers" :headers="headers"
...@@ -153,7 +187,7 @@ ...@@ -153,7 +187,7 @@
</v-toolbar> </v-toolbar>
</template> </template>
<template v-slot:item.actions="{ item }"> <template v-slot:item.actions="{ item }">
<v-icon small class="mr-2" @click="editItem(id)" :id ="item.id"> mdi-pencil </v-icon> <v-icon small class="mr-2" @click=" editUser(item.id);" :id ="item.id"> mdi-pencil </v-icon>
<v-icon small @click="deleteUser(item.id)" :id ="item.id"> mdi-delete </v-icon> <v-icon small @click="deleteUser(item.id)" :id ="item.id"> mdi-delete </v-icon>
</template> </template>
<template v-slot:no-data> <template v-slot:no-data>
...@@ -167,7 +201,7 @@ ...@@ -167,7 +201,7 @@
import Nav from "@/components/Nav"; import Nav from "@/components/Nav";
import Navigation from "@/components/Navigation"; import Navigation from "@/components/Navigation";
import axios from "axios"; import axios from "axios";
import notification from "@/components/notification"; import notification from "@/components/Notification";
import Toasted from 'vue-toasted'; import Toasted from 'vue-toasted';
import { ModalPlugin } from 'bootstrap-vue'; import { ModalPlugin } from 'bootstrap-vue';
...@@ -200,6 +234,10 @@ export default { ...@@ -200,6 +234,10 @@ export default {
{ text: 'Actions', value: 'actions', sortable: false }, { text: 'Actions', value: 'actions', sortable: false },
], ],
users: [], users: [],
eID: '',
eEmail:'',
eName:'',
ePassword:'',
message: [], message: [],
editedIndex: -1, editedIndex: -1,
editedItem: { editedItem: {
...@@ -298,7 +336,9 @@ export default { ...@@ -298,7 +336,9 @@ export default {
}) })
.then(response => { .then(response => {
// $bvModal.hide('modal-login'); // $bvModal.hide('modal-login');
self.$toast.success('User created successfully!'); self.$toast.success('User created successfully!',{
duration: 3000
});
console.log(response); console.log(response);
}) })
.catch(errors => { .catch(errors => {
...@@ -312,18 +352,45 @@ export default { ...@@ -312,18 +352,45 @@ export default {
}, },
deleteUser(userID) { deleteUser(userID) {
if(confirm("Do you really want to delete?")){
try{ try{
axios axios
.delete(`http://127.0.0.1:8000/api/users/${userID}`) .delete(`http://127.0.0.1:8000/api/users/${userID}`)
} catch(error){ } catch(error){
console.log(error) console.log(error)
} }
}
}, },
editUser(userID) { editUser(userID) {
this.$bvModal.show('modal-edit');
this.eID = userID;
console.log(this?.eID);
},
updateUser(userID) {
const self = this
console.log(this.eName);
console.log(this.eEmail);
console.log(this?.eID);
try{
axios
.put(`http://127.0.0.1:8000/api/users/${this?.eID}`,{
email: this.eEmail,
password: this.ePassword,
name:this.eName,} )
.then(response => {
self.$toast.success('User updated successfully!',{
duration: 3000
});
console.log(response);
})
} catch(error){
console.log(error)
}
} }
}, },
created() { created() {
this.getUsers(); this.getUsers();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment