From 4a1c28954d360b6969be564406423725cf404280 Mon Sep 17 00:00:00 2001 From: "MSI\\derek" Date: Thu, 29 Aug 2024 15:47:31 +0800 Subject: [PATCH] update staff project history --- src/app/api/staff/index.ts | 17 ++++++ src/components/EditStaff/EditStaff.tsx | 38 +++++++++++-- src/components/EditStaff/EditStaffWrapper.tsx | 9 ++-- src/components/EditStaff/ProjectHistory.tsx | 53 +++++++++++++++++++ src/components/EditStaff/StaffInfo.tsx | 41 ++++++++++++-- .../MailSetting/TimesheetMailDetails.tsx | 4 +- 6 files changed, 149 insertions(+), 13 deletions(-) create mode 100644 src/components/EditStaff/ProjectHistory.tsx diff --git a/src/app/api/staff/index.ts b/src/app/api/staff/index.ts index 41bc922..20fe03c 100644 --- a/src/app/api/staff/index.ts +++ b/src/app/api/staff/index.ts @@ -30,6 +30,17 @@ export type IndivStaff = { data: IndividualStaff } +export type projects = { + id: number, + code: string, + name: string, + status: string +} + +// export type InvolvedProject = { +// records: projects[] +// } + export type IndividualStaff = { id: number staffId: string @@ -110,6 +121,12 @@ export const fetchIndivStaff = cache(async (id: number) => { }); }); +export const fetchStaffInvolvedProjects = cache(async (id: number) => { + return serverFetchJson(`${BASE_API_URL}/staffs/staff-projects/${id}`, { + next: { tags: ["staffs"] }, + }); +}); + export const fetchStaffWithoutTeam = cache(async () => { return serverFetchJson(`${BASE_API_URL}/staffs/noteam`, { next: { tags: ["staffs"] }, diff --git a/src/components/EditStaff/EditStaff.tsx b/src/components/EditStaff/EditStaff.tsx index 709f7a3..9426e1a 100644 --- a/src/components/EditStaff/EditStaff.tsx +++ b/src/components/EditStaff/EditStaff.tsx @@ -11,14 +11,15 @@ import { useForm, } from "react-hook-form"; import { CreateStaffInputs, saveStaff } from "@/app/api/staff/actions"; -import { Button, Stack, Typography } from "@mui/material"; +import { Button, Stack, Tab, Tabs, TabsProps, Typography } from "@mui/material"; // import CreateStaffForm from "../CreateStaffForm"; import { comboProp } from "@/app/api/companys/actions"; // import StaffInfo from "./StaffInfo"; import { Check, Close, RestartAlt } from "@mui/icons-material"; import StaffInfo from "./StaffInfo"; -import { IndividualStaff, SalaryEffectiveInfo } from "@/app/api/staff"; +import { IndividualStaff, projects, SalaryEffectiveInfo } from "@/app/api/staff"; import dayjs from "dayjs"; +import ProjectHistory from "./ProjectHistory"; // import { useGridApiContext } from '@mui/x-data-grid'; export interface comboItem { @@ -35,14 +36,16 @@ interface formProps { Staff: IndividualStaff combos: comboItem; SalaryEffectiveInfo: SalaryEffectiveInfo[]; + InvolvedProject?: projects[] } -const EditStaff: React.FC = ({ Staff, combos, SalaryEffectiveInfo }) => { - // console.log(Staff.joinDate) +const EditStaff: React.FC = ({ Staff, combos, SalaryEffectiveInfo, InvolvedProject }) => { + console.log(InvolvedProject) const defaultSkillset = Staff.skillset.map((s: any) => s.skill.id) const { t } = useTranslation(); const searchParams = useSearchParams() + const [tabIndex, setTabIndex] = useState(0); const id = parseInt(searchParams.get("id") || "0"); const formProps = useForm({ defaultValues: { @@ -190,6 +193,13 @@ const EditStaff: React.FC = ({ Staff, combos, SalaryEffectiveInfo }) return null; } + const handleTabChange = useCallback>( + (_e, newValue) => { + setTabIndex(newValue); + }, + [] + ); + // const resetStaff = useCallback(() => { // window.location.reload() // console.log(dayjs(Staff.joinDate).format(INPUT_DATE_FORMAT)) @@ -258,7 +268,24 @@ const EditStaff: React.FC = ({ Staff, combos, SalaryEffectiveInfo }) {serverError} )} - {Staff && } + + + + + + + {tabIndex == 0 && Staff && } + {tabIndex == 1 && } + {tabIndex == 0 && + } diff --git a/src/components/EditStaff/EditStaffWrapper.tsx b/src/components/EditStaff/EditStaffWrapper.tsx index fc50eb9..cd97c09 100644 --- a/src/components/EditStaff/EditStaffWrapper.tsx +++ b/src/components/EditStaff/EditStaffWrapper.tsx @@ -1,8 +1,7 @@ import React from "react"; import EditStaff, { comboItem } from "./EditStaff"; import EditStaffLoading from "./EditStaffLoading"; -import { StaffResult, fetchIndivStaff, fetchStaff, fetchStaffSalaryEffectiveInfo, fetchTeamLeads, preloadStaff } from "@/app/api/staff"; -import { useSearchParams } from "next/navigation"; +import { fetchIndivStaff, fetchStaffInvolvedProjects, fetchStaffSalaryEffectiveInfo, preloadStaff } from "@/app/api/staff"; import { fetchTeamCombo } from "@/app/api/team/actions"; import { fetchDepartmentCombo } from "@/app/api/departments/actions"; import { fetchPositionCombo } from "@/app/api/positions/actions"; @@ -23,6 +22,7 @@ const EditStaffWrapper: React.FC & SubComponents = async ({ id }) => { preloadStaff() + const [ Staff, CompanyCombo, @@ -33,6 +33,7 @@ const EditStaffWrapper: React.FC & SubComponents = async ({ SkillCombo, SalaryCombo, SalaryEffectiveInfo, + InvolvedProject ] = await Promise.all([ fetchIndivStaff(id), fetchCompanyCombo(), @@ -43,8 +44,10 @@ const EditStaffWrapper: React.FC & SubComponents = async ({ fetchSkillCombo(), fetchSalaryCombo(), fetchStaffSalaryEffectiveInfo(id), + fetchStaffInvolvedProjects(id) ]); + console.log(InvolvedProject) console.log(SalaryCombo.records) const combos: comboItem = { company: CompanyCombo.records, @@ -61,7 +64,7 @@ Staff.data.departDate = Staff.data.departDate && dateArrayToString(Staff.data.de // [{id:0, salaryPoint: 1, date:"2021-05-05"}, {id:1, salaryPoint: 43, date:"2024-05-05"}] console.log(Staff.data) - return ; + return ; }; EditStaffWrapper.Loading = EditStaffLoading; diff --git a/src/components/EditStaff/ProjectHistory.tsx b/src/components/EditStaff/ProjectHistory.tsx new file mode 100644 index 0000000..2014e92 --- /dev/null +++ b/src/components/EditStaff/ProjectHistory.tsx @@ -0,0 +1,53 @@ +import { projects } from "@/app/api/staff"; +import { Box, Card, CardContent, Grid, Stack } from "@mui/material"; +import StyledDataGrid from "../StyledDataGrid"; +import { useMemo } from "react"; +import { useTranslation } from "react-i18next"; + + +interface Props { + InvolvedProject?: projects[] + } + + +const ProjectHistory: React.FC = async ({ InvolvedProject }) => { + const { t } = useTranslation(); + const projectCols = useMemo( + () => [ + { + field: 'code', + headerName: t("Code"), + flex: .4, + }, + { + field: 'name', + headerName: t("Name"), + flex: 1, + }, + ], [InvolvedProject]) + + return ( + + + + + + item.status === "On-going") ?? []} + columns={projectCols} + /> + + + item.status === "Completed") ?? []} + columns={projectCols} + /> + + + + + + ) + +} +export default ProjectHistory; diff --git a/src/components/EditStaff/StaffInfo.tsx b/src/components/EditStaff/StaffInfo.tsx index c77fcb8..3039844 100644 --- a/src/components/EditStaff/StaffInfo.tsx +++ b/src/components/EditStaff/StaffInfo.tsx @@ -16,6 +16,8 @@ import { Checkbox, FormControl, InputLabel, + List, + ListItem, ListItemText, MenuItem, Select, @@ -27,10 +29,11 @@ import { DemoItem } from "@mui/x-date-pickers/internals/demo"; import dayjs from "dayjs"; import { INPUT_DATE_FORMAT } from "@/app/utils/formatUtil"; import SalaryEffectiveModel from "./SalaryEffectiveModel"; -import { SalaryEffectiveInfo } from "@/app/api/staff"; +import { SalaryEffectiveInfo, projects } from "@/app/api/staff"; interface Props { combos: comboItem; + // InvolvedProject?: projects[] } const StaffInfo: React.FC = ({ combos }) => { @@ -411,8 +414,40 @@ const StaffInfo: React.FC = ({ combos }) => { /> + {/* */} + {/* + + {t("on-going")} + + + {InvolvedProject.filter((item: projects) => item.status === "On-going") + .map((item: projects) => ( + + + + )) + } + + + + + {t("completed")} + + + + + + + + */} - + {/* = ({ combos }) => { : t("Please input correct Emergency Contact Phone")) } /> - + */} = ({ isActive }) => { label={t("Required Params")} fullWidth value={"${date}"} - disabled - error={Boolean(errors.template?.template)} + // disabled + // error={Boolean(errors.template?.template)} />