refactor: update form store

This commit is contained in:
Methapon2001 2024-08-05 10:14:54 +07:00
parent 28159e3445
commit 16e295c6bb

View file

@ -17,35 +17,35 @@ export const useCustomerForm = defineStore('form-customer', () => {
taxNo: '', taxNo: '',
registeredBranchId: branchStore.currentMyBranch?.id || '', registeredBranchId: branchStore.currentMyBranch?.id || '',
customerBranch: [ customerBranch: [
{ // {
code: '', // code: '',
branchNo: 1, // branchNo: 1,
address: '', // address: '',
addressEN: '', // addressEN: '',
provinceId: '', // provinceId: '',
districtId: '', // districtId: '',
subDistrictId: '', // subDistrictId: '',
zipCode: '', // zipCode: '',
email: '', // email: '',
telephoneNo: '', // telephoneNo: '',
name: '', // name: '',
status: 'CREATED', // status: 'CREATED',
taxNo: '', // taxNo: '',
nameEN: '', // nameEN: '',
legalPersonNo: '', // legalPersonNo: '',
registerName: '', // registerName: '',
registerDate: new Date(), // registerDate: new Date(),
authorizedCapital: '', // authorizedCapital: '',
employmentOffice: '', // employmentOffice: '',
bussinessType: '', // bussinessType: '',
bussinessTypeEN: '', // bussinessTypeEN: '',
jobPosition: '', // jobPosition: '',
jobPositionEN: '', // jobPositionEN: '',
jobDescription: '', // jobDescription: '',
saleEmployee: '', // saleEmployee: '',
payDate: new Date(), // payDate: new Date(),
wageRate: 0, // wageRate: 0,
}, // },
], ],
image: null, image: null,
}; };
@ -55,13 +55,19 @@ export const useCustomerForm = defineStore('form-customer', () => {
const state = ref<{ const state = ref<{
dialogType: 'info' | 'create' | 'edit'; dialogType: 'info' | 'create' | 'edit';
dialogOpen: boolean; dialogOpen: boolean;
dialogModal: boolean;
branchIndex: number; branchIndex: number;
customerType: 'CORP' | "PERS" customerType: 'CORP' | 'PERS';
saveMode: 'customer' | 'branch';
editId?: string;
}>({ }>({
dialogType: 'info', dialogType: 'info',
dialogOpen: false, dialogOpen: false,
dialogModal: false,
branchIndex: 0, branchIndex: 0,
customerType: "CORP" customerType: 'CORP',
saveMode: 'customer',
editId: '',
}); });
function isFormDataDifferent() { function isFormDataDifferent() {
@ -123,7 +129,21 @@ export const useCustomerForm = defineStore('form-customer', () => {
currentFormData.value = structuredClone(resetCustomerData); currentFormData.value = structuredClone(resetCustomerData);
} }
// TODO: Submit function async function submitForm() {
if (state.value.dialogType === 'edit' && !state.value.editId) {
throw new Error('Form mode is set to edit but no ID is provided.');
}
if (state.value.dialogType === 'edit') {
return submitEdit();
}
return submitCreate();
}
async function submitCreate() {
customerStore.create(currentFormData.value);
}
async function submitEdit() {}
return { return {
state, state,
@ -131,6 +151,7 @@ export const useCustomerForm = defineStore('form-customer', () => {
isFormDataDifferent, isFormDataDifferent,
resetFormData, resetFormData,
assignFormData, assignFormData,
submitForm,
}; };
}); });
@ -138,6 +159,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
return {}; return {};
}); });
export const useCustomerBranchForm = defineStore('form-customer-branch', () => { export const useCustomerBranchForm = defineStore(
'form-customer-branch',
}) () => {},
);