From e2877506fce21ed19bd6593cd0503bf3e4ba6087 Mon Sep 17 00:00:00 2001 From: "MSI\\derek" Date: Fri, 16 Aug 2024 16:54:17 +0800 Subject: [PATCH] update --- src/components/EditStaff/EditStaff.tsx | 18 +++++------------- src/components/EditStaff/StaffInfo.tsx | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/components/EditStaff/EditStaff.tsx b/src/components/EditStaff/EditStaff.tsx index 356a6c5..37c8910 100644 --- a/src/components/EditStaff/EditStaff.tsx +++ b/src/components/EditStaff/EditStaff.tsx @@ -39,7 +39,7 @@ interface formProps { const EditStaff: React.FC = ({ Staff, combos, SalaryEffectiveInfo }) => { - console.log(Staff) + // console.log(Staff.joinDate) const defaultSkillset = Staff.skillset.map((s: any) => s.skill.id) const { t } = useTranslation(); const searchParams = useSearchParams() @@ -62,9 +62,9 @@ const EditStaff: React.FC = ({ Staff, combos, SalaryEffectiveInfo }) phone2: Staff.phone2, emergContactName: Staff.emergContactName, emergContactPhone: Staff.emergContactPhone, - joinDate: dayjs(Staff.joinDate).toString() || "", + joinDate: Staff.joinDate ? dayjs(Staff.joinDate).toString() : null, joinPositionId: Staff.joinPosition?.id || null, - departDate: dayjs(Staff.departDate).toString() || "", + departDate: Staff.departDate ? dayjs(Staff.departDate).toString() : null, departReason: Staff.departReason, remark: Staff.remark, salaryEffectiveInfo: SalaryEffectiveInfo.map(item => { @@ -152,20 +152,12 @@ const EditStaff: React.FC = ({ Staff, combos, SalaryEffectiveInfo }) date: dayjs(item.date).format('YYYY-MM-DD').toString() })) } - // remove useless data - if (postData.joinDate === 'Invalid Date') { - postData.joinDate = null - } else { + if (postData.joinDate) { postData.joinDate = dayjs(postData.joinDate).format("YYYY-MM-DD") } - if (postData.departDate === 'Invalid Date') { - postData.departDate = null - } else { + if (postData.departDate) { postData.departDate = dayjs(postData.departDate).format("YYYY-MM-DD") } - if (!postData.joinPositionId) - postData.joinPositionId = null - console.log(postData) await saveStaff(postData) router.replace("/settings/staff") diff --git a/src/components/EditStaff/StaffInfo.tsx b/src/components/EditStaff/StaffInfo.tsx index 7e915b8..77761b6 100644 --- a/src/components/EditStaff/StaffInfo.tsx +++ b/src/components/EditStaff/StaffInfo.tsx @@ -80,7 +80,7 @@ const StaffInfo: React.FC = ({ combos }) => { const joinDate = watch("joinDate"); const departDate = watch("departDate"); - + useEffect(() => { if (joinDate) clearErrors("joinDate"); if (departDate) clearErrors("departDate"); @@ -457,19 +457,19 @@ const StaffInfo: React.FC = ({ combos }) => { sx={{ width: "100%" }} label={t("Join Date")} // defaultValue={dayjs(getValues("joinDate"))} - value={joinDate ? dayjs(joinDate) : null} + value={joinDate && joinDate !== undefined ? dayjs(joinDate) : null} onChange={(date) => { if (!date) return; setValue("joinDate", date.format(INPUT_DATE_FORMAT)); }} - slotProps={{ - textField: { - // required: true, - error: - !joinDate ?? false, - // value: errors.joinDate?.message, - }, - }} + // slotProps={{ + // textField: { + // required: true, + // error: + // !joinDate ?? false, + // value: errors.joinDate?.message, + // }, + // }} />