import { JoDetail } from "@/app/api/jo"; import { Box, Button, Stack, Typography } from "@mui/material"; import { useMemo } from "react"; import { useFormContext } from "react-hook-form"; import { useTranslation } from "react-i18next"; import StartIcon from "@mui/icons-material/Start"; import PlayCircleFilledWhiteIcon from '@mui/icons-material/PlayCircleFilledWhite'; type Props = { handleRelease: () => void; handleStart: () => void; }; interface ErrorEntry { qtyErr: boolean; scanErr: boolean; } const ActionButtons: React.FC = ({ handleRelease, handleStart }) => { const { t } = useTranslation("jo"); const { watch } = useFormContext(); const status = useMemo(() => { return watch("status").toLowerCase() }, [watch("status")]) const pickLines = useMemo(() => { return watch("pickLines") }, [watch("pickLines")]) // Check Error Handling (e.g. start jo) const errors: ErrorEntry = useMemo(() => { let qtyErr = false; let scanErr = false; pickLines.forEach((line) => { if (!qtyErr) { const pickedQty = line.pickedLotNo?.reduce((acc, cur) => acc + cur.qty, 0) ?? 0 qtyErr = pickedQty > 0 && pickedQty >= line.reqQty } if (!scanErr) { scanErr = line.pickedLotNo?.some((lotNo) => Boolean(lotNo.isScanned) === false) ?? false // default false } }) return { qtyErr: qtyErr, scanErr: scanErr } }, [pickLines]) return ( {status === "planning" && ( )} {status === "pending" && ( {errors.scanErr && ({t("Please scan the item qr code.")})} {errors.qtyErr && ({t("Please make sure the qty is enough.")})} )} ) } export default ActionButtons;