UNPKG

@adyen/kyc-components

Version:

This guide assumes that you have already an account with Adyen. A legalEntity needs to be created, and you need to have a `legalEntityId` to instatiate a Component.

99 lines (98 loc) 4.29 kB
try { let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack; n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "d870174f-04a7-4b6d-8723-8ac890acaab1", e._sentryDebugIdIdentifier = "sentry-dbid-d870174f-04a7-4b6d-8723-8ac890acaab1"); } catch (e) {} function getFormProps(props, innerFormId) { if (!innerFormId) return null; const activeFormId = props.activeForm?.formId; const trustedFields = props.trustedFields?.[innerFormId] ?? []; const readOnlyFields = props.readOnlyFields?.[innerFormId] ?? []; return { labels: props.labels?.[innerFormId] ?? {}, masks: props.masks?.[innerFormId] ?? {}, data: props.data?.[innerFormId] ?? {}, allFields: props.allFields?.[innerFormId] ?? [], readOnlyFields: [...readOnlyFields, ...trustedFields], requiredFields: props.requiredFields?.[innerFormId] ?? [], optionalFields: props.optionalFields?.[innerFormId] ?? [], obscuredFields: props.obscuredFields?.[innerFormId] ?? [], verifyFields: props.verifyFields?.[innerFormId] ?? [], trustedFields, trustedFieldsProvider: props.trustedFields, formVerificationErrors: props.problems?.verificationErrors?.[innerFormId] ?? {}, fieldValidationErrors: props.problems?.validationErrors?.[innerFormId] ?? {}, validators: props.validators?.[innerFormId] ? { ...props.validators?.[innerFormId] } : null, shouldValidate: (activeFormId ? activeFormId === innerFormId : true) && props.shouldValidate }; } /** * we want to preserve getFormProps' utility of digging into the data structure without turning * the special fields like requiredFields into arrays, like BaseInnerFormProps. * * @param props * @param innerFormId */ function getNestedOuterFormPropsFromOuterFormProps(props, innerFormId) { const newProps = getFormProps(props, innerFormId); if (newProps === null) return null; const { labels, data, masks } = newProps; const { readOnlyFields, requiredFields, optionalFields, obscuredFields, verifyFields, trustedFields, problems, validators, shouldValidate } = props; return { labels, data, masks, readOnlyFields, requiredFields, optionalFields, obscuredFields, verifyFields, trustedFields, problems, validators, shouldValidate }; } function getFieldProps(props, innerFormFields) { if (innerFormFields) { const nestedFormProps = { labels: {}, masks: {}, data: {}, allFields: [], requiredFields: [], obscuredFields: [], optionalFields: [], readOnlyFields: [], verifyFields: [], trustedFields: [], fieldValidationErrors: {}, errors: {}, valid: {} }; innerFormFields.forEach((field) => { nestedFormProps.labels[field] = props.labels?.[field]; nestedFormProps.masks[field] = props.masks?.[field]; nestedFormProps.data[field] = props.data?.[field]; if (props.allFields?.includes(field)) nestedFormProps.allFields.push(field); if (props.readOnlyFields?.includes(field)) nestedFormProps.readOnlyFields.push(field); if (props.requiredFields?.includes(field)) nestedFormProps.requiredFields.push(field); if (props.optionalFields?.includes(field)) nestedFormProps.optionalFields.push(field); if (props.verifyFields?.includes(field)) nestedFormProps.verifyFields.push(field); if (props.fieldValidationErrors?.[field]) nestedFormProps.fieldValidationErrors[field] = props.fieldValidationErrors[field]; if (props.obscuredFields?.includes(field)) nestedFormProps.obscuredFields.push(field); if (props.trustedFields?.includes(field)) nestedFormProps.trustedFields.push(field); if (props.validators?.[field]) { if (!nestedFormProps?.validators) nestedFormProps.validators = {}; nestedFormProps.validators[field] = props.validators?.[field]; } if (props.errors?.[field]) nestedFormProps.errors[field] = props.errors?.[field]; if (props.valid?.[field]) nestedFormProps.valid[field] = props.valid?.[field]; }); nestedFormProps.shouldValidate = props.shouldValidate; nestedFormProps.handleFieldChange = props.handleFieldChange; return nestedFormProps; } return null; } //#endregion export { getFormProps as n, getNestedOuterFormPropsFromOuterFormProps as r, getFieldProps as t };