diff --git a/apps/rest-api/package.json b/apps/rest-api/package.json index 3a497905a..a6a4e103e 100644 --- a/apps/rest-api/package.json +++ b/apps/rest-api/package.json @@ -10,7 +10,7 @@ "dev": "tsup src/* --watch" }, "dependencies": { - "@atj/interviews": "workspace:*" + "@atj/form-service": "workspace:*" }, "devDependencies": { "@types/aws-lambda": "^8.10.109", diff --git a/apps/spotlight/package.json b/apps/spotlight/package.json index 3ead725d5..d15bd2f30 100644 --- a/apps/spotlight/package.json +++ b/apps/spotlight/package.json @@ -12,8 +12,8 @@ "dependencies": { "@astrojs/react": "^3.0.3", "@atj/design": "workspace:*", - "@atj/docassemble": "workspace:*", "@atj/documents": "workspace:*", + "@atj/form-service": "workspace:*", "@atj/forms": "workspace:*", "@atj/interviews": "workspace:*", "astro": "^3.5.4", diff --git a/apps/spotlight/src/components/react/form-builder/document-importer.tsx b/apps/spotlight/src/components/react/form-builder/document-importer.tsx index 01281df13..a0be9de3c 100644 --- a/apps/spotlight/src/components/react/form-builder/document-importer.tsx +++ b/apps/spotlight/src/components/react/form-builder/document-importer.tsx @@ -1,37 +1,22 @@ import React, { PropsWithChildren, useReducer } from 'react'; +import { useNavigate } from 'react-router-dom'; import { - DocumentFieldMap, addDocumentFieldsToForm, getDocumentFieldData, suggestFormDetails, } from '@atj/documents'; +import { + DocumentFieldMap, + Form, + addDocument, + createFormContext, + createPrompt, +} from '@atj/forms'; import { onFileInputChangeGetFile } from '../../../lib/file-input'; import { FormView } from '../form/view'; -import { Form, createFormContext, createPrompt } from '@atj/forms'; -import { saveFormToStorage } from '../../../lib/form-repo'; -import { useNavigate } from 'react-router-dom'; - -type State = { - page: number; - form: Form; - documentFields?: DocumentFieldMap; - previewForm?: Form; -}; -type Action = - | { - type: 'SELECT_PDF'; - data: DocumentFieldMap; - } - | { - type: 'PREVIEW_FORM'; - data: DocumentFieldMap; - } - | { - type: 'GOTO_PAGE'; - page: number; - }; +import { saveFormToStorage } from '@atj/form-service'; export const DocumentImporter = ({ formId, @@ -40,46 +25,7 @@ export const DocumentImporter = ({ formId: string; form: Form; }) => { - const navigate = useNavigate(); - const [state, dispatch] = useReducer( - (state: State, action: Action) => { - if (action.type === 'SELECT_PDF') { - return { - page: 2, - documentFields: action.data, - form: state.form, - }; - } - if (action.type === 'PREVIEW_FORM') { - return { - page: 3, - documentFields: action.data, - form: state.form, - }; - } - if (action.type === 'GOTO_PAGE') { - return { - ...state, - page: action.page, - form: state.form, - }; - } - return state; - }, - { - page: 1, - form: form, - } - ); - - const selectDocumentByUrl = async (url: string) => { - const response = await fetch(url); - const blob = await response.blob(); - const data = new Uint8Array(await blob.arrayBuffer()); - const fieldData = await getDocumentFieldData(data); - const fieldInfo = suggestFormDetails(fieldData); - dispatch({ type: 'SELECT_PDF', data: fieldInfo }); - }; + const { state, actions } = useDocumentImporter(form); const Step: React.FC< PropsWithChildren<{ title: string; step: number; current: number }> @@ -108,7 +54,7 @@ export const DocumentImporter = ({