"use client"; import React, { useCallback, useState } from "react"; import { useTranslation } from "react-i18next"; import Button from "@mui/material/Button"; import Stack from "@mui/material/Stack"; import { CalendarMonth, EditCalendar, Luggage, MoreTime, } from "@mui/icons-material"; import { Menu, MenuItem, SxProps, Typography } from "@mui/material"; import AssignedProjects from "./AssignedProjects"; import TimesheetModal from "../TimesheetModal"; import { AssignedProject, ProjectWithTasks } from "@/app/api/projects"; import { RecordLeaveInput, RecordTimesheetInput, revalidateCacheAfterAmendment, } from "@/app/api/timesheets/actions"; import LeaveModal from "../LeaveModal"; import { LeaveType, TeamTimeSheets } from "@/app/api/timesheets"; import { CalendarIcon } from "@mui/x-date-pickers"; import PastEntryCalendarModal from "../PastEntryCalendar/PastEntryCalendarModal"; import { HolidaysResult } from "@/app/api/holidays"; import { TimesheetAmendmentModal } from "../TimesheetAmendment/TimesheetAmendmentModal"; export interface Props { leaveTypes: LeaveType[]; allProjects: ProjectWithTasks[]; assignedProjects: AssignedProject[]; username: string; defaultLeaveRecords: RecordLeaveInput; defaultTimesheets: RecordTimesheetInput; holidays: HolidaysResult[]; teamTimesheets: TeamTimeSheets; fastEntryEnabled?: boolean; } const menuItemSx: SxProps = { gap: 1, color: "neutral.700", }; const UserWorkspacePage: React.FC = ({ leaveTypes, allProjects, assignedProjects, username, defaultLeaveRecords, defaultTimesheets, holidays, teamTimesheets, fastEntryEnabled, }) => { const [anchorEl, setAnchorEl] = useState(null); const [isTimeheetModalVisible, setTimeheetModalVisible] = useState(false); const [isLeaveModalVisible, setLeaveModalVisible] = useState(false); const [isPastEventModalVisible, setPastEventModalVisible] = useState(false); const [isTimesheetAmendmentVisible, setisTimesheetAmendmentVisible] = useState(false); const { t } = useTranslation("home"); const showTimesheetAmendment = Object.keys(teamTimesheets).length > 0; const handleOpenActionMenu = useCallback< React.MouseEventHandler >((event) => { setAnchorEl(event.currentTarget); }, []); const handleCloseActionMenu = useCallback(() => { setAnchorEl(null); }, []); const handleAddTimesheetButtonClick = useCallback(() => { setAnchorEl(null); setTimeheetModalVisible(true); }, []); const handleCloseTimesheetModal = useCallback(() => { setTimeheetModalVisible(false); }, []); const handleAddLeaveButtonClick = useCallback(() => { setAnchorEl(null); setLeaveModalVisible(true); }, []); const handleCloseLeaveModal = useCallback(() => { setLeaveModalVisible(false); }, []); const handlePastEventClick = useCallback(() => { setAnchorEl(null); setPastEventModalVisible(true); }, []); const handlePastEventClose = useCallback(() => { setPastEventModalVisible(false); }, []); const handleAmendmentClick = useCallback(() => { setAnchorEl(null); setisTimesheetAmendmentVisible(true); }, []); const handleAmendmentClose = useCallback(() => { setisTimesheetAmendmentVisible(false); revalidateCacheAfterAmendment(); }, []); return ( <> {t("User Workspace")} {t("Enter Time")} {t("Record Leave")} {t("View Past Entries")} {showTimesheetAmendment && ( {t("Timesheet Amendment")} )} {assignedProjects.length > 0 ? ( ) : ( {t("You have no assigned projects!")} )} {showTimesheetAmendment && ( )} ); }; export default UserWorkspacePage;