diff --git a/apps/backoffice-v2/src/lib/blocks/components/EditableDetails/EditableDetails.tsx b/apps/backoffice-v2/src/lib/blocks/components/EditableDetails/EditableDetails.tsx index afc153780f..b29cfdf8f0 100644 --- a/apps/backoffice-v2/src/lib/blocks/components/EditableDetails/EditableDetails.tsx +++ b/apps/backoffice-v2/src/lib/blocks/components/EditableDetails/EditableDetails.tsx @@ -8,6 +8,7 @@ import { useCallback, useEffect, useState, + useMemo, } from 'react'; import { SubmitHandler, useForm } from 'react-hook-form'; import { toTitleCase } from 'string-ts'; @@ -125,13 +126,16 @@ export const EditableDetails: FunctionComponent = ({ return isDecisionComponent && !!value && NEGATIVE_VALUE_INDICATOR.includes(value.toLowerCase()); }; - const defaultValues = data?.reduce((acc, curr) => { - acc[curr.title] = curr.value; + const formValues = useMemo(() => { + return data?.reduce((acc, curr) => { + acc[curr.title] = curr.value; + + return acc; + }, {}); + }, [data]); - return acc; - }, {}); const form = useForm({ - defaultValues, + values: formValues, }); const { mutate: mutateUpdateWorkflowById } = useUpdateDocumentByIdMutation({ directorId, @@ -249,11 +253,6 @@ export const EditableDetails: FunctionComponent = ({ data, }); - // Ensures that the form is reset when the data changes from other instances of `useUpdateWorkflowByIdMutation` i.e. in `useCaseCallToActionLogic`. - useEffect(() => { - form.reset(defaultValues); - }, [form.reset, data]); - return (
@@ -281,7 +280,9 @@ export const EditableDetails: FunctionComponent = ({ const originalValue = form.watch(title); const displayValue = (value: unknown) => { - if (isEditable) return originalValue; + if (isEditable) { + return originalValue; + } return isNullish(value) || value === '' ? 'N/A' : value; }; @@ -299,7 +300,9 @@ export const EditableDetails: FunctionComponent = ({ control={form.control} name={title} render={({ field }) => { - if (isDecisionComponent && !value) return null; + if (isDecisionComponent && !value) { + return null; + } const isInput = [ !checkIsUrl(value) || isEditable,