From 94f5a3127f3a81c2db66a58bfc43a3236a5d2211 Mon Sep 17 00:00:00 2001 From: NatSquared Date: Tue, 24 Sep 2024 15:42:04 -0700 Subject: [PATCH] Address PR comments --- CONTRIBUTING.md | 3 +++ met-web/src/components/common/Typography/Body.tsx | 4 +--- .../admin/create/authoring/AuthoringContext.tsx | 11 ++++++++++- .../admin/create/authoring/AuthoringFeedback.tsx | 3 --- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d475f89cb..b99b62211 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -96,3 +96,6 @@ Examples of when to Request Changes - `FormStep`: A wrapper around a form component that accepts a completion criteria and displays the user's progress. Accepts a `step` prop that is a number (from 1 to 9) that represents the current step in the form. This will be rendered as an icon with a checkmark if the step is complete, and a number if it's the current step or if it's incomplete. - `SystemMessage`: An informational message that can be displayed to the user. Accepts a `type` prop that can be "error", "warning", "info", or "success", which affects the display of the message. - `WidgetPicker`: A modular widget picker component that can be placed anywhere in the engagement editing area. In order to align widgets in the backend with the frontend, a "location" prop is required. Add new locations to the `WidgetLocation` enum. + - `ErrorMessage`: A styled error message that can be displayed to the user. Accepts a `message` prop that is the error message to display. + - `TextInput`: A styled text input that can be used in forms. Accepts a `placeholder` and all other props that a normal MUI TextField would accept. + - `TextField`: A convenience wrapper around `TextInput` that includes a label, requirement decorations, and helper/error text. Error text is internally rendered by `ErrorMessage`. diff --git a/met-web/src/components/common/Typography/Body.tsx b/met-web/src/components/common/Typography/Body.tsx index 248299772..65adf36b4 100644 --- a/met-web/src/components/common/Typography/Body.tsx +++ b/met-web/src/components/common/Typography/Body.tsx @@ -51,9 +51,7 @@ export const BodyText = ({ }; export const ErrorMessage = ({ error }: { error?: string }) => { - if (!error) { - return <>; - } + if (!error) return null; return ( { } }, [fetcher.data]); const pageName = useMatch('/engagements/:engagementId/details/authoring/:page')?.params.page; + // Set the form resolver based on the page name + const resolver = useMemo(() => { + switch (pageName) { + case 'banner': + return yupResolver(authoringTemplateSchema); + default: + return undefined; + } + }, [pageName]); const engagementUpdateForm = useForm({ defaultValues: useMemo(() => defaultValues, [defaultValues]), mode: 'onSubmit', reValidateMode: 'onChange', - resolver: pageName === 'banner' ? yupResolver(authoringTemplateSchema) : undefined, + resolver: resolver, }); const onSubmit = async (data: EngagementUpdateData) => { const savedImageDetails = data.image_file diff --git a/met-web/src/components/engagement/admin/create/authoring/AuthoringFeedback.tsx b/met-web/src/components/engagement/admin/create/authoring/AuthoringFeedback.tsx index f61093cdc..52c04cccd 100644 --- a/met-web/src/components/engagement/admin/create/authoring/AuthoringFeedback.tsx +++ b/met-web/src/components/engagement/admin/create/authoring/AuthoringFeedback.tsx @@ -9,7 +9,6 @@ import { Palette } from 'styles/Theme'; const AuthoringFeedback = () => { const [sectionHeading, setSectionHeading] = useState(''); - // const [bodyText, setBodyText] = useState(''); const [editorState, setEditorState] = useState(); const [surveyButtonText, setSurveyButtonText] = useState(''); const [thirdPartyCtaText, setThirdPartyCtaText] = useState(''); @@ -78,8 +77,6 @@ const AuthoringFeedback = () => { const handleEditorChange = (newEditorState: EditorState) => { setEditorState(newEditorState); - // const plainText = newEditorState.getCurrentContent().getPlainText(); - // setBodyText(plainText); }; const handleWidgetChange = (event: SelectChangeEvent) => {