diff --git a/src/app/api/staff/index.ts b/src/app/api/staff/index.ts index 240b821..41bc922 100644 --- a/src/app/api/staff/index.ts +++ b/src/app/api/staff/index.ts @@ -48,7 +48,7 @@ export type IndividualStaff = { phone2?: string emergContactName: string; emergContactPhone: string; - joinDate: string; + joinDate: string | number[]; joinPosition: data; departDate?: string; departReason?: string; diff --git a/src/components/EditStaff/EditStaff.tsx b/src/components/EditStaff/EditStaff.tsx index 37c8910..709f7a3 100644 --- a/src/components/EditStaff/EditStaff.tsx +++ b/src/components/EditStaff/EditStaff.tsx @@ -62,9 +62,9 @@ const EditStaff: React.FC = ({ Staff, combos, SalaryEffectiveInfo }) phone2: Staff.phone2, emergContactName: Staff.emergContactName, emergContactPhone: Staff.emergContactPhone, - joinDate: Staff.joinDate ? dayjs(Staff.joinDate).toString() : null, + joinDate: Staff.joinDate ? dayjs(Staff.joinDate as string).format("YYYY-MM-DD") : null, joinPositionId: Staff.joinPosition?.id || null, - departDate: Staff.departDate ? dayjs(Staff.departDate).toString() : null, + departDate: Staff.departDate ? dayjs(Staff.departDate as string).format("YYYY-MM-DD") : null, departReason: Staff.departReason, remark: Staff.remark, salaryEffectiveInfo: SalaryEffectiveInfo.map(item => { diff --git a/src/components/EditStaff/EditStaffWrapper.tsx b/src/components/EditStaff/EditStaffWrapper.tsx index 3382362..fc50eb9 100644 --- a/src/components/EditStaff/EditStaffWrapper.tsx +++ b/src/components/EditStaff/EditStaffWrapper.tsx @@ -56,6 +56,8 @@ const EditStaffWrapper: React.FC & SubComponents = async ({ salary: SalaryCombo.records, } +Staff.data.joinDate = Staff.data.joinDate && dateArrayToString(Staff.data.joinDate) as string +Staff.data.departDate = Staff.data.departDate && dateArrayToString(Staff.data.departDate) as string // [{id:0, salaryPoint: 1, date:"2021-05-05"}, {id:1, salaryPoint: 43, date:"2024-05-05"}] console.log(Staff.data) @@ -65,3 +67,17 @@ console.log(Staff.data) EditStaffWrapper.Loading = EditStaffLoading; export default EditStaffWrapper; + + +function dateArrayToString(dateArray: number[] | string): string { + if (typeof dateArray === 'string'){ + return dateArray + } + const [year, month, day] = dateArray; + console.log(dateArray) + // Ensure the month is in the correct range (0-11) + const monthIndex = month; + + // Create the date string in the format "YYYY-MM-DD" + return `${year}-${monthIndex.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`; +} \ No newline at end of file diff --git a/src/components/EditStaff/StaffInfo.tsx b/src/components/EditStaff/StaffInfo.tsx index 77761b6..c77fcb8 100644 --- a/src/components/EditStaff/StaffInfo.tsx +++ b/src/components/EditStaff/StaffInfo.tsx @@ -460,6 +460,8 @@ const StaffInfo: React.FC = ({ combos }) => { value={joinDate && joinDate !== undefined ? dayjs(joinDate) : null} onChange={(date) => { if (!date) return; + dayjs(date).add(1, 'month') + console.log(date) setValue("joinDate", date.format(INPUT_DATE_FORMAT)); }} // slotProps={{ @@ -509,6 +511,7 @@ const StaffInfo: React.FC = ({ combos }) => { value={departDate ? dayjs(departDate) : null} onChange={(date) => { if (!date) return; + dayjs(date).add(1, 'month') setValue("departDate", date.format(INPUT_DATE_FORMAT)); }} slotProps={{