diff --git a/frontend/src/features/admin-form/assistance/mutations.ts b/frontend/src/features/admin-form/assistance/mutations.ts index 4170eb2b7c..0e24ee1cb8 100644 --- a/frontend/src/features/admin-form/assistance/mutations.ts +++ b/frontend/src/features/admin-form/assistance/mutations.ts @@ -54,6 +54,9 @@ export const useAssistanceMutations = () => { onSuccess: () => { queryClient.invalidateQueries(adminFormKeys.id(formId)) }, + onError: (error) => { + console.error(error) + }, }) }), { @@ -66,12 +69,19 @@ export const useAssistanceMutations = () => { 'Too many forms created! Please try creating again later.' break default: - errorMessage = 'An error occured. Please try again.' + errorMessage = + 'Sorry, we are unable to generate a form with your prompt. Please try another prompt or manually create form fields.' } toast({ description: `${errorMessage}`, status: 'danger', }) + } else { + toast({ + description: + 'Sorry, we are unable to generate a form with your prompt. Please try another prompt or manually create form fields.', + status: 'danger', + }) } }, }, diff --git a/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignContent/FormBuilder.tsx b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignContent/FormBuilder.tsx index edb47afa16..8cefc35e7d 100644 --- a/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignContent/FormBuilder.tsx +++ b/frontend/src/features/admin-form/create/builder-and-design/BuilderAndDesignContent/FormBuilder.tsx @@ -1,4 +1,4 @@ -import { createContext, useCallback, useMemo } from 'react' +import { useCallback, useMemo } from 'react' import { Droppable } from 'react-beautiful-dnd' import { Box, @@ -48,12 +48,6 @@ interface FormBuilderProps extends FlexProps { placeholderProps: DndPlaceholderProps } -type OnCloseContext = { - onClose: () => void -} -export const MagicFormBuilderModalOnCloseContext = - createContext({ onClose: () => undefined }) - export const FormBuilder = ({ placeholderProps, ...props @@ -112,14 +106,10 @@ export const FormBuilder = ({ return ( <> - - - + { [toast], ) + const handleAssistanceError = useCallback( + (error: Error) => { + toast.closeAll() + toast({ + description: + 'Sorry, we are unable to generate a form with your prompt. Please try another prompt or manually create form fields.', + status: 'danger', + }) + }, + [toast], + ) + const insertionIndex = useMemo(() => { if (stateData.state === FieldBuilderState.CreatingField) { return stateData.insertionIndex @@ -119,7 +131,7 @@ export const useCreateFormField = () => { createFormFields({ createFieldsBody, formId }), { onSuccess: handleMultiFieldMutationSuccess, - onError: handleError, + onError: handleAssistanceError, }, ), }