diff --git a/src/app/api/jo/actions.ts b/src/app/api/jo/actions.ts index 217bbc0..07b56e0 100644 --- a/src/app/api/jo/actions.ts +++ b/src/app/api/jo/actions.ts @@ -254,21 +254,31 @@ export const fetchJos = cache(async (data?: SearchJoResultRequest) => { }) export const releaseJo = cache(async (data: CommonActionJoRequest) => { - return serverFetchJson(`${BASE_API_URL}/jo/release`, + const response = serverFetchJson(`${BASE_API_URL}/jo/release`, { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" }, }) + + // Invalidate the cache after releasing + revalidateTag("jo"); + + return response; }) export const startJo = cache(async (data: CommonActionJoRequest) => { - return serverFetchJson(`${BASE_API_URL}/jo/start`, + const response = serverFetchJson(`${BASE_API_URL}/jo/start`, { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" }, }) + + // Invalidate the cache after starting + revalidateTag("jo"); + + return response; }) export const manualCreateJo = cache(async (data: SaveJo) => { diff --git a/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx b/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx index 2e283cd..f940350 100644 --- a/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx +++ b/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx @@ -75,7 +75,7 @@ const PickOrderSearch: React.FC = ({ pickOrders }) => { const currentFgOrder = fgPickOrdersData[0]; const printRequest = { - printerId: 2, + printerId: 1, printQty: 1, isDraft: true, numOfCarton: 0, @@ -141,7 +141,7 @@ const PickOrderSearch: React.FC = ({ pickOrders }) => { const currentFgOrder = fgPickOrdersData[0]; const printRequest = { - printerId: 2, + printerId: 1, printQty: 1, isDraft: false, numOfCarton: numOfCartons, @@ -208,7 +208,7 @@ const PickOrderSearch: React.FC = ({ pickOrders }) => { const currentFgOrder = fgPickOrdersData[0]; const printDNRequest = { - printerId: 2, + printerId: 1, printQty: 1, isDraft: false, numOfCarton: numOfCartons, diff --git a/src/components/JoSave/InfoCard.tsx b/src/components/JoSave/InfoCard.tsx index 2342b5b..56bc9fa 100644 --- a/src/components/JoSave/InfoCard.tsx +++ b/src/components/JoSave/InfoCard.tsx @@ -88,9 +88,7 @@ const InfoCard: React.FC = ({ label={t("Production Priority")} fullWidth disabled={true} - { - ...register("id") - } + value={50} /> diff --git a/src/components/JoSave/JoRelease.tsx b/src/components/JoSave/JoRelease.tsx index 88cfb10..1d9813f 100644 --- a/src/components/JoSave/JoRelease.tsx +++ b/src/components/JoSave/JoRelease.tsx @@ -24,6 +24,12 @@ const JoRelease: React.FC = ({ const { watch } = useFormContext(); + const status = useMemo(() => { + const currentStatus = watch("status").toLowerCase(); + console.log("JoRelease status:", currentStatus, "id:", pickLines[0]?.id); + return currentStatus; + }, [watch("status")]) + useEffect(() => { const fetchInventoryData = async () => { try { @@ -98,6 +104,7 @@ const JoRelease: React.FC = ({ variant="contained" color="primary" onClick={handleRelease} + disabled={stockCounts.insufficient > 0 || status !== "planning"} > {t("Release")} diff --git a/src/components/JoSave/JoSave.tsx b/src/components/JoSave/JoSave.tsx index a627a3f..5f44057 100644 --- a/src/components/JoSave/JoSave.tsx +++ b/src/components/JoSave/JoSave.tsx @@ -32,7 +32,8 @@ const JoSave: React.FC = ({ const scanner = useQrCodeScannerContext() const [serverError, setServerError] = useState(""); - const finalDefaultValues = useMemo(() => { + const finalDefaultValues = useMemo(() => { + console.log("finalDefaultValues recalculated", defaultValues?.status, id); const values = { ...defaultValues, pickLines: defaultValues?.pickLines?.map(line => ({ @@ -47,11 +48,16 @@ const JoSave: React.FC = ({ } return values; - }, [defaultValues]) + }, [defaultValues, id]) const formProps = useForm({ - defaultValues: finalDefaultValues + defaultValues: finalDefaultValues, }) + + useEffect(() => { + formProps.reset(finalDefaultValues); + }, [finalDefaultValues, formProps.reset]) + const pickLines = useMemo(() => { return formProps.watch("pickLines") }, [formProps.watch("pickLines")]) diff --git a/src/components/JoSave/PickTable.tsx b/src/components/JoSave/PickTable.tsx index 5f4dd6e..91237f8 100644 --- a/src/components/JoSave/PickTable.tsx +++ b/src/components/JoSave/PickTable.tsx @@ -65,16 +65,6 @@ const PickTable: React.FC = ({ return 0; }; - const getUomShortDesc = (pickLine: JoDetailPickLine) => { - const inventory = inventoryData.find(inventory => - inventory.itemCode === pickLine.code || inventory.itemName === pickLine.name - ); - - console.log("inventory", inventory) - - return inventory?.uomShortDesc; // || pickLine.uom; - }; - const isStockSufficient = (pickLine: JoDetailPickLine) => { const stockAvailable = getStockAvailable(pickLine); return stockAvailable >= pickLine.reqQty; @@ -180,7 +170,6 @@ const PickTable: React.FC = ({ align: "right", headerAlign: "right", renderCell: (params: GridRenderCellParams) => { - const uomShortDesc = getUomShortDesc(params.row); return `${decimalFormatter.format(params.value)} (${params.row.shortUom})`; }, }, @@ -192,7 +181,6 @@ const PickTable: React.FC = ({ headerAlign: "right", type: "number", renderCell: (params: GridRenderCellParams) => { - const uomShortDesc = getUomShortDesc(params.row); return `${decimalFormatter.format(params.value)} (${params.row.shortUom})`; }, }, diff --git a/src/i18n/zh/pickOrder.json b/src/i18n/zh/pickOrder.json index 6fbdc2d..c80f181 100644 --- a/src/i18n/zh/pickOrder.json +++ b/src/i18n/zh/pickOrder.json @@ -291,7 +291,8 @@ "You need to enter a number": "箱數不能為空", "Number must be at least 1": "箱數最少為一", "Printed Successfully.": "已成功列印", - "Total exceeds required qty":"總數超出所需數量" + "Total exceeds required qty":"總數超出所需數量", + "Enter the number of cartons:": "請輸入總箱數"