diff --git a/src/components/PickOrderSearch/QcSelect.tsx b/src/components/PickOrderSearch/QcSelect.tsx index b42732b..57374dc 100644 --- a/src/components/PickOrderSearch/QcSelect.tsx +++ b/src/components/PickOrderSearch/QcSelect.tsx @@ -26,7 +26,7 @@ interface SingleAutocompleteProps extends CommonProps { type Props = SingleAutocompleteProps; const QcSelect: React.FC = ({ allQcs, value, error, onQcSelect }) => { - const { t } = useTranslation("home"); + const { t } = useTranslation("common"); const filteredQc = useMemo(() => { // do filtering here if any return allQcs; diff --git a/src/components/Qc/QcStockInModal.tsx b/src/components/Qc/QcStockInModal.tsx index 62e3b37..2a83c48 100644 --- a/src/components/Qc/QcStockInModal.tsx +++ b/src/components/Qc/QcStockInModal.tsx @@ -88,23 +88,18 @@ const QcStockInModal: React.FC = ({ // const [skipQc, setSkipQc] = useState(false); // const [viewOnly, setViewOnly] = useState(false); - // Select Printer + const printerStorageKey = useMemo( + () => `qcStockInModal_selectedPrinterId_${session?.id ?? "guest"}`, + [session?.id], + ); const getDefaultPrinter = useMemo(() => { - if (typeof window === 'undefined' || printerCombo.length === 0) { - return printerCombo[0]; - } - - const savedPrinterId = localStorage.getItem('qcStockInModal_selectedPrinterId'); - if (savedPrinterId) { - const savedId = Number(savedPrinterId); - const foundPrinter = printerCombo.find(p => p.id === savedId); - if (foundPrinter) { - return foundPrinter; - } - } - - return printerCombo[0]; - }, [printerCombo]); + if (!printerCombo.length) return undefined; + if (typeof window === "undefined") return printerCombo[0]; + + const savedId = sessionStorage.getItem(printerStorageKey); + const matched = savedId ? printerCombo.find(p => p.id === Number(savedId)) : undefined; + return matched ?? printerCombo[0]; + }, [printerCombo, printerStorageKey]); const [selectedPrinter, setSelectedPrinter] = useState(printerCombo[0]); const [printQty, setPrintQty] = useState(1); const [tabIndex, setTabIndex] = useState(0); @@ -474,23 +469,16 @@ const QcStockInModal: React.FC = ({ ); // Print handler useEffect(() => { - if (printerCombo.length > 0) { - const savedPrinterId = typeof window !== 'undefined' - ? localStorage.getItem('qcStockInModal_selectedPrinterId') - : null; - - if (savedPrinterId) { - const savedId = Number(savedPrinterId); - const foundPrinter = printerCombo.find(p => p.id === savedId); - if (foundPrinter) { - setSelectedPrinter(foundPrinter); - return; - } - } - + if (!printerCombo.length) return; + if (typeof window === "undefined") { setSelectedPrinter(printerCombo[0]); + return; } - }, [printerCombo]); + + const savedId = sessionStorage.getItem(printerStorageKey); + const matched = savedId ? printerCombo.find(p => p.id === Number(savedId)) : undefined; + setSelectedPrinter(matched ?? printerCombo[0]); + }, [printerCombo, printerStorageKey]); const [isPrinting, setIsPrinting] = useState(false) const handlePrint = useCallback(async () => { // console.log("Print putaway documents"); @@ -522,7 +510,7 @@ const QcStockInModal: React.FC = ({ console.log(response) } if (typeof window !== 'undefined' && selectedPrinter) { - localStorage.setItem('qcStockInModal_selectedPrinterId', String(selectedPrinter.id)); + sessionStorage.setItem(printerStorageKey, String(selectedPrinter.id)); } } finally { setIsPrinting(() => false) diff --git a/src/components/SearchResults/TempInputGridForMockUp.tsx b/src/components/SearchResults/TempInputGridForMockUp.tsx index 6c0843d..eee74af 100644 --- a/src/components/SearchResults/TempInputGridForMockUp.tsx +++ b/src/components/SearchResults/TempInputGridForMockUp.tsx @@ -439,7 +439,7 @@ function TempInputGridForMockUp({ stockInLine }: Props) { ); } const NoRowsOverlay: React.FC = () => { - const { t } = useTranslation("home"); + const { t } = useTranslation("common"); return (