@adyen/kyc-components 2.3.2 → 2.4.0

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.
Files changed (44) hide show
  1. package/dist/es/adyen-kyc-components.es.js +789 -464
  2. package/dist/types/components/Company/types.d.ts +2 -2
  3. package/dist/types/components/Dropins/FormComposer/components/FormNavigation/FormNavigation.d.ts +1 -1
  4. package/dist/types/components/Dropins/FormComposer/components/FormNavigation/types.d.ts +4 -1
  5. package/dist/types/components/Dropins/IndividualDropin/components/IndividualDropinComponent.d.ts +1 -1
  6. package/dist/types/components/Dropins/RoleAndTypeDropin/components/RoleAndTypeDropinComponent.d.ts +1 -1
  7. package/dist/types/components/Dropins/RoleAndTypeDropin/types.d.ts +7 -14
  8. package/dist/types/components/Individual/types.d.ts +2 -2
  9. package/dist/types/components/TrustMembers/component/CompanyTrustMemberTaskItem.d.ts +12 -0
  10. package/dist/types/components/TrustMembers/component/ExemptSettlorTaskItem.d.ts +10 -0
  11. package/dist/types/components/TrustMembers/component/RegularTrustMemberTaskItem.d.ts +10 -0
  12. package/dist/types/components/TrustMembers/component/RootTrusteeTaskItem.d.ts +8 -0
  13. package/dist/types/components/TrustMembers/component/TrustMembersOverview.d.ts +12 -0
  14. package/dist/types/components/TrustMembers/component/UndefinedBeneficiaryTaskItem.d.ts +7 -0
  15. package/dist/types/components/TrustMembers/types.d.ts +62 -19
  16. package/dist/types/components/TrustRoleAndEntityType/component/TrustRoleAndEntityType.d.ts +2 -0
  17. package/dist/types/components/TrustRoleAndEntityType/convertExistingTrustMember.d.ts +3 -0
  18. package/dist/types/components/TrustRoleAndEntityType/types.d.ts +7 -6
  19. package/dist/types/components/internal/Address/utils.d.ts +1 -1
  20. package/dist/types/components/internal/EntityAssociation/types.d.ts +6 -2
  21. package/dist/types/core/Context/StateContext/StateContextWatcher.d.ts +2 -2
  22. package/dist/types/core/Context/StateContext/types.d.ts +3 -5
  23. package/dist/types/core/hooks/useExemptSettlor.d.ts +8 -0
  24. package/dist/types/core/models/api/trust-member-type.d.ts +1 -1
  25. package/dist/types/language/config.d.ts +4 -0
  26. package/dist/types/utils/decision-maker-roles.d.ts +1 -1
  27. package/dist/types/utils/entity-status-util.d.ts +2 -2
  28. package/dist/types/utils/mapping/trustMembers/getTrustMembers.d.ts +3 -0
  29. package/dist/types/utils/mapping/trustMembers/mapEntityAssociationsToTrustMembers.d.ts +10 -0
  30. package/dist/types/utils/mapping/trustMembers/mapRootLegalEntityToTrustMember.d.ts +3 -0
  31. package/dist/types/utils/mapping/trustMembers/mapUndefinedBeneficiaryInfoToTrustMembers.d.ts +3 -0
  32. package/dist/types/utils/splitAtFirstOccurrence.d.ts +1 -0
  33. package/dist/types/utils/trust-util.d.ts +2 -15
  34. package/dist/types/utils/trustMembers/handlers/addOrUpdateAssociatedTrustMember.d.ts +8 -0
  35. package/dist/types/utils/trustMembers/handlers/addOrUpdateUndefinedBeneficiary.d.ts +8 -0
  36. package/dist/types/utils/trustMembers/handlers/createExemptSettlor.d.ts +8 -0
  37. package/dist/types/utils/trustMembers/handlers/deleteAssociatedTrustMember.d.ts +8 -0
  38. package/dist/types/utils/trustMembers/handlers/deleteUndefinedBeneficiary.d.ts +12 -0
  39. package/dist/types/utils/trustMembers/handlers/updateExemptSettlorName.d.ts +8 -0
  40. package/package.json +1 -1
  41. package/dist/types/components/TrustMembers/component/TrustMembersComponent.d.ts +0 -4
  42. package/dist/types/components/TrustMembers/component/UndefinedBeneficiaries.d.ts +0 -8
  43. package/dist/types/components/TrustRoleAndEntityType/component/TrustRoleAndEntityTypeComponent.d.ts +0 -3
  44. package/dist/types/utils/mapping/mapEntityAssociationsToUniqueTrustMembers.d.ts +0 -12
@@ -1199,6 +1199,10 @@ const deceased = "My settlor is deceased";
1199
1199
  const noneOfTheAbove = "None of the above";
1200
1200
  const settlorExemptionReason = "Settlor exemption reasons";
1201
1201
  const otherInformation = "Other information";
1202
+ const firstNameOfSettlor = "First name of settlor";
1203
+ const lastNameOfSettlor = "Last name of settlor";
1204
+ const enterSettlorsFirstNameExactlyAsItAppearsInID = "Enter the settlor's first name(s) exactly as it appears on their identity document";
1205
+ const enterSettlorsLastNameExactlyAsItAppearsInID = "Enter the settlor's last name(s) exactly as it appears on their identity document";
1202
1206
  const defaultTrans = {
1203
1207
  close,
1204
1208
  individual,
@@ -2169,7 +2173,11 @@ const defaultTrans = {
2169
2173
  deceased,
2170
2174
  noneOfTheAbove,
2171
2175
  settlorExemptionReason,
2172
- otherInformation
2176
+ otherInformation,
2177
+ firstNameOfSettlor,
2178
+ lastNameOfSettlor,
2179
+ enterSettlorsFirstNameExactlyAsItAppearsInID,
2180
+ enterSettlorsLastNameExactlyAsItAppearsInID
2173
2181
  };
2174
2182
  const FALLBACK_LOCALE = "en-US";
2175
2183
  const defaultTranslation = defaultTrans;
@@ -3059,10 +3067,11 @@ function StateContextWatcher({
3059
3067
  }
3060
3068
  }, [JSON.stringify(formState == null ? void 0 : formState.currentState)]);
3061
3069
  return o(StateContext.Consumer, {
3062
- children: ({
3063
- state: state2
3064
- }) => {
3065
- setFormState(state2);
3070
+ children: (stateContextValue) => {
3071
+ if (!stateContextValue) {
3072
+ throw new Error("<StateContextWatcher> needs to be mounted inside a <StateProvider>");
3073
+ }
3074
+ setFormState(stateContextValue.state);
3066
3075
  return null;
3067
3076
  }
3068
3077
  });
@@ -3179,10 +3188,14 @@ function StateContextSetter({
3179
3188
  return null;
3180
3189
  }
3181
3190
  return o(StateContext.Consumer, {
3182
- children: ({
3183
- dispatch,
3184
- setActiveForms
3185
- }) => {
3191
+ children: (stateContextValue) => {
3192
+ if (!stateContextValue) {
3193
+ throw new Error("<StateContextSetter> needs to be mounted inside a <StateProvider>");
3194
+ }
3195
+ const {
3196
+ dispatch,
3197
+ setActiveForms
3198
+ } = stateContextValue;
3186
3199
  stateRef.current.setState = dispatch;
3187
3200
  stateRef.current.setActiveForms = setActiveForms;
3188
3201
  return null;
@@ -4509,7 +4522,7 @@ const lengthValidationPatterns = {
4509
4522
  message: "validationEnter9Or12Digits"
4510
4523
  }
4511
4524
  };
4512
- const bankStatementDescriptionPattern = /^[\s+$\xA2-\xA5\u058F\u060B\u09F2\u09F3\u09FB\u0AF1\u0BF9\u0E3F\u17DB\u20A0-\u20BD\uA838\uFDFC\uFE69\uFF04\uFFE0\uFFE1\uFFE5\uFFE6a-zA-Z0-9-."_,:;'*!@#%()+?¿/&「」]*$/;
4525
+ const bankStatementDescriptionPattern = /^[$\xA2-\xA5\u058F\u060B\u09F2\u09F3\u09FB\u0AF1\u0BF9\u0E3F\u17DB\u20A0-\u20BD\uA838\uFDFC\uFE69\uFF04\uFFE0\uFFE1\uFFE5\uFFE6a-zA-Z0-9-."_,:;'*!@#%()+?¿/&「」]*$/;
4513
4526
  const businessRegistrationNumberPatterns = {
4514
4527
  [CountryCodes.Australia]: {
4515
4528
  default: {
@@ -8799,7 +8812,7 @@ var TrustMemberTypes = /* @__PURE__ */ ((TrustMemberTypes2) => {
8799
8812
  TrustMemberTypes2["DEFINED_BENEFICIARY"] = "definedBeneficiary";
8800
8813
  TrustMemberTypes2["UNDEFINED_BENEFICIARY"] = "undefinedBeneficiary";
8801
8814
  TrustMemberTypes2["PROTECTOR"] = "protector";
8802
- TrustMemberTypes2["TRUSTEE"] = "trustee";
8815
+ TrustMemberTypes2["TRUSTEE"] = "secondaryTrustee";
8803
8816
  TrustMemberTypes2["SETTLOR"] = "settlor";
8804
8817
  return TrustMemberTypes2;
8805
8818
  })(TrustMemberTypes || {});
@@ -11834,21 +11847,6 @@ const getOwnTrustMembers = (trustEntity) => {
11834
11847
  return [];
11835
11848
  return trustEntity.entityAssociations.filter((entityAssociation) => Object.values(TrustMemberTypes).includes(entityAssociation.type) && entityAssociation.associatorId === trustEntity.id);
11836
11849
  };
11837
- const getRootTrusteeInfo = (rootLegalEntity) => ({
11838
- id: rootLegalEntity.id,
11839
- type: TrustMemberTypes.TRUSTEE
11840
- });
11841
- const getUndefinedBeneficiaries = (legalEntity) => {
11842
- var _a;
11843
- return ((_a = legalEntity.trust) == null ? void 0 : _a.undefinedBeneficiaryInfo) || [];
11844
- };
11845
- const getAllTrustMembers = (rootLegalEntity, trustEntity) => [getRootTrusteeInfo(rootLegalEntity), ...getOwnTrustMembers(trustEntity).map((association) => ({
11846
- id: association.legalEntityId || "",
11847
- type: association.type
11848
- })), ...getUndefinedBeneficiaries(trustEntity).map((undefinedBeneficiaryInfo) => ({
11849
- id: undefinedBeneficiaryInfo.reference,
11850
- type: TrustMemberTypes.UNDEFINED_BENEFICIARY
11851
- }))];
11852
11850
  const getOwnTrustMembersLegalEntityIds = (legalEntity) => getOwnTrustMembers(legalEntity).map((ea) => ea.legalEntityId).filter((id2) => id2 !== void 0);
11853
11851
  const getOwnTrustLegalEntityId = (legalEntity) => {
11854
11852
  var _a, _b;
@@ -15147,7 +15145,8 @@ function NameComponent(props) {
15147
15145
  setState: null
15148
15146
  });
15149
15147
  p(() => {
15150
- stateRef.current.setState({
15148
+ var _a, _b, _c;
15149
+ (_b = (_a = stateRef.current) == null ? void 0 : _a.setState) == null ? void 0 : _b.call(_a, {
15151
15150
  type: "addToState",
15152
15151
  value: {
15153
15152
  data,
@@ -15158,6 +15157,14 @@ function NameComponent(props) {
15158
15157
  dataStoreId
15159
15158
  }
15160
15159
  });
15160
+ (_c = props.onChange) == null ? void 0 : _c.call(props, {
15161
+ schema,
15162
+ data,
15163
+ valid,
15164
+ errors,
15165
+ fieldProblems,
15166
+ isValid
15167
+ });
15161
15168
  }, [data, valid, errors, isValid]);
15162
15169
  const formUtils = formUtilities(props, i18n);
15163
15170
  return o("div", {
@@ -15170,7 +15177,7 @@ function NameComponent(props) {
15170
15177
  classNameModifiers: ["firstName", "col-50"],
15171
15178
  errorMessage: formUtils.getErrorMessage("firstName", errors, fieldProblems),
15172
15179
  isValid: valid.firstName,
15173
- helper: i18n.get("enterNameExactlyAsAppearInID"),
15180
+ helper: formUtils.getLabel("enterNameExactlyAsAppearInID"),
15174
15181
  children: (childProps) => o(InputText, {
15175
15182
  ...childProps,
15176
15183
  name: "firstName",
@@ -15191,7 +15198,7 @@ function NameComponent(props) {
15191
15198
  classNameModifiers: ["lastName", "col-50"],
15192
15199
  errorMessage: formUtils.getErrorMessage("lastName", errors, fieldProblems),
15193
15200
  isValid: valid.lastName,
15194
- helper: i18n.get("enterLastNameExactlyAsAppearInID"),
15201
+ helper: formUtils.getLabel("enterLastNameExactlyAsAppearInID"),
15195
15202
  children: (childProps) => o(InputText, {
15196
15203
  ...childProps,
15197
15204
  name: "lastName",
@@ -17589,7 +17596,7 @@ function PayoutBankStatementComponent(props) {
17589
17596
  }) : null]
17590
17597
  });
17591
17598
  }
17592
- const PayoutBankStatement = x(PayoutBankStatementComponent, (prevProps, nextProps) => objectsDeepEqual(prevProps.requiredFields, nextProps.requiredFields) && objectsDeepEqual(prevProps.optionalFields, nextProps.optionalFields) && objectsDeepEqual(prevProps.data, nextProps.data) && objectsDeepEqual(prevProps.formVerificationErrors, nextProps.formVerificationErrors) && objectsDeepEqual(prevProps.fieldValidationErrors, nextProps.fieldValidationErrors) && prevProps.country === nextProps.country && prevProps.shouldValidate === nextProps.shouldValidate);
17599
+ const PayoutBankStatement = x(PayoutBankStatementComponent, (prevProps, nextProps) => objectsDeepEqual(prevProps.requiredFields, nextProps.requiredFields) && objectsDeepEqual(prevProps.optionalFields, nextProps.optionalFields) && objectsDeepEqual(prevProps.data, nextProps.data) && objectsDeepEqual(prevProps.formVerificationErrors, nextProps.formVerificationErrors) && objectsDeepEqual(prevProps.fieldValidationErrors, nextProps.fieldValidationErrors) && prevProps.country === nextProps.country && prevProps.shouldValidate === nextProps.shouldValidate && prevProps.heading === nextProps.heading);
17593
17600
  const VerificationMethod = "";
17594
17601
  const hasLoaded = (loadedValue) => loadedValue !== "loading";
17595
17602
  const eeaCountries = [CountryCodes.Austria, CountryCodes.Belgium, CountryCodes.Bulgaria, CountryCodes.Croatia, CountryCodes.Cyprus, CountryCodes.CzechRepublic, CountryCodes.Denmark, CountryCodes.Estonia, CountryCodes.Finland, CountryCodes.France, CountryCodes.Germany, CountryCodes.Greece, CountryCodes.Hungary, CountryCodes.Ireland, CountryCodes.Italy, CountryCodes.Latvia, CountryCodes.Lithuania, CountryCodes.Luxembourg, CountryCodes.Netherlands, CountryCodes.Norway, CountryCodes.Poland, CountryCodes.Portugal, CountryCodes.Romania, CountryCodes.Slovakia, CountryCodes.Slovenia, CountryCodes.Spain, CountryCodes.Sweden];
@@ -19686,6 +19693,9 @@ const solePropBase = {
19686
19693
  tradingName: {
19687
19694
  rule: "REQUIRED"
19688
19695
  },
19696
+ dateOfIncorporation: {
19697
+ rule: "countryRequiresDateOfIncorporationForCompanies"
19698
+ },
19689
19699
  exemptedFromRegistrationNumber: {
19690
19700
  rule: "countryHasRegistrationExemptionsForSomeSoleProps"
19691
19701
  },
@@ -20031,12 +20041,14 @@ const getRequiredForms = (forms, requiredFields, optionalFields) => {
20031
20041
  };
20032
20042
  const addValidityToForms = (forms, formValidity, problems) => forms.map(({
20033
20043
  formId,
20034
- formName
20044
+ formName,
20045
+ fields
20035
20046
  }) => {
20036
20047
  var _a;
20037
20048
  return {
20038
20049
  formId,
20039
20050
  formName,
20051
+ fields,
20040
20052
  isValid: (formValidity == null ? void 0 : formValidity[formId]) ?? false,
20041
20053
  hasServerValidationErrors: Boolean((_a = problems == null ? void 0 : problems.validationErrors) == null ? void 0 : _a[formId])
20042
20054
  };
@@ -20130,6 +20142,7 @@ const FormNavigationItem = ({
20130
20142
  const {
20131
20143
  i18n
20132
20144
  } = useCoreContext();
20145
+ const hasError = form.hasServerValidationErrors || hasVerificationErrors;
20133
20146
  return o("li", {
20134
20147
  className: cx("adyen-kyc-form-navigation__item", {
20135
20148
  "adyen-kyc-form-navigation__item--active": isActive,
@@ -20142,7 +20155,7 @@ const FormNavigationItem = ({
20142
20155
  children: o(AlertIcon, {
20143
20156
  type: AlertTypes.WARNING
20144
20157
  })
20145
- }), form.isValid && !form.hasServerValidationErrors && !hasVerificationErrors && o("span", {
20158
+ }), form.isValid && !hasError && o("span", {
20146
20159
  className: "adyen-kyc-form-navigation__item-icon adyen-kyc-form-navigation__item-icon--success",
20147
20160
  children: o(Icon, {
20148
20161
  name: "checkmark-small"
@@ -20157,7 +20170,7 @@ function FormNavigation({
20157
20170
  validateForm,
20158
20171
  className,
20159
20172
  taskName,
20160
- hasVerificationErrors = false,
20173
+ verificationErrors,
20161
20174
  trackNavigation: trackNavigation2 = noop
20162
20175
  }) {
20163
20176
  const {
@@ -20205,7 +20218,7 @@ function FormNavigation({
20205
20218
  form,
20206
20219
  isActive: form.formId === activeForm.formId,
20207
20220
  onClick: getNavigateHandler(form, activeForm),
20208
- hasVerificationErrors
20221
+ hasVerificationErrors: Boolean((verificationErrors == null ? void 0 : verificationErrors[form.formId]) ?? false)
20209
20222
  }, form.formId))]
20210
20223
  })]
20211
20224
  });
@@ -20314,7 +20327,7 @@ const FormWrapper = ({
20314
20327
  baseTrackingPayload,
20315
20328
  i18n
20316
20329
  }),
20317
- hasVerificationErrors: Object.keys((problems == null ? void 0 : problems.verificationErrors) ?? {}).length > 0
20330
+ verificationErrors: problems == null ? void 0 : problems.verificationErrors
20318
20331
  })
20319
20332
  });
20320
20333
  return o(DropinLayout, {
@@ -20475,7 +20488,7 @@ function CompanyDropinComponent({
20475
20488
  const existingRoles = (_a2 = existingEntityAssociations == null ? void 0 : existingEntityAssociations.filter((ea) => ea.legalEntityId === parentLegalEntity.id)) == null ? void 0 : _a2.map(({
20476
20489
  type
20477
20490
  }) => type);
20478
- const newRoles = associationDetail == null ? void 0 : associationDetail.types;
20491
+ const newRoles = associationDetail == null ? void 0 : associationDetail.roles;
20479
20492
  if (newRoles && !doArraysMatch(existingRoles, newRoles)) {
20480
20493
  const updatedParentLegalEntity = {
20481
20494
  entityAssociations: [...newRoles.map((role2) => ({
@@ -20662,6 +20675,7 @@ function CompanyDropinComponent({
20662
20675
  validateForm: () => setShouldValidate(true),
20663
20676
  baseTrackingPayload,
20664
20677
  onSubmit,
20678
+ problems,
20665
20679
  canSubmit: canSubmit(data) && hasDataChanged(dataFromResponse, data),
20666
20680
  summary: {
20667
20681
  data: formatDataForSummary(data, forms),
@@ -20683,6 +20697,22 @@ function CompanyDropinComponent({
20683
20697
  })
20684
20698
  });
20685
20699
  }
20700
+ const logger$3 = createLogger("useExemptSettlor");
20701
+ const useExemptSettlor = ({
20702
+ trust,
20703
+ handleGetLegalEntity
20704
+ }) => {
20705
+ const [exemptSettlor, setExemptSettlor] = h();
20706
+ const updateExemptSettlor = T$1(async (trustLE) => {
20707
+ const exemptSettlorAssociation = getOwnEntityAssociations(trustLE).find((association) => association.type === TrustMemberTypes.SETTLOR && Boolean(association.settlorExemptionReason));
20708
+ const exemptSettlorLE = (exemptSettlorAssociation == null ? void 0 : exemptSettlorAssociation.legalEntityId) ? await handleGetLegalEntity(exemptSettlorAssociation.legalEntityId) : void 0;
20709
+ setExemptSettlor(exemptSettlorLE);
20710
+ }, [handleGetLegalEntity]);
20711
+ p(() => {
20712
+ updateExemptSettlor(trust).catch(logger$3.error);
20713
+ }, [trust, updateExemptSettlor]);
20714
+ return exemptSettlor;
20715
+ };
20686
20716
  const downloadFile = async (base64, filename) => {
20687
20717
  saveBlobAsFile(base64ToBlob(base64), filename);
20688
20718
  };
@@ -20745,6 +20775,190 @@ const getPayoutAccountHolderName = (legalEntity, i18n) => {
20745
20775
  }
20746
20776
  return getLegalEntityNameBasedOnType(legalEntity);
20747
20777
  };
20778
+ const splitAtFirstOccurrence = (str, separator) => {
20779
+ const firstOccurrence = str.indexOf(separator);
20780
+ if (firstOccurrence === -1)
20781
+ return [str];
20782
+ return [str.slice(0, firstOccurrence), str.slice(firstOccurrence + 1)];
20783
+ };
20784
+ const getTrustMemberOwnerId = (trustMemberId, entityAssociations) => {
20785
+ var _a;
20786
+ return (_a = entityAssociations.find((association) => association.associatorId === trustMemberId && association.type === TrustMemberTypes.TRUSTEE)) == null ? void 0 : _a.legalEntityId;
20787
+ };
20788
+ const getFallbackName = (exemptSettlorAssociation) => {
20789
+ const [firstName2, lastName2] = splitAtFirstOccurrence(exemptSettlorAssociation.name ?? "", " ");
20790
+ return {
20791
+ firstName: firstName2,
20792
+ lastName: lastName2
20793
+ };
20794
+ };
20795
+ const convertEntityAssociationIntoTrustMember = (association, associations, exemptSettlorLE) => {
20796
+ var _a;
20797
+ if (association.settlorExemptionReason)
20798
+ return {
20799
+ trustMemberType: "exemptSettlor",
20800
+ roles: [TrustMemberTypes.SETTLOR],
20801
+ legalEntityType: LegalEntityType.INDIVIDUAL,
20802
+ legalEntityId: association.legalEntityId,
20803
+ settlorExemptionReason: association.settlorExemptionReason,
20804
+ exemptSettlorName: ((_a = exemptSettlorLE == null ? void 0 : exemptSettlorLE.individual) == null ? void 0 : _a.name) ?? getFallbackName(association)
20805
+ };
20806
+ if (association.entityType === LegalEntityType.ORGANIZATION)
20807
+ return {
20808
+ trustMemberType: "company",
20809
+ roles: [],
20810
+ legalEntityType: LegalEntityType.ORGANIZATION,
20811
+ legalEntityId: association.legalEntityId,
20812
+ name: association.name,
20813
+ ownerId: getTrustMemberOwnerId(association.legalEntityId, associations)
20814
+ };
20815
+ if (association.entityType === LegalEntityType.INDIVIDUAL)
20816
+ return {
20817
+ trustMemberType: "regular",
20818
+ roles: [],
20819
+ legalEntityType: LegalEntityType.INDIVIDUAL,
20820
+ legalEntityId: association.legalEntityId,
20821
+ name: association.name
20822
+ };
20823
+ throw new Error(`Not a valid trust member: ${JSON.stringify(association)}`);
20824
+ };
20825
+ const mapEntityAssociationsToTrustMembers = (trustEntityId, entityAssociations, exemptSettlorLE) => {
20826
+ const mappedTrustMembers = entityAssociations.reduce((acc, entityAssociation) => {
20827
+ if (!Object.values(TrustMemberTypes).includes(entityAssociation.type) || entityAssociation.associatorId !== trustEntityId || !entityAssociation.legalEntityId) {
20828
+ return acc;
20829
+ }
20830
+ const trustMember = acc[entityAssociation.legalEntityId] ?? convertEntityAssociationIntoTrustMember(entityAssociation, entityAssociations, exemptSettlorLE);
20831
+ const trustMemberType = entityAssociation.type;
20832
+ acc[entityAssociation.legalEntityId] = {
20833
+ ...trustMember,
20834
+ roles: [.../* @__PURE__ */ new Set([...trustMember.roles, trustMemberType])]
20835
+ };
20836
+ return acc;
20837
+ }, {});
20838
+ return Object.values(mappedTrustMembers);
20839
+ };
20840
+ const mapRootLegalEntityToTrustMember = (rootLegalEntity) => ({
20841
+ trustMemberType: "rootTrustee",
20842
+ roles: [TrustMemberTypes.TRUSTEE],
20843
+ legalEntityType: rootLegalEntity.type,
20844
+ legalEntityId: rootLegalEntity.id,
20845
+ name: getLegalEntityNameBasedOnType(rootLegalEntity)
20846
+ });
20847
+ const mapUndefinedBeneficiaryInfoToTrustMembers = (undefinedBeneficiaryInfo) => undefinedBeneficiaryInfo.map(({
20848
+ reference,
20849
+ description: description2
20850
+ }) => ({
20851
+ trustMemberType: "undefinedBeneficiary",
20852
+ roles: [TrustMemberTypes.UNDEFINED_BENEFICIARY],
20853
+ reference,
20854
+ description: description2
20855
+ }));
20856
+ const getTrustMembers = (trustLE, rootLegalEntity, exemptSettlorLE) => {
20857
+ var _a;
20858
+ return [mapRootLegalEntityToTrustMember(rootLegalEntity), ...mapEntityAssociationsToTrustMembers(trustLE.id, trustLE.entityAssociations ?? [], exemptSettlorLE), ...mapUndefinedBeneficiaryInfoToTrustMembers(((_a = trustLE.trust) == null ? void 0 : _a.undefinedBeneficiaryInfo) ?? [])];
20859
+ };
20860
+ const mapTrustMemberToEntityAssociations = (trustMember) => {
20861
+ if (trustMember.trustMemberType === "exemptSettlor")
20862
+ return [{
20863
+ legalEntityId: trustMember.legalEntityId,
20864
+ entityType: trustMember.legalEntityType,
20865
+ type: TrustMemberTypes.SETTLOR,
20866
+ settlorExemptionReason: trustMember.settlorExemptionReason,
20867
+ name: `${trustMember.exemptSettlorName.firstName} ${trustMember.exemptSettlorName.lastName}`
20868
+ }];
20869
+ return trustMember.roles.map((role2) => ({
20870
+ legalEntityId: trustMember.legalEntityId,
20871
+ type: role2
20872
+ }));
20873
+ };
20874
+ const addOrUpdateAssociatedTrustMember = async ({
20875
+ newOrUpdated,
20876
+ trust,
20877
+ handleUpdateLegalEntity
20878
+ }) => {
20879
+ const otherAssociations = getOwnEntityAssociations(trust).filter((existingAssociation) => existingAssociation.legalEntityId !== newOrUpdated.legalEntityId);
20880
+ const updatedAssociations = mapTrustMemberToEntityAssociations(newOrUpdated);
20881
+ const patchLE = {
20882
+ entityAssociations: [...otherAssociations, ...updatedAssociations]
20883
+ };
20884
+ await handleUpdateLegalEntity(patchLE, trust.id);
20885
+ };
20886
+ const addOrUpdateUndefinedBeneficiary = async ({
20887
+ newOrUpdated,
20888
+ trust,
20889
+ handleUpdateLegalEntity
20890
+ }) => {
20891
+ var _a, _b;
20892
+ const otherUndefinedBeneficiaries = ((_b = (_a = trust.trust) == null ? void 0 : _a.undefinedBeneficiaryInfo) == null ? void 0 : _b.filter((ub) => ub.reference !== newOrUpdated.reference)) ?? [];
20893
+ const patchLE = {
20894
+ trust: {
20895
+ undefinedBeneficiaryInfo: [...otherUndefinedBeneficiaries, {
20896
+ reference: newOrUpdated.reference,
20897
+ description: newOrUpdated.description
20898
+ }]
20899
+ }
20900
+ };
20901
+ await handleUpdateLegalEntity(patchLE, trust.id);
20902
+ };
20903
+ const createExemptSettlor = async ({
20904
+ exemptSettlor,
20905
+ trust,
20906
+ handleCreateLegalEntity
20907
+ }) => {
20908
+ const exemptSettlorLE = {
20909
+ type: LegalEntityType.INDIVIDUAL,
20910
+ individual: {
20911
+ name: {
20912
+ firstName: exemptSettlor.exemptSettlorName.firstName,
20913
+ lastName: exemptSettlor.exemptSettlorName.lastName
20914
+ },
20915
+ residentialAddress: {
20916
+ country: trust.trust.registeredAddress.country
20917
+ }
20918
+ }
20919
+ };
20920
+ return handleCreateLegalEntity(exemptSettlorLE);
20921
+ };
20922
+ const deleteAssociatedTrustMember = async ({
20923
+ associatedTrustMember,
20924
+ trust,
20925
+ handleUpdateLegalEntity
20926
+ }) => {
20927
+ const ownEntityAssociations = getOwnEntityAssociations(trust);
20928
+ const updatedTrustAssociations = {
20929
+ entityAssociations: ownEntityAssociations.filter((entityAssociation) => entityAssociation.legalEntityId !== associatedTrustMember.legalEntityId)
20930
+ };
20931
+ await handleUpdateLegalEntity(updatedTrustAssociations, trust.id);
20932
+ };
20933
+ const deleteUndefinedBeneficiary = async ({
20934
+ undefinedBeneficiary: undefinedBeneficiary2,
20935
+ trust,
20936
+ handleUpdateLegalEntity
20937
+ }) => {
20938
+ var _a;
20939
+ const existingUndefinedBeneficiaries = ((_a = trust.trust) == null ? void 0 : _a.undefinedBeneficiaryInfo) ?? [];
20940
+ const updatedTrust = {
20941
+ trust: {
20942
+ undefinedBeneficiaryInfo: existingUndefinedBeneficiaries.filter((ub) => ub.reference !== undefinedBeneficiary2.reference)
20943
+ }
20944
+ };
20945
+ await handleUpdateLegalEntity(updatedTrust, trust.id);
20946
+ };
20947
+ const exemptSettlorNamesTheSame = (existingSettlor, newSettlor) => JSON.stringify(existingSettlor.exemptSettlorName) === JSON.stringify(newSettlor.exemptSettlorName);
20948
+ const updateExemptSettlorName = async ({
20949
+ exemptSettlor,
20950
+ handleUpdateLegalEntity
20951
+ }) => {
20952
+ const exemptSettlorPatch = {
20953
+ individual: {
20954
+ name: {
20955
+ firstName: exemptSettlor.exemptSettlorName.firstName,
20956
+ lastName: exemptSettlor.exemptSettlorName.lastName
20957
+ }
20958
+ }
20959
+ };
20960
+ return handleUpdateLegalEntity(exemptSettlorPatch, exemptSettlor.legalEntityId);
20961
+ };
20748
20962
  const DecisionMakers = "";
20749
20963
  const iconStatus = (current, min, max) => {
20750
20964
  const isEmpty2 = current === 0;
@@ -21364,7 +21578,6 @@ const DecisionMakersComponent = ({
21364
21578
  }), (uniqueDecisionMakers == null ? void 0 : uniqueDecisionMakers.length) > 0 ? o(CardGroup, {
21365
21579
  children: uniqueDecisionMakers.map((decisionMaker2) => o(EntityAssociation, {
21366
21580
  types: decisionMaker2.types,
21367
- reference: decisionMaker2.reference,
21368
21581
  name: decisionMaker2.name,
21369
21582
  status: decisionMaker2.status,
21370
21583
  actions: actions(decisionMaker2),
@@ -21863,221 +22076,210 @@ function TaskListComponent({
21863
22076
  })
21864
22077
  });
21865
22078
  }
21866
- const TrustMembers = "";
21867
- const getReference = (entityAssociation) => entityAssociation.legalEntityId ?? (entityAssociation.type === "settlor" ? "exemptSettlor" : "");
21868
- const mapEntityAssociationsToUniqueTrustMembers = (entityAssociations, getTaskStatusForEntityAssociation) => {
21869
- const mappedTrustMembers = entityAssociations.reduce((acc, entityAssociation) => {
21870
- const reference = getReference(entityAssociation);
21871
- const mappedTrustMember = acc[reference];
21872
- const trustMemberType = entityAssociation.type;
21873
- acc[reference] = {
21874
- reference,
21875
- types: mappedTrustMember ? [...mappedTrustMember.types, trustMemberType] : [trustMemberType],
21876
- status: getTaskStatusForEntityAssociation(entityAssociation),
21877
- name: entityAssociation.name ?? "",
21878
- legalEntityType: entityAssociation.entityType,
21879
- settlorExemptionReason: entityAssociation.settlorExemptionReason
21880
- };
21881
- return acc;
21882
- }, {});
21883
- return Object.values(mappedTrustMembers);
21884
- };
21885
- const makeUndefinedBeneficiaryTrustMember = (undefinedBeneficiary2) => ({
21886
- types: [TrustMemberTypes.UNDEFINED_BENEFICIARY],
21887
- reference: undefinedBeneficiary2.reference,
21888
- descriptionUndefinedBeneficiary: undefinedBeneficiary2.description,
21889
- status: TaskStatus.FINISHED,
21890
- name: ""
21891
- });
21892
- function UndefinedBeneficiaries({
21893
- undefinedBeneficiaries,
21894
- onDelete,
21895
- onEdit
21896
- }) {
22079
+ const TrustMembersOverview$1 = "";
22080
+ const CompanyTrustMemberTaskItem = ({
22081
+ companyTrustMember,
22082
+ taskStatus,
22083
+ onEditOwner,
22084
+ onAddOwner,
22085
+ onEdit,
22086
+ onDelete
22087
+ }) => {
21897
22088
  const {
21898
22089
  i18n
21899
22090
  } = useCoreContext();
21900
- const actions = (undefinedBeneficiary2) => {
21901
- const trustMember = makeUndefinedBeneficiaryTrustMember(undefinedBeneficiary2);
21902
- return [{
21903
- icon: "edit",
21904
- onSelect: () => onEdit(trustMember),
21905
- label: i18n.get("editEntityDetails"),
21906
- title: i18n.get("editTrustMember", {
21907
- values: {
21908
- trustMember: i18n.get("undefinedBeneficiary")
21909
- }
21910
- })
21911
- }, {
21912
- icon: "bin",
21913
- onSelect: () => onDelete(trustMember.reference),
21914
- label: i18n.get("remove"),
21915
- title: i18n.get("removeTrustMember", {
21916
- values: {
21917
- trustMember: i18n.get("undefinedBeneficiary")
21918
- }
21919
- })
21920
- }];
21921
- };
21922
- return o(Fragment, {
21923
- children: undefinedBeneficiaries.map((undefinedBeneficiary2) => o(EntityAssociation, {
21924
- types: [TrustMemberTypes.UNDEFINED_BENEFICIARY],
21925
- reference: undefinedBeneficiary2.reference,
21926
- status: TaskStatus.FINISHED,
21927
- name: undefinedBeneficiary2.description,
21928
- actions: actions(undefinedBeneficiary2),
21929
- onNavigateToEntity: () => onEdit(makeUndefinedBeneficiaryTrustMember(undefinedBeneficiary2))
21930
- }, undefinedBeneficiary2.reference))
21931
- });
21932
- }
21933
- const TrustMembersComponent = ({
21934
- parentLegalEntity,
21935
- trustResponse,
21936
- capabilityProblems,
22091
+ const actions = [{
22092
+ icon: "edit",
22093
+ onSelect: onEdit,
22094
+ label: i18n.get("editEntityDetails"),
22095
+ title: i18n.get("editTrustMember", {
22096
+ values: {
22097
+ trustMember: companyTrustMember.name
22098
+ }
22099
+ })
22100
+ }, companyTrustMember.ownerId ? {
22101
+ icon: "edit",
22102
+ onSelect: onEditOwner,
22103
+ label: i18n.get("editEntityOwner"),
22104
+ title: i18n.get("editOwnerOfTrustMember", {
22105
+ values: {
22106
+ trustMember: companyTrustMember.name
22107
+ }
22108
+ })
22109
+ } : {
22110
+ icon: "plus",
22111
+ onSelect: onAddOwner,
22112
+ label: i18n.get("addEntityOwner"),
22113
+ title: i18n.get("addOwnerToTrustMember", {
22114
+ values: {
22115
+ trustMember: companyTrustMember.name
22116
+ }
22117
+ })
22118
+ }, {
22119
+ icon: "bin",
22120
+ onSelect: onDelete,
22121
+ label: i18n.get("remove"),
22122
+ title: i18n.get("removeTrustMember", {
22123
+ values: {
22124
+ trustMember: companyTrustMember.name
22125
+ }
22126
+ })
22127
+ }];
22128
+ const infoContent = companyTrustMember.ownerId ? void 0 : o(Alert, {
22129
+ type: AlertTypes.BASIC,
22130
+ hasCloseButton: false,
22131
+ title: o(Fragment, {
22132
+ children: [i18n.get("helpUsVerifyCompany"), " ", o(Link, {
22133
+ onClick: (e2) => {
22134
+ e2.preventDefault();
22135
+ onAddOwner();
22136
+ },
22137
+ href: "to-company-owner",
22138
+ children: i18n.get("providePersonalDetailsOfOwner")
22139
+ })]
22140
+ }),
22141
+ className: "adl-u-margin-top-16"
22142
+ });
22143
+ return o(EntityAssociation, {
22144
+ types: companyTrustMember.roles,
22145
+ name: companyTrustMember.name,
22146
+ status: taskStatus,
22147
+ actions,
22148
+ infoContent,
22149
+ onNavigateToEntity: onEdit
22150
+ }, companyTrustMember.legalEntityId);
22151
+ };
22152
+ const ExemptSettlorTaskItem = ({
22153
+ exemptSettlor,
22154
+ taskStatus,
22155
+ onEdit,
22156
+ onDelete
22157
+ }) => {
22158
+ const {
22159
+ i18n
22160
+ } = useCoreContext();
22161
+ const settlorName = `${exemptSettlor.exemptSettlorName.firstName} ${exemptSettlor.exemptSettlorName.lastName}`;
22162
+ const actions = [{
22163
+ icon: "edit",
22164
+ onSelect: onEdit,
22165
+ label: i18n.get("editEntityDetails"),
22166
+ title: i18n.get("editTrustMember", {
22167
+ values: {
22168
+ trustMember: settlorName
22169
+ }
22170
+ })
22171
+ }, {
22172
+ icon: "bin",
22173
+ onSelect: onDelete,
22174
+ label: i18n.get("remove"),
22175
+ title: i18n.get("removeTrustMember", {
22176
+ values: {
22177
+ trustMember: settlorName
22178
+ }
22179
+ })
22180
+ }];
22181
+ return o(EntityAssociation, {
22182
+ types: exemptSettlor.roles,
22183
+ name: settlorName,
22184
+ status: taskStatus,
22185
+ actions,
22186
+ onNavigateToEntity: onEdit
22187
+ }, exemptSettlor.legalEntityId);
22188
+ };
22189
+ const RegularTrustMemberTaskItem = ({
22190
+ trustMember,
22191
+ taskStatus,
22192
+ onEdit,
22193
+ onDelete
22194
+ }) => {
22195
+ const {
22196
+ i18n
22197
+ } = useCoreContext();
22198
+ const actions = [{
22199
+ icon: "edit",
22200
+ onSelect: onEdit,
22201
+ label: i18n.get("editEntityDetails"),
22202
+ title: i18n.get("editTrustMember", {
22203
+ values: {
22204
+ trustMember: trustMember.name
22205
+ }
22206
+ })
22207
+ }, {
22208
+ icon: "bin",
22209
+ onSelect: onDelete,
22210
+ label: i18n.get("remove"),
22211
+ title: i18n.get("removeTrustMember", {
22212
+ values: {
22213
+ trustMember: trustMember.name
22214
+ }
22215
+ })
22216
+ }];
22217
+ return o(EntityAssociation, {
22218
+ types: trustMember.roles,
22219
+ name: trustMember.name,
22220
+ status: taskStatus,
22221
+ actions,
22222
+ onNavigateToEntity: onEdit
22223
+ }, trustMember.legalEntityId);
22224
+ };
22225
+ const RootTrusteeTaskItem = ({
22226
+ rootTrustee,
22227
+ taskStatus
22228
+ }) => o(EntityAssociation, {
22229
+ types: [TrustMemberTypes.TRUSTEE],
22230
+ name: rootTrustee.name,
22231
+ status: taskStatus
22232
+ }, rootTrustee.legalEntityId);
22233
+ const UndefinedBeneficiaryTaskItem = ({
22234
+ undefinedBeneficiary: undefinedBeneficiary2,
22235
+ onEdit,
22236
+ onDelete
22237
+ }) => {
22238
+ const {
22239
+ i18n
22240
+ } = useCoreContext();
22241
+ const actions = [{
22242
+ icon: "edit",
22243
+ onSelect: onEdit,
22244
+ label: i18n.get("editEntityDetails"),
22245
+ title: i18n.get("editTrustMember", {
22246
+ values: {
22247
+ trustMember: i18n.get("undefinedBeneficiary")
22248
+ }
22249
+ })
22250
+ }, {
22251
+ icon: "bin",
22252
+ onSelect: onDelete,
22253
+ label: i18n.get("remove"),
22254
+ title: i18n.get("removeTrustMember", {
22255
+ values: {
22256
+ trustMember: i18n.get("undefinedBeneficiary")
22257
+ }
22258
+ })
22259
+ }];
22260
+ return o(EntityAssociation, {
22261
+ name: undefinedBeneficiary2.description,
22262
+ types: [TrustMemberTypes.UNDEFINED_BENEFICIARY],
22263
+ status: TaskStatus.FINISHED,
22264
+ actions,
22265
+ onNavigateToEntity: onEdit
22266
+ }, undefinedBeneficiary2.reference);
22267
+ };
22268
+ const TrustMembersOverview = ({
22269
+ trustMembers: trustMembers2,
21937
22270
  navigateBackToTaskList,
21938
22271
  navigateToEditTrustMember,
21939
22272
  navigateToEditTrustMemberOwner,
21940
- handleUpdateLegalEntity,
21941
- onTrustMemberDelete
22273
+ deleteTrustMember,
22274
+ getTrustMemberTaskStatus
21942
22275
  }) => {
21943
- var _a;
21944
22276
  const {
21945
22277
  i18n
21946
22278
  } = useCoreContext();
21947
- const {
21948
- showToast
21949
- } = useToastContext();
21950
22279
  const trustMemberRequirements = DEFAULT_TRUST_MEMBER_REQUIREMENTS;
21951
- const allTrustMembers = getAllTrustMembers(parentLegalEntity, trustResponse);
21952
- const allMappedTrustMembers = allTrustMembers.reduce((mappedTrustMembers, trustMember) => {
21953
- const existingMapping = mappedTrustMembers[trustMember.id];
21954
- mappedTrustMembers[trustMember.id] = {
21955
- id: trustMember.id,
21956
- types: [...(existingMapping == null ? void 0 : existingMapping.types) ?? [], trustMember.type]
21957
- };
21958
- return mappedTrustMembers;
21959
- }, {});
21960
- const allUniqueTrustMembers = allMappedTrustMembers ? Object.values(allMappedTrustMembers) : [];
21961
- const uniqueTrustMembersPerType = (roleTypes) => {
21962
- const filteredTrustMembers = allUniqueTrustMembers.filter(({
21963
- types
21964
- }) => {
21965
- const typeSet = new Set(types);
21966
- return roleTypes.some((label) => typeSet.has(label));
21967
- });
21968
- return filteredTrustMembers.length;
21969
- };
21970
- const trusteeName = getLegalEntityNameBasedOnType(parentLegalEntity);
21971
- const uniqueTrustMembers = mapEntityAssociationsToUniqueTrustMembers(getOwnTrustMembers(trustResponse), (entityAssociation) => getTaskStatus(EntityType.LEGAL_ENTITY, capabilityProblems, parentLegalEntity, entityAssociation.legalEntityId ? [entityAssociation.legalEntityId] : void 0));
21972
- const deleteTrustMember = async (legalEntityId) => {
21973
- try {
21974
- const ownEntityAssociations = getOwnEntityAssociations(trustResponse);
21975
- const updatedTrustAssociations = {
21976
- entityAssociations: ownEntityAssociations.filter((entityAssociation) => entityAssociation.legalEntityId !== legalEntityId)
21977
- };
21978
- await handleUpdateLegalEntity(updatedTrustAssociations, trustResponse.id);
21979
- onTrustMemberDelete();
21980
- showToast({
21981
- type: ToastType.SUCCESS,
21982
- label: i18n.get("successFullyRemovedTrustMember")
21983
- });
21984
- } catch (e2) {
21985
- showToast({
21986
- type: ToastType.ERROR,
21987
- label: i18n.get("failedToRemoveTrustMember")
21988
- });
21989
- }
21990
- };
21991
- const deleteUndefinedBeneficiary = async (undefinedBeneficiaryReference) => {
21992
- var _a2;
21993
- try {
21994
- const existingUndefinedBeneficiaries = ((_a2 = trustResponse.trust) == null ? void 0 : _a2.undefinedBeneficiaryInfo) ?? [];
21995
- const updatedTrust = {
21996
- trust: {
21997
- undefinedBeneficiaryInfo: existingUndefinedBeneficiaries.filter((undefinedBeneficiary2) => undefinedBeneficiary2.reference !== undefinedBeneficiaryReference)
21998
- }
21999
- };
22000
- await handleUpdateLegalEntity(updatedTrust, trustResponse.id);
22001
- onTrustMemberDelete();
22002
- showToast({
22003
- type: ToastType.SUCCESS,
22004
- label: i18n.get("successFullyRemovedTrustMember")
22005
- });
22006
- } catch (e2) {
22007
- showToast({
22008
- type: ToastType.ERROR,
22009
- label: i18n.get("failedToRemoveTrustMember")
22010
- });
22011
- }
22012
- };
22013
- const getTrustMemberOwnerId = (trustMemberId, trustResponse2) => {
22014
- var _a2;
22015
- const associations = trustResponse2.entityAssociations;
22016
- if (associations) {
22017
- return (_a2 = associations.find((association) => association.associatorId === trustMemberId && association.type === TrustMemberTypes.TRUSTEE)) == null ? void 0 : _a2.legalEntityId;
22018
- }
22019
- };
22020
- const infoContent = (trustMember) => {
22021
- const ownerId = getTrustMemberOwnerId(trustMember.reference, trustResponse);
22022
- if (trustMember.legalEntityType === LegalEntityType.ORGANIZATION && !ownerId) {
22023
- return o(Alert, {
22024
- type: AlertTypes.BASIC,
22025
- hasCloseButton: false,
22026
- title: o(Fragment, {
22027
- children: [i18n.get("helpUsVerifyCompany"), " ", o(Link, {
22028
- onClick: (e2) => {
22029
- e2.preventDefault();
22030
- navigateToEditTrustMemberOwner("", trustMember.reference);
22031
- },
22032
- href: "to-company-owner",
22033
- children: i18n.get("providePersonalDetailsOfOwner")
22034
- })]
22035
- }),
22036
- className: "adl-u-margin-top-16"
22037
- });
22038
- }
22039
- };
22040
- const actions = (trustMember) => {
22041
- const ownerId = getTrustMemberOwnerId(trustMember.reference, trustResponse);
22042
- const editCompanyTrusteeAction = trustMember.legalEntityType === LegalEntityType.ORGANIZATION ? ownerId ? {
22043
- icon: "edit",
22044
- onSelect: () => navigateToEditTrustMemberOwner(ownerId, trustMember.reference),
22045
- label: i18n.get("editEntityOwner"),
22046
- title: i18n.get("editOwnerOfTrustMember", {
22047
- values: {
22048
- trustMember: trustMember.name
22049
- }
22050
- })
22051
- } : {
22052
- icon: "plus",
22053
- onSelect: () => navigateToEditTrustMemberOwner("", trustMember.reference),
22054
- label: i18n.get("addEntityOwner"),
22055
- title: i18n.get("addOwnerToTrustMember", {
22056
- values: {
22057
- trustMember: trustMember.name
22058
- }
22059
- })
22060
- } : void 0;
22061
- return [{
22062
- icon: "edit",
22063
- onSelect: () => navigateToEditTrustMember(trustMember),
22064
- label: i18n.get("editEntityDetails"),
22065
- title: i18n.get("editTrustMember", {
22066
- values: {
22067
- trustMember: trustMember.name
22068
- }
22069
- })
22070
- }, editCompanyTrusteeAction, {
22071
- icon: "bin",
22072
- onSelect: () => deleteTrustMember(trustMember.reference),
22073
- label: i18n.get("remove"),
22074
- title: i18n.get("removeTrustMember", {
22075
- values: {
22076
- trustMember: trustMember.name
22077
- }
22078
- })
22079
- }].filter((action) => Boolean(action));
22080
- };
22280
+ const trustMembersWithOneOfGivenRoles = (roleTypes) => trustMembers2.filter(({
22281
+ roles
22282
+ }) => roleTypes.some((label) => roles.includes(label)));
22081
22283
  return o(DropinLayout, {
22082
22284
  content: o("div", {
22083
22285
  className: "adl-trust-members adl-u-width-full",
@@ -22092,10 +22294,10 @@ const TrustMembersComponent = ({
22092
22294
  max,
22093
22295
  label
22094
22296
  }) => o(EntityGuidanceStatus, {
22095
- country: "AU",
22297
+ country: CountryCodes.Australia,
22096
22298
  currentTask: TaskTypes.TRUST_MEMBER_OVERVIEW,
22097
22299
  entityLabel: label,
22098
- status: iconStatus(uniqueTrustMembersPerType(roleTypes), min, max)
22300
+ status: iconStatus(trustMembersWithOneOfGivenRoles(roleTypes).length, min, max)
22099
22301
  }, label))
22100
22302
  }), o(ReviewAlert, {}), o(ContextGuidance, {
22101
22303
  page: "Trust members",
@@ -22113,36 +22315,54 @@ const TrustMembersComponent = ({
22113
22315
  titleId: "whatIsTheDifferenceBetweenTheseRoles",
22114
22316
  contentId: "differenceBetweenTrustMemberRoles"
22115
22317
  }), o(CardGroup, {
22116
- children: [o(EntityAssociation, {
22117
- types: [TrustMemberTypes.TRUSTEE],
22118
- reference: parentLegalEntity.id,
22119
- status: getTaskStatus(EntityType.LEGAL_ENTITY, capabilityProblems, parentLegalEntity, [parentLegalEntity.id]),
22120
- name: trusteeName,
22121
- legalEntityType: parentLegalEntity.type
22122
- }, parentLegalEntity.id), uniqueTrustMembers.map((trustMember) => o(EntityAssociation, {
22123
- types: trustMember.types,
22124
- reference: trustMember.reference,
22125
- status: trustMember.status,
22126
- name: trustMember.name,
22127
- legalEntityType: trustMember.legalEntityType,
22128
- actions: actions(trustMember),
22129
- infoContent: infoContent(trustMember),
22130
- onNavigateToEntity: () => navigateToEditTrustMember(trustMember)
22131
- }, trustMember.reference)), o(UndefinedBeneficiaries, {
22132
- undefinedBeneficiaries: ((_a = trustResponse.trust) == null ? void 0 : _a.undefinedBeneficiaryInfo) ?? [],
22133
- onDelete: deleteUndefinedBeneficiary,
22134
- onEdit: navigateToEditTrustMember
22135
- })]
22318
+ children: trustMembers2.map((trustMember) => {
22319
+ switch (trustMember.trustMemberType) {
22320
+ case "rootTrustee":
22321
+ return o(RootTrusteeTaskItem, {
22322
+ rootTrustee: trustMember,
22323
+ taskStatus: getTrustMemberTaskStatus(trustMember)
22324
+ });
22325
+ case "regular":
22326
+ return o(RegularTrustMemberTaskItem, {
22327
+ trustMember,
22328
+ taskStatus: getTrustMemberTaskStatus(trustMember),
22329
+ onEdit: () => navigateToEditTrustMember(trustMember),
22330
+ onDelete: () => deleteTrustMember(trustMember)
22331
+ });
22332
+ case "company":
22333
+ return o(CompanyTrustMemberTaskItem, {
22334
+ companyTrustMember: trustMember,
22335
+ taskStatus: getTrustMemberTaskStatus(trustMember),
22336
+ onEdit: () => navigateToEditTrustMember(trustMember),
22337
+ onDelete: () => deleteTrustMember(trustMember),
22338
+ onEditOwner: () => navigateToEditTrustMemberOwner(trustMember.ownerId, trustMember.legalEntityId),
22339
+ onAddOwner: () => navigateToEditTrustMemberOwner("", trustMember.legalEntityId)
22340
+ });
22341
+ case "exemptSettlor":
22342
+ return o(ExemptSettlorTaskItem, {
22343
+ exemptSettlor: trustMember,
22344
+ taskStatus: getTrustMemberTaskStatus(trustMember),
22345
+ onEdit: () => navigateToEditTrustMember(trustMember),
22346
+ onDelete: () => deleteTrustMember(trustMember)
22347
+ });
22348
+ case "undefinedBeneficiary":
22349
+ return o(UndefinedBeneficiaryTaskItem, {
22350
+ undefinedBeneficiary: trustMember,
22351
+ onEdit: () => navigateToEditTrustMember(trustMember),
22352
+ onDelete: () => deleteTrustMember(trustMember)
22353
+ });
22354
+ }
22355
+ })
22136
22356
  }), o(Button, {
22137
22357
  secondary: true,
22138
22358
  className: cx("adl-trust-members__add", {
22139
- "adl-trust-members__add--more": uniqueTrustMembers.length > 0
22359
+ "adl-trust-members__add--more": trustMembers2.length > 0
22140
22360
  }),
22141
22361
  icon: "plus",
22142
22362
  title: i18n.get("addTrustMember"),
22143
22363
  onClick: (e2) => {
22144
22364
  e2.stopPropagation();
22145
- navigateToEditTrustMember();
22365
+ navigateToEditTrustMember("new");
22146
22366
  },
22147
22367
  label: i18n.get("addTrustMember")
22148
22368
  }), o(ActionBar, {
@@ -22257,7 +22477,7 @@ function IndividualDropinComponent({
22257
22477
  onChange,
22258
22478
  problems: propProblems,
22259
22479
  handleUpdateLegalEntity,
22260
- associationDetail,
22480
+ trustMember,
22261
22481
  onSubmit: externalOnSubmit,
22262
22482
  onTypeSwitch
22263
22483
  }) {
@@ -22456,7 +22676,7 @@ function IndividualDropinComponent({
22456
22676
  dataSubmitted
22457
22677
  }) => {
22458
22678
  var _a2;
22459
- const newRoles = taskType === TaskTypes.DECISION_MAKER || taskType === TaskTypes.TRUST_MEMBER_COMPANY_OWNER ? (_a2 = dataSubmitted == null ? void 0 : dataSubmitted.personalDetails) == null ? void 0 : _a2.role : taskType === TaskTypes.TRUST_MEMBER_INDIVIDUAL ? associationDetail == null ? void 0 : associationDetail.types : null;
22679
+ const newRoles = taskType === TaskTypes.DECISION_MAKER || taskType === TaskTypes.TRUST_MEMBER_COMPANY_OWNER ? (_a2 = dataSubmitted == null ? void 0 : dataSubmitted.personalDetails) == null ? void 0 : _a2.role : taskType === TaskTypes.TRUST_MEMBER_INDIVIDUAL ? trustMember == null ? void 0 : trustMember.roles : null;
22460
22680
  const existingEntityAssociations = getOwnEntityAssociations(parentLegalEntity);
22461
22681
  if (newRoles && hasRolesChanged(legalEntity, existingEntityAssociations, newRoles)) {
22462
22682
  const updatedParentLegalEntity = {
@@ -22597,11 +22817,14 @@ function IndividualDropinComponent({
22597
22817
  };
22598
22818
  };
22599
22819
  const formatDataForSummary = () => {
22600
- var _a2, _b2;
22820
+ var _a2, _b2, _c2;
22601
22821
  let summaryData = cloneObject(data);
22602
22822
  if ((_a2 = summaryData.personalDetails) == null ? void 0 : _a2.residencyCountry) {
22603
22823
  summaryData.personalDetails.residencyCountry = datasetUtils.getCountryName(summaryData.personalDetails.residencyCountry);
22604
22824
  }
22825
+ if ((_b2 = summaryData.personalDetails) == null ? void 0 : _b2.nationality) {
22826
+ summaryData.personalDetails.nationality = datasetUtils.getCountryName(summaryData.personalDetails.nationality);
22827
+ }
22605
22828
  if (summaryData.address) {
22606
22829
  summaryData.address = mapAddressLabels(summaryData.address, datasetUtils);
22607
22830
  }
@@ -22612,7 +22835,7 @@ function IndividualDropinComponent({
22612
22835
  ...formatFileSummaryData2(data)
22613
22836
  };
22614
22837
  }
22615
- if ((_b2 = summaryData == null ? void 0 : summaryData.personalDetails) == null ? void 0 : _b2.accountHolder) {
22838
+ if ((_c2 = summaryData == null ? void 0 : summaryData.personalDetails) == null ? void 0 : _c2.accountHolder) {
22616
22839
  summaryData.personalDetails.accountHolder = i18n.get(summaryData.personalDetails.accountHolder);
22617
22840
  }
22618
22841
  return summaryData;
@@ -22780,7 +23003,8 @@ function PayoutDetailsDropinComponent({
22780
23003
  }) {
22781
23004
  var _a, _b, _c;
22782
23005
  const {
22783
- i18n
23006
+ i18n,
23007
+ setLocale
22784
23008
  } = useCoreContext();
22785
23009
  const {
22786
23010
  showToast,
@@ -22831,6 +23055,7 @@ function PayoutDetailsDropinComponent({
22831
23055
  task: taskType
22832
23056
  });
22833
23057
  p(() => {
23058
+ eventEmitter.on("updateLocale", (locale) => setLocale(locale));
22834
23059
  userEvents.addPageView("Payout dropin");
22835
23060
  userEvents.addEvent("Started payout task", {
22836
23061
  segmentation: {
@@ -23712,11 +23937,42 @@ function PciDropinComponent({
23712
23937
  footer
23713
23938
  });
23714
23939
  }
23940
+ const convertExistingSettlorExemptionReasons = (existingReasons) => {
23941
+ if (!existingReasons || !existingReasons.length)
23942
+ return ["noneOfTheAbove"];
23943
+ return existingReasons;
23944
+ };
23945
+ const convertExistingTrustMember = (trustMember) => {
23946
+ switch (trustMember.trustMemberType) {
23947
+ case "undefinedBeneficiary":
23948
+ return {
23949
+ entityType: LegalEntityType.INDIVIDUAL,
23950
+ role: ["undefinedBeneficiary"],
23951
+ descriptionUndefinedBeneficiary: trustMember.description
23952
+ };
23953
+ case "regular":
23954
+ case "company":
23955
+ case "rootTrustee":
23956
+ return {
23957
+ entityType: trustMember.legalEntityType,
23958
+ role: trustMember.roles,
23959
+ settlorExemptionReason: ["noneOfTheAbove"]
23960
+ };
23961
+ case "exemptSettlor":
23962
+ return {
23963
+ entityType: LegalEntityType.INDIVIDUAL,
23964
+ role: ["settlor"],
23965
+ settlorExemptionReason: convertExistingSettlorExemptionReasons(trustMember.settlorExemptionReason),
23966
+ firstName: trustMember.exemptSettlorName.firstName,
23967
+ lastName: trustMember.exemptSettlorName.lastName
23968
+ };
23969
+ }
23970
+ };
23715
23971
  const allowedCrossoverRolesMatrix = {
23716
- settlor: ["trustee", "protector"],
23717
- trustee: ["settlor", "protector", "definedBeneficiary"],
23718
- protector: ["settlor", "trustee", "definedBeneficiary"],
23719
- definedBeneficiary: ["trustee", "protector"],
23972
+ settlor: ["secondaryTrustee", "protector"],
23973
+ secondaryTrustee: ["settlor", "protector", "definedBeneficiary"],
23974
+ protector: ["settlor", "secondaryTrustee", "definedBeneficiary"],
23975
+ definedBeneficiary: ["secondaryTrustee", "protector"],
23720
23976
  undefinedBeneficiary: []
23721
23977
  };
23722
23978
  const getAvailableRoles = (currentRoles) => {
@@ -23773,31 +24029,22 @@ const decideFields = (data) => {
23773
24029
  return ["role", "descriptionUndefinedBeneficiary"];
23774
24030
  }
23775
24031
  if ((_b = data.role) == null ? void 0 : _b.length) {
23776
- return couldBeExemptSettlor(data) ? ["role", "entityType", "settlorExemptionReason"] : ["role", "entityType"];
24032
+ if (couldBeExemptSettlor(data)) {
24033
+ return isExemptSettlor(data) ? ["role", "entityType", "settlorExemptionReason", "firstName", "lastName"] : ["role", "entityType", "settlorExemptionReason"];
24034
+ }
24035
+ return ["role", "entityType"];
23777
24036
  }
23778
24037
  return ["role"];
23779
24038
  };
23780
- const convertExistingSettlorExemptionReasons = (existingReasons) => {
23781
- if (!existingReasons || !existingReasons.length)
23782
- return ["noneOfTheAbove"];
23783
- return existingReasons;
23784
- };
23785
- function TrustRoleAndEntityTypeComponent(props) {
24039
+ const TrustRoleAndEntityType = (props) => {
23786
24040
  const {
23787
- trustMember,
24041
+ existingTrustMember,
23788
24042
  id: id2
23789
24043
  } = props;
23790
24044
  const {
23791
24045
  i18n
23792
24046
  } = useCoreContext();
23793
- const defaultData = {
23794
- entityType: trustMember == null ? void 0 : trustMember.legalEntityType,
23795
- role: trustMember == null ? void 0 : trustMember.types,
23796
- descriptionUndefinedBeneficiary: trustMember == null ? void 0 : trustMember.descriptionUndefinedBeneficiary
23797
- };
23798
- if (couldBeExemptSettlor(defaultData)) {
23799
- defaultData.settlorExemptionReason = convertExistingSettlorExemptionReasons(trustMember == null ? void 0 : trustMember.settlorExemptionReason);
23800
- }
24047
+ const defaultData = existingTrustMember ? convertExistingTrustMember(existingTrustMember) : {};
23801
24048
  const formUtils = formUtilities(props, i18n);
23802
24049
  const {
23803
24050
  data,
@@ -23806,7 +24053,10 @@ function TrustRoleAndEntityTypeComponent(props) {
23806
24053
  errors,
23807
24054
  fieldProblems,
23808
24055
  handleChangeFor,
23809
- isValid
24056
+ isValid,
24057
+ setData,
24058
+ setValid,
24059
+ setErrors
23810
24060
  } = useForm({
23811
24061
  ...props,
23812
24062
  schema: decideFields,
@@ -23849,6 +24099,19 @@ function TrustRoleAndEntityTypeComponent(props) {
23849
24099
  }
23850
24100
  handleChangeFor("settlorExemptionReason")(exemptionReasons);
23851
24101
  };
24102
+ const nameProps = getFieldProps(props, nameFields);
24103
+ const onNameChange = ({
24104
+ data: data2,
24105
+ valid: valid2,
24106
+ errors: errors2
24107
+ }) => {
24108
+ setData("firstName", data2.firstName);
24109
+ setValid("firstName", valid2.firstName);
24110
+ setErrors("firstName", errors2.firstName);
24111
+ setData("lastName", data2.lastName);
24112
+ setValid("lastName", valid2.lastName);
24113
+ setErrors("lastName", errors2.lastName);
24114
+ };
23852
24115
  return o("form", {
23853
24116
  className: "adyen-kyc-trust__role-and-entity-type adl-u-width-full",
23854
24117
  children: [o(FormHeader, {
@@ -23882,7 +24145,7 @@ function TrustRoleAndEntityTypeComponent(props) {
23882
24145
  errorMessage: formUtils.getErrorMessage("entityType", errors, fieldProblems),
23883
24146
  label: formUtils.getLabel("entityType", "whatTypeOfYourMembersEntity"),
23884
24147
  classNameModifiers: ["entityType"],
23885
- disabled: !!(trustMember == null ? void 0 : trustMember.reference),
24148
+ disabled: Boolean(existingTrustMember),
23886
24149
  children: (childProps) => o(RadioCardSelect, {
23887
24150
  ...childProps,
23888
24151
  options: trustMemberLegalEntityTypes,
@@ -23928,14 +24191,29 @@ function TrustRoleAndEntityTypeComponent(props) {
23928
24191
  name: i18n.get(reason)
23929
24192
  })
23930
24193
  })
23931
- })]
24194
+ }), (schema == null ? void 0 : schema.includes("firstName")) || schema.includes("lastName") ? o(Name, {
24195
+ ...nameProps,
24196
+ data: {
24197
+ firstName: defaultData.firstName,
24198
+ lastName: defaultData.lastName
24199
+ },
24200
+ requiredFields: schema.filter((field) => nameFields.includes(field)),
24201
+ labels: {
24202
+ firstName: "firstNameOfSettlor",
24203
+ lastName: "lastNameOfSettlor",
24204
+ enterNameExactlyAsAppearInID: "enterSettlorsFirstNameExactlyAsItAppearsInID",
24205
+ enterLastNameExactlyAsAppearInID: "enterSettlorsLastNameExactlyAsItAppearsInID"
24206
+ },
24207
+ onChange: onNameChange,
24208
+ dataStoreId: id2
24209
+ }) : void 0]
23932
24210
  });
23933
- }
24211
+ };
23934
24212
  const summary = {
23935
24213
  formId: "summary",
23936
24214
  formName: "summary"
23937
24215
  };
23938
- const roleAndTypeForms = {
24216
+ const regularForms = {
23939
24217
  roleAndEntityType: {
23940
24218
  formId: "roleAndEntityType",
23941
24219
  formName: "roleAndEntityType",
@@ -23963,124 +24241,98 @@ const exemptSettlorForms = {
23963
24241
  },
23964
24242
  summary
23965
24243
  };
23966
- const logger$3 = createLogger("RoleAndTypeDropin");
23967
- function RoleAndTypeDropinComponent(props) {
23968
- var _a, _b;
24244
+ const decideForms = (trustMember) => {
24245
+ if (trustMember === "incomplete")
24246
+ return regularForms;
24247
+ switch (trustMember.trustMemberType) {
24248
+ case "undefinedBeneficiary":
24249
+ return undefinedBeneficiaryForms;
24250
+ case "exemptSettlor":
24251
+ return exemptSettlorForms;
24252
+ case "rootTrustee":
24253
+ case "regular":
24254
+ case "company":
24255
+ return regularForms;
24256
+ }
24257
+ };
24258
+ const convertDataToTrustMember = (data, existingTrustMember) => {
24259
+ var _a;
24260
+ const existingId = existingTrustMember ? existingTrustMember.trustMemberType === "undefinedBeneficiary" ? existingTrustMember.reference : existingTrustMember.legalEntityId : void 0;
24261
+ if ((_a = data.role) == null ? void 0 : _a.length) {
24262
+ if (isExemptSettlor(data))
24263
+ return {
24264
+ trustMemberType: "exemptSettlor",
24265
+ roles: [TrustMemberTypes.SETTLOR],
24266
+ legalEntityType: LegalEntityType.INDIVIDUAL,
24267
+ settlorExemptionReason: data.settlorExemptionReason.filter((reason) => reason !== "noneOfTheAbove"),
24268
+ exemptSettlorName: {
24269
+ firstName: data.firstName ?? "",
24270
+ lastName: data.lastName ?? ""
24271
+ },
24272
+ legalEntityId: existingId ?? ""
24273
+ };
24274
+ if (data.role.includes("undefinedBeneficiary"))
24275
+ return {
24276
+ trustMemberType: "undefinedBeneficiary",
24277
+ roles: [TrustMemberTypes.UNDEFINED_BENEFICIARY],
24278
+ description: data.descriptionUndefinedBeneficiary ?? "",
24279
+ reference: existingId ?? ""
24280
+ };
24281
+ if (data.entityType === LegalEntityType.ORGANIZATION)
24282
+ return {
24283
+ trustMemberType: "company",
24284
+ roles: data.role,
24285
+ legalEntityType: LegalEntityType.ORGANIZATION,
24286
+ legalEntityId: existingId ?? "",
24287
+ name: ""
24288
+ };
24289
+ if (data.entityType === LegalEntityType.INDIVIDUAL)
24290
+ return {
24291
+ trustMemberType: "regular",
24292
+ roles: data.role,
24293
+ legalEntityType: LegalEntityType.INDIVIDUAL,
24294
+ legalEntityId: existingId ?? "",
24295
+ name: ""
24296
+ };
24297
+ }
24298
+ return "incomplete";
24299
+ };
24300
+ function RoleAndTypeDropinComponent({
24301
+ existingTrustMember,
24302
+ navigateToFullDropinFor,
24303
+ navigateBack,
24304
+ addOrUpdateTrustMember
24305
+ }) {
23969
24306
  const {
23970
24307
  i18n
23971
24308
  } = useCoreContext();
23972
- const {
23973
- showToast
23974
- } = useToastContext();
23975
- const [trustMember, setTrustMember] = h(props.trustMember);
24309
+ const [trustMember, setTrustMember] = h(existingTrustMember ?? "incomplete");
23976
24310
  const [shouldValidate, setShouldValidate] = h(false);
23977
- const roleAndEntityTypeFormID = "roleAndEntityType";
23978
- const [formList, setFormList] = h([...Object.values(roleAndTypeForms)]);
24311
+ const formList = decideForms(trustMember);
24312
+ const forms = Object.values(formList);
23979
24313
  const [formValidity, setFormValidity] = h({
23980
- [roleAndEntityTypeFormID]: false
24314
+ roleAndEntityType: false
23981
24315
  });
23982
- const taskName = "trustMembers";
23983
- const [activeForm, setActiveForm] = h(formList[0]);
24316
+ const [activeForm, setActiveForm] = h(regularForms.roleAndEntityType);
23984
24317
  const isSummaryStep = activeForm.formId === summaryStep.formId;
23985
- const trustMemberCase = ((_a = trustMember == null ? void 0 : trustMember.settlorExemptionReason) == null ? void 0 : _a.length) ? "exemptSettlor" : ((_b = trustMember == null ? void 0 : trustMember.types) == null ? void 0 : _b.includes(TrustMemberTypes.UNDEFINED_BENEFICIARY)) ? "undefinedBeneficiary" : "fullEntity";
23986
- const navigateToTrustMember = () => {
23987
- const trustMemberAssociation = {
23988
- ...props.trustMember,
23989
- legalEntityType: trustMember == null ? void 0 : trustMember.legalEntityType,
23990
- types: trustMember == null ? void 0 : trustMember.types
23991
- };
23992
- props.navigateNext(trustMemberAssociation);
23993
- };
23994
- const submitExemptSettlor = async (exemptSettlor, trustLE) => {
23995
- var _a2;
23996
- const existingTrustMembers = getOwnTrustMembers(trustLE);
23997
- const existingSettlor = existingTrustMembers.find((member) => member.type === "settlor");
23998
- const updatedAssociations = [...(trustLE.entityAssociations ?? []).filter((association) => association !== existingSettlor), exemptSettlor];
23999
- const updatedTrustLE = {
24000
- ...trustLE,
24001
- entityAssociations: updatedAssociations
24002
- };
24003
- try {
24004
- await ((_a2 = props.handleUpdateLegalEntity) == null ? void 0 : _a2.call(props, updatedTrustLE, trustLE.id));
24005
- showToast({
24006
- label: i18n.get("successfullyUpdatedDetails"),
24007
- type: ToastType.SUCCESS
24008
- });
24009
- props.onSubmit(updatedTrustLE);
24010
- } catch (e2) {
24011
- logger$3.error(e2);
24012
- showToast({
24013
- label: i18n.get("failedToUpdateDetails"),
24014
- type: ToastType.ERROR
24015
- });
24016
- }
24017
- };
24018
- const submitUndefinedBeneficiary = async () => {
24019
- var _a2, _b2, _c;
24020
- if (((_a2 = props.trustMember) == null ? void 0 : _a2.descriptionUndefinedBeneficiary) === (trustMember == null ? void 0 : trustMember.descriptionUndefinedBeneficiary)) {
24021
- props.onSubmit(props.trust);
24022
- return;
24023
- }
24024
- const existingUndefinedBeneficiaryInfo = (((_b2 = props.trust.trust) == null ? void 0 : _b2.undefinedBeneficiaryInfo) ?? []).filter((ub) => ub.reference !== (trustMember == null ? void 0 : trustMember.reference));
24025
- const updatedTrust = {
24026
- trust: {
24027
- undefinedBeneficiaryInfo: [{
24028
- ...(trustMember == null ? void 0 : trustMember.reference) && {
24029
- reference: trustMember == null ? void 0 : trustMember.reference
24030
- },
24031
- description: (trustMember == null ? void 0 : trustMember.descriptionUndefinedBeneficiary) || ""
24032
- }, ...existingUndefinedBeneficiaryInfo]
24033
- }
24034
- };
24035
- try {
24036
- await ((_c = props.handleUpdateLegalEntity) == null ? void 0 : _c.call(props, updatedTrust, props.trust.id));
24037
- showToast({
24038
- label: i18n.get("successfullyUpdatedDetails"),
24039
- type: ToastType.SUCCESS
24040
- });
24041
- props.onSubmit(updatedTrust);
24042
- } catch (e2) {
24043
- logger$3.error(e2);
24044
- showToast({
24045
- label: i18n.get("failedToUpdateDetails"),
24046
- type: ToastType.ERROR
24047
- });
24048
- }
24049
- };
24050
24318
  const formatRolesForSummary = (roles) => roles.map((role2) => i18n.get(getTrustMemberName(role2))).join(", ");
24051
24319
  const formatSettlorExemptionReasonsForSummary = (reasons) => reasons.map((reason) => i18n.get(reason)).join(", ");
24052
- const summaryData = {
24320
+ const summaryData = trustMember === "incomplete" ? {} : {
24053
24321
  roleAndEntityType: {
24054
- role: formatRolesForSummary((trustMember == null ? void 0 : trustMember.types) ?? []),
24055
- entityType: (trustMember == null ? void 0 : trustMember.legalEntityType) ? i18n.get(trustMember == null ? void 0 : trustMember.legalEntityType) : void 0,
24056
- descriptionUndefinedBeneficiary: trustMember == null ? void 0 : trustMember.descriptionUndefinedBeneficiary,
24057
- otherInformation: formatSettlorExemptionReasonsForSummary((trustMember == null ? void 0 : trustMember.settlorExemptionReason) ?? [])
24322
+ role: formatRolesForSummary(trustMember.roles),
24323
+ entityType: trustMember.trustMemberType !== "undefinedBeneficiary" ? i18n.get(trustMember.legalEntityType) : void 0,
24324
+ descriptionUndefinedBeneficiary: trustMember.trustMemberType === "undefinedBeneficiary" ? trustMember.description : void 0,
24325
+ otherInformation: trustMember.trustMemberType === "exemptSettlor" ? formatSettlorExemptionReasonsForSummary(trustMember.settlorExemptionReason ?? []) : void 0,
24326
+ firstName: trustMember.trustMemberType === "exemptSettlor" ? trustMember.exemptSettlorName.firstName : void 0,
24327
+ lastName: trustMember.trustMemberType === "exemptSettlor" ? trustMember.exemptSettlorName.lastName : void 0
24058
24328
  }
24059
24329
  };
24060
24330
  const onNavigateToNextStep = () => {
24061
- if (isSummaryStep) {
24062
- switch (trustMemberCase) {
24063
- case "exemptSettlor":
24064
- if (!trustMember)
24065
- return;
24066
- submitExemptSettlor(trustMember, props.trust).catch(logger$3.error);
24067
- break;
24068
- case "undefinedBeneficiary":
24069
- submitUndefinedBeneficiary().catch(logger$3.error);
24070
- break;
24071
- default:
24072
- return;
24073
- }
24074
- }
24075
- if (!formValidity[roleAndEntityTypeFormID]) {
24076
- setShouldValidate(true);
24331
+ if (isSummaryStep && trustMember !== "incomplete") {
24332
+ addOrUpdateTrustMember(trustMember);
24077
24333
  return;
24078
24334
  }
24079
- if (trustMemberCase === "fullEntity") {
24080
- navigateToTrustMember();
24081
- } else {
24082
- setActiveForm(summary);
24083
- }
24335
+ gotoFormByFormIndex(forms.findIndex((form) => form.formId === activeForm.formId) + 1);
24084
24336
  };
24085
24337
  const onTrustMemberChange = ({
24086
24338
  data,
@@ -24093,69 +24345,51 @@ function RoleAndTypeDropinComponent(props) {
24093
24345
  [dataStoreId]: isValid
24094
24346
  });
24095
24347
  }
24096
- if ((data == null ? void 0 : data.role) && data.role.includes(TrustMemberTypes.UNDEFINED_BENEFICIARY)) {
24097
- setFormList([...Object.values(undefinedBeneficiaryForms)]);
24098
- } else if (isExemptSettlor(data)) {
24099
- setFormList([...Object.values(exemptSettlorForms)]);
24100
- } else {
24101
- setFormList([...Object.values(roleAndTypeForms)]);
24102
- }
24103
- setTrustMember({
24104
- ...props.trustMember,
24105
- ...data.role ? {
24106
- types: data.role
24107
- } : {},
24108
- legalEntityType: data.entityType,
24109
- ...data.descriptionUndefinedBeneficiary ? {
24110
- descriptionUndefinedBeneficiary: data.descriptionUndefinedBeneficiary
24111
- } : {},
24112
- ...isExemptSettlor(data) ? {
24113
- settlorExemptionReason: data.settlorExemptionReason.filter((reason) => reason !== "noneOfTheAbove")
24114
- } : {}
24115
- });
24348
+ setTrustMember(convertDataToTrustMember(data, existingTrustMember));
24116
24349
  };
24117
24350
  const saveRolesAndNavigate = async () => {
24118
- var _a2, _b2, _c;
24119
- if (!trustMember) {
24351
+ if (trustMember === "incomplete")
24120
24352
  return;
24353
+ if (hasRolesChanged(trustMember.roles, existingTrustMember == null ? void 0 : existingTrustMember.roles)) {
24354
+ addOrUpdateTrustMember(trustMember);
24121
24355
  }
24122
- const {
24123
- reference
24124
- } = trustMember;
24125
- if (reference && hasRolesChanged(trustMember.types, (_a2 = props.trustMember) == null ? void 0 : _a2.types) && props.trust.id) {
24126
- const existingTrustAssociations = getOwnEntityAssociations(props.trust);
24127
- const updatedTrustAssociations = {
24128
- entityAssociations: [...((_b2 = trustMember.types) == null ? void 0 : _b2.map((role2) => ({
24129
- type: role2,
24130
- reference
24131
- }))) || [], ...existingTrustAssociations.filter((ea) => ea.legalEntityId !== trustMember.reference) || []]
24132
- };
24133
- await ((_c = props.handleUpdateLegalEntity) == null ? void 0 : _c.call(props, updatedTrustAssociations, props.trust.id));
24134
- }
24135
- props.navigateBack();
24356
+ navigateBack();
24136
24357
  };
24137
24358
  const hasRolesChanged = (newRoles = [], existingRoles = []) => newRoles.length !== existingRoles.length || !newRoles.every((newRole) => existingRoles.includes(newRole));
24138
- const formsWithValidity = Object.values(formList).map((form) => ({
24359
+ const formsWithValidity = forms.map((form) => ({
24139
24360
  formId: form.formId,
24140
24361
  formName: form.formName,
24141
24362
  isValid: formValidity[form.formId]
24142
24363
  }));
24143
24364
  const gotoFormByFormIndex = (formIndex) => {
24144
- setActiveForm(formList[formIndex]);
24365
+ const targetForm = forms[formIndex];
24366
+ if (!formValidity.roleAndEntityType || trustMember === "incomplete") {
24367
+ setShouldValidate(true);
24368
+ return;
24369
+ }
24370
+ if (trustMember.trustMemberType === "regular" || trustMember.trustMemberType === "company") {
24371
+ if (targetForm.formId === regularForms.memberDetails.formId) {
24372
+ navigateToFullDropinFor(trustMember);
24373
+ return;
24374
+ }
24375
+ if (targetForm.formId === summaryStep.formId)
24376
+ return;
24377
+ }
24378
+ setActiveForm(targetForm);
24145
24379
  };
24146
24380
  const content = o(Fragment, {
24147
24381
  children: [o(FormNavigation, {
24148
24382
  forms: formsWithValidity,
24149
24383
  activeForm: formsWithValidity.find((form) => form.formId === activeForm.formId),
24150
- taskName,
24151
- gotoForm: noop
24384
+ taskName: "trustMembers",
24385
+ gotoForm: gotoFormByFormIndex
24152
24386
  }), o("div", {
24153
24387
  className: "adyen-kyc-form-container",
24154
24388
  children: [o("div", {
24155
24389
  className: activeForm.formId !== "roleAndEntityType" ? "adyen-kyc-form-wrapper adyen-kyc-form-wrapper--hidden" : "adyen-kyc-form-wrapper",
24156
- children: o(TrustRoleAndEntityTypeComponent, {
24157
- id: roleAndEntityTypeFormID,
24158
- trustMember: props.trustMember,
24390
+ children: o(TrustRoleAndEntityType, {
24391
+ id: "roleAndEntityType",
24392
+ existingTrustMember,
24159
24393
  onChange: onTrustMemberChange,
24160
24394
  shouldValidate
24161
24395
  })
@@ -24699,7 +24933,7 @@ function withFormComposer(WrappedComponent, {
24699
24933
  getConfigFor = "contextCountry"
24700
24934
  }) {
24701
24935
  const WithFormComposer = (props) => {
24702
- var _a, _b, _c, _d, _e;
24936
+ var _a, _b, _c;
24703
24937
  const {
24704
24938
  i18n,
24705
24939
  loadingContext,
@@ -25045,7 +25279,7 @@ function withFormComposer(WrappedComponent, {
25045
25279
  validateForm: validateCurrentForm,
25046
25280
  taskName,
25047
25281
  trackNavigation: trackNavigation2,
25048
- hasVerificationErrors: ((_c = props == null ? void 0 : props.problems) == null ? void 0 : _c.verificationErrors) && ((_e = Object.keys((_d = props == null ? void 0 : props.problems) == null ? void 0 : _d.verificationErrors)) == null ? void 0 : _e.length) > 0
25282
+ verificationErrors: (_c = props == null ? void 0 : props.problems) == null ? void 0 : _c.verificationErrors
25049
25283
  })
25050
25284
  });
25051
25285
  const content = o(Fragment, {
@@ -25514,6 +25748,10 @@ function DropinComposerComponent({
25514
25748
  const [legalEntityType, setLegalEntityType] = h(null);
25515
25749
  const [solePropietor, setSolePropietor] = h(null);
25516
25750
  const [trust, setTrust] = h(null);
25751
+ const exemptSettlor = useExemptSettlor({
25752
+ trust,
25753
+ handleGetLegalEntity: args.handleGetLegalEntity
25754
+ });
25517
25755
  const [trustMember, setTrustMember] = h(null);
25518
25756
  const [pciTemplateResponse, setPciTemplateResponse] = h(null);
25519
25757
  const [pciStatus, setPciStatus] = h(null);
@@ -25655,6 +25893,101 @@ function DropinComposerComponent({
25655
25893
  }
25656
25894
  }
25657
25895
  };
25896
+ const deleteTrustMember = async (trustMember2) => {
25897
+ try {
25898
+ switch (trustMember2.trustMemberType) {
25899
+ case "regular":
25900
+ case "exemptSettlor":
25901
+ case "company":
25902
+ await deleteAssociatedTrustMember({
25903
+ associatedTrustMember: trustMember2,
25904
+ trust,
25905
+ handleUpdateLegalEntity: args.handleUpdateLegalEntity
25906
+ });
25907
+ break;
25908
+ case "undefinedBeneficiary":
25909
+ await deleteUndefinedBeneficiary({
25910
+ undefinedBeneficiary: trustMember2,
25911
+ trust,
25912
+ handleUpdateLegalEntity: args.handleUpdateLegalEntity
25913
+ });
25914
+ break;
25915
+ case "rootTrustee":
25916
+ throw new Error("Cannot delete root trustee");
25917
+ }
25918
+ await refreshTrust();
25919
+ showToast({
25920
+ type: ToastType.SUCCESS,
25921
+ label: i18n.get("successFullyRemovedTrustMember")
25922
+ });
25923
+ } catch (err) {
25924
+ logger$1.error(`Failed to delete trust member`, err);
25925
+ showToast({
25926
+ type: ToastType.ERROR,
25927
+ label: i18n.get("failedToRemoveTrustMember")
25928
+ });
25929
+ }
25930
+ };
25931
+ const addOrUpdateTrustMember = async (updated, existing) => {
25932
+ if ((existing == null ? void 0 : existing.trustMemberType) === "undefinedBeneficiary" && updated.trustMemberType === "undefinedBeneficiary" && existing.description === updated.description) {
25933
+ await refreshTrustAndRunOnSubmit(trust);
25934
+ return;
25935
+ }
25936
+ try {
25937
+ switch (updated.trustMemberType) {
25938
+ case "undefinedBeneficiary":
25939
+ await addOrUpdateUndefinedBeneficiary({
25940
+ newOrUpdated: updated,
25941
+ trust,
25942
+ handleUpdateLegalEntity: args.handleUpdateLegalEntity
25943
+ });
25944
+ break;
25945
+ case "exemptSettlor":
25946
+ if (!existing) {
25947
+ const newSettlorLE = await createExemptSettlor({
25948
+ exemptSettlor: updated,
25949
+ trust,
25950
+ handleCreateLegalEntity: args.handleCreateLegalEntity
25951
+ });
25952
+ updated.legalEntityId = newSettlorLE.id;
25953
+ }
25954
+ if (existing && !exemptSettlorNamesTheSame(existing, updated)) {
25955
+ await updateExemptSettlorName({
25956
+ exemptSettlor: updated,
25957
+ handleUpdateLegalEntity: args.handleUpdateLegalEntity
25958
+ });
25959
+ }
25960
+ await addOrUpdateAssociatedTrustMember({
25961
+ newOrUpdated: updated,
25962
+ trust,
25963
+ handleUpdateLegalEntity: args.handleUpdateLegalEntity
25964
+ });
25965
+ break;
25966
+ case "regular":
25967
+ case "company":
25968
+ await addOrUpdateAssociatedTrustMember({
25969
+ newOrUpdated: updated,
25970
+ trust,
25971
+ handleUpdateLegalEntity: args.handleUpdateLegalEntity
25972
+ });
25973
+ break;
25974
+ case "rootTrustee":
25975
+ default:
25976
+ logger$1.warn(`Updating trust member type "${trustMember.trustMemberType}" is not implemented.`);
25977
+ }
25978
+ showToast({
25979
+ label: i18n.get("successfullyUpdatedDetails"),
25980
+ type: ToastType.SUCCESS
25981
+ });
25982
+ await refreshTrustAndRunOnSubmit(trust);
25983
+ } catch (err) {
25984
+ logger$1.error(err);
25985
+ showToast({
25986
+ label: i18n.get("failedToUpdateDetails"),
25987
+ type: ToastType.ERROR
25988
+ });
25989
+ }
25990
+ };
25658
25991
  const onNavigateTo = (task) => {
25659
25992
  setTaskHistory([...taskHistory, task]);
25660
25993
  onNavigate(task);
@@ -25735,14 +26068,14 @@ function DropinComposerComponent({
25735
26068
  };
25736
26069
  const onNavigateToTrustMember = async (tm) => {
25737
26070
  try {
25738
- if (tm == null ? void 0 : tm.reference) {
25739
- const response = await (args == null ? void 0 : args.handleGetLegalEntity(tm.reference));
26071
+ if (tm == null ? void 0 : tm.legalEntityId) {
26072
+ const response = await (args == null ? void 0 : args.handleGetLegalEntity(tm.legalEntityId));
25740
26073
  setAssociatedLegalEntity(response);
25741
26074
  } else {
25742
26075
  setAssociatedLegalEntity(null);
25743
26076
  }
25744
26077
  setTrustMember(tm);
25745
- onNavigateTo(tm.legalEntityType === LegalEntityType.ORGANIZATION ? TaskTypes.TRUST_MEMBER_COMPANY : TaskTypes.TRUST_MEMBER_INDIVIDUAL);
26078
+ onNavigateTo(tm.trustMemberType === "company" ? TaskTypes.TRUST_MEMBER_COMPANY : TaskTypes.TRUST_MEMBER_INDIVIDUAL);
25746
26079
  } catch (e2) {
25747
26080
  showToast({
25748
26081
  label: i18n.get("failedToFetchTrustMemberDetails"),
@@ -25751,11 +26084,7 @@ function DropinComposerComponent({
25751
26084
  }
25752
26085
  };
25753
26086
  const onNavigateToTrustMemberRoleAndType = (tm) => {
25754
- if (tm) {
25755
- setTrustMember(tm);
25756
- } else {
25757
- setTrustMember(null);
25758
- }
26087
+ setTrustMember(tm === "new" ? null : tm);
25759
26088
  onNavigateTo(TaskTypes.TRUST_MEMBER_ROLE_AND_TYPE);
25760
26089
  };
25761
26090
  const navigateBack = (stepCount = 1) => {
@@ -26026,7 +26355,7 @@ function DropinComposerComponent({
26026
26355
  handleBackClick: navigateBack,
26027
26356
  handleHomeClick: () => onNavigateTo(TaskTypes.TRUST_MEMBER_OVERVIEW),
26028
26357
  homeButtonLabel: i18n.get("saveAndGoToOverview"),
26029
- associationDetail: trustMember,
26358
+ trustMember,
26030
26359
  handleAddressSearch: args == null ? void 0 : args.handleAddressSearch,
26031
26360
  handleFindAddress: args == null ? void 0 : args.handleFindAddress,
26032
26361
  handleGetIdVerificationToken: args == null ? void 0 : args.handleGetIdVerificationToken
@@ -26123,27 +26452,23 @@ function DropinComposerComponent({
26123
26452
  handleFindAddress: args == null ? void 0 : args.handleFindAddress
26124
26453
  });
26125
26454
  case TaskTypes.TRUST_MEMBER_OVERVIEW:
26126
- return o(TrustMembersComponent, {
26127
- parentLegalEntity: legalEntity,
26128
- trustResponse: trust,
26129
- capabilityProblems,
26455
+ return o(TrustMembersOverview, {
26456
+ trustMembers: getTrustMembers(trust, legalEntity, exemptSettlor),
26457
+ getTrustMemberTaskStatus: (member) => getTaskStatus(EntityType.LEGAL_ENTITY, capabilityProblems, legalEntity, member.trustMemberType === "undefinedBeneficiary" ? void 0 : [member.legalEntityId]),
26458
+ navigateBackToTaskList: navigateBack,
26130
26459
  navigateToEditTrustMember: onNavigateToTrustMemberRoleAndType,
26131
26460
  navigateToEditTrustMemberOwner: (trustMemberOwnerId, trustMemberId) => onNavigateToDecisionMakerIndividual(TaskTypes.TRUST_MEMBER_COMPANY_OWNER, trustMemberOwnerId, trustMemberId),
26132
- navigateBackToTaskList: navigateBack,
26133
- handleUpdateLegalEntity: args == null ? void 0 : args.handleUpdateLegalEntity,
26134
- onTrustMemberDelete: refreshTrust
26461
+ deleteTrustMember
26135
26462
  });
26136
26463
  case TaskTypes.TRUST_MEMBER_ROLE_AND_TYPE:
26137
26464
  return o(RoleAndTypeDropinComponent, {
26138
- navigateNext: onNavigateToTrustMember,
26465
+ navigateToFullDropinFor: onNavigateToTrustMember,
26139
26466
  navigateBack: async () => {
26140
26467
  await refreshTrust();
26141
26468
  navigateBack();
26142
26469
  },
26143
- trust,
26144
- trustMember,
26145
- handleUpdateLegalEntity: args == null ? void 0 : args.handleUpdateLegalEntity,
26146
- onSubmit: refreshTrustAndRunOnSubmit
26470
+ existingTrustMember: trustMember,
26471
+ addOrUpdateTrustMember: (newOrUpdated) => addOrUpdateTrustMember(newOrUpdated, trustMember)
26147
26472
  });
26148
26473
  case TaskTypes.PCI_DSS:
26149
26474
  return o(PciDropinComponent, {