diff --git a/src/components/UserWorkspacePage/ProjectGrid.tsx b/src/components/UserWorkspacePage/ProjectGrid.tsx index 9eab16f..dd4dc5c 100644 --- a/src/components/UserWorkspacePage/ProjectGrid.tsx +++ b/src/components/UserWorkspacePage/ProjectGrid.tsx @@ -13,9 +13,10 @@ import { import { useTranslation } from "react-i18next"; import { manhourFormatter } from "@/app/utils/formatUtil"; import { AssignedProject } from "@/app/api/projects"; -import { ViewList, ViewModule } from "@mui/icons-material"; +import { TableRows, ViewModule, TableChart } from "@mui/icons-material"; +import ProjectTable from "./ProjectTable"; -interface Props { +export interface Props { projects: AssignedProject[]; maintainNormalStaffWorkspaceAbility?: boolean; maintainManagementStaffWorkspaceAbility?: boolean; @@ -27,7 +28,7 @@ const ProjectGrid: React.FC = ({ maintainManagementStaffWorkspaceAbility, }) => { const { t } = useTranslation("home"); - const [view, setView] = useState<"grid" | "list">("grid"); + const [view, setView] = useState<"grid" | "list" | "table">("grid"); const handleViewChange = useCallback< NonNullable @@ -53,44 +54,94 @@ const ProjectGrid: React.FC = ({ - + + + + + + - - {projects.map((project, idx) => ( - - - - {project.code} - + ) : ( + + {projects.map((project, idx) => ( + + + - {project.name} - - {/* Spacer */} - - {/* Hours Spent */} - {(Boolean(maintainNormalStaffWorkspaceAbility) || - Boolean(maintainManagementStaffWorkspaceAbility)) && ( - <> - - {t("Hours Spent:")} - + {project.code} + + {project.name} + + {/* Spacer */} + + {/* Hours Spent */} + {(Boolean(maintainNormalStaffWorkspaceAbility) || + Boolean(maintainManagementStaffWorkspaceAbility)) && ( + <> + + {t("Hours Spent:")} + + + {t("Normal")} + + {manhourFormatter.format( + Boolean(maintainManagementStaffWorkspaceAbility) + ? project.hoursSpent + : project.currentStaffHoursSpent, + )} + + + + {t("Others")} + {`${manhourFormatter.format( + Boolean(maintainManagementStaffWorkspaceAbility) + ? project.hoursSpentOther + : project.currentStaffHoursSpentOther, + )}`} + + + )} + {/* Hours Allocated */} + {Boolean(maintainManagementStaffWorkspaceAbility) && ( = ({ alignItems: "baseline", }} > - {t("Normal")} + + {t("Hours Allocated:")} + - {manhourFormatter.format( - Boolean(maintainManagementStaffWorkspaceAbility) - ? project.hoursSpent - : project.currentStaffHoursSpent, - )} + {manhourFormatter.format(project.hoursAllocated)} - - {t("Others")} - {`${manhourFormatter.format( - Boolean(maintainManagementStaffWorkspaceAbility) - ? project.hoursSpentOther - : project.currentStaffHoursSpentOther, - )}`} - - - )} - {/* Hours Allocated */} - {Boolean(maintainManagementStaffWorkspaceAbility) && ( - - - {t("Hours Allocated:")} - - - {manhourFormatter.format(project.hoursAllocated)} - - - )} - - - - ))} - + )} + + + + ))} + + )} ); }; diff --git a/src/components/UserWorkspacePage/ProjectTable.tsx b/src/components/UserWorkspacePage/ProjectTable.tsx new file mode 100644 index 0000000..66ead4f --- /dev/null +++ b/src/components/UserWorkspacePage/ProjectTable.tsx @@ -0,0 +1,106 @@ +import { useTranslation } from "react-i18next"; +import { Props } from "./ProjectGrid"; +import { + Paper, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow, +} from "@mui/material"; +import { useMemo } from "react"; +import { AssignedProject } from "@/app/api/projects"; +import { manhourFormatter } from "@/app/utils/formatUtil"; + +interface Column { + name: keyof AssignedProject; + label: string; +} + +const hourColumns: Array = [ + "currentStaffHoursSpent", + "currentStaffHoursSpentOther", + "hoursAllocated", + "hoursSpent", + "hoursSpentOther", +]; + +const ProjectTable: React.FC = ({ + projects, + maintainManagementStaffWorkspaceAbility, + maintainNormalStaffWorkspaceAbility, +}) => { + const { t } = useTranslation("home"); + const columns = useMemo(() => { + return [ + { name: "code", label: t("Project Code") }, + { name: "name", label: t("Project Name") }, + ...(maintainManagementStaffWorkspaceAbility || + maintainNormalStaffWorkspaceAbility + ? maintainManagementStaffWorkspaceAbility + ? ([ + { name: "hoursSpent", label: t("Total Normal Hours Spent") }, + { name: "hoursSpentOther", label: t("Total Other Hours Spent") }, + { name: "hoursAllocated", label: t("Hours Allocated") }, + ] satisfies Column[]) + : ([ + { + name: "currentStaffHoursSpent", + label: t("Normal Hours Spent"), + }, + { + name: "currentStaffHoursSpentOther", + label: t("Other Hours Spent"), + }, + ] satisfies Column[]) + : []), + ]; + }, [ + maintainManagementStaffWorkspaceAbility, + maintainNormalStaffWorkspaceAbility, + t, + ]); + + return ( + + + + + + {columns.map((column, idx) => ( + + {column.label} + + ))} + + + + {projects.map((project) => { + return ( + + {columns.map((column, idx) => { + const columnName = column.name; + const needsFormatting = hourColumns.includes(columnName); + + return ( + + {needsFormatting + ? manhourFormatter.format( + project[columnName] as number, + ) + : project[columnName]?.toString()} + + ); + })} + + ); + })} + +
+
+
+ ); +}; + +export default ProjectTable;