From 5bc2eb1ba55e3fe783b67d94d4ebec7a7c69340f Mon Sep 17 00:00:00 2001 From: Daniel Naab Date: Wed, 13 Mar 2024 21:12:28 -0500 Subject: [PATCH] Fix issue preventing preview form from displaying updates after save. --- packages/design/src/Form/index.tsx | 13 ++++++++++--- .../design/src/FormManager/FormEdit/Preview.tsx | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/design/src/Form/index.tsx b/packages/design/src/Form/index.tsx index b95919e7..a8c3c968 100644 --- a/packages/design/src/Form/index.tsx +++ b/packages/design/src/Form/index.tsx @@ -1,5 +1,5 @@ import deepEqual from 'deep-equal'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { FormProvider, useForm } from 'react-hook-form'; import { @@ -59,7 +59,7 @@ const usePrompt = ( const prompt = createPrompt(config, result.data, { validate: true }); setPrompt(prompt); }; - return { prompt, updatePrompt }; + return { prompt, setPrompt, updatePrompt }; }; export default function Form({ @@ -76,12 +76,18 @@ export default function Form({ const initialPrompt = createPrompt(context.config, session, { validate: false, }); - const { prompt, updatePrompt } = usePrompt( + const { prompt, setPrompt, updatePrompt } = usePrompt( initialPrompt, context.config, session ); + // So the preview view can update the session, regen the prompt. + // This feels smelly. + useEffect(() => { + setPrompt(initialPrompt); + }, [initialPrompt]); + const formMethods = useForm>({}); /** @@ -91,6 +97,7 @@ export default function Form({ updatePrompt(allFormData); }, [allFormData]); */ + return (
diff --git a/packages/design/src/FormManager/FormEdit/Preview.tsx b/packages/design/src/FormManager/FormEdit/Preview.tsx index e06aac4c..3ee3c8da 100644 --- a/packages/design/src/FormManager/FormEdit/Preview.tsx +++ b/packages/design/src/FormManager/FormEdit/Preview.tsx @@ -24,6 +24,7 @@ export const PreviewForm = () => { uswdsRoot: uiContext.uswdsRoot, }; const disposable = createFormSession(form); // nullSession instead? + return (