diff --git a/src/components/TimesheetAmendment/TimesheetAmendment.tsx b/src/components/TimesheetAmendment/TimesheetAmendment.tsx index 95561a9..ad8da21 100644 --- a/src/components/TimesheetAmendment/TimesheetAmendment.tsx +++ b/src/components/TimesheetAmendment/TimesheetAmendment.tsx @@ -53,6 +53,8 @@ export interface Props { miscTasks: Task[]; isSaturdayWorker: boolean; userId: number; + handleTeamTimesheetsUpdate: (ts: TeamTimeSheets) => void; + handleTeamLeavesUpdate: (le: TeamLeaves) => void; } type MemberOption = TeamTimeSheets[0] & TeamLeaves[0] & { id: string }; @@ -82,7 +84,9 @@ const TimesheetAmendment: React.FC = ({ leaveTypes, miscTasks, isSaturdayWorker, - userId + userId, + handleTeamTimesheetsUpdate, + handleTeamLeavesUpdate, }) => { const { t, i18n:{language}} = useTranslation(["home", "common"]); const locale = language === "zh" ? "zh-tw" : "en"; @@ -412,6 +416,7 @@ const TimesheetAmendment: React.FC = ({ entry: timeEntry, recordDate, }); + setLocalTeamTimesheets((timesheets) => ({ ...timesheets, [intStaffId]: { @@ -419,6 +424,15 @@ const TimesheetAmendment: React.FC = ({ timeEntries: newMemberTimesheets, }, })); + + handleTeamTimesheetsUpdate({ + ...localTeamTimesheets, + [intStaffId]: { + ...localTeamTimesheets[intStaffId], + timeEntries: newMemberTimesheets, + }, + }); + setEditModalOpen(false); }, [checkTotalHoursForDate, selectedStaff.id], @@ -440,6 +454,15 @@ const TimesheetAmendment: React.FC = ({ leaveEntries: newMemberLeaves, }, })); + + handleTeamLeavesUpdate({ + ...localTeamLeaves, + [intStaffId]: { + ...localTeamLeaves[intStaffId], + leaveEntries: newMemberLeaves, + }, + }); + setLeaveEditModalOpen(false); }, [checkTotalHoursForDate, selectedStaff.id], diff --git a/src/components/TimesheetAmendment/TimesheetAmendmentModal.tsx b/src/components/TimesheetAmendment/TimesheetAmendmentModal.tsx index 6cfd193..028c781 100644 --- a/src/components/TimesheetAmendment/TimesheetAmendmentModal.tsx +++ b/src/components/TimesheetAmendment/TimesheetAmendmentModal.tsx @@ -13,6 +13,7 @@ import { useTranslation } from "react-i18next"; import TimesheetAmendment, { Props as TimesheetAmendmentProps, } from "./TimesheetAmendment"; +// import { TeamLeaves, TeamTimeSheets } from "@/app/api/timesheets"; const modalSx: SxProps = { position: "absolute", @@ -28,6 +29,8 @@ interface Props extends TimesheetAmendmentProps { open: boolean; onClose: () => void; isSaturdayWorker: boolean; + handleTeamLeavesUpdate: (le: any) => void; + handleTeamTimesheetsUpdate: (ts: any) => void; } export const TimesheetAmendmentModal: React.FC = ({ @@ -40,7 +43,9 @@ export const TimesheetAmendmentModal: React.FC = ({ allProjects, miscTasks, isSaturdayWorker, - userId + userId, + handleTeamLeavesUpdate, + handleTeamTimesheetsUpdate }) => { const { t } = useTranslation("home"); const isMobile = useIsMobile(); @@ -56,6 +61,8 @@ export const TimesheetAmendmentModal: React.FC = ({ miscTasks={miscTasks} isSaturdayWorker={isSaturdayWorker} userId={userId} + handleTeamLeavesUpdate={handleTeamLeavesUpdate} + handleTeamTimesheetsUpdate={handleTeamTimesheetsUpdate} /> ); diff --git a/src/components/UserWorkspacePage/UserWorkspacePage.tsx b/src/components/UserWorkspacePage/UserWorkspacePage.tsx index 32d3a25..c61b114 100644 --- a/src/components/UserWorkspacePage/UserWorkspacePage.tsx +++ b/src/components/UserWorkspacePage/UserWorkspacePage.tsx @@ -70,6 +70,9 @@ const UserWorkspacePage: React.FC = ({ isSaturdayWorker, userId }) => { + const [latestTeamTimesheets, setLatestTeamTimesheets] = useState(teamTimesheets) + const [latestTeamLeaves, setLatestTeamLeaves] = useState(teamLeaves) + const [anchorEl, setAnchorEl] = useState(null); const [isTimeLeaveModalVisible, setTimeLeaveModalVisible] = useState(false); @@ -128,6 +131,15 @@ const UserWorkspacePage: React.FC = ({ revalidateCacheAfterAmendment(); }, []); + + const handleTeamTimesheetsUpdate = useCallback((ts: TeamTimeSheets) => { + setLatestTeamTimesheets(() => ts) + }, []) + + const handleTeamLeavesUpdate = useCallback((le: TeamLeaves) => { + setLatestTeamLeaves(() => le) + }, []) + return ( <> = ({ allProjects={allProjects} leaveTypes={leaveTypes} companyHolidays={holidays} - teamLeaves={teamLeaves} - teamTimesheets={teamTimesheets} + teamLeaves={latestTeamLeaves} + handleTeamLeavesUpdate={handleTeamLeavesUpdate} + teamTimesheets={latestTeamTimesheets} + handleTeamTimesheetsUpdate={handleTeamTimesheetsUpdate} open={isTimesheetAmendmentVisible} onClose={handleAmendmentClose} miscTasks={miscTasks}