diff --git a/src/components/form/fields/DescriptionField.tsx b/src/components/form/fields/DescriptionField.tsx index 98d5a693..629ad075 100644 --- a/src/components/form/fields/DescriptionField.tsx +++ b/src/components/form/fields/DescriptionField.tsx @@ -1,46 +1,8 @@ import i18n from '@dhis2/d2-i18n' import { TextAreaFieldFF } from '@dhis2/ui' -import React, { useMemo } from 'react' -import { Field as FieldRFF, useField } from 'react-final-form' -import { useParams } from 'react-router-dom' -import { - composeAsyncValidators, - required, - useCheckMaxLengthFromSchema, - useIsFieldValueUnique, - SchemaSection, -} from '../../../lib' - -function useValidator({ - schemaSection, - fieldName, -}: { - schemaSection: SchemaSection - fieldName: string -}) { - const params = useParams() - const modelId = params.id as string - const checkIsValueTaken = useIsFieldValueUnique({ - model: schemaSection.namePlural, - field: fieldName, - id: modelId, - }) - - const checkMaxLength = useCheckMaxLengthFromSchema( - schemaSection.name, - fieldName - ) - - return useMemo( - () => - composeAsyncValidators([ - checkIsValueTaken, - checkMaxLength, - required, - ]), - [checkIsValueTaken, checkMaxLength] - ) -} +import React from 'react' +import { Field as FieldRFF } from 'react-final-form' +import { SchemaSection, useCheckMaxLengthFromSchema } from '../../../lib' export function DescriptionField({ helpText, @@ -49,27 +11,20 @@ export function DescriptionField({ helpText?: string schemaSection: SchemaSection }) { - const validator = useValidator({ schemaSection, fieldName: 'description' }) - const { meta } = useField('description', { - subscription: { validating: true }, - }) - - const helpString = - helpText || - i18n.t('A description should be clear and provide necessary details.') + const validate = useCheckMaxLengthFromSchema( + schemaSection.name, + 'description' + ) return ( - - loading={meta.validating} + validator(description)} + label={i18n.t('Description')} + helpText={helpText} + validate={validate} validateFields={[]} /> )