From 1c8d08359e8f1d2f22e55a1a52711a5d22618427 Mon Sep 17 00:00:00 2001 From: "cyril.tsui" Date: Thu, 28 Aug 2025 17:10:04 +0800 Subject: [PATCH] put away update --- src/components/InputDataGrid/InputDataGrid.tsx | 8 ++++++++ src/components/PoDetail/PutAwayForm.tsx | 7 +++++-- src/components/PoDetail/QcStockInModalVer2.tsx | 14 +++++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/components/InputDataGrid/InputDataGrid.tsx b/src/components/InputDataGrid/InputDataGrid.tsx index 622d7e2..bea6875 100644 --- a/src/components/InputDataGrid/InputDataGrid.tsx +++ b/src/components/InputDataGrid/InputDataGrid.tsx @@ -75,6 +75,7 @@ export interface InputDataGridProps { needAdd?: boolean; showRemoveBtn?: boolean; addRowDefaultValue?: Partial; + _setRowModesModel?: Dispatch>; } export interface SelectionInputDataGridProps { @@ -87,6 +88,7 @@ export interface SelectionInputDataGridProps { needAdd?: boolean; showRemoveBtn?: boolean; addRowDefaultValue?: Partial; + _setRowModesModel?: Dispatch>; } export type Props = @@ -115,6 +117,7 @@ function InputDataGrid({ needAdd, showRemoveBtn = true, addRowDefaultValue = {}, + _setRowModesModel = undefined, }: Props) { const { t, @@ -123,6 +126,11 @@ function InputDataGrid({ const formKey = _formKey.toString(); const { setValue, getValues } = useFormContext(); const [rowModesModel, setRowModesModel] = useState({}); + useEffect(() => { + if (_setRowModesModel) { + _setRowModesModel(rowModesModel) + } + }, [rowModesModel]) // const apiRef = useGridApiRef(); const getRowId = useCallback>>( (row) => row.id! as number, diff --git a/src/components/PoDetail/PutAwayForm.tsx b/src/components/PoDetail/PutAwayForm.tsx index c76452b..1454dc9 100644 --- a/src/components/PoDetail/PutAwayForm.tsx +++ b/src/components/PoDetail/PutAwayForm.tsx @@ -19,7 +19,7 @@ import { import { Controller, useFormContext } from "react-hook-form"; import { useTranslation } from "react-i18next"; import StyledDataGrid from "../StyledDataGrid"; -import { useCallback, useEffect, useMemo, useState } from "react"; +import { Dispatch, SetStateAction, useCallback, useEffect, useMemo, useState } from "react"; import { GridColDef, GridRowIdGetter, @@ -52,6 +52,7 @@ import dayjs from "dayjs"; import arraySupport from "dayjs/plugin/arraySupport"; import { dummyPutAwayLine } from "./dummyQcTemplate"; import { PrinterCombo } from "@/app/api/settings/printer"; +import { GridRowModesModel } from "@mui/x-data-grid"; dayjs.extend(arraySupport); interface Props { @@ -60,6 +61,7 @@ interface Props { disabled: boolean; // qc: QcItemWithChecks[]; printerCombo: PrinterCombo[]; + setRowModesModel: Dispatch>; } type EntryError = | { @@ -81,7 +83,7 @@ const style = { width: "auto", }; -const PutAwayForm: React.FC = ({ itemDetail, warehouse, disabled, printerCombo }) => { +const PutAwayForm: React.FC = ({ itemDetail, warehouse, disabled, printerCombo, setRowModesModel }) => { const { t } = useTranslation("purchaseOrder"); const apiRef = useGridApiRef(); const { @@ -541,6 +543,7 @@ const PutAwayForm: React.FC = ({ itemDetail, warehouse, disabled, printer needAdd={true} showRemoveBtn={false} addRowDefaultValue={addRowDefaultValue} + _setRowModesModel={setRowModesModel} /> diff --git a/src/components/PoDetail/QcStockInModalVer2.tsx b/src/components/PoDetail/QcStockInModalVer2.tsx index 0e042af..69a6fb3 100644 --- a/src/components/PoDetail/QcStockInModalVer2.tsx +++ b/src/components/PoDetail/QcStockInModalVer2.tsx @@ -23,7 +23,7 @@ import QcComponent from "./QcComponent"; import { dummyPutAwayLine, dummyQCData } from "./dummyQcTemplate"; // import QcFormVer2 from "./QcFormVer2"; import PutAwayForm from "./PutAwayForm"; -import { useGridApiRef } from "@mui/x-data-grid"; +import { GridRowModes, useGridApiRef } from "@mui/x-data-grid"; import {submitDialogWithWarning} from "../Swal/CustomAlerts"; import { INPUT_DATE_FORMAT, arrayToDateString, arrayToInputDateString, dayjsToInputDateString } from "@/app/utils/formatUtil"; import dayjs from "dayjs"; @@ -32,6 +32,8 @@ import { downloadFile } from "@/app/utils/commonUtil"; import { PrinterCombo } from "@/app/api/settings/printer"; import { EscalationResult } from "@/app/api/escalation"; import { SessionWithTokens } from "@/config/authConfig"; +import { GridRowModesModel } from "@mui/x-data-grid"; +import { isEmpty } from "lodash"; const style = { @@ -355,6 +357,14 @@ const [qcItems, setQcItems] = useState(dummyQCData) }, [], ); + + // Put away model + const [pafRowModesModel, setPafRowModesModel] = useState({}) + const pafSubmitDisable = useMemo(() => { + // console.log("%c mode: ", "background:#90EE90; color:red", Object.entries(pafRowModesModel)) + // console.log("%c mode: ", "background:pink; color:#87CEEB", Object.entries(pafRowModesModel)) + return Object.entries(pafRowModesModel).length > 0 || Object.entries(pafRowModesModel).some(([key, value], index) => value.mode === GridRowModes.Edit) + }, [pafRowModesModel]) // Putaway submission handler const onSubmitPutaway = useCallback>( async (data, event) => { @@ -480,6 +490,7 @@ const [qcItems, setQcItems] = useState(dummyQCData) itemDetail={itemDetail} warehouse={warehouse!} disabled={viewOnly} + setRowModesModel={setPafRowModesModel} /> {t("confirm putaway")}