fixed update employee with password change
This commit is contained in:
@@ -67,9 +67,6 @@ export const useEmployee = defineStore({
|
||||
headers: user.header
|
||||
})).data
|
||||
|
||||
console.log(this.clean.employee)
|
||||
console.log(data)
|
||||
|
||||
Object.assign(this.clean.employee, data)
|
||||
Object.assign(this.employee, data)
|
||||
}
|
||||
@@ -87,20 +84,34 @@ export const useEmployee = defineStore({
|
||||
async persist() {
|
||||
try {
|
||||
let result
|
||||
let payload = Object.assign({}, this.employee)
|
||||
|
||||
if (this.employee.password === this.clean.employee.password) {
|
||||
payload.username = ''
|
||||
payload.password = ''
|
||||
}
|
||||
|
||||
result = await axios.patch(
|
||||
'employees/'+this.employee.id,
|
||||
this.employee,
|
||||
payload,
|
||||
{
|
||||
headers: user.header
|
||||
}
|
||||
)
|
||||
|
||||
console.log(result)
|
||||
|
||||
this.employee.password = ''
|
||||
this.employee.passwordConfirm = ''
|
||||
|
||||
Object.assign(this.clean.employee, this.employee)
|
||||
notifications.add('success', result.statusText)
|
||||
}
|
||||
catch(error) {
|
||||
if(error instanceof Error) notifications.add('danger', error.message, -1)
|
||||
if(error instanceof Error) {
|
||||
console.log(error)
|
||||
notifications.add('danger', error.message, -1)
|
||||
}
|
||||
else console.log(error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,6 @@
|
||||
|
||||
<VProfileControls class="mb-5" :isActive="editEmployee || createUser" @save="onUpdateEmployee" @toggleEdit="onToggleEdit" />
|
||||
|
||||
<h5>Clean State</h5>
|
||||
{{ state.clean.employee }}
|
||||
<br>
|
||||
<h5>Dirty State</h5>
|
||||
{{ state.employee }}
|
||||
|
||||
<form @keydown.enter="onEnter" class="text-start">
|
||||
<div class="row mb-5">
|
||||
<div class="col pe-5">
|
||||
@@ -168,7 +162,7 @@ const rules = computed(() => ({
|
||||
requiredIf: requiredIf(() => createUser.value)
|
||||
},
|
||||
password: {
|
||||
requiredIf: requiredIf(() => state.employee.username !== '')
|
||||
requiredIf: requiredIf(() => createUser.value)
|
||||
},
|
||||
passwordConfirm: {
|
||||
sameAs: sameAs(state.employee.password)
|
||||
|
||||
Reference in New Issue
Block a user