diff --git a/apps/frontend/src/pages/document-new/document-new.tsx b/apps/frontend/src/pages/document-new/document-new.tsx index a61b08b2..70268c9b 100644 --- a/apps/frontend/src/pages/document-new/document-new.tsx +++ b/apps/frontend/src/pages/document-new/document-new.tsx @@ -463,38 +463,57 @@ const DocumentNew: React.FC = () => { } }, [goToDocument, ingestingDocumentId]); - const handleProcessDocument = useCallback((): void => { - const targetId = createdDocumentIdReference.current ?? resumeDocumentId; + const handleProcessDocument = useCallback( + (values: UploadFormValues): void => { + const targetId = createdDocumentIdReference.current ?? resumeDocumentId; - if (!targetId || isStartingProcessing) { - return; - } + if (!targetId || isStartingProcessing) { + return; + } - const documentId = Number(targetId); + const documentId = Number(targetId); - setRejection(null); - setIsStartingProcessing(true); + setRejection(null); + setIsStartingProcessing(true); - setIngestingDocumentId(documentId); + void (async (): Promise => { + try { + await dispatch( + documentActions.getUploadUrl({ + id: documentId, + payload: { + presetId: values.presetId, + title: values.title, + }, + }), + ).unwrap(); + } catch { + // The error notification is shown by errorHandlingMiddleware. + setIsStartingProcessing(false); + return; + } - void (async (): Promise => { - try { - await dispatch(documentActions.ingest(documentId)).unwrap(); - createdDocumentIdReference.current = null; - } catch (error: unknown) { - setIngestingDocumentId(null); - const message = - error instanceof Error - ? error.message - : ((error as { message?: string }).message ?? - INGESTION_FAILED_MESSAGE); - notification.error(message); - setRejection(message); - } finally { - setIsStartingProcessing(false); - } - })(); - }, [dispatch, isStartingProcessing, resumeDocumentId]); + setIngestingDocumentId(documentId); + + try { + await dispatch(documentActions.ingest(documentId)).unwrap(); + createdDocumentIdReference.current = null; + } catch (error: unknown) { + setIngestingDocumentId(null); + const message = + error instanceof Error + ? error.message + : ((error as { message?: string }).message ?? + INGESTION_FAILED_MESSAGE); + notification.error(message); + setRejection(message); + } finally { + setIsStartingProcessing(false); + } + })(); + }, + [dispatch, isStartingProcessing, resumeDocumentId], + ); const acceptFile = useCallback( (file: File): void => {