Skip to content

Commit

Permalink
chore: removing unwanted context from code review and amending error …
Browse files Browse the repository at this point in the history
…toast
  • Loading branch information
kathleenkhy committed May 9, 2024
1 parent a6ef373 commit c0e57c7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
12 changes: 11 additions & 1 deletion frontend/src/features/admin-form/assistance/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export const useAssistanceMutations = () => {
onSuccess: () => {
queryClient.invalidateQueries(adminFormKeys.id(formId))
},
onError: (error) => {
console.error(error)
},
})
}),
{
Expand All @@ -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',
})
}
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useCallback, useMemo } from 'react'
import { useCallback, useMemo } from 'react'
import { Droppable } from 'react-beautiful-dnd'
import {
Box,
Expand Down Expand Up @@ -48,12 +48,6 @@ interface FormBuilderProps extends FlexProps {
placeholderProps: DndPlaceholderProps
}

type OnCloseContext = {
onClose: () => void
}
export const MagicFormBuilderModalOnCloseContext =
createContext<OnCloseContext>({ onClose: () => undefined })

export const FormBuilder = ({
placeholderProps,
...props
Expand Down Expand Up @@ -112,14 +106,10 @@ export const FormBuilder = ({

return (
<>
<MagicFormBuilderModalOnCloseContext.Provider
value={{ onClose: magicFormBuilderModalDisclosure.onClose }}
>
<MagicFormBuilderModal
isOpen={magicFormBuilderModalDisclosure.isOpen}
onClose={magicFormBuilderModalDisclosure.onClose}
/>
</MagicFormBuilderModalOnCloseContext.Provider>
<MagicFormBuilderModal
isOpen={magicFormBuilderModalDisclosure.isOpen}
onClose={magicFormBuilderModalDisclosure.onClose}
/>
<Flex
mb={0}
flex={1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ export const useCreateFormField = () => {
[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
Expand All @@ -119,7 +131,7 @@ export const useCreateFormField = () => {
createFormFields({ createFieldsBody, formId }),
{
onSuccess: handleMultiFieldMutationSuccess,
onError: handleError,
onError: handleAssistanceError,
},
),
}
Expand Down

0 comments on commit c0e57c7

Please sign in to comment.