From df18c802d7cce60dde054fc1581f4cb5601e79d5 Mon Sep 17 00:00:00 2001 From: Areos Chen Date: Tue, 9 Apr 2024 23:01:30 +0930 Subject: [PATCH] fix: deduction display error --- src/configs/i18n/scriptEn.ts | 2 ++ src/configs/schema/workSchema.ts | 15 ++++++++------- src/configs/zustore/worklogStore.ts | 3 +++ src/pageComponents/modals/mJobEdit/mJobEdit.tsx | 5 ++++- src/pages/workLogs.tsx | 4 ++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/configs/i18n/scriptEn.ts b/src/configs/i18n/scriptEn.ts index 4bb3372..041f8e6 100644 --- a/src/configs/i18n/scriptEn.ts +++ b/src/configs/i18n/scriptEn.ts @@ -293,6 +293,7 @@ const en = { updateLogo: "Updated Logo.", updateWorkLog: "Updated Work Assignment.", updateWorkHours: "Updated Work Hours.", + updateWL: "Updated Work Log.", }, toastF: { addOrder: "Error: Adding New Order Failed", @@ -307,6 +308,7 @@ const en = { overPaid: "Error: Over Paid Amount", unMatchPW: "Error: Passwords do not match", updateWorkHours: "Error: Updating Work Hours Failed", + updateWL: "Error: Updating Work Log.", }, toastW: { selectDate: "Please select a date first.", diff --git a/src/configs/schema/workSchema.ts b/src/configs/schema/workSchema.ts index 65f8399..7a614ff 100644 --- a/src/configs/schema/workSchema.ts +++ b/src/configs/schema/workSchema.ts @@ -59,6 +59,13 @@ const workLogSchema = z.object({ archive: z.boolean().default(false), }); +export const deductionSchema = z.object({ + did: z.string().default(""), + fk_wlid: z.string().default(""), + note: z.string().trim().nullable().default(""), + amount: z.number().default(0), +}); + export const assignedWorkSchema = workLogSchema.extend({ first_name: z.string().default(""), last_name: z.string().default(""), @@ -84,6 +91,7 @@ export const assignedWorkSchema = workLogSchema.extend({ .default("your_email@email.com"), role: z.string().trim().default(defaultStaffRole), hr: z.number().default(25), + deduction: deductionSchema.array().default([]), }); export const workLogsSchema = z.object({ @@ -108,13 +116,6 @@ export const wlTableRowSchema = assignedWorkSchema.extend({ postcode: z.string().trim().nullable().default(""), }); -export const deductionSchema = z.object({ - did: z.string().default(""), - fk_wlid: z.string().default(""), - note: z.string().trim().nullable().default(""), - amount: z.number().default(0), -}); - export type TworkLog = z.infer; export type TassignedWork = z.infer; export type TworkLogs = z.infer; diff --git a/src/configs/zustore/worklogStore.ts b/src/configs/zustore/worklogStore.ts index f4bd02f..90c647f 100644 --- a/src/configs/zustore/worklogStore.ts +++ b/src/configs/zustore/worklogStore.ts @@ -18,6 +18,7 @@ type Taction = { setDeductionNote: (index: number, note: string) => void; appendDeduction: (deduction: Partial) => void; removeDeduction: (index: number) => void; + setDeduction: (deduction: Partial[]) => void; }; export const worklogStore = createStore((set) => ({ @@ -53,6 +54,8 @@ export const worklogStore = createStore((set) => ({ console.log("-> new deduction: ", newDeduction); return { ...state, deduction: newDeduction }; }), + setDeduction: (deduction: Partial[]) => + set((state) => ({ ...state, deduction })), })); export const useWorklogStore = (selector: (state: Tstate & Taction) => T) => diff --git a/src/pageComponents/modals/mJobEdit/mJobEdit.tsx b/src/pageComponents/modals/mJobEdit/mJobEdit.tsx index 88efa40..2515a5f 100644 --- a/src/pageComponents/modals/mJobEdit/mJobEdit.tsx +++ b/src/pageComponents/modals/mJobEdit/mJobEdit.tsx @@ -31,15 +31,18 @@ const MJobEdit = () => { const setETime = useWorklogStore((state) => state.setETime); const setBHour = useWorklogStore((state) => state.setBHour); const deduction = useWorklogStore((state) => state.deduction); + const setDeduction = useWorklogStore((state) => state.setDeduction); useEffect(() => { setSTime(worklog.s_time ? worklog.s_time : "00:00"); setETime(worklog.e_time ? worklog.e_time : "00:00"); setBHour(worklog.b_hour ? worklog.b_hour : "00:00"); - }, [modalOpen, worklog, setSTime, setETime, setBHour]); + setDeduction(worklog.deduction ? worklog.deduction : []); + }, [modalOpen, worklog, setSTime, setETime, setBHour, setDeduction]); const onClose = () => { setModalOpen(mOpenOps.default); + setDeduction([]); }; const onSubmit = async (e: FormEvent) => { diff --git a/src/pages/workLogs.tsx b/src/pages/workLogs.tsx index 5bd79fb..17ff975 100644 --- a/src/pages/workLogs.tsx +++ b/src/pages/workLogs.tsx @@ -29,13 +29,13 @@ const WorkLogs: FC = () => { if (actionData?.status === RES_STATUS.SUC_UPDATE_WORKLOG) { if (modalOpen === mOpenOps.edit) { setModalOpen(mOpenOps.default); - toastSuccess(t("toastS.updateWorkHours")); + toastSuccess(t("toastS.updateWL")); actionData.status = RES_STATUS.DEFAULT; } } else if (actionData?.status === RES_STATUS.FAILED_UPDATE_WORKLOG) { if (modalOpen === mOpenOps.edit) { setModalOpen(mOpenOps.default); - toastError(t("toastF.updateWorkHours")); + toastError(t("toastF.updateWL")); actionData.status = RES_STATUS.DEFAULT; } } else if (actionData?.status === RES_STATUS.SUC_DELETE_WORKLOG) {