-
Notifications
You must be signed in to change notification settings - Fork 816
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1470 from mfts/marc/pm-72-migrate-to-trigger-v3-f…
…or-the-document-upload feat: migrate to trigger v3
- Loading branch information
Showing
20 changed files
with
1,207 additions
and
769 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { useEffect } from "react"; | ||
|
||
import useSWRImmutable from "swr/immutable"; | ||
|
||
import { Progress } from "@/components/ui/progress"; | ||
|
||
import { cn, fetcher } from "@/lib/utils"; | ||
import { useDocumentProgressStatus } from "@/lib/utils/use-progress-status"; | ||
|
||
export default function FileProcessStatusBar({ | ||
documentVersionId, | ||
className, | ||
mutateDocument, | ||
onProcessingChange, | ||
}: { | ||
documentVersionId: string; | ||
className?: string; | ||
mutateDocument: () => void; | ||
onProcessingChange?: (processing: boolean) => void; | ||
}) { | ||
const { data } = useSWRImmutable<{ publicAccessToken: string }>( | ||
`/api/progress-token?documentVersionId=${documentVersionId}`, | ||
fetcher, | ||
); | ||
|
||
const { status: progressStatus, error: progressError } = | ||
useDocumentProgressStatus(documentVersionId, data?.publicAccessToken); | ||
|
||
// Update processing state whenever status changes | ||
useEffect(() => { | ||
if (onProcessingChange) { | ||
onProcessingChange( | ||
progressStatus.state === "QUEUED" || | ||
progressStatus.state === "EXECUTING", | ||
); | ||
} | ||
}, [progressStatus.state, onProcessingChange]); | ||
|
||
if (progressStatus.state === "QUEUED") { | ||
return ( | ||
<Progress | ||
value={0} | ||
text="Processing document..." | ||
className={cn( | ||
"w-full rounded-none text-[8px] font-semibold", | ||
className, | ||
)} | ||
/> | ||
); | ||
} | ||
|
||
if ( | ||
progressError || | ||
["FAILED", "CRASHED", "CANCELED", "SYSTEM_FAILURE"].includes( | ||
progressStatus.state, | ||
) | ||
) { | ||
return ( | ||
<Progress | ||
value={0} | ||
text={ | ||
progressError?.message || | ||
progressStatus.text || | ||
"Error processing document" | ||
} | ||
error={true} | ||
className={cn( | ||
"w-full rounded-none text-[8px] font-semibold", | ||
className, | ||
)} | ||
/> | ||
); | ||
} | ||
|
||
if (progressStatus.state === "COMPLETED") { | ||
mutateDocument(); | ||
return null; | ||
} | ||
|
||
return ( | ||
<Progress | ||
value={progressStatus.progress || 0} | ||
text={progressStatus.text || "Processing document..."} | ||
className={cn("w-full rounded-none text-[8px] font-semibold", className)} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.