Skip to content

Commit

Permalink
Fix issue preventing preview form from displaying updates after save.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnaab committed Mar 14, 2024
1 parent 30c9386 commit 5bc2eb1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/design/src/Form/index.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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({
Expand All @@ -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<Record<string, string>>({});

/**
Expand All @@ -91,6 +97,7 @@ export default function Form({
updatePrompt(allFormData);
}, [allFormData]);
*/

return (
<FormProvider {...formMethods}>
<div className="preview">
Expand Down
1 change: 1 addition & 0 deletions packages/design/src/FormManager/FormEdit/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const PreviewForm = () => {
uswdsRoot: uiContext.uswdsRoot,
};
const disposable = createFormSession(form); // nullSession instead?

return (
<Form
isPreview={true}
Expand Down

0 comments on commit 5bc2eb1

Please sign in to comment.