From 79b0ce39613d986657c6c51596d96fea8ff86835 Mon Sep 17 00:00:00 2001 From: Daniel Naab Date: Fri, 12 Jan 2024 11:54:05 -0600 Subject: [PATCH] Link document importer from edit form page. --- .../react/experiments/interview-form.tsx | 4 ++-- .../react/form-builder/document-importer.tsx | 5 ++--- .../spotlight/src/components/react/form/edit.tsx | 13 +++++-------- .../components/react/form/import-document.tsx | 16 ++++++++++++++++ .../src/components/react/form/index.tsx | 11 +++++++++++ packages/documents/src/index.ts | 2 +- packages/interviews/src/index.ts | 2 ++ 7 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 apps/spotlight/src/components/react/form/import-document.tsx diff --git a/apps/spotlight/src/components/react/experiments/interview-form.tsx b/apps/spotlight/src/components/react/experiments/interview-form.tsx index 724e8d3b9..de4ce55d9 100644 --- a/apps/spotlight/src/components/react/experiments/interview-form.tsx +++ b/apps/spotlight/src/components/react/experiments/interview-form.tsx @@ -5,8 +5,8 @@ import { createInterviewContext, nextContext, } from '@atj/interviews'; -import { Field } from '@atj/interviews/src/prompt'; -import { BooleanFact, TextFact } from '@atj/interviews/src/fact'; +import { Field } from '@atj/interviews'; +import { BooleanFact, TextFact } from '@atj/interviews'; const form = { action: 'https://yaawr84uu7.execute-api.us-east-2.amazonaws.com', 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 7eb04e47e..821f936e7 100644 --- a/apps/spotlight/src/components/react/form-builder/document-importer.tsx +++ b/apps/spotlight/src/components/react/form-builder/document-importer.tsx @@ -1,11 +1,10 @@ import React, { PropsWithChildren, useReducer } from 'react'; import { extractFormFieldData, suggestFormDetails } from '@atj/documents'; -import { SuggestedForm, UD105_TEST_DATA } from '@atj/documents/src/suggestions'; +import { SuggestedForm, UD105_TEST_DATA } from '@atj/documents'; import { onFileInputChangeGetFile } from '../../../lib/file-input'; import { FormView } from '../form/view'; -import { EditFieldset } from '../form/edit'; type State = { page: number; suggestedForm?: SuggestedForm }; type Action = @@ -145,7 +144,7 @@ export const DocumentImporter = () => { }); }} > - + {/**/} ); diff --git a/apps/spotlight/src/components/react/form/edit.tsx b/apps/spotlight/src/components/react/form/edit.tsx index 91f50b087..66fd5b1df 100644 --- a/apps/spotlight/src/components/react/form/edit.tsx +++ b/apps/spotlight/src/components/react/form/edit.tsx @@ -2,13 +2,7 @@ import React from 'react'; import { useForm } from 'react-hook-form'; import { Link } from 'react-router-dom'; -import { - Form, - Question, - addQuestions, - createForm, - getFlatFieldList, -} from '@atj/forms'; +import { Form, addQuestions, createForm, getFlatFieldList } from '@atj/forms'; import { getFormFromStorage, saveFormToStorage } from '../../../lib/form-repo'; export const FormEdit = ({ formId }: { formId: string }) => { @@ -48,7 +42,10 @@ export const FormEdit = ({ formId }: { formId: string }) => {
  • - View form + Preview this form +
  • +
  • + Import document
  • View all forms diff --git a/apps/spotlight/src/components/react/form/import-document.tsx b/apps/spotlight/src/components/react/form/import-document.tsx new file mode 100644 index 000000000..831d7ad49 --- /dev/null +++ b/apps/spotlight/src/components/react/form/import-document.tsx @@ -0,0 +1,16 @@ +import React from 'react'; +import { getFormFromStorage } from '../../../lib/form-repo'; +import { createFormContext, createPrompt } from '@atj/forms'; +import { DocumentImporter } from '../form-builder/document-importer'; + +export const FormDocumentImport = ({ formId }: { formId: string }) => { + // Fallback to hardcoded data if a magic ID is chosen. + const form = getFormFromStorage(window.localStorage, formId); + if (!form) { + return 'null form retrieved from storage'; + } + const context = createFormContext(form); + const prompt = createPrompt(context); + + return ; +}; diff --git a/apps/spotlight/src/components/react/form/index.tsx b/apps/spotlight/src/components/react/form/index.tsx index d5d6ac38a..4b78105a9 100644 --- a/apps/spotlight/src/components/react/form/index.tsx +++ b/apps/spotlight/src/components/react/form/index.tsx @@ -5,6 +5,7 @@ import { FormDelete } from './delete'; import { FormEdit } from './edit'; import { FormList } from './list'; import { FormViewById } from './view'; +import { FormDocumentImport } from './import-document'; export const FormSection = () => { return ( @@ -41,6 +42,16 @@ export const FormSection = () => { return ; }} /> + { + const { formId } = useParams(); + if (formId === undefined) { + return
    formId is undefined
    ; + } + return ; + }} + /> ); diff --git a/packages/documents/src/index.ts b/packages/documents/src/index.ts index 07fd16686..deb22a6cc 100644 --- a/packages/documents/src/index.ts +++ b/packages/documents/src/index.ts @@ -1,2 +1,2 @@ export * from './pdf'; -export { suggestFormDetails } from './suggestions'; +export * from './suggestions'; diff --git a/packages/interviews/src/index.ts b/packages/interviews/src/index.ts index aaf58eb40..f9659b893 100644 --- a/packages/interviews/src/index.ts +++ b/packages/interviews/src/index.ts @@ -1,5 +1,7 @@ +export * from './fact'; export { type Interview } from './interview'; export { createInterviewContext, nextContext } from './interview-context'; +export * from './prompt'; export { createSequentialInterview, type SequentialInterview,