Browse Source

Merge branch 'master' of https://git.2fi-solutions.com/derek/FPSMS-frontend

# Conflicts:
#	src/components/PoDetail/PoDetail.tsx
master
CANCERYS\kw093 2 weeks ago
parent
commit
a0da23f8a7
3 changed files with 43 additions and 15 deletions
  1. +11
    -2
      src/components/PoDetail/PoDetail.tsx
  2. +30
    -11
      src/components/PoDetail/PoInputGrid.tsx
  3. +2
    -2
      src/theme/ThemeRegistry.tsx

+ 11
- 2
src/components/PoDetail/PoDetail.tsx View File

@@ -53,7 +53,7 @@ import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp"; import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp";
import PoInputGrid from "./PoInputGrid"; import PoInputGrid from "./PoInputGrid";
import { QcItemWithChecks } from "@/app/api/qc"; import { QcItemWithChecks } from "@/app/api/qc";
import { useSearchParams } from "next/navigation";
import { useRouter, useSearchParams, usePathname } from "next/navigation";
import { WarehouseResult } from "@/app/api/warehouse"; import { WarehouseResult } from "@/app/api/warehouse";
import { calculateWeight, returnWeightUnit } from "@/app/utils/formatUtil"; import { calculateWeight, returnWeightUnit } from "@/app/utils/formatUtil";
import { CameraContext } from "../Cameras/CameraProvider"; import { CameraContext } from "../Cameras/CameraProvider";
@@ -177,11 +177,14 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => {
const [rows, setRows] = useState<PurchaseOrderLine[]>( const [rows, setRows] = useState<PurchaseOrderLine[]>(
purchaseOrder.pol || [], purchaseOrder.pol || [],
); );
const pathname = usePathname()
const router = useRouter();
const searchParams = useSearchParams();
const [row, setRow] = useState(rows[0]); const [row, setRow] = useState(rows[0]);
const [stockInLine, setStockInLine] = useState(rows[0].stockInLine); const [stockInLine, setStockInLine] = useState(rows[0].stockInLine);
const [processedQty, setProcessedQty] = useState(rows[0].processed); const [processedQty, setProcessedQty] = useState(rows[0].processed);


const searchParams = useSearchParams();
// const [currPoStatus, setCurrPoStatus] = useState(purchaseOrder.status); // const [currPoStatus, setCurrPoStatus] = useState(purchaseOrder.status);




@@ -407,6 +410,12 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => {
); );


const [isOpenScanner, setOpenScanner] = useState(false); const [isOpenScanner, setOpenScanner] = useState(false);
// const testing = useCallback(() => {
// // setOpenScanner(true);
// const newParams = new URLSearchParams(searchParams.toString());
// console.log(pathname)
// }, [pathname, router, searchParams]);

const onOpenScanner = useCallback(() => { const onOpenScanner = useCallback(() => {
setOpenScanner(true); setOpenScanner(true);
}, []); }, []);


+ 30
- 11
src/components/PoDetail/PoInputGrid.tsx View File

@@ -34,7 +34,7 @@ import { QcItemWithChecks } from "src/app/api/qc";
import PlayArrowIcon from "@mui/icons-material/PlayArrow"; import PlayArrowIcon from "@mui/icons-material/PlayArrow";
import { PurchaseOrderLine, StockInLine } from "@/app/api/po"; import { PurchaseOrderLine, StockInLine } from "@/app/api/po";
import { createStockInLine, PurchaseQcResult } from "@/app/api/po/actions"; import { createStockInLine, PurchaseQcResult } from "@/app/api/po/actions";
import { useSearchParams } from "next/navigation";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { import {
returnWeightUnit, returnWeightUnit,
calculateWeight, calculateWeight,
@@ -124,6 +124,10 @@ function PoInputGrid({
const [modalInfo, setModalInfo] = useState< const [modalInfo, setModalInfo] = useState<
StockInLine & { qcResult?: PurchaseQcResult[] } StockInLine & { qcResult?: PurchaseQcResult[] }
>(); >();
const pathname = usePathname()
const router = useRouter();
const searchParams = useSearchParams();

const [qcOpen, setQcOpen] = useState(false); const [qcOpen, setQcOpen] = useState(false);
const [escalOpen, setEscalOpen] = useState(false); const [escalOpen, setEscalOpen] = useState(false);
const [stockInOpen, setStockInOpen] = useState(false); const [stockInOpen, setStockInOpen] = useState(false);
@@ -259,13 +263,29 @@ function PoInputGrid({
); );


const [newOpen, setNewOpen] = useState(false); const [newOpen, setNewOpen] = useState(false);
const closeNewModal = useCallback(() => {
setNewOpen(false);
}, []);
const stockInLineId = searchParams.get("stockInLineId");
const closeNewModal = useCallback(() => {
const newParams = new URLSearchParams(searchParams.toString());
newParams.delete("stockInLineId"); // Remove the parameter
router.replace(`${pathname}?${newParams.toString()}`);
setTimeout(() => {
setNewOpen(false); // Close the modal first
}, 300); // Add a delay to avoid immediate re-trigger of useEffect
}, [searchParams, pathname, router]);

// Open modal
const openNewModal = useCallback(() => { const openNewModal = useCallback(() => {
setNewOpen(true); setNewOpen(true);
}, []); }, []);


// Open modal if `stockInLineId` exists in the URL
useEffect(() => {
if (stockInLineId && !newOpen) {
openNewModal();
}
}, [stockInLineId, newOpen, openNewModal]);

// Button handler to update the URL and open the modal
const handleNewQC = useCallback( const handleNewQC = useCallback(
(id: GridRowId, params: any) => async () => { (id: GridRowId, params: any) => async () => {
setBtnIsLoading(true); setBtnIsLoading(true);
@@ -273,22 +293,21 @@ function PoInputGrid({
...prev, ...prev,
[id]: { mode: GridRowModes.View }, [id]: { mode: GridRowModes.View },
})); }));

const qcResult = await fetchQcDefaultValue(id); const qcResult = await fetchQcDefaultValue(id);
console.log(params.row);
console.log(qcResult);
setModalInfo({ setModalInfo({
...params.row, ...params.row,
qcResult: qcResult, qcResult: qcResult,
}); });
// set default values
setTimeout(() => { setTimeout(() => {
// open qc modal
console.log("delayed");
openNewModal();
const newParams = new URLSearchParams(searchParams.toString());
newParams.set("stockInLineId", id.toString()); // Ensure `set` to avoid duplicates
router.replace(`${pathname}?${newParams.toString()}`);
setBtnIsLoading(false); setBtnIsLoading(false);
}, 200); }, 200);
}, },
[fetchQcDefaultValue, openNewModal],
[fetchQcDefaultValue, searchParams, router, pathname]
); );


const handleEscalation = useCallback( const handleEscalation = useCallback(


+ 2
- 2
src/theme/ThemeRegistry.tsx View File

@@ -17,7 +17,7 @@ const getLocalizationFromLang = (lang: string) => {
// Copied from https://github.com/mui/material-ui/blob/master/examples/material-ui-nextjs-ts/src/components/ThemeRegistry/ThemeRegistry.tsx // Copied from https://github.com/mui/material-ui/blob/master/examples/material-ui-nextjs-ts/src/components/ThemeRegistry/ThemeRegistry.tsx
export default function ThemeRegistry({ export default function ThemeRegistry({
children, children,
lang,
lang = "zh",
}: { }: {
children: React.ReactNode; children: React.ReactNode;
lang: string; lang: string;
@@ -28,7 +28,7 @@ export default function ThemeRegistry({
); );
return ( return (
<NextAppDirEmotionCacheProvider options={{ key: "mui" }}> <NextAppDirEmotionCacheProvider options={{ key: "mui" }}>
<ThemeProvider theme={theme}>
<ThemeProvider theme={themeWithLocale}>
<CssBaseline /> <CssBaseline />
{children} {children}
</ThemeProvider> </ThemeProvider>


Loading…
Cancel
Save