|
|
|
@@ -88,23 +88,18 @@ const QcStockInModal: React.FC<Props> = ({ |
|
|
|
// const [skipQc, setSkipQc] = useState<Boolean>(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<Props> = ({ |
|
|
|
); |
|
|
|
// 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<Props> = ({ |
|
|
|
console.log(response) |
|
|
|
} |
|
|
|
if (typeof window !== 'undefined' && selectedPrinter) { |
|
|
|
localStorage.setItem('qcStockInModal_selectedPrinterId', String(selectedPrinter.id)); |
|
|
|
sessionStorage.setItem(printerStorageKey, String(selectedPrinter.id)); |
|
|
|
} |
|
|
|
} finally { |
|
|
|
setIsPrinting(() => false) |
|
|
|
|