"use client"; import Stack from "@mui/material/Stack"; import Box from "@mui/material/Box"; import Card from "@mui/material/Card"; import CardContent from "@mui/material/CardContent"; import Grid from "@mui/material/Grid"; import TextField from "@mui/material/TextField"; import Typography from "@mui/material/Typography"; import { CreateGroupInputs } from "@/app/api/group/actions"; import { Controller, useFormContext } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { useCallback, useEffect, useMemo, useState } from "react"; import { CreateStaffInputs } from "@/app/api/staff/actions"; import { Button, Checkbox, FormControl, InputLabel, ListItemText, MenuItem, Select, } from "@mui/material"; import { comboItem } from "./EditStaff"; import { DatePicker, LocalizationProvider } from "@mui/x-date-pickers"; import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; 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"; interface Props { combos: comboItem; } const StaffInfo: React.FC = ({ combos }) => { const { t, i18n: { language }, } = useTranslation(); const { register, formState: { errors, defaultValues }, control, reset, resetField, setValue, getValues, watch, clearErrors, } = useFormContext(); const employType = [ { id: 1, label: "FT" }, { id: 2, label: "PT" }, ]; const skillIdNameMap = combos.skill.reduce<{ [id: number]: string }>( (acc, skill) => ({ ...acc, [skill.id]: skill.label }), {} ); // Salary Effiective History edit modal related const [salaryEffectiveModelOpen, setSalaaryEffectiveModelOpen] = useState(false); const closeSalaryEffectiveModel = useCallback(() => { setSalaaryEffectiveModelOpen(false); }, []); const openSalaryEffectiveModel = useCallback(() => { setSalaaryEffectiveModelOpen(true); }, []); const onSalaryEffectiveSave = useCallback(async () => { console.log(getValues()) setSalaaryEffectiveModelOpen(false); }, []); const resetStaff = useCallback(() => { console.log(defaultValues); if (defaultValues !== undefined) { resetField("joinDate"); resetField("departDate"); } }, [defaultValues]); useEffect(() => { resetStaff() }, [defaultValues]); const joinDate = watch("joinDate"); const departDate = watch("departDate"); useEffect(() => { if (joinDate) clearErrors("joinDate"); if (departDate) clearErrors("departDate"); }, [joinDate, departDate]); const salaryCols = useMemo( () => [ { field: 'salaryPoint', headerName: 'salaryPoint', flex: 1, editable: true, type: 'singleSelect', valueOptions: combos?.salary.map(item => item.label), // valueOptions: [], // width: 150 }, { field: 'date', headerName: 'date', flex: 1, editable: true, type: 'date', // width: 150 }, ], [combos]) return ( {t("Staff")} {t("Company")} ( )} /> {t("Team")} ( )} /> {t("Department")} ( )} /> {t("Grade")} ( )} /> {t("Skillset")} ( )} /> {t("Current Position")} ( )} /> {t("Salary Point")} ( )} /> {t("Employ Type")} ( )} /> { if (!date) return; setValue("joinDate", date.format(INPUT_DATE_FORMAT)); }} slotProps={{ textField: { // required: true, error: joinDate === "Invalid Date", // value: errors.joinDate?.message, }, }} /> {t("Join Position")} ( )} /> { if (!date) return; setValue("departDate", date.format(INPUT_DATE_FORMAT)); }} slotProps={{ textField: { error: joinDate && departDate ? new Date(joinDate) > new Date(departDate) : false, }, }} /> ); }; export default StaffInfo;