@adyen/kyc-components 2.26.1 → 2.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7918,6 +7918,24 @@ function CompanyRegistrationNumberTypeSelector({
7918
7918
  })
7919
7919
  });
7920
7920
  }
7921
+ const inferCompanyRegistrationNumberType = (registrationNumber2, country2, companyType2) => {
7922
+ const optionsForCountry = companyRegistrationNumberOptions[country2];
7923
+ const metadataFn = defaultFieldConfig[country2];
7924
+ if (!optionsForCountry || !metadataFn || typeof metadataFn !== "function")
7925
+ return void 0;
7926
+ for (const option of optionsForCountry) {
7927
+ const fieldMetadata = metadataFn({
7928
+ companyType: companyType2,
7929
+ registrationNumberType: option.id
7930
+ });
7931
+ if (!fieldMetadata.validators)
7932
+ continue;
7933
+ const validators = Array.isArray(fieldMetadata.validators) ? fieldMetadata.validators : [fieldMetadata.validators];
7934
+ if (validators.every((validator) => validator.validate(registrationNumber2))) {
7935
+ return option.id;
7936
+ }
7937
+ }
7938
+ };
7921
7939
  function TaxIdNumberTypeSelector({
7922
7940
  country: country2,
7923
7941
  selected,
@@ -8934,14 +8952,14 @@ const FLOWS_THAT_HIDE_REGISTRATION_NUMBER = [{
8934
8952
  }];
8935
8953
  const companyRegistrationDetailsFields = ["tradingName", "sameNameAsLegalName", ...businessRegistrationNumberFields, "stockExchangeMIC", "stockISIN", ...vatNumberFields, ...taxIdFields, "dateOfIncorporation"];
8936
8954
  function CompanyRegistrationDetailsComponent(props) {
8937
- var _a, _b, _c, _d, _e, _f, _g, _h;
8955
+ var _a, _b, _c, _d, _e, _f, _g;
8938
8956
  const {
8939
8957
  i18n
8940
8958
  } = useI18nContext();
8941
8959
  const {
8942
8960
  isExperimentEnabled
8943
8961
  } = useExperimentsContext();
8944
- const isIdentityFieldTypeSelectorEnabled = isExperimentEnabled(ExperimentNames.EnableIdentityFieldTypeSelector);
8962
+ const isTypeSelectorEnabled = isExperimentEnabled(ExperimentNames.EnableIdentityFieldTypeSelector);
8945
8963
  const hideOptionalRegistrationNumberField = FLOWS_THAT_HIDE_REGISTRATION_NUMBER.some((f) => f.country === props.country && f.companyType.includes(props.companyType));
8946
8964
  const stateRef = useRef({
8947
8965
  setState: null
@@ -8974,8 +8992,8 @@ function CompanyRegistrationDetailsComponent(props) {
8974
8992
  rules: companyRegistrationDetailsValidationRules,
8975
8993
  fieldProblems: props == null ? void 0 : props.fieldValidationErrors
8976
8994
  });
8977
- const defaultRegistrationNumberType = ((_e = companyRegistrationNumberOptions == null ? void 0 : companyRegistrationNumberOptions[companyCountry2]) == null ? void 0 : _e[0].id) || ((_f = props.labels) == null ? void 0 : _f.registrationNumber);
8978
- const defaultVatNumberType = ((_g = taxIdNumberOptions == null ? void 0 : taxIdNumberOptions[companyCountry2]) == null ? void 0 : _g[0].id) || ((_h = props.labels) == null ? void 0 : _h.vatNumber);
8995
+ const defaultRegistrationNumberType = props.data.registrationNumber ? inferCompanyRegistrationNumberType(props.data.registrationNumber, props.country, props.companyType) : (_e = companyRegistrationNumberOptions[companyCountry2]) == null ? void 0 : _e[0].id;
8996
+ const defaultVatNumberType = ((_f = taxIdNumberOptions[companyCountry2]) == null ? void 0 : _f[0].id) ?? ((_g = props.labels) == null ? void 0 : _g.vatNumber);
8979
8997
  const [registrationNumberType, setRegistrationNumberType] = useState(defaultRegistrationNumberType);
8980
8998
  const [vatNumberType, setVatNumberType] = useState(defaultVatNumberType);
8981
8999
  useEffect(() => {
@@ -9143,7 +9161,7 @@ function CompanyRegistrationDetailsComponent(props) {
9143
9161
  "aria-label": formUtils.getLabel("stockISIN"),
9144
9162
  "aria-invalid": !valid.stockISIN
9145
9163
  })
9146
- }), isIdentityFieldTypeSelectorEnabled && formUtils.isRequiredField("registrationNumber") && jsx(CompanyRegistrationNumberTypeSelector, {
9164
+ }), isTypeSelectorEnabled && formUtils.isRequiredField("registrationNumber") && jsx(CompanyRegistrationNumberTypeSelector, {
9147
9165
  companyType: props.companyType,
9148
9166
  country: props.country,
9149
9167
  setSelected: setRegistrationNumberType,
@@ -9155,7 +9173,7 @@ function CompanyRegistrationDetailsComponent(props) {
9155
9173
  dataStoreId: COMPANY_REGISTRATION_DETAILS,
9156
9174
  labels: registrationNumberCustomLabel,
9157
9175
  registrationNumberType
9158
- }), isIdentityFieldTypeSelectorEnabled && formUtils.isRequiredField("vatNumber") && jsx(TaxIdNumberTypeSelector, {
9176
+ }), isTypeSelectorEnabled && formUtils.isRequiredField("vatNumber") && jsx(TaxIdNumberTypeSelector, {
9159
9177
  country: props.country,
9160
9178
  setSelected: setVatNumberType,
9161
9179
  selected: vatNumberType
@@ -0,0 +1,12 @@
1
+ import { CompanyTypesValue } from '../../../core/models/api/company-types-value';
2
+ import { CountryCode } from '../../../core/models/country-code';
3
+ import { CompanyRegistrationNumberType } from './countryIdNumberTypes';
4
+ /**
5
+ * For existing data, we need to infer the company registration number type from the existing data.
6
+ * Otherwise, the incorrect mask will be applied.
7
+ * We don't store this choice in the API.
8
+ * @param registrationNumber the existing company registration number
9
+ * @param country the country of the LE
10
+ * @param companyType the company type, e.g. `nonProfit`
11
+ */
12
+ export declare const inferCompanyRegistrationNumberType: (registrationNumber: string, country: CountryCode, companyType: CompanyTypesValue) => CompanyRegistrationNumberType | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adyen/kyc-components",
3
- "version": "2.26.1",
3
+ "version": "2.26.2",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "files": [