@swan-io/shared-business 5.2.0 → 6.0.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.
package/package.json
CHANGED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { CountryCCA3 } from "../constants/countries";
|
|
3
|
-
type BeneficiaryType = "HasCapital" | "LegalRepresentative" | "Other";
|
|
4
|
-
type AccountCountry = "DEU" | "ESP" | "FRA" | "NLD";
|
|
5
|
-
export type BeneficiaryFormStep = "common" | "address";
|
|
6
|
-
export type EditorState = {
|
|
7
|
-
reference: string;
|
|
8
|
-
firstName: string;
|
|
9
|
-
lastName: string;
|
|
10
|
-
birthDate: string;
|
|
11
|
-
birthCountryCode: CountryCCA3 | undefined;
|
|
12
|
-
birthCity: string;
|
|
13
|
-
birthCityPostalCode: string;
|
|
14
|
-
type: BeneficiaryType;
|
|
15
|
-
indirect: boolean;
|
|
16
|
-
direct: boolean;
|
|
17
|
-
totalCapitalPercentage?: number;
|
|
18
|
-
residencyAddressLine1?: string;
|
|
19
|
-
residencyAddressCity?: string;
|
|
20
|
-
residencyAddressCountry?: string;
|
|
21
|
-
residencyAddressPostalCode?: string;
|
|
22
|
-
taxIdentificationNumber?: string;
|
|
23
|
-
};
|
|
24
|
-
type Props = {
|
|
25
|
-
initialState?: EditorState;
|
|
26
|
-
accountCountry: AccountCountry;
|
|
27
|
-
step: BeneficiaryFormStep;
|
|
28
|
-
placekitApiKey: string;
|
|
29
|
-
onStepChange: (step: BeneficiaryFormStep) => void;
|
|
30
|
-
onSave: (editorState: EditorState) => void | Promise<void>;
|
|
31
|
-
onClose: () => void;
|
|
32
|
-
onCityLoadError: (error: unknown) => void;
|
|
33
|
-
};
|
|
34
|
-
export type BeneficiaryFormRef = {
|
|
35
|
-
cancel: () => void;
|
|
36
|
-
submit: () => void;
|
|
37
|
-
};
|
|
38
|
-
export declare const validateUbo: (editorState: EditorState, accountCountry: AccountCountry) => Partial<Record<keyof EditorState, string | undefined>>;
|
|
39
|
-
export declare const BeneficiaryForm: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<BeneficiaryFormRef | undefined>>;
|
|
40
|
-
export {};
|
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { Option } from "@swan-io/boxed";
|
|
3
|
-
import { Box } from "@swan-io/lake/src/components/Box";
|
|
4
|
-
import { LakeLabelledCheckbox } from "@swan-io/lake/src/components/LakeCheckbox";
|
|
5
|
-
import { LakeLabel } from "@swan-io/lake/src/components/LakeLabel";
|
|
6
|
-
import { LakeText } from "@swan-io/lake/src/components/LakeText";
|
|
7
|
-
import { LakeTextInput } from "@swan-io/lake/src/components/LakeTextInput";
|
|
8
|
-
import { RadioGroup } from "@swan-io/lake/src/components/RadioGroup";
|
|
9
|
-
import { ResponsiveContainer } from "@swan-io/lake/src/components/ResponsiveContainer";
|
|
10
|
-
import { Space } from "@swan-io/lake/src/components/Space";
|
|
11
|
-
import { StepDots } from "@swan-io/lake/src/components/StepDots";
|
|
12
|
-
import { breakpoints, colors } from "@swan-io/lake/src/constants/design";
|
|
13
|
-
import { noop } from "@swan-io/lake/src/utils/function";
|
|
14
|
-
import { isNotNullishOrEmpty } from "@swan-io/lake/src/utils/nullish";
|
|
15
|
-
import { pick } from "@swan-io/lake/src/utils/object";
|
|
16
|
-
import { combineValidators, useForm } from "@swan-io/use-form";
|
|
17
|
-
import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
18
|
-
import { StyleSheet, View } from "react-native";
|
|
19
|
-
import { Rifm } from "rifm";
|
|
20
|
-
import { match } from "ts-pattern";
|
|
21
|
-
import { v4 as uuid } from "uuid";
|
|
22
|
-
import { allCountries, isCountryCCA3 } from "../constants/countries";
|
|
23
|
-
import { decodeBirthDate, encodeBirthDate } from "../utils/date";
|
|
24
|
-
import { locale, rifmDateProps, t } from "../utils/i18n";
|
|
25
|
-
import { validateBooleanRequired, validateIndividualTaxNumber, validateNullableRequired, validateRequired, } from "../utils/validation";
|
|
26
|
-
import { CountryPicker } from "./CountryPicker";
|
|
27
|
-
import { PlacekitAddressSearchInput } from "./PlacekitAddressSearchInput";
|
|
28
|
-
import { PlacekitCityInput } from "./PlacekitCityInput";
|
|
29
|
-
import { TaxIdentificationNumberInput } from "./TaxIdentificationNumberInput";
|
|
30
|
-
const styles = StyleSheet.create({
|
|
31
|
-
inputContainer: {
|
|
32
|
-
flex: 1,
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
const beneficiaryTypes = [
|
|
36
|
-
{ value: "HasCapital", name: t("beneficiaryForm.beneficiary.ownershipOfCapital") },
|
|
37
|
-
{
|
|
38
|
-
value: "LegalRepresentative",
|
|
39
|
-
name: t("beneficiaryForm.beneficiary.legalRepresentative"),
|
|
40
|
-
},
|
|
41
|
-
{ value: "Other", name: t("beneficiaryForm.beneficiary.other") },
|
|
42
|
-
];
|
|
43
|
-
const validateCca3CountryCode = value => {
|
|
44
|
-
if (value == null) {
|
|
45
|
-
return t("error.requiredField");
|
|
46
|
-
}
|
|
47
|
-
if (!isCountryCCA3(value)) {
|
|
48
|
-
// no need to set an error message because country picker contains only valid values
|
|
49
|
-
// this is used only for validateUbo function to display an error indicator without opening UBO modal
|
|
50
|
-
return " ";
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
export const validateUbo = (editorState, accountCountry) => {
|
|
54
|
-
var _a, _b;
|
|
55
|
-
const isAddressRequired = match(accountCountry)
|
|
56
|
-
.with("DEU", "ESP", () => true)
|
|
57
|
-
.otherwise(() => false);
|
|
58
|
-
const isBirthInfoRequired = match(accountCountry)
|
|
59
|
-
.with("ESP", "FRA", "NLD", () => true)
|
|
60
|
-
.otherwise(() => false);
|
|
61
|
-
const isTaxIdentificationNumberRequired = accountCountry === "DEU" && editorState.residencyAddressCountry === "DEU";
|
|
62
|
-
const validateTaxNumber = isTaxIdentificationNumberRequired
|
|
63
|
-
? combineValidators(validateNullableRequired, validateIndividualTaxNumber(accountCountry))
|
|
64
|
-
: validateIndividualTaxNumber(accountCountry);
|
|
65
|
-
return {
|
|
66
|
-
firstName: validateNullableRequired(editorState.firstName),
|
|
67
|
-
lastName: validateNullableRequired(editorState.lastName),
|
|
68
|
-
birthDate: isBirthInfoRequired
|
|
69
|
-
? validateNullableRequired(editorState.birthDate)
|
|
70
|
-
: undefined,
|
|
71
|
-
birthCountryCode: validateCca3CountryCode(editorState.birthCountryCode),
|
|
72
|
-
birthCity: isBirthInfoRequired
|
|
73
|
-
? validateNullableRequired(editorState.birthCity)
|
|
74
|
-
: undefined,
|
|
75
|
-
birthCityPostalCode: isBirthInfoRequired
|
|
76
|
-
? validateNullableRequired(editorState.birthCityPostalCode)
|
|
77
|
-
: undefined,
|
|
78
|
-
type: validateNullableRequired(editorState.type),
|
|
79
|
-
totalCapitalPercentage: editorState.type === "HasCapital"
|
|
80
|
-
? validateNullableRequired((_a = editorState.totalCapitalPercentage) === null || _a === void 0 ? void 0 : _a.toString())
|
|
81
|
-
: undefined,
|
|
82
|
-
residencyAddressLine1: isAddressRequired
|
|
83
|
-
? validateNullableRequired(editorState.residencyAddressLine1)
|
|
84
|
-
: undefined,
|
|
85
|
-
residencyAddressCity: isAddressRequired
|
|
86
|
-
? validateNullableRequired(editorState.residencyAddressCity)
|
|
87
|
-
: undefined,
|
|
88
|
-
residencyAddressCountry: isAddressRequired
|
|
89
|
-
? validateNullableRequired(editorState.residencyAddressCountry)
|
|
90
|
-
: undefined,
|
|
91
|
-
residencyAddressPostalCode: isAddressRequired
|
|
92
|
-
? validateNullableRequired(editorState.residencyAddressPostalCode)
|
|
93
|
-
: undefined,
|
|
94
|
-
taxIdentificationNumber: validateTaxNumber((_b = editorState.taxIdentificationNumber) !== null && _b !== void 0 ? _b : ""),
|
|
95
|
-
indirect: editorState.type !== "HasCapital" || editorState.direct === true
|
|
96
|
-
? undefined
|
|
97
|
-
: validateBooleanRequired(editorState.indirect),
|
|
98
|
-
direct: editorState.type !== "HasCapital" || editorState.indirect === true
|
|
99
|
-
? undefined
|
|
100
|
-
: validateBooleanRequired(editorState.direct),
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* This component was created to handle validation easily with react-ux-form
|
|
105
|
-
* Without this component, we have to validate direct and indirect checkboxes separately
|
|
106
|
-
* But validation is run only onChange or onSubmit, so when both checkboxes were unchecked, check one of them doesn't revalidate the other one
|
|
107
|
-
* Another way is combining direct and indirect values with `formStatus` but the error appears or disappears too early
|
|
108
|
-
* So with this component we need only 1 validator making possible the best UX without caveats
|
|
109
|
-
*/
|
|
110
|
-
const CapitalTypeCheckboxes = ({ value, error, onChange }) => {
|
|
111
|
-
return (_jsxs(View, { children: [_jsxs(Box, { direction: "row", alignItems: "center", children: [_jsx(LakeLabelledCheckbox, { value: value === "direct" || value === "both", onValueChange: direct => {
|
|
112
|
-
match({ direct, value })
|
|
113
|
-
.with({ direct: true, value: "none" }, () => onChange("direct"))
|
|
114
|
-
.with({ direct: true, value: "indirect" }, () => onChange("both"))
|
|
115
|
-
.with({ direct: false, value: "direct" }, () => onChange("none"))
|
|
116
|
-
.with({ direct: false, value: "both" }, () => onChange("indirect"))
|
|
117
|
-
// other cases are impossible so we don't need to handle them
|
|
118
|
-
.otherwise(noop);
|
|
119
|
-
}, label: t("beneficiaryForm.beneficiary.directly"), isError: error != null }), _jsx(Space, { width: 24 }), _jsx(LakeLabelledCheckbox, { value: value === "indirect" || value === "both", onValueChange: indirect => {
|
|
120
|
-
match({ indirect, value })
|
|
121
|
-
.with({ indirect: true, value: "none" }, () => onChange("indirect"))
|
|
122
|
-
.with({ indirect: true, value: "direct" }, () => onChange("both"))
|
|
123
|
-
.with({ indirect: false, value: "indirect" }, () => onChange("none"))
|
|
124
|
-
.with({ indirect: false, value: "both" }, () => onChange("direct"))
|
|
125
|
-
// other cases are impossible so we don't need to handle them
|
|
126
|
-
.otherwise(noop);
|
|
127
|
-
}, label: t("beneficiaryForm.beneficiary.indirectly"), isError: error != null })] }), _jsx(Space, { height: 4 }), _jsx(LakeText, { color: colors.negative[400], children: error !== null && error !== void 0 ? error : " " })] }));
|
|
128
|
-
};
|
|
129
|
-
const formSteps = ["common", "address"];
|
|
130
|
-
const requiredStepFields = [
|
|
131
|
-
"firstName",
|
|
132
|
-
"lastName",
|
|
133
|
-
"birthDate",
|
|
134
|
-
"birthCountryCode",
|
|
135
|
-
"birthCity",
|
|
136
|
-
"birthCityPostalCode",
|
|
137
|
-
"type",
|
|
138
|
-
];
|
|
139
|
-
export const BeneficiaryForm = forwardRef(({ initialState, accountCountry, step, placekitApiKey, onStepChange, onClose, onSave, onCityLoadError, }, ref) => {
|
|
140
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
141
|
-
const [reference] = useState(() => { var _a; return (_a = initialState === null || initialState === void 0 ? void 0 : initialState.reference) !== null && _a !== void 0 ? _a : uuid(); });
|
|
142
|
-
const isAddressRequired = match(accountCountry)
|
|
143
|
-
.with("DEU", "ESP", () => true)
|
|
144
|
-
.otherwise(() => false);
|
|
145
|
-
const isBirthInfoRequired = match(accountCountry)
|
|
146
|
-
.with("ESP", "FRA", "NLD", () => true)
|
|
147
|
-
.otherwise(() => false);
|
|
148
|
-
const initialAddress = useRef({
|
|
149
|
-
residencyAddressLine1: initialState === null || initialState === void 0 ? void 0 : initialState.residencyAddressLine1,
|
|
150
|
-
residencyAddressCity: initialState === null || initialState === void 0 ? void 0 : initialState.residencyAddressCity,
|
|
151
|
-
residencyAddressPostalCode: initialState === null || initialState === void 0 ? void 0 : initialState.residencyAddressPostalCode,
|
|
152
|
-
});
|
|
153
|
-
const commonStepValues = useRef();
|
|
154
|
-
const initialBirthDate = initialState === null || initialState === void 0 ? void 0 : initialState.birthDate;
|
|
155
|
-
const { Field, FieldsListener, setFieldValue, submitForm, listenFields, validateField } = useForm({
|
|
156
|
-
firstName: {
|
|
157
|
-
initialValue: (_a = initialState === null || initialState === void 0 ? void 0 : initialState.firstName) !== null && _a !== void 0 ? _a : "",
|
|
158
|
-
validate: validateNullableRequired,
|
|
159
|
-
sanitize: value => value === null || value === void 0 ? void 0 : value.trim(),
|
|
160
|
-
},
|
|
161
|
-
lastName: {
|
|
162
|
-
initialValue: (_b = initialState === null || initialState === void 0 ? void 0 : initialState.lastName) !== null && _b !== void 0 ? _b : "",
|
|
163
|
-
validate: validateNullableRequired,
|
|
164
|
-
sanitize: value => value === null || value === void 0 ? void 0 : value.trim(),
|
|
165
|
-
},
|
|
166
|
-
birthDate: {
|
|
167
|
-
initialValue: isNotNullishOrEmpty(initialBirthDate)
|
|
168
|
-
? decodeBirthDate(initialBirthDate)
|
|
169
|
-
: "",
|
|
170
|
-
validate: isBirthInfoRequired ? validateNullableRequired : undefined,
|
|
171
|
-
sanitize: value => value === null || value === void 0 ? void 0 : value.trim(),
|
|
172
|
-
},
|
|
173
|
-
birthCountryCode: {
|
|
174
|
-
initialValue: (_c = initialState === null || initialState === void 0 ? void 0 : initialState.birthCountryCode) !== null && _c !== void 0 ? _c : accountCountry,
|
|
175
|
-
validate: validateNullableRequired,
|
|
176
|
-
},
|
|
177
|
-
birthCity: {
|
|
178
|
-
initialValue: (_d = initialState === null || initialState === void 0 ? void 0 : initialState.birthCity) !== null && _d !== void 0 ? _d : "",
|
|
179
|
-
validate: isBirthInfoRequired ? validateNullableRequired : undefined,
|
|
180
|
-
sanitize: value => value === null || value === void 0 ? void 0 : value.trim(),
|
|
181
|
-
},
|
|
182
|
-
birthCityPostalCode: {
|
|
183
|
-
initialValue: (_e = initialState === null || initialState === void 0 ? void 0 : initialState.birthCityPostalCode) !== null && _e !== void 0 ? _e : "",
|
|
184
|
-
validate: isBirthInfoRequired ? validateNullableRequired : undefined,
|
|
185
|
-
sanitize: value => value === null || value === void 0 ? void 0 : value.trim(),
|
|
186
|
-
},
|
|
187
|
-
type: {
|
|
188
|
-
initialValue: (_f = initialState === null || initialState === void 0 ? void 0 : initialState.type) !== null && _f !== void 0 ? _f : "HasCapital",
|
|
189
|
-
validate: validateRequired,
|
|
190
|
-
},
|
|
191
|
-
capitalType: {
|
|
192
|
-
initialValue: match({
|
|
193
|
-
direct: initialState === null || initialState === void 0 ? void 0 : initialState.direct,
|
|
194
|
-
indirect: initialState === null || initialState === void 0 ? void 0 : initialState.indirect,
|
|
195
|
-
})
|
|
196
|
-
.returnType()
|
|
197
|
-
.with({ direct: true, indirect: true }, () => "both")
|
|
198
|
-
.with({ direct: true }, () => "direct")
|
|
199
|
-
.with({ indirect: true }, () => "indirect")
|
|
200
|
-
.otherwise(() => "none"),
|
|
201
|
-
validate: (value, { getFieldValue }) => {
|
|
202
|
-
if (getFieldValue("type") === "HasCapital" && value === "none") {
|
|
203
|
-
return t("beneficiaryForm.beneficiary.directOrIndirect");
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
totalCapitalPercentage: {
|
|
208
|
-
initialValue: (_g = initialState === null || initialState === void 0 ? void 0 : initialState.totalCapitalPercentage) === null || _g === void 0 ? void 0 : _g.toString(),
|
|
209
|
-
validate: validateNullableRequired,
|
|
210
|
-
sanitize: value => value === null || value === void 0 ? void 0 : value.trim(),
|
|
211
|
-
},
|
|
212
|
-
address: {
|
|
213
|
-
initialValue: initialState === null || initialState === void 0 ? void 0 : initialState.residencyAddressLine1,
|
|
214
|
-
validate: isAddressRequired ? validateNullableRequired : undefined,
|
|
215
|
-
sanitize: value => value === null || value === void 0 ? void 0 : value.trim(),
|
|
216
|
-
},
|
|
217
|
-
city: {
|
|
218
|
-
initialValue: initialState === null || initialState === void 0 ? void 0 : initialState.residencyAddressCity,
|
|
219
|
-
validate: isAddressRequired ? validateNullableRequired : undefined,
|
|
220
|
-
sanitize: value => value === null || value === void 0 ? void 0 : value.trim(),
|
|
221
|
-
},
|
|
222
|
-
postalCode: {
|
|
223
|
-
initialValue: initialState === null || initialState === void 0 ? void 0 : initialState.residencyAddressPostalCode,
|
|
224
|
-
validate: isAddressRequired ? validateNullableRequired : undefined,
|
|
225
|
-
sanitize: value => value === null || value === void 0 ? void 0 : value.trim(),
|
|
226
|
-
},
|
|
227
|
-
country: {
|
|
228
|
-
initialValue: isCountryCCA3(initialState === null || initialState === void 0 ? void 0 : initialState.residencyAddressCountry)
|
|
229
|
-
? initialState === null || initialState === void 0 ? void 0 : initialState.residencyAddressCountry
|
|
230
|
-
: accountCountry,
|
|
231
|
-
validate: isAddressRequired ? validateNullableRequired : undefined,
|
|
232
|
-
},
|
|
233
|
-
taxIdentificationNumber: {
|
|
234
|
-
initialValue: initialState === null || initialState === void 0 ? void 0 : initialState.taxIdentificationNumber,
|
|
235
|
-
validate: (value, { getFieldValue }) => {
|
|
236
|
-
const uboCountry = getFieldValue("country");
|
|
237
|
-
if (accountCountry === "DEU" && uboCountry === "DEU") {
|
|
238
|
-
return combineValidators(validateNullableRequired, validateIndividualTaxNumber(accountCountry))(value);
|
|
239
|
-
}
|
|
240
|
-
return validateIndividualTaxNumber(accountCountry)(value);
|
|
241
|
-
},
|
|
242
|
-
sanitize: value => value === null || value === void 0 ? void 0 : value.trim(),
|
|
243
|
-
},
|
|
244
|
-
});
|
|
245
|
-
const hasBeenSubmittedOnce = useRef(false);
|
|
246
|
-
useEffect(() => {
|
|
247
|
-
if (initialState != null) {
|
|
248
|
-
// submit form to validate all fields
|
|
249
|
-
submitForm();
|
|
250
|
-
}
|
|
251
|
-
}, [initialState, submitForm]);
|
|
252
|
-
useEffect(() => {
|
|
253
|
-
// store address values on change to set initial values when user use cancel button and go back
|
|
254
|
-
// without this, address form part initial values stays empty and city and postal code aren't automatically mounted
|
|
255
|
-
return listenFields(["address", "city", "postalCode"], ({ address, city, postalCode }) => {
|
|
256
|
-
initialAddress.current = {
|
|
257
|
-
residencyAddressLine1: address === null || address === void 0 ? void 0 : address.value,
|
|
258
|
-
residencyAddressCity: city === null || city === void 0 ? void 0 : city.value,
|
|
259
|
-
residencyAddressPostalCode: postalCode === null || postalCode === void 0 ? void 0 : postalCode.value,
|
|
260
|
-
};
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
useEffect(() => {
|
|
264
|
-
return listenFields(["type"], () => {
|
|
265
|
-
if (hasBeenSubmittedOnce.current) {
|
|
266
|
-
// The setTimeout is needed here so that the `validateField`
|
|
267
|
-
// runs *after* the <Field /> mounts, as it's a no-op if not mounted
|
|
268
|
-
setTimeout(() => {
|
|
269
|
-
void validateField("totalCapitalPercentage");
|
|
270
|
-
}, 100);
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
}, [listenFields, validateField]);
|
|
274
|
-
useImperativeHandle(ref, () => {
|
|
275
|
-
return {
|
|
276
|
-
cancel: () => {
|
|
277
|
-
match(step)
|
|
278
|
-
.with("common", () => onClose())
|
|
279
|
-
.with("address", () => onStepChange("common"))
|
|
280
|
-
.exhaustive();
|
|
281
|
-
},
|
|
282
|
-
submit: () => {
|
|
283
|
-
hasBeenSubmittedOnce.current = true;
|
|
284
|
-
submitForm({
|
|
285
|
-
onSuccess: values => {
|
|
286
|
-
const firstStepValues = Option.allFromDict(pick(values, requiredStepFields));
|
|
287
|
-
if (step === "common" && isAddressRequired && firstStepValues.isSome()) {
|
|
288
|
-
commonStepValues.current = {
|
|
289
|
-
...firstStepValues.get(),
|
|
290
|
-
capitalType: values.capitalType.getWithDefault(undefined),
|
|
291
|
-
totalCapitalPercentage: values.totalCapitalPercentage.getWithDefault(undefined),
|
|
292
|
-
address: values.address.getWithDefault(undefined),
|
|
293
|
-
city: values.city.getWithDefault(undefined),
|
|
294
|
-
postalCode: values.postalCode.getWithDefault(undefined),
|
|
295
|
-
country: values.country.getWithDefault(undefined),
|
|
296
|
-
taxIdentificationNumber: values.taxIdentificationNumber.getWithDefault(undefined),
|
|
297
|
-
};
|
|
298
|
-
return onStepChange("address");
|
|
299
|
-
}
|
|
300
|
-
const secondStepValues = Option.allFromDict(pick({ ...commonStepValues.current, ...values }, requiredStepFields));
|
|
301
|
-
if (secondStepValues.isSome()) {
|
|
302
|
-
const { birthDate, ...rest } = secondStepValues.get();
|
|
303
|
-
const capitalType = values.capitalType.getWithDefault("none");
|
|
304
|
-
return onSave({
|
|
305
|
-
...rest,
|
|
306
|
-
reference,
|
|
307
|
-
birthDate: encodeBirthDate(birthDate),
|
|
308
|
-
direct: capitalType === "both" || capitalType === "direct",
|
|
309
|
-
indirect: capitalType === "both" || capitalType === "indirect",
|
|
310
|
-
totalCapitalPercentage: values.totalCapitalPercentage
|
|
311
|
-
.flatMap(value => Option.fromNullable(value))
|
|
312
|
-
.map(value => parseInt(value, 10))
|
|
313
|
-
.getWithDefault(undefined),
|
|
314
|
-
residencyAddressLine1: values.address.getWithDefault(undefined),
|
|
315
|
-
residencyAddressCity: values.city.getWithDefault(undefined),
|
|
316
|
-
residencyAddressCountry: values.country.getWithDefault(undefined),
|
|
317
|
-
residencyAddressPostalCode: values.postalCode.getWithDefault(undefined),
|
|
318
|
-
taxIdentificationNumber: values.taxIdentificationNumber.getWithDefault(undefined),
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
},
|
|
322
|
-
});
|
|
323
|
-
},
|
|
324
|
-
};
|
|
325
|
-
});
|
|
326
|
-
const onSuggestion = useCallback((place) => {
|
|
327
|
-
setFieldValue("address", place.completeAddress);
|
|
328
|
-
setFieldValue("city", place.city);
|
|
329
|
-
if (place.postalCode != null) {
|
|
330
|
-
setFieldValue("postalCode", place.postalCode);
|
|
331
|
-
}
|
|
332
|
-
}, [setFieldValue]);
|
|
333
|
-
return (_jsx(ResponsiveContainer, { breakpoint: breakpoints.tiny, children: ({ small }) => (_jsxs(_Fragment, { children: [match(step)
|
|
334
|
-
.with("common", () => (_jsxs(View, { role: "form", children: [_jsxs(Box, { direction: small ? "column" : "row", children: [_jsx(Field, { name: "firstName", children: ({ value, onChange, error }) => (_jsx(LakeLabel, { label: t("beneficiaryForm.beneficiary.firstName"), style: styles.inputContainer, render: id => (_jsx(LakeTextInput, { error: error, placeholder: t("beneficiaryForm.beneficiary.firstNamePlaceholder"), id: id, value: value, onChangeText: onChange })) })) }), _jsx(Space, { width: 12 }), _jsx(Field, { name: "lastName", children: ({ value, onChange, error }) => (_jsx(LakeLabel, { label: t("beneficiaryForm.beneficiary.lastName"), style: styles.inputContainer, render: id => (_jsx(LakeTextInput, { error: error, placeholder: t("beneficiaryForm.beneficiary.lastNamePlaceholder"), id: id, value: value, onChangeText: onChange })) })) })] }), _jsxs(Box, { direction: small ? "column" : "row", children: [_jsx(Field, { name: "birthDate", children: ({ value, onChange, error }) => (_jsx(LakeLabel, { label: t("beneficiaryForm.beneficiary.birthDate"), optionalLabel: isBirthInfoRequired ? undefined : t("common.optional"), style: styles.inputContainer, render: id => (_jsx(Rifm, { value: value !== null && value !== void 0 ? value : "", onChange: onChange, ...rifmDateProps, children: ({ value, onChange }) => (_jsx(LakeTextInput, { error: error, placeholder: locale.datePlaceholder, id: id, value: value, onChange: onChange })) })) })) }), _jsx(Space, { width: 12 }), _jsx(Field, { name: "birthCountryCode", children: ({ value, onChange, error }) => (_jsx(LakeLabel, { label: t("beneficiaryForm.beneficiary.birthCountry"), style: styles.inputContainer, render: id => (_jsx(CountryPicker, { id: id, error: error, value: value, placeholder: t("beneficiaryForm.beneficiary.birthCountryPlaceholder"), countries: allCountries, onValueChange: onChange })) })) })] }), _jsx(Box, { direction: small ? "column" : "row", children: _jsx(FieldsListener, { names: ["birthCountryCode"], children: ({ birthCountryCode }) => (_jsxs(_Fragment, { children: [_jsx(Field, { name: "birthCity", children: ({ value, onChange, error }) => (_jsx(LakeLabel, { label: t("beneficiaryForm.beneficiary.birthCity"), optionalLabel: isBirthInfoRequired ? undefined : t("common.optional"), style: styles.inputContainer, render: id => (_jsx(PlacekitCityInput, { id: id, apiKey: placekitApiKey, error: error, country: birthCountryCode.value, value: value !== null && value !== void 0 ? value : "", onValueChange: onChange, placeholder: birthCountryCode.value == null
|
|
335
|
-
? t("beneficiaryForm.beneficiary.fillBirthCountry")
|
|
336
|
-
: t("beneficiaryForm.beneficiary.birthCityPlaceholder"), onSuggestion: place => {
|
|
337
|
-
onChange(place.city);
|
|
338
|
-
if (place.postalCode != null) {
|
|
339
|
-
setFieldValue("birthCityPostalCode", place.postalCode);
|
|
340
|
-
}
|
|
341
|
-
}, onLoadError: onCityLoadError })) })) }), _jsx(Space, { width: 12 }), _jsx(Field, { name: "birthCityPostalCode", children: ({ value, onChange, error }) => (_jsx(LakeLabel, { label: t("beneficiaryForm.beneficiary.birthPostalCode"), optionalLabel: isBirthInfoRequired ? undefined : t("common.optional"), style: styles.inputContainer, render: id => (_jsx(LakeTextInput, { error: error, placeholder: birthCountryCode.value == null
|
|
342
|
-
? t("beneficiaryForm.beneficiary.fillBirthCountry")
|
|
343
|
-
: t("beneficiaryForm.beneficiary.birthPostalCodePlaceholder"), id: id, disabled: birthCountryCode.value === undefined, value: value, onChangeText: onChange })) })) })] })) }) }), _jsx(Field, { name: "type", children: ({ value, onChange }) => (_jsx(LakeLabel, { label: t("beneficiaryForm.beneficiary.type"), type: "radioGroup", render: () => (_jsx(RadioGroup, { direction: "row", value: value, onValueChange: onChange, items: beneficiaryTypes })) })) }), _jsx(FieldsListener, { names: ["type"], children: ({ type }) => type.value === "HasCapital" ? (_jsxs(_Fragment, { children: [_jsx(Field, { name: "totalCapitalPercentage", children: ({ value, onChange, error }) => (_jsx(LakeLabel, { label: t("beneficiaryForm.beneficiary.totalCapitalPercentage"), render: id => (_jsx(LakeTextInput, { error: error, unit: "%", inputMode: "decimal", "aria-valuemin": 0, "aria-valuemax": 100, id: id, value: value, onChangeText: onChange })) })) }), _jsx(Space, { height: 12 }), _jsx(Field, { name: "capitalType", children: ({ value, error, onChange }) => (_jsx(CapitalTypeCheckboxes, { value: value !== null && value !== void 0 ? value : "none", error: error, onChange: onChange })) })] })) : null })] })))
|
|
344
|
-
.with("address", () => (_jsxs(View, { role: "form", children: [_jsx(Field, { name: "country", children: ({ value, onChange }) => (_jsx(LakeLabel, { label: t("beneficiaryForm.beneficiary.country"), render: id => (_jsx(CountryPicker, { id: id, value: value, countries: allCountries, onValueChange: onChange })) })) }), _jsx(Space, { height: 12 }), _jsx(FieldsListener, { names: ["country"], children: ({ country }) => (_jsxs(_Fragment, { children: [_jsx(Field, { name: "address", children: ({ ref, value, onChange, error }) => (_jsx(LakeLabel, { label: t("beneficiaryForm.beneficiary.address"), render: id => {
|
|
345
|
-
var _a;
|
|
346
|
-
return (_jsx(PlacekitAddressSearchInput, { inputRef: ref, apiKey: placekitApiKey, emptyResultText: t("common.noResult"), placeholder: t("addressFormPart.placeholder"), language: locale.language, id: id, country: (_a = country.value) !== null && _a !== void 0 ? _a : accountCountry, value: value, error: error, onValueChange: onChange, onSuggestion: onSuggestion }));
|
|
347
|
-
} })) }), _jsx(Space, { height: 12 }), _jsx(Field, { name: "city", children: ({ ref, value, valid, error, onChange }) => (_jsx(LakeLabel, { label: t("addressFormPart.cityLabel"), render: id => (_jsx(LakeTextInput, { ref: ref, id: id, value: value, valid: valid, error: error, onChangeText: onChange })) })) }), _jsx(Space, { height: 12 }), _jsx(Field, { name: "postalCode", children: ({ ref, value, valid, error, onChange }) => (_jsx(LakeLabel, { label: t("addressFormPart.postCodeLabel"), render: id => (_jsx(LakeTextInput, { ref: ref, id: id, value: value, valid: valid, error: error, onChangeText: onChange })) })) }), ((accountCountry === "DEU" && (country === null || country === void 0 ? void 0 : country.value) === "DEU") ||
|
|
348
|
-
accountCountry === "ESP") && (_jsxs(_Fragment, { children: [_jsx(Space, { height: 12 }), _jsx(Field, { name: "taxIdentificationNumber", children: ({ value, error, valid, onChange }) => (_jsx(TaxIdentificationNumberInput, { value: value !== null && value !== void 0 ? value : "", error: error, valid: valid, onChange: onChange, accountCountry: accountCountry, isCompany: false,
|
|
349
|
-
// is mandatory for German accounts with UBO living in Germany
|
|
350
|
-
required: accountCountry === "DEU" && (country === null || country === void 0 ? void 0 : country.value) === "DEU" })) })] }))] })) })] })))
|
|
351
|
-
.exhaustive(), isAddressRequired && (_jsxs(_Fragment, { children: [_jsx(Space, { height: 12 }), _jsx(StepDots, { currentStep: step, steps: formSteps })] }))] })) }));
|
|
352
|
-
});
|