Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions frontend/pages/community/timesheet/my-timesheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,33 @@ import EmployeeTimesheet from "~community/attendance/components/organisms/Employ
import { EmployeeTimesheetModalTypes } from "~community/attendance/enums/timesheetEnums";
import useManualEntryRestriction from "~community/attendance/hooks/useManualEntryRestriction";
import { useAttendanceStore } from "~community/attendance/store/attendanceStore";
import { useAuth } from "~community/auth/providers/AuthProvider";
Comment thread
shakila-kamalasena marked this conversation as resolved.
import ContentLayout from "~community/common/components/templates/ContentLayout/ContentLayout";
import { ButtonStyle } from "~community/common/enums/ComponentEnums";
import { useTranslator } from "~community/common/hooks/useTranslator";

const MyTimeSheet: NextPage = () => {
const translateText = useTranslator("attendanceModule");
const { user } = useAuth();
const {
setIsEmployeeTimesheetModalOpen,
setEmployeeTimesheetModalType,
setDirectManualTimeEntryEligibleEmployee
setDirectManualTimeEntryEligibleEmployee,
setIsSelfDirectTimeEntry
} = useAttendanceStore(
useShallow((state) => ({
setIsEmployeeTimesheetModalOpen: state.setIsEmployeeTimesheetModalOpen,
setEmployeeTimesheetModalType: state.setEmployeeTimesheetModalType,
setDirectManualTimeEntryEligibleEmployee:
state.setDirectManualTimeEntryEligibleEmployee
state.setDirectManualTimeEntryEligibleEmployee,
setIsSelfDirectTimeEntry: state.setIsSelfDirectTimeEntry
}))
);
const { isManualEntryRestricted, isLoading: isRestrictionLoading } =
useManualEntryRestriction();
const {
isManualEntryRestricted,
canDirectlyAddOrEditEntry,
isLoading: isRestrictionLoading
} = useManualEntryRestriction();

return (
<ContentLayout
Expand All @@ -46,7 +53,11 @@ const MyTimeSheet: NextPage = () => {
primaryButtonType={ButtonStyle.PRIMARY}
isPrimaryBtnDisabled={isRestrictionLoading}
onPrimaryButtonClick={() => {
setDirectManualTimeEntryEligibleEmployee(null);
const isEligible = canDirectlyAddOrEditEntry && !!user?.userId;
Comment thread
shakila-kamalasena marked this conversation as resolved.
setDirectManualTimeEntryEligibleEmployee(
Comment thread
shakila-kamalasena marked this conversation as resolved.
isEligible ? { employeeId: user.userId, employeeName: "" } : null
Comment thread
shakila-kamalasena marked this conversation as resolved.
);
setIsSelfDirectTimeEntry(isEligible);
setIsEmployeeTimesheetModalOpen(true);
setEmployeeTimesheetModalType(
EmployeeTimesheetModalTypes.ADD_TIME_ENTRY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ const AddEditTimeEntry = ({ setFromDateTime, setToDateTime }: Props) => {
employeeTimesheetModalType,
currentAddTimeChanges,
setIsEmployeeTimesheetModalOpen,
directManualTimeEntryEligibleEmployee
directManualTimeEntryEligibleEmployee,
isSelfDirectTimeEntry
} = useAttendanceStore((state) => state);

const {
Expand Down Expand Up @@ -351,7 +352,7 @@ const AddEditTimeEntry = ({ setFromDateTime, setToDateTime }: Props) => {

return (
<Form onSubmit={handleSubmit}>
{directManualTimeEntryEligibleEmployee && (
{directManualTimeEntryEligibleEmployee && !isSelfDirectTimeEntry && (
<InputField
label={translateText(["directEntryEmployeeLabel"])}
inputName={"direct_entry_employee"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ const EmployeeTimeRecordsTable = ({
setSelectedDailyRecord,
setDirectManualTimeEntryEligibleEmployee,
setEmployeeTimesheetModalType,
setIsEmployeeTimesheetModalOpen
setIsEmployeeTimesheetModalOpen,
setIsSelfDirectTimeEntry
} = useAttendanceStore(
useShallow((state) => ({
timesheetAnalyticsParams: state.timesheetAnalyticsParams,
Expand All @@ -80,7 +81,8 @@ const EmployeeTimeRecordsTable = ({
setDirectManualTimeEntryEligibleEmployee:
state.setDirectManualTimeEntryEligibleEmployee,
setEmployeeTimesheetModalType: state.setEmployeeTimesheetModalType,
setIsEmployeeTimesheetModalOpen: state.setIsEmployeeTimesheetModalOpen
setIsEmployeeTimesheetModalOpen: state.setIsEmployeeTimesheetModalOpen,
setIsSelfDirectTimeEntry: state.setIsSelfDirectTimeEntry
}))
);

Expand Down Expand Up @@ -156,6 +158,7 @@ const EmployeeTimeRecordsTable = ({
if (modalType === null) return;

setDirectManualTimeEntryEligibleEmployee({ employeeId, employeeName });
setIsSelfDirectTimeEntry(false);
setSelectedDailyRecord(dayRecord);
setEmployeeTimesheetModalType(modalType);
setIsEmployeeTimesheetModalOpen(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DailyLogType } from "~community/attendance/types/timeSheetTypes";
import Icon from "~community/common/components/atoms/Icon/Icon";
import { useTranslator } from "~community/common/hooks/useTranslator";
import { IconName } from "~community/common/types/IconTypes";
import { L1EmployeeType } from "~community/people/types/PeopleTypes";

import TimesheetDailyRecordTable from "../TimesheetDailyRecordTable/TimesheetDailyRecordTable";
import TimesheetStatCard from "../TimesheetStatCard/TimesheetStatCard";
Expand All @@ -14,13 +15,19 @@ interface Props {
dailyLogData: DailyLogType[];
downloadEmployeeDailyLogCsv: () => void;
isDailyLogLoading?: boolean;
targetEmployeeId?: number;
Comment thread
shakila-kamalasena marked this conversation as resolved.
targetEmployeeDetails?: L1EmployeeType;
isSelfTargetEntry?: boolean;
}

const TimesheetDailyLog = ({
workSummaryData,
dailyLogData,
downloadEmployeeDailyLogCsv,
isDailyLogLoading = false
isDailyLogLoading = false,
targetEmployeeId,
targetEmployeeDetails,
isSelfTargetEntry
}: Props): JSX.Element => {
const translateText = useTranslator("attendanceModule", "timesheet");

Expand Down Expand Up @@ -48,6 +55,9 @@ const TimesheetDailyLog = ({
dailyLogData={dailyLogData}
downloadEmployeeDailyLogCsv={downloadEmployeeDailyLogCsv}
isDailyLogLoading={isDailyLogLoading}
targetEmployeeId={targetEmployeeId}
targetEmployeeDetails={targetEmployeeDetails}
isSelfTargetEntry={isSelfTargetEntry}
/>
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useCommonStore } from "~community/common/stores/commonStore";
import { IconName } from "~community/common/types/IconTypes";
import { getTabIndex } from "~community/common/utils/keyboardUtils";
import { useDefaultCapacity } from "~community/configurations/api/timeConfigurationApi";
import { EmployeeDetails } from "~community/people/types/EmployeeTypes";
import { L1EmployeeType } from "~community/people/types/PeopleTypes";

import TimesheetDailyRecordSkeleton from "../AttendanceSkeletons/TimesheetDailyRecordSkeleton";
import TimesheetDailyRecordTableHeader from "../TimesheetDailyRecordTableHeader/TimesheetDailyRecordTableHeader";
Expand All @@ -30,15 +30,17 @@ interface Props {
downloadEmployeeDailyLogCsv?: () => void;
isDailyLogLoading?: boolean;
targetEmployeeId?: number;
targetEmployeeDetails?: EmployeeDetails;
targetEmployeeDetails?: L1EmployeeType;
Comment thread
shakila-kamalasena marked this conversation as resolved.
isSelfTargetEntry?: boolean;
Comment thread
shakila-kamalasena marked this conversation as resolved.
}

const TimesheetDailyRecordTable = ({
dailyLogData,
downloadEmployeeDailyLogCsv,
isDailyLogLoading,
targetEmployeeId,
targetEmployeeDetails
targetEmployeeDetails,
isSelfTargetEntry
}: Props): JSX.Element => {
const { isFreeTier } = useSessionData();
const {
Expand Down Expand Up @@ -149,6 +151,7 @@ const TimesheetDailyRecordTable = ({
targetEmployeeDetails={targetEmployeeDetails}
isRowInteractive={isRowInteractive}
isManualEntryRestricted={isManualEntryRestricted}
isSelfTargetEntry={isSelfTargetEntry}
/>
))
) : (
Expand All @@ -162,6 +165,7 @@ const TimesheetDailyRecordTable = ({
targetEmployeeDetails={targetEmployeeDetails}
isRowInteractive={isRowInteractive}
isManualEntryRestricted={isManualEntryRestricted}
isSelfTargetEntry={isSelfTargetEntry}
/>
))}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface Props {
targetEmployeeDetails?: L1EmployeeType;
isRowInteractive: boolean;
isManualEntryRestricted: boolean;
isSelfTargetEntry?: boolean;
Comment thread
shakila-kamalasena marked this conversation as resolved.
}

const TimesheetDailyRecordTableRow: FC<Props> = ({
Expand All @@ -64,7 +65,8 @@ const TimesheetDailyRecordTableRow: FC<Props> = ({
targetEmployeeId,
targetEmployeeDetails,
isRowInteractive,
isManualEntryRestricted
isManualEntryRestricted,
isSelfTargetEntry = false
}) => {
const { isFreeTier } = useSessionData();

Expand Down Expand Up @@ -93,7 +95,8 @@ const TimesheetDailyRecordTableRow: FC<Props> = ({
setSelectedDailyRecord,
setIsEmployeeTimesheetModalOpen,
setEmployeeTimesheetModalType,
setDirectManualTimeEntryEligibleEmployee
setDirectManualTimeEntryEligibleEmployee,
setIsSelfDirectTimeEntry
} = useAttendanceStore((state) => state);
const status = attendanceParams.slotType;

Expand Down Expand Up @@ -212,11 +215,13 @@ const TimesheetDailyRecordTableRow: FC<Props> = ({
employeeGeneralDetails?.lastName ?? ""
]).trim()
});
setIsSelfDirectTimeEntry(isSelfTargetEntry);
handleEdit();
return;
}

setDirectManualTimeEntryEligibleEmployee(null);
setIsSelfDirectTimeEntry(false);
mutate();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import EmployeeTimesheetRequestTable from "~community/attendance/components/mole
import TimesheetDailyLog from "~community/attendance/components/molecules/TimesheetDailyLog/TimesheetDailyLog";
import TimesheetDailyLogFilter from "~community/attendance/components/molecules/TimesheetDailyLogFilter/TimesheetDailyLogFilter";
import EmployeeTimesheetPopupController from "~community/attendance/components/organisms/EmployeeTimesheetPopupController/EmployeeTimesheetPopupController";
import useManualEntryRestriction from "~community/attendance/hooks/useManualEntryRestriction";
Comment thread
shakila-kamalasena marked this conversation as resolved.
import { downloadEmployeeDailyLogCsv } from "~community/attendance/utils/TimesheetCsvUtil";
import { useAuth } from "~community/auth/providers/AuthProvider";
import { dateValidation } from "~community/common/utils/validation";
Expand All @@ -18,6 +19,7 @@ const EmployeeTimesheet = (): JSX.Element => {
const [startTime, setStartTime] = useState<string>("");
const [endTime, setEndTime] = useState<string>("");
const { user } = useAuth();
const { canDirectlyAddOrEditEntry } = useManualEntryRestriction();

const { data: workSummaryData } = useGetEmployeeWorkSummary(
startTime,
Expand All @@ -34,6 +36,23 @@ const EmployeeTimesheet = (): JSX.Element => {

const { data: timeConfigData } = useDefaultCapacity();

const isSelfDirectEntryEligible = canDirectlyAddOrEditEntry && !!user?.userId;

const selfTargetEmployeeId = isSelfDirectEntryEligible
? user?.userId
: undefined;

const selfTargetEmployeeDetails = isSelfDirectEntryEligible
Comment thread
shakila-kamalasena marked this conversation as resolved.
Comment thread
shakila-kamalasena marked this conversation as resolved.
? {
personal: {
general: {
firstName: user?.employee?.firstName,
lastName: user?.employee?.lastName
}
}
}
: undefined;

return (
<>
<TimesheetDailyLogFilter
Expand All @@ -52,6 +71,9 @@ const EmployeeTimesheet = (): JSX.Element => {
);
}}
isDailyLogLoading={isDailyLogLoading}
targetEmployeeId={selfTargetEmployeeId}
Comment thread
shakila-kamalasena marked this conversation as resolved.
targetEmployeeDetails={selfTargetEmployeeDetails}
Comment thread
shakila-kamalasena marked this conversation as resolved.
isSelfTargetEntry={canDirectlyAddOrEditEntry}
Comment thread
shakila-kamalasena marked this conversation as resolved.
/>
<EmployeeTimesheetRequestTable
requestData={requestData}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ const EmployeeTimesheetPopupController = (): JSX.Element => {
employeeTimesheetModalType,
setIsEmployeeTimesheetModalOpen,
setCurrentAddTimeChanges,
setDirectManualTimeEntryEligibleEmployee
setDirectManualTimeEntryEligibleEmployee,
setIsSelfDirectTimeEntry
} = useAttendanceStore((state) => state);

const [fromDateTime, setFromDateTime] = useState<string>("");
Expand Down Expand Up @@ -63,6 +64,7 @@ const EmployeeTimesheetPopupController = (): JSX.Element => {
if (!isEmployeeTimesheetModalOpen) {
setCurrentAddTimeChanges(undefined);
setDirectManualTimeEntryEligibleEmployee(null);
setIsSelfDirectTimeEntry(false);
}
}, [isEmployeeTimesheetModalOpen]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const employeeTimesheetModalSlice = (
currentAddTimeChanges: {} as CurrentAddTimeChangesType,
employeeTimesheetModalType: EmployeeTimesheetModalTypes.ADD_TIME_ENTRY,
directManualTimeEntryEligibleEmployee: null,
isSelfDirectTimeEntry: false,

setSelectedDailyRecord: (record: DailyLogType) =>
set((state: EmployeeTimesheetModalSliceType) => ({
Expand Down Expand Up @@ -49,5 +50,10 @@ export const employeeTimesheetModalSlice = (
set((state: EmployeeTimesheetModalSliceType) => ({
...state,
directManualTimeEntryEligibleEmployee: value
})),
Comment thread
shakila-kamalasena marked this conversation as resolved.
setIsSelfDirectTimeEntry: (value: boolean) =>
set((state: EmployeeTimesheetModalSliceType) => ({
...state,
isSelfDirectTimeEntry: value
}))
});
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export interface EmployeeTimesheetModalSliceType extends Pick<
| "currentAddTimeChanges"
| "directManualTimeEntryEligibleEmployee"
| "setDirectManualTimeEntryEligibleEmployee"
| "isSelfDirectTimeEntry"
| "setIsSelfDirectTimeEntry"
> {}

export interface EmployeeTimesheetFilterSliceTypes extends Pick<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface actionsTypes {
setDirectManualTimeEntryEligibleEmployee: (
value: DirectEntryEmployeeType | null
) => void;
setIsSelfDirectTimeEntry: (value: boolean) => void;
setClockInType: (type: { [key: string]: (string | number)[] }) => void;
}

Expand Down Expand Up @@ -98,6 +99,7 @@ export interface AttendanceStore extends actionsTypes {
timeAvailabilityForPeriod: TimeAvailabilityType;
currentAddTimeChanges: CurrentAddTimeChangesType;
directManualTimeEntryEligibleEmployee: DirectEntryEmployeeType | null;
isSelfDirectTimeEntry: boolean;
clockInType: {
[key: string]: (string | number)[];
};
Expand Down
Loading