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.

47 lines (46 loc) 2.11 kB
import type { FormState } from '../../hooks/useForm/types'; import type { Translatable } from '../../../types'; import type { CountryCode } from '../../types/datasets/country-code'; export type ValidatorMode = 'blur' | 'input'; export interface FieldData<FormSchema> { key: keyof FormSchema; value: FormSchema[keyof FormSchema] | null; mode?: ValidatorMode; formName?: any; } export interface FieldContext<FormSchema> { state: FormState<FormSchema>; } export type Formatter<ValueType> = (value: ValueType | null, context?: FieldContext<any>) => ValueType | null; export interface Format<ValueType> { formatter?: Formatter<ValueType>; format?: string; maxlength?: number; } export type FormatRules<FormSchema> = Partial<{ [field in keyof FormSchema]: Format<FormSchema[field]>; }>; export type CountryFormatRules<FormSchema> = Partial<Record<CountryCode, FormatRules<FormSchema>>>; export interface ValidationRuleResult { isValid: boolean; errorMessage?: Translatable; hasError: boolean; } export type ValidationRuleResults<Schema> = Partial<Record<keyof Schema, ValidationRuleResult | null | undefined>>; export interface ValidatorRule<ValueType, FormSchema> { validate: (value: ValueType | null, context?: FieldContext<FormSchema>) => boolean; errorMessage?: Translatable | ((value: ValueType | null, context?: FieldContext<FormSchema>) => Translatable | undefined); modes: readonly ValidatorMode[]; } interface AsyncValidatorRule<ValueType, FormSchema> { asyncValidate: (value: ValueType | null, context?: FieldContext<FormSchema>) => Promise<boolean>; errorMessage?: Translatable | ((value: ValueType | null, context?: FieldContext<FormSchema>) => Translatable); modes: readonly ValidatorMode[]; } export type ValidatorRules<FormSchema> = Partial<{ [field in keyof FormSchema]: ValidatorRule<FormSchema[field], FormSchema> | ValidatorRule<FormSchema[field], FormSchema>[]; }>; export type AsyncValidatorRules<FormSchema> = Partial<{ [field in keyof FormSchema]: AsyncValidatorRule<FormSchema[field], FormSchema>; }>; export {};