Преглед изворни кода

[Timesheet Amendment] Quick fix for 208

main
cyril.tsui пре 1 месец
родитељ
комит
d4dc80663a
3 измењених фајлова са 48 додато и 4 уклоњено
  1. +24
    -1
      src/components/TimesheetAmendment/TimesheetAmendment.tsx
  2. +8
    -1
      src/components/TimesheetAmendment/TimesheetAmendmentModal.tsx
  3. +16
    -2
      src/components/UserWorkspacePage/UserWorkspacePage.tsx

+ 24
- 1
src/components/TimesheetAmendment/TimesheetAmendment.tsx Прегледај датотеку

@@ -53,6 +53,8 @@ export interface Props {
miscTasks: Task[]; miscTasks: Task[];
isSaturdayWorker: boolean; isSaturdayWorker: boolean;
userId: number; userId: number;
handleTeamTimesheetsUpdate: (ts: TeamTimeSheets) => void;
handleTeamLeavesUpdate: (le: TeamLeaves) => void;
} }


type MemberOption = TeamTimeSheets[0] & TeamLeaves[0] & { id: string }; type MemberOption = TeamTimeSheets[0] & TeamLeaves[0] & { id: string };
@@ -82,7 +84,9 @@ const TimesheetAmendment: React.FC<Props> = ({
leaveTypes, leaveTypes,
miscTasks, miscTasks,
isSaturdayWorker, isSaturdayWorker,
userId
userId,
handleTeamTimesheetsUpdate,
handleTeamLeavesUpdate,
}) => { }) => {
const { t, i18n:{language}} = useTranslation(["home", "common"]); const { t, i18n:{language}} = useTranslation(["home", "common"]);
const locale = language === "zh" ? "zh-tw" : "en"; const locale = language === "zh" ? "zh-tw" : "en";
@@ -412,6 +416,7 @@ const TimesheetAmendment: React.FC<Props> = ({
entry: timeEntry, entry: timeEntry,
recordDate, recordDate,
}); });

setLocalTeamTimesheets((timesheets) => ({ setLocalTeamTimesheets((timesheets) => ({
...timesheets, ...timesheets,
[intStaffId]: { [intStaffId]: {
@@ -419,6 +424,15 @@ const TimesheetAmendment: React.FC<Props> = ({
timeEntries: newMemberTimesheets, timeEntries: newMemberTimesheets,
}, },
})); }));

handleTeamTimesheetsUpdate({
...localTeamTimesheets,
[intStaffId]: {
...localTeamTimesheets[intStaffId],
timeEntries: newMemberTimesheets,
},
});

setEditModalOpen(false); setEditModalOpen(false);
}, },
[checkTotalHoursForDate, selectedStaff.id], [checkTotalHoursForDate, selectedStaff.id],
@@ -440,6 +454,15 @@ const TimesheetAmendment: React.FC<Props> = ({
leaveEntries: newMemberLeaves, leaveEntries: newMemberLeaves,
}, },
})); }));

handleTeamLeavesUpdate({
...localTeamLeaves,
[intStaffId]: {
...localTeamLeaves[intStaffId],
leaveEntries: newMemberLeaves,
},
});

setLeaveEditModalOpen(false); setLeaveEditModalOpen(false);
}, },
[checkTotalHoursForDate, selectedStaff.id], [checkTotalHoursForDate, selectedStaff.id],


+ 8
- 1
src/components/TimesheetAmendment/TimesheetAmendmentModal.tsx Прегледај датотеку

@@ -13,6 +13,7 @@ import { useTranslation } from "react-i18next";
import TimesheetAmendment, { import TimesheetAmendment, {
Props as TimesheetAmendmentProps, Props as TimesheetAmendmentProps,
} from "./TimesheetAmendment"; } from "./TimesheetAmendment";
// import { TeamLeaves, TeamTimeSheets } from "@/app/api/timesheets";


const modalSx: SxProps = { const modalSx: SxProps = {
position: "absolute", position: "absolute",
@@ -28,6 +29,8 @@ interface Props extends TimesheetAmendmentProps {
open: boolean; open: boolean;
onClose: () => void; onClose: () => void;
isSaturdayWorker: boolean; isSaturdayWorker: boolean;
handleTeamLeavesUpdate: (le: any) => void;
handleTeamTimesheetsUpdate: (ts: any) => void;
} }


export const TimesheetAmendmentModal: React.FC<Props> = ({ export const TimesheetAmendmentModal: React.FC<Props> = ({
@@ -40,7 +43,9 @@ export const TimesheetAmendmentModal: React.FC<Props> = ({
allProjects, allProjects,
miscTasks, miscTasks,
isSaturdayWorker, isSaturdayWorker,
userId
userId,
handleTeamLeavesUpdate,
handleTeamTimesheetsUpdate
}) => { }) => {
const { t } = useTranslation("home"); const { t } = useTranslation("home");
const isMobile = useIsMobile(); const isMobile = useIsMobile();
@@ -56,6 +61,8 @@ export const TimesheetAmendmentModal: React.FC<Props> = ({
miscTasks={miscTasks} miscTasks={miscTasks}
isSaturdayWorker={isSaturdayWorker} isSaturdayWorker={isSaturdayWorker}
userId={userId} userId={userId}
handleTeamLeavesUpdate={handleTeamLeavesUpdate}
handleTeamTimesheetsUpdate={handleTeamTimesheetsUpdate}
/> />
); );




+ 16
- 2
src/components/UserWorkspacePage/UserWorkspacePage.tsx Прегледај датотеку

@@ -70,6 +70,9 @@ const UserWorkspacePage: React.FC<Props> = ({
isSaturdayWorker, isSaturdayWorker,
userId userId
}) => { }) => {
const [latestTeamTimesheets, setLatestTeamTimesheets] = useState(teamTimesheets)
const [latestTeamLeaves, setLatestTeamLeaves] = useState(teamLeaves)

const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);


const [isTimeLeaveModalVisible, setTimeLeaveModalVisible] = useState(false); const [isTimeLeaveModalVisible, setTimeLeaveModalVisible] = useState(false);
@@ -128,6 +131,15 @@ const UserWorkspacePage: React.FC<Props> = ({
revalidateCacheAfterAmendment(); revalidateCacheAfterAmendment();
}, []); }, []);



const handleTeamTimesheetsUpdate = useCallback((ts: TeamTimeSheets) => {
setLatestTeamTimesheets(() => ts)
}, [])

const handleTeamLeavesUpdate = useCallback((le: TeamLeaves) => {
setLatestTeamLeaves(() => le)
}, [])

return ( return (
<> <>
<Stack <Stack
@@ -235,8 +247,10 @@ const UserWorkspacePage: React.FC<Props> = ({
allProjects={allProjects} allProjects={allProjects}
leaveTypes={leaveTypes} leaveTypes={leaveTypes}
companyHolidays={holidays} companyHolidays={holidays}
teamLeaves={teamLeaves}
teamTimesheets={teamTimesheets}
teamLeaves={latestTeamLeaves}
handleTeamLeavesUpdate={handleTeamLeavesUpdate}
teamTimesheets={latestTeamTimesheets}
handleTeamTimesheetsUpdate={handleTeamTimesheetsUpdate}
open={isTimesheetAmendmentVisible} open={isTimesheetAmendmentVisible}
onClose={handleAmendmentClose} onClose={handleAmendmentClose}
miscTasks={miscTasks} miscTasks={miscTasks}


Loading…
Откажи
Сачувај