feat: add function edit quotation data

This commit is contained in:
Methapon Metanipat 2024-10-03 14:43:41 +07:00
parent 017f757de2
commit b7308d1833
2 changed files with 23 additions and 10 deletions

View file

@ -7,7 +7,7 @@ import { QuotationPayload, EmployeeWorker } from 'src/stores/quotations/types';
// NOTE: Import stores
import { useQuotationStore } from 'stores/quotations';
const DEFAULT_DATA: QuotationPayload = {
const DEFAULT_DATA: QuotationPayload & { id?: string } = {
productServiceList: [],
urgent: false,
customerBranchId: '',
@ -56,12 +56,24 @@ export const useQuotationForm = defineStore('form-quotation', () => {
currentFormData.value = structuredClone(resetFormData);
}
async function assignFormData(id: string) {
async function assignFormData(id: string, mode: 'info' | 'edit' = 'info') {
const data = await quotationStore.getQuotation(id);
if (!data) return; // NOTE: Error should be handled globally by axios instance
currentFormState.value.mode = 'edit';
resetFormData = Object.assign(data, {
dueDate: new Date(data.dueDate),
payBillDate: data.payBillDate ? new Date(data.payBillDate) : undefined,
worker: data.worker.map((v) =>
Object.assign(v.employee, {
dateOfBirth: new Date(v.employee.dateOfBirth),
}),
),
});
currentFormData.value = structuredClone(resetFormData);
currentFormState.value.mode = mode;
}
function submiQuotationt() {
@ -87,6 +99,7 @@ export const useQuotationForm = defineStore('form-quotation', () => {
return {
currentFormData,
currentFormState,
injectNewEmployee,
isFormDataDifferent,