@@ -5,8 +5,6 @@
|
||||
@save="submitForm"
|
||||
@toggleEdit="toggleEdit"
|
||||
/>
|
||||
{{employeeStore.employee }}
|
||||
|
||||
<form class="text-start" @keyup.enter="submitForm">
|
||||
<div class="row mb-5">
|
||||
<div class="col pe-5">
|
||||
@@ -180,8 +178,6 @@ import { useUser } from '@/stores/user'
|
||||
import { useEmployee } from '@/stores/employee'
|
||||
import EmployeeFormControls from '@/components/Employees/EmployeeFormControls.vue'
|
||||
import { IMaskComponent as MaskInput } from 'vue-imask'
|
||||
import employees from '@/stores/employees'
|
||||
|
||||
|
||||
/**
|
||||
* Props
|
||||
@@ -247,7 +243,7 @@ const editEmployee = ref(props.id ? false : true)
|
||||
}
|
||||
}))
|
||||
|
||||
const v$ = useVuelidate(rules, employee)
|
||||
const v$ = useVuelidate(rules, employee) // error because wrong return type in validateApiErrors()...
|
||||
|
||||
|
||||
/**
|
||||
@@ -279,13 +275,14 @@ function toggleEdit() {
|
||||
}
|
||||
|
||||
async function submitForm(){
|
||||
if(await v$.value.$validate()) {
|
||||
|
||||
if(await v$.value.$validate()){
|
||||
if(employee.value.id){
|
||||
await employeeStore.patchEmployee()
|
||||
|
||||
toggleEdit()
|
||||
if(await employeeStore.patchEmployee()){
|
||||
toggleEdit()
|
||||
}
|
||||
}
|
||||
else if(await employeeStore.postEmployee()){
|
||||
else if(await employeeStore.postEmployee()) {
|
||||
router.push({name: "Employees/Index"})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import axios from '@/axios'
|
||||
import { useUser } from './user'
|
||||
import { useNotifications } from './notifications'
|
||||
import Axios from 'axios'
|
||||
import { stubFalse } from 'lodash'
|
||||
|
||||
const user = useUser()
|
||||
const notifications = useNotifications()
|
||||
@@ -117,13 +116,19 @@ export const useEmployee = defineStore({
|
||||
|
||||
Object.assign(this.clean.employee, this.employee)
|
||||
notifications.add('success', result.statusText)
|
||||
return true
|
||||
}
|
||||
catch(error) {
|
||||
if(error instanceof Error) {
|
||||
console.log(error)
|
||||
console.log("Patch Employee Error")
|
||||
if(Axios.isAxiosError(error)) {
|
||||
let data = error.response?.data as { errors: EmployeeApiValidationError[] }
|
||||
this.apiValidationErrors = [...data.errors]
|
||||
}
|
||||
else if(error instanceof Error) {
|
||||
notifications.add('danger', error.message, -1)
|
||||
}
|
||||
else console.log(error)
|
||||
console.log(error)
|
||||
return false
|
||||
}
|
||||
},
|
||||
|
||||
@@ -142,17 +147,18 @@ export const useEmployee = defineStore({
|
||||
this.assignTruthyValues(this.clean.employee, result.data)
|
||||
notifications.add('success', result.statusText)
|
||||
|
||||
console.log(result)
|
||||
return true
|
||||
}
|
||||
catch(error){
|
||||
console.log("enter catch")
|
||||
console.log("Post Employee Error")
|
||||
if(Axios.isAxiosError(error)) {
|
||||
console.log("enter axios error")
|
||||
let data = error.response?.data as { errors: EmployeeApiValidationError[] }
|
||||
console.log(data)
|
||||
this.apiValidationErrors = [...data.errors]
|
||||
}
|
||||
else if(error instanceof Error) {
|
||||
notifications.add('danger', error.message, -1)
|
||||
}
|
||||
console.log(error)
|
||||
return false
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user