refactor: assign after submit

This commit is contained in:
Thanaphon Frappet 2024-10-21 12:05:49 +07:00
parent c5aa7e94a1
commit 226da5ccfe

View file

@ -143,10 +143,12 @@ export const useQuotationForm = defineStore('form-quotation', () => {
} }
async function submitQuotation() { async function submitQuotation() {
let status = false;
if (currentFormState.value.mode === 'create') { if (currentFormState.value.mode === 'create') {
const res = await quotationStore.createQuotation(currentFormData.value); const res = await quotationStore.createQuotation(currentFormData.value);
if (res !== null) { if (res !== null) {
currentFormData.value.id = res.id;
fileItemNewWorker.value.forEach(async (v) => { fileItemNewWorker.value.forEach(async (v) => {
if (v.group === undefined) return; if (v.group === undefined) return;
await employeeStore.postMeta({ await employeeStore.postMeta({
@ -156,7 +158,7 @@ export const useQuotationForm = defineStore('form-quotation', () => {
file: v.file, file: v.file,
}); });
}); });
return true; status = true;
} }
} }
if (currentFormState.value.mode === 'edit' && currentFormData.value.id) { if (currentFormState.value.mode === 'edit' && currentFormData.value.id) {
@ -169,11 +171,16 @@ export const useQuotationForm = defineStore('form-quotation', () => {
id: currentFormData.value.id, id: currentFormData.value.id,
}); });
if (res) return true; if (res) status = true;
} }
currentFormState.value.mode = 'info'; currentFormState.value.mode = 'info';
if (currentFormData.value.id !== undefined) {
assignFormData(currentFormData.value.id, 'info');
}
currentFormState.value.createdBy = (_) => getName() || ''; currentFormState.value.createdBy = (_) => getName() || '';
return status;
} }
function injectNewEmployee( function injectNewEmployee(