diff options
Diffstat (limited to 'components/ship-vendor-document/new-revision-dialog.tsx')
| -rw-r--r-- | components/ship-vendor-document/new-revision-dialog.tsx | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/components/ship-vendor-document/new-revision-dialog.tsx b/components/ship-vendor-document/new-revision-dialog.tsx index bdbb1bc6..39025fa4 100644 --- a/components/ship-vendor-document/new-revision-dialog.tsx +++ b/components/ship-vendor-document/new-revision-dialog.tsx @@ -248,6 +248,14 @@ export function NewRevisionDialog({ // Serial No μ‘°ν const fetchNextSerialNo = React.useCallback(async () => { console.log('π fetchNextSerialNo called with documentId:', documentId) + + // documentId μ ν¨μ± κ²μ¬ + if (!documentId || documentId === undefined || documentId === null) { + console.warn('β οΈ Invalid documentId, using default serialNo: 1') + setNextSerialNo("1") + return + } + setIsLoadingSerialNo(true) try { const apiUrl = `/api/revisions/max-serial-no?documentId=${documentId}` @@ -267,11 +275,16 @@ export function NewRevisionDialog({ setNextSerialNo(serialNoString) console.log('π nextSerialNo state updated') } else { - console.error('π API call failed with status:', response.status) + const errorData = await response.json().catch(() => ({})) + console.error('π API call failed with status:', response.status, errorData) + // API μ€ν¨ μ κΈ°λ³Έκ° 1 μ¬μ© + console.warn('β οΈ Using default serialNo: 1') + setNextSerialNo("1") } } catch (error) { console.error('β Failed to fetch serial no:', error) // μλ¬ μ κΈ°λ³Έκ° 1 μ¬μ© + console.warn('β οΈ Using default serialNo: 1 due to error') setNextSerialNo("1") } finally { setIsLoadingSerialNo(false) @@ -280,12 +293,15 @@ export function NewRevisionDialog({ // Dialog μ΄λ¦΄ λ Serial No μ‘°ν React.useEffect(() => { - console.log('π― useEffect triggered - open:', open, 'documentId:', documentId) - if (open && documentId) { - console.log('π― Calling fetchNextSerialNo') - fetchNextSerialNo() - } else { - console.log('π― Conditions not met for fetchNextSerialNo') + console.log('π― useEffect triggered - open:', open, 'documentId:', documentId, 'type:', typeof documentId) + if (open) { + if (documentId && typeof documentId === 'number' && documentId > 0) { + console.log('π― Calling fetchNextSerialNo') + fetchNextSerialNo() + } else { + console.warn('π― Invalid documentId, using default serialNo: 1') + setNextSerialNo("1") + } } }, [open, documentId, fetchNextSerialNo]) @@ -475,17 +491,12 @@ export function NewRevisionDialog({ <DialogDescription className="text-sm space-y-1"> <div>Document: {documentTitle}</div> <div className="text-xs text-muted-foreground"> - Drawing Type: {drawingKind} | Serial No: {nextSerialNo} - {isLoadingSerialNo && ( + Drawing Type: {drawingKind} | Serial No: {isLoadingSerialNo ? ( <> - <Loader2 className="inline-block ml-2 h-3 w-3 animate-spin" /> + <Loader2 className="inline-block ml-1 h-3 w-3 animate-spin" /> <span className="ml-1">Loading...</span> </> - )} - {/* λλ²κ·Έμ© μμ νμ */} - <div className="mt-1 text-xs text-orange-600"> - Debug: nextSerialNo={nextSerialNo}, isLoading={isLoadingSerialNo} - </div> + ) : nextSerialNo} </div> </DialogDescription> )} |
