diff --git a/frontend/.changeset/busy-terms-pull.md b/frontend/.changeset/busy-terms-pull.md new file mode 100644 index 0000000..a1b25b3 --- /dev/null +++ b/frontend/.changeset/busy-terms-pull.md @@ -0,0 +1,5 @@ +--- +'pydantic-forms': minor +--- + +Removes some unused functionality. Introduces shouldRegister=true to react-hook-form creation. diff --git a/frontend/packages/pydantic-forms/src/components/zodValidationsPresets.ts b/frontend/packages/pydantic-forms/src/components/zodValidationsPresets.ts index e4f312c..464ea25 100644 --- a/frontend/packages/pydantic-forms/src/components/zodValidationsPresets.ts +++ b/frontend/packages/pydantic-forms/src/components/zodValidationsPresets.ts @@ -18,27 +18,16 @@ export const zodValidationPresets: PydanticFormZodValidationPresets = { let validationRule = z.string().trim(); if (minLength) { - validationRule = validationRule?.min( - minLength, - minLength === 1 - ? 'Moet ingevuld zijn' - : `Dit veld heeft een minimum lengte van ${minLength} karakters`, - ); + validationRule = validationRule?.min(minLength); } if (maxLength) { - validationRule = validationRule?.max( - maxLength, - `Dit veld heeft een maximum lengte van ${maxLength} karakters`, - ); + validationRule = validationRule?.max(maxLength); } if (pattern) { try { - validationRule = validationRule?.regex( - new RegExp(pattern), - `De invoer is niet volgens het juiste formaat: ${pattern}`, - ); + validationRule = validationRule?.regex(new RegExp(pattern)); } catch (error) { console.error( 'Could not parse validation rule regex', diff --git a/frontend/packages/pydantic-forms/src/core/PydanticFormContextProvider.tsx b/frontend/packages/pydantic-forms/src/core/PydanticFormContextProvider.tsx index 66700c1..badaffa 100644 --- a/frontend/packages/pydantic-forms/src/core/PydanticFormContextProvider.tsx +++ b/frontend/packages/pydantic-forms/src/core/PydanticFormContextProvider.tsx @@ -14,7 +14,6 @@ import React, { useState, } from 'react'; import { FieldValues, useForm } from 'react-hook-form'; -import { Subscription } from 'react-hook-form/dist/utils/createSubject'; import _ from 'lodash'; import { z } from 'zod/v4'; @@ -54,7 +53,6 @@ function PydanticFormContextProvider({ successNotice, onSuccess, onCancel, - onChange, children, config, }: PydanticFormInitialContextProps) { @@ -65,7 +63,6 @@ function PydanticFormContextProvider({ customDataProviderCacheKey, formStructureMutator, fieldDetailProvider, - onFieldChangeHandler, resetButtonAlternative, allowUntouchedSubmit, skipSuccessNotice, @@ -81,21 +78,6 @@ function PydanticFormContextProvider({ const formRef = useRef(formKey); - useEffect(() => { - const getLocale = () => { - switch (locale) { - case Locale.enGB: - return z.locales.en(); - case Locale.nlNL: - return z.locales.nl(); - default: - return z.locales.en(); - } - }; - - z.config(getLocale()); - }, [locale]); - const updateHistory = async ( formInput: object, previousSteps: object[], @@ -131,10 +113,7 @@ function PydanticFormContextProvider({ const [isFullFilled, setIsFullFilled] = useState(false); const [isSending, setIsSending] = useState(false); - // TODO: Fix leave confirmation functionality - const [, setSaveToLeavePageInCurrentState] = useState(false); - - // fetch the labels of the form, but can also include the current form values + // fetch the labels of the form, can also contain default values const { data: formLabels, isLoading: isLoadingFormLabels } = useLabelProvider(labelProvider, formKey, formIdKey); @@ -144,20 +123,16 @@ function PydanticFormContextProvider({ customDataProvider, ); - // fetch the form definition using SWR hook const { data: apiResponse, isLoading: isLoadingSchema, error, } = useApiProvider(formKey, formInputData, apiProvider, metaData); - // we cache the form scheme so when there is an error, we still have the form - // the form is not in the error response const [rawSchema, setRawSchema] = useState(); const [hasNext, setHasNext] = useState(false); // extract the JSON schema to a more usable custom schema - const { pydanticFormSchema, isLoading: isParsingSchema } = usePydanticFormParser( rawSchema, @@ -166,12 +141,9 @@ function PydanticFormContextProvider({ formStructureMutator, ); - const rhfRef = useRef>(); - // build validation rules based on custom schema const zodSchema = useGetZodValidator( pydanticFormSchema, - rhfRef.current, componentMatcherExtender, ); @@ -197,42 +169,99 @@ function PydanticFormContextProvider({ mode: 'all', defaultValues: initialData, values: initialData, + shouldUnregister: true, }); + const submitFormFn = useCallback(() => { + setIsSending(true); + const rhfValues = rhf.getValues(); + // Note. If we don't use cloneDeep here we are adding a reference to the rhfValues + // that changes on every change in the form and triggering effects before we want to. + addFormInputData(_.cloneDeep(rhfValues), !!errorDetails); + window.scrollTo(0, 0); + }, [rhf, errorDetails, addFormInputData]); + + const onClientSideError = useCallback( + (data?: FieldValues) => { + // TODO implement save with errors toggle + if (data) { + rhf.clearErrors(); + submitFormFn(); + } + }, + [rhf, submitFormFn], + ); + + const submitForm = rhf.handleSubmit(submitFormFn, onClientSideError); + + const resetForm = useCallback( + (e: React.MouseEvent) => { + e.preventDefault(); + setErrorDetails(undefined); + rhf.reset(); + rhf.trigger(); + }, + [rhf], + ); + + const resetErrorDetails = useCallback(() => { + setErrorDetails(undefined); + }, []); + + const isLoading = + isLoadingFormLabels || + isLoadingSchema || + isParsingSchema || + (customDataProvider ? isLoadingCustomData : false); + + const clearForm = useCallback(() => { + setFormInputData([]); + setIsFullFilled(false); + setRawSchema(undefined); + setHasNext(false); + }, []); + + const PydanticFormContextState = { + // to prevent an issue where the sending state hangs + // we check both the SWR hook state as our manual state + isSending: isSending && isLoadingSchema, + isLoading, + rhf, + pydanticFormSchema, + loadingComponent, + onPrevious: () => goToPreviousStep(rhf?.getValues()), + onCancel, + title, + sendLabel, + isFullFilled, + customDataProvider, + errorDetails, + resetErrorDetails, + successNotice, + submitForm, + resetForm, + cancelButton, + skipSuccessNotice, + allowUntouchedSubmit, + resetButtonAlternative, + config, + formKey, + formIdKey, + clearForm, + formInputData, + hasNext, + initialData, + }; + + /** UseEffects */ useEffect(() => { if (formKey !== formRef.current) { // When the formKey changes we need to reset the form input data setFormInputData([]); setFormInputHistory(new Map()); - rhf?.reset({}); formRef.current = formKey; } - }, [formKey, rhf]); - - rhfRef.current = rhf; - - // Adds watch subscripton on form values - useEffect(() => { - const sub = rhf.watch((values) => { - setSaveToLeavePageInCurrentState(false); - onChange?.(values); - }); - - return () => sub.unsubscribe(); - }, [rhf, onChange]); - - /* TODO: Reimplement - // prevent user from navigating away when there are unsaved changes - const hasUnsavedData = - !saveToLeavePageInCurrentState && - !isFullFilled && - rhf.formState.isDirty; - - useLeavePageConfirm( - hasUnsavedData, - 'Er zijn aanpassingen in het formulier. \nWeet je zeker dat je de pagina wilt verlaten?', - ); - */ + }, [formKey]); // handle successfull submits useEffect(() => { @@ -252,7 +281,6 @@ function PydanticFormContextProvider({ } setFormInputHistory(new Map()); - rhf.reset({}); }, [apiResponse, isFullFilled, onSuccess, rhf, skipSuccessNotice]); // a useeffect for whenever the error response updates @@ -266,7 +294,6 @@ function PydanticFormContextProvider({ // when we receive a new form from JSON, we fully reset the form if (apiResponse?.form && rawSchema !== apiResponse.form) { - rhf.reset({}); setRawSchema(apiResponse.form); if (apiResponse.meta) { setHasNext(!!apiResponse.meta.hasNext); @@ -282,7 +309,6 @@ function PydanticFormContextProvider({ setIsSending(false); // eslint-disable-next-line react-hooks/exhaustive-deps }, [apiResponse]); // Avoid completing the dependencies array here to avoid unwanted resetFormData calls - // a useeffect for filling data whenever formdefinition or labels update useEffect(() => { @@ -309,112 +335,20 @@ function PydanticFormContextProvider({ }); }, [error]); - const submitFormFn = useCallback(() => { - setIsSending(true); - const rhfValues = rhf.getValues(); - // Note. If we don't use cloneDeep here we are adding a reference to the rhfValues - // that changes on every change in the form and triggering effects before we want to. - addFormInputData(_.cloneDeep(rhfValues), !!errorDetails); - window.scrollTo(0, 0); - }, [rhf, errorDetails, addFormInputData]); - - const onClientSideError = useCallback( - (data?: FieldValues) => { - // TODO implement save with errors toggle - if (data) { - rhf.clearErrors(); - submitFormFn(); - } - }, - [rhf, submitFormFn], - ); - - const submitForm = rhf.handleSubmit(submitFormFn, onClientSideError); - - const resetForm = useCallback( - (e: React.MouseEvent) => { - e.preventDefault(); - setErrorDetails(undefined); - rhf.reset(); - rhf.trigger(); - }, - [rhf], - ); - - const resetErrorDetails = useCallback(() => { - setErrorDetails(undefined); - }, []); - - // with this we have the possibility to have listeners for specific fields - // this could be used to trigger validations of related fields, casting changes to elsewhere, etc. useEffect(() => { - let sub: Subscription; - - if (onFieldChangeHandler) { - sub = rhf.watch((value, { name, type }) => { - onFieldChangeHandler( - { - name, - type, - value, - }, - rhf, - ); - }); - } - - return () => { - if (sub) { - return sub.unsubscribe(); + const getLocale = () => { + switch (locale) { + case Locale.enGB: + return z.locales.en(); + case Locale.nlNL: + return z.locales.nl(); + default: + return z.locales.en(); } }; - }, [rhf, onFieldChangeHandler]); - const isLoading = - isLoadingFormLabels || - isLoadingSchema || - isParsingSchema || - (customDataProvider ? isLoadingCustomData : false); - - const clearForm = useCallback(() => { - setFormInputData([]); - setIsFullFilled(false); - setRawSchema(undefined); - setHasNext(false); - }, []); - - const PydanticFormContextState = { - // to prevent an issue where the sending state hangs - // we check both the SWR hook state as our manual state - isSending: isSending && isLoadingSchema, - isLoading, - rhf, - pydanticFormSchema, - loadingComponent, - onPrevious: () => goToPreviousStep(rhf?.getValues()), - onCancel, - title, - sendLabel, - isFullFilled, - customDataProvider, - errorDetails, - resetErrorDetails, - successNotice, - submitForm, - resetForm, - cancelButton, - skipSuccessNotice, - allowUntouchedSubmit, - resetButtonAlternative, - config, - setSaveToLeavePageInCurrentState, - formKey, - formIdKey, - clearForm, - formInputData, - hasNext, - initialData, - }; + z.config(getLocale()); + }, [locale]); return ( diff --git a/frontend/packages/pydantic-forms/src/core/helper.ts b/frontend/packages/pydantic-forms/src/core/helper.ts index 516309c..0d7402d 100644 --- a/frontend/packages/pydantic-forms/src/core/helper.ts +++ b/frontend/packages/pydantic-forms/src/core/helper.ts @@ -477,7 +477,6 @@ export const getMatcher = ( export const getClientSideValidationRule = ( pydanticFormField: PydanticFormField | undefined, - rhf?: ReturnType, componentMatcherExtender?: PydanticFormsContextConfig['componentMatcherExtender'], ): ZodType => { if (!pydanticFormField) return z.unknown(); @@ -486,7 +485,7 @@ export const getClientSideValidationRule = ( const componentMatch = matcher(pydanticFormField); let validationRule = - componentMatch?.validator?.(pydanticFormField, rhf) ?? z.unknown(); + componentMatch?.validator?.(pydanticFormField) ?? z.unknown(); if (!pydanticFormField.required) { validationRule = validationRule.optional(); diff --git a/frontend/packages/pydantic-forms/src/core/hooks/hooks.spec.ts b/frontend/packages/pydantic-forms/src/core/hooks/hooks.spec.ts index 000fc98..ee11862 100644 --- a/frontend/packages/pydantic-forms/src/core/hooks/hooks.spec.ts +++ b/frontend/packages/pydantic-forms/src/core/hooks/hooks.spec.ts @@ -1,5 +1,3 @@ -import { useForm } from 'react-hook-form'; - import { z } from 'zod/v4'; import { jest } from '@jest/globals'; @@ -139,8 +137,6 @@ describe('getZodValidationObject', () => { }; }; - const rhf = useForm(); - const basicMatchers: PydanticComponentMatcher[] = [ { id: 'stringMatcher', @@ -189,7 +185,7 @@ describe('getZodValidationObject', () => { }); it('Returns undefined when no properties are passed', () => { - const zodObject = getZodValidationObject({}, rhf, getMockMatcher()); + const zodObject = getZodValidationObject({}, getMockMatcher()); const expectedZodObject = z.any(); expect(z.toJSONSchema(zodObject)).toEqual( z.toJSONSchema(expectedZodObject), @@ -235,7 +231,6 @@ describe('getZodValidationObject', () => { const schema = getZodValidationObject( properties, - rhf, getMockMatcher(matchers), ); @@ -292,7 +287,6 @@ describe('getZodValidationObject', () => { const schema = getZodValidationObject( properties, - rhf, getMockMatcher(matchers), ); @@ -348,7 +342,6 @@ describe('getZodValidationObject', () => { const schema = getZodValidationObject( properties, - rhf, getMockMatcher(matchers), ); @@ -371,11 +364,7 @@ describe('getZodValidationObject', () => { const properties: Properties = { test: pydanticFormField, }; - const zodObject = getZodValidationObject( - properties, - rhf, - getMockMatcher(), - ); + const zodObject = getZodValidationObject(properties, getMockMatcher()); const expectedZodObject = z.object({ test: z.any() }); expect(z.toJSONSchema(zodObject)).toEqual( @@ -402,7 +391,7 @@ describe('getZodValidationObject', () => { string: pydanticFormStringField, integer: pydanticFormIntegerField, }; - const zodObject = getZodValidationObject(properties, rhf, mockMatcher); + const zodObject = getZodValidationObject(properties, mockMatcher); const expectedZodObject = z.object({ string: z.string(), integer: z.number().int(), @@ -419,7 +408,7 @@ describe('getZodValidationObject', () => { const properties: Properties = { person: personObjectField, }; - const zodObject = getZodValidationObject(properties, rhf, mockMatcher); + const zodObject = getZodValidationObject(properties, mockMatcher); const expectedZodObject = z.object({ person: z.object({ name: z.string(), @@ -499,7 +488,7 @@ describe('getZodValidationObject', () => { person: personObjectField, }; - const zodObject = getZodValidationObject(properties, rhf, mockMatcher); + const zodObject = getZodValidationObject(properties, mockMatcher); const expectedZodObject = z.object({ person: z.object({ name: z.string(), @@ -537,7 +526,7 @@ describe('getZodValidationObject', () => { persons: personsArrayField, }; const mockMatcher = getMockMatcher(basicMatchers); - const zodObject = getZodValidationObject(properties, rhf, mockMatcher); + const zodObject = getZodValidationObject(properties, mockMatcher); const expectedZodObject = z.object({ persons: z.array(z.string()), @@ -579,7 +568,7 @@ describe('getZodValidationObject', () => { persons: personsArrayField, }; const mockMatcher = getMockMatcher(basicMatchers); - const zodObject = getZodValidationObject(properties, rhf, mockMatcher); + const zodObject = getZodValidationObject(properties, mockMatcher); const expectedZodObject = z.object({ persons: z.array( @@ -624,7 +613,7 @@ describe('getZodValidationObject', () => { persons: personsArrayArrayArrayField, }; const mockMatcher = getMockMatcher(basicMatchers); - const zodObject = getZodValidationObject(properties, rhf, mockMatcher); + const zodObject = getZodValidationObject(properties, mockMatcher); const expectedZodObject = z.object({ personsArrayArrayArrayField: z.array(z.array(z.array(z.string()))), @@ -663,7 +652,7 @@ describe('getZodValidationObject', () => { person: personObjectField, }; const mockMatcher = getMockMatcher(basicMatchers); - const zodObject = getZodValidationObject(properties, rhf, mockMatcher); + const zodObject = getZodValidationObject(properties, mockMatcher); const expectedZodObject = z.object({ name: z.string(), @@ -713,7 +702,7 @@ describe('getZodValidationObject', () => { person: personsArrayField, }; const mockMatcher = getMockMatcher(basicMatchers); - const zodObject = getZodValidationObject(properties, rhf, mockMatcher); + const zodObject = getZodValidationObject(properties, mockMatcher); const expectedZodObject = z.object({ name: z.string(), diff --git a/frontend/packages/pydantic-forms/src/core/hooks/useGetZodValidator.tsx b/frontend/packages/pydantic-forms/src/core/hooks/useGetZodValidator.tsx index 60150a2..0e20da1 100644 --- a/frontend/packages/pydantic-forms/src/core/hooks/useGetZodValidator.tsx +++ b/frontend/packages/pydantic-forms/src/core/hooks/useGetZodValidator.tsx @@ -8,7 +8,6 @@ * ZOD react-hook-form: https://github.com/react-hook-form/resolvers?tab=readme-ov-file#zod */ import { useMemo } from 'react'; -import { useForm } from 'react-hook-form'; import { z } from 'zod/v4'; import { ZodAny, ZodArray, ZodObject, ZodType } from 'zod/v4'; @@ -27,13 +26,11 @@ import { export const getZodRule = ( pydanticFormField: PydanticFormField, - rhf: ReturnType, componentMatcherExtender?: PydanticFormsContextConfig['componentMatcherExtender'], ): ZodType | ZodObject | ZodArray => { if (pydanticFormField.type === PydanticFormFieldType.OBJECT) { const objectValidationObject = getZodValidationObject( pydanticFormField.properties || {}, - rhf, componentMatcherExtender, ); return objectValidationObject; @@ -42,7 +39,7 @@ export const getZodRule = ( const arrayItem = pydanticFormField.arrayItem; const arrayItemRule = arrayItem - ? getZodRule(arrayItem, rhf, componentMatcherExtender) + ? getZodRule(arrayItem, componentMatcherExtender) : z.any(); const arrayRule = z .array(arrayItemRule || z.unknown()) @@ -67,7 +64,6 @@ export const getZodRule = ( return getClientSideValidationRule( pydanticFormField, - rhf, componentMatcherExtender, ); }; @@ -80,7 +76,6 @@ export const getZodRule = ( */ export const getZodValidationObject = ( properties: Properties, - rhf: ReturnType, componentMatcherExtender?: PydanticFormsContextConfig['componentMatcherExtender'], ): ZodObject | ZodAny => { const pydanticFormComponents = getPydanticFormComponents( @@ -105,11 +100,7 @@ export const getZodValidationObject = ( return; const id = pydanticFormField.id; - const zodRule = getZodRule( - pydanticFormField, - rhf, - componentMatcherExtender, - ); + const zodRule = getZodRule(pydanticFormField, componentMatcherExtender); validationObject[id] = zodRule ?? z.any(); }); @@ -118,20 +109,18 @@ export const getZodValidationObject = ( export const useGetZodValidator = ( pydanticFormSchema?: PydanticFormSchema, - rhf?: ReturnType, componentMatcherExtender?: PydanticFormsContextConfig['componentMatcherExtender'], ): ZodObject | ZodAny => { return useMemo(() => { - if (!pydanticFormSchema || !rhf) { + if (!pydanticFormSchema) { return z.any(); } // Get all fields ids including the nested ones to generate the correct validation schema const validationObject = getZodValidationObject( pydanticFormSchema.properties, - rhf, componentMatcherExtender, ); return validationObject; - }, [componentMatcherExtender, pydanticFormSchema, rhf]); + }, [componentMatcherExtender, pydanticFormSchema]); }; diff --git a/frontend/packages/pydantic-forms/src/core/translations/en.json b/frontend/packages/pydantic-forms/src/core/translations/en.json deleted file mode 100644 index a953983..0000000 --- a/frontend/packages/pydantic-forms/src/core/translations/en.json +++ /dev/null @@ -1,113 +0,0 @@ -{ - "errors": { - "invalid_type": "Ongeldig type: {{received}}. Type {{expected}} vereist", - "invalid_type_received_undefined": "Moet ingevuld zijn", - "invalid_type_received_null": "Moet ingevuld zijn", - "invalid_literal": "Ongeldige letterlijke waarde, vereist {{expected}}", - "unrecognized_keys": "Onbekende sleutel(s) in object: {{- keys}}", - "invalid_union": "Ongeldige invoer", - "invalid_union_discriminator": "Ongeldige discriminatorwaarde. vereist {{- options}}", - "invalid_enum_value": "Waarde '{{received}}' is ongeldig. Antwoordmogelijkheden zijn: {{- options}}", - "invalid_arguments": "Ongeldige functieargumenten", - "invalid_return_type": "Ongeldig functietype teruggegeven waarde", - "invalid_date": "Ongeldige datum", - "custom": "Ongeldige invoer", - "invalid_intersection_types": "Types konden niet worden samengevoegd", - "not_multiple_of": "Getal moet een veelvoud zijn van {{multipleOf}}", - "not_finite": "Getal moet finiet zijn", - "invalid_string": { - "email": "Ongeldige {{validation}}", - "url": "Ongeldige {{validation}}", - "uuid": "Ongeldige {{validation}}", - "cuid": "Ongeldige {{validation}}", - "regex": "Ongeldig", - "datetime": "Ongeldige {{validation}}", - "startsWith": "Ongeldige invoer: moet beginnen met \"{{startsWith}}\"", - "endsWith": "Ongeldige invoer: moet eindigen met \"{{endsWith}}\"" - }, - "too_small": { - "array": { - "exact": "Array moet precies {{minimum}} element(en) bevatten", - "inclusive": "Array moet minstens {{minimum}} element(en) bevatten", - "not_inclusive": "Array moet meer dan {{minimum}} element(en) bevatten" - }, - "string": { - "exact": "Tekst moet precies {{minimum}} karakter(s) bevatten", - "inclusive": "Tekst moet minstens {{minimum}} karakter(s) bevatten", - "not_inclusive": "Tekst moet meer dan {{minimum}} karakter(s) bevatten" - }, - "number": { - "exact": "Getal moet precies {{minimum}} zijn", - "inclusive": "Getal moet {{minimum}} of groter zijn", - "not_inclusive": "Getal moet groter zijn dan {{minimum}}" - }, - "set": { - "exact": "Ongeldige invoer", - "inclusive": "Ongeldige invoer", - "not_inclusive": "Ongeldige invoer" - }, - "date": { - "exact": "Datum moet precies {{- minimum, datetime}} zijn", - "inclusive": "Datum moet op of later dan {{- minimum, datetime}} zijn", - "not_inclusive": "Datum moet later dan {{- minimum, datetime}} zijn" - } - }, - "too_big": { - "array": { - "exact": "Array moet precies {{maximum}} element(en) bevatten", - "inclusive": "Array mag niet meer dan {{maximum}} element(en) bevatten", - "not_inclusive": "Array moet minder dan {{maximum}} element(en) bevatten" - }, - "string": { - "exact": "Tekst moet precies {{maximum}} karakter(s) bevatten", - "inclusive": "Tekst mag niet meer dan {{maximum}} karakter(s) bevatten", - "not_inclusive": "Tekst moet minder dan {{maximum}} karakter(s) bevatten" - }, - "number": { - "exact": "Getal moet precies {{maximum}} zijn", - "inclusive": "Getal moet {{maximum}} of kleiner zijn", - "not_inclusive": "Getal moet kleiner zijn dan {{maximum}}" - }, - "set": { - "exact": "Ongeldige invoer", - "inclusive": "Ongeldige invoer", - "not_inclusive": "Ongeldige invoer" - }, - "date": { - "exact": "Datum moet precies {{- maximum, datetime}} zijn", - "inclusive": "Datum moet op of eerder dan {{- maximum, datetime}} zijn", - "not_inclusive": "Datum moet eerder dan {{- maximum, datetime}} zijn" - } - } - }, - "validations": { - "email": "e-mail", - "url": "url", - "uuid": "uuid", - "cuid": "cuid", - "regex": "regex", - "datetime": "datumtijd" - }, - "types": { - "function": "functie", - "number": "nummer", - "string": "tekst", - "nan": "nan", - "integer": "geheel getal", - "float": "kommagetal", - "boolean": "boolean", - "date": "datum", - "bigint": "bigint", - "undefined": "ongedefinieerd", - "symbol": "symbool", - "null": "null", - "array": "array", - "object": "object", - "unknown": "onbekend", - "promise": "promise", - "void": "void", - "never": "never", - "map": "map", - "set": "set" - } -} diff --git a/frontend/packages/pydantic-forms/src/core/translations/nl.json b/frontend/packages/pydantic-forms/src/core/translations/nl.json deleted file mode 100644 index 667592f..0000000 --- a/frontend/packages/pydantic-forms/src/core/translations/nl.json +++ /dev/null @@ -1,116 +0,0 @@ -{ - "errors": { - "invalid_type": "Ongeldig type: {{received}}. Type {{expected}} vereist", - "invalid_type_received_undefined": "Moet ingevuld zijn", - "invalid_type_received_null": "Moet ingevuld zijn", - "invalid_literal": "Ongeldige letterlijke waarde, vereist {{expected}}", - "unrecognized_keys": "Onbekende sleutel(s) in object: {{- keys}}", - "invalid_union": "Ongeldige invoer", - "invalid_union_discriminator": "Ongeldige discriminatorwaarde. vereist {{- options}}", - "invalid_enum_value": "Waarde '{{received}}' is ongeldig. Antwoordmogelijkheden zijn: {{- options}}", - "invalid_arguments": "Ongeldige functieargumenten", - "invalid_return_type": "Ongeldig functietype teruggegeven waarde", - "invalid_date": "Ongeldige datum", - "custom": "Ongeldige invoer", - "invalid_intersection_types": "Types konden niet worden samengevoegd", - "not_multiple_of": "Getal moet een veelvoud zijn van {{multipleOf}}", - "not_finite": "Getal moet finiet zijn", - "invalid_string": { - "email": "Ongeldige {{validation}}", - "url": "Ongeldige {{validation}}", - "uuid": "Ongeldige {{validation}}", - "cuid": "Ongeldige {{validation}}", - "regex": "Ongeldig", - "datetime": "Ongeldige {{validation}}", - "startsWith": "Ongeldige invoer: moet beginnen met \"{{startsWith}}\"", - "endsWith": "Ongeldige invoer: moet eindigen met \"{{endsWith}}\"" - }, - "too_small": { - "array": { - "exact": "Array moet precies {{minimum}} element(en) bevatten", - "inclusive": "Array moet minstens {{minimum}} element(en) bevatten", - "not_inclusive": "Array moet meer dan {{minimum}} element(en) bevatten" - }, - "string": { - "exact": "Tekst moet precies {{minimum}} karakter(s) bevatten", - "inclusive": "Tekst moet minstens {{minimum}} karakter(s) bevatten", - "not_inclusive": "Tekst moet meer dan {{minimum}} karakter(s) bevatten" - }, - "number": { - "exact": "Getal moet precies {{minimum}} zijn", - "inclusive": "Getal moet {{minimum}} of groter zijn", - "not_inclusive": "Getal moet groter zijn dan {{minimum}}" - }, - "set": { - "exact": "Ongeldige invoer", - "inclusive": "Ongeldige invoer", - "not_inclusive": "Ongeldige invoer" - }, - "date": { - "exact": "Datum moet precies {{- minimum, datetime}} zijn", - "inclusive": "Datum moet op of later dan {{- minimum, datetime}} zijn", - "not_inclusive": "Datum moet later dan {{- minimum, datetime}} zijn" - } - }, - "too_big": { - "array": { - "exact": "Array moet precies {{maximum}} element(en) bevatten", - "inclusive": "Array mag niet meer dan {{maximum}} element(en) bevatten", - "not_inclusive": "Array moet minder dan {{maximum}} element(en) bevatten" - }, - "string": { - "exact": "Tekst moet precies {{maximum}} karakter(s) bevatten", - "inclusive": "Tekst mag niet meer dan {{maximum}} karakter(s) bevatten", - "not_inclusive": "Tekst moet minder dan {{maximum}} karakter(s) bevatten" - }, - "number": { - "exact": "Getal moet precies {{maximum}} zijn", - "inclusive": "Getal moet {{maximum}} of kleiner zijn", - "not_inclusive": "Getal moet kleiner zijn dan {{maximum}}" - }, - "set": { - "exact": "Ongeldige invoer", - "inclusive": "Ongeldige invoer", - "not_inclusive": "Ongeldige invoer" - }, - "date": { - "exact": "Datum moet precies {{- maximum, datetime}} zijn", - "inclusive": "Datum moet op of eerder dan {{- maximum, datetime}} zijn", - "not_inclusive": "Datum moet eerder dan {{- maximum, datetime}} zijn" - } - } - }, - "validations": { - "email": "e-mail", - "url": "url", - "uuid": "uuid", - "cuid": "cuid", - "regex": "regex", - "datetime": "datumtijd" - }, - "types": { - "function": "functie", - "number": "nummer", - "string": "tekst", - "nan": "nan", - "integer": "geheel getal", - "float": "kommagetal", - "boolean": "boolean", - "date": "datum", - "bigint": "bigint", - "undefined": "ongedefinieerd", - "symbol": "symbool", - "null": "null", - "array": "array", - "object": "object", - "unknown": "onbekend", - "promise": "promise", - "void": "void", - "never": "never", - "map": "map", - "set": "set" - }, - "newTranslations": { - "loading": "Formulier aan het ophalen..." - } -} diff --git a/frontend/packages/pydantic-forms/src/types.ts b/frontend/packages/pydantic-forms/src/types.ts index 59196b9..03b6aa9 100644 --- a/frontend/packages/pydantic-forms/src/types.ts +++ b/frontend/packages/pydantic-forms/src/types.ts @@ -1,5 +1,5 @@ import React from 'react'; -import type { Dispatch, FormEventHandler, SetStateAction } from 'react'; +import type { FormEventHandler } from 'react'; import type { ControllerRenderProps, FieldValues, @@ -53,7 +53,6 @@ export interface PydanticFormContextProps { isFullFilled: boolean; rhf: ReturnType; errorDetails?: PydanticFormValidationErrorDetails; - resetErrorDetails: () => void; pydanticFormSchema?: PydanticFormSchema; title?: string | boolean; sendLabel?: string; @@ -61,20 +60,14 @@ export interface PydanticFormContextProps { onCancel?: () => void; cancelButton?: React.ReactNode; resetButtonAlternative?: React.ReactNode; - disableSaveProgress?: boolean; submitForm: FormEventHandler; resetForm: (e: React.MouseEvent) => void; successNotice?: React.ReactNode; loadingComponent?: React.ReactNode; allowUntouchedSubmit?: boolean; skipSuccessNotice?: boolean; - footerCtaPrimaryVariant?: string; - setSaveToLeavePageInCurrentState: Dispatch>; - hasCardWrapper?: boolean; config?: PydanticFormsContextConfig; formKey: string; - formIdKey?: string; - clearForm: () => void; hasNext: boolean; formInputData: object[]; initialData: FieldValues; @@ -244,7 +237,6 @@ export interface PydanticFormInputFieldProps { } export type PydanticFormZodValidationFn = ( field: PydanticFormField, - rhf?: ReturnType, ) => z.ZodTypeAny; export type RowRenderComponent = React.JSXElementConstructor<{