@afosto/checkout-ui 0.0.10 → 0.0.11
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/dist/CheckoutInformationStep/CheckoutInformationStep.d.ts +2 -0
- package/dist/CheckoutInformationStep/CheckoutInformationStep.d.ts.map +1 -1
- package/dist/CheckoutInformationStep/CheckoutInformationStep.js +37 -30
- package/dist/CheckoutProvider/CheckoutProvider.d.ts.map +1 -1
- package/dist/CheckoutProvider/CheckoutProvider.js +22 -20
- package/dist/CheckoutSalutationSection/CheckoutSalutationSection.d.ts +13 -0
- package/dist/CheckoutSalutationSection/CheckoutSalutationSection.d.ts.map +1 -0
- package/dist/CheckoutSalutationSection/CheckoutSalutationSection.js +26 -0
- package/dist/CheckoutSalutationSection/index.d.ts +3 -0
- package/dist/CheckoutSalutationSection/index.d.ts.map +1 -0
- package/dist/CheckoutSalutationSection/index.js +4 -0
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +422 -420
- package/dist/steps/informationStep.d.ts +1 -0
- package/dist/steps/informationStep.d.ts.map +1 -1
- package/dist/steps/informationStep.js +238 -234
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -2,8 +2,8 @@ import { CheckoutInformationStep as ni } from "../CheckoutInformationStep/Checko
|
|
|
2
2
|
import { addressDefaultValues as q } from "../constants/addressDefaultValues.js";
|
|
3
3
|
import { formatAddressResponse as j } from "../utils/formatAddressResponse.js";
|
|
4
4
|
import { getErrorMessage as W } from "../utils/getErrorMessage.js";
|
|
5
|
-
import { capitalize as X, isDefined as
|
|
6
|
-
import * as
|
|
5
|
+
import { capitalize as X, isDefined as O } from "@afosto/utils";
|
|
6
|
+
import * as a from "yup";
|
|
7
7
|
import { formatUpdateAccountInformationPayload as si } from "../utils/formatUpdateAccountInformationPayload.js";
|
|
8
8
|
import { formatUpdateOrganisationOnAccountPayload as ri } from "../utils/formatUpdateOrganisationOnAccountPayload.js";
|
|
9
9
|
import { setupCustomValidationRules as ti } from "../utils/setupCustomValidationRules.js";
|
|
@@ -25,10 +25,10 @@ const ai = {
|
|
|
25
25
|
"shippingAddress",
|
|
26
26
|
"billingAddress"
|
|
27
27
|
],
|
|
28
|
-
defaultValues: (
|
|
29
|
-
const { defaultCountry:
|
|
28
|
+
defaultValues: (I) => {
|
|
29
|
+
const { defaultCountry: d, formatCountryAsOption: S, settings: R } = I || {}, { isB2cExcluded: f, isSharedOrganisationRequired: s } = R || {};
|
|
30
30
|
return {
|
|
31
|
-
type:
|
|
31
|
+
type: f ? "business" : "private",
|
|
32
32
|
contact: null,
|
|
33
33
|
email: "",
|
|
34
34
|
emailOptIn: !1,
|
|
@@ -38,188 +38,189 @@ const ai = {
|
|
|
38
38
|
cocNumber: "",
|
|
39
39
|
type: s ? "SHARED" : "DEFAULT",
|
|
40
40
|
vatNumber: "",
|
|
41
|
-
vatNumberCountry:
|
|
41
|
+
vatNumberCountry: f && d ? S(d) : null
|
|
42
42
|
},
|
|
43
43
|
password: "",
|
|
44
44
|
passwordConfirm: "",
|
|
45
45
|
phoneNumber: "",
|
|
46
|
-
phoneNumberCountry:
|
|
46
|
+
phoneNumberCountry: d ? S(d) : null,
|
|
47
47
|
phoneNumberId: "",
|
|
48
48
|
phoneNumberIsDirty: !1,
|
|
49
|
+
salutation: "",
|
|
49
50
|
sameBillingAsShippingAddress: !0,
|
|
50
51
|
shipping: {
|
|
51
52
|
...q,
|
|
52
|
-
country:
|
|
53
|
-
countryCode:
|
|
53
|
+
country: d ? S(d) : null,
|
|
54
|
+
countryCode: d ? d.alpha2Code : ""
|
|
54
55
|
},
|
|
55
56
|
shippingAddressId: "",
|
|
56
57
|
billing: {
|
|
57
58
|
...q,
|
|
58
|
-
country:
|
|
59
|
-
countryCode:
|
|
59
|
+
country: d ? S(d) : null,
|
|
60
|
+
countryCode: d ? d.alpha2Code : ""
|
|
60
61
|
},
|
|
61
62
|
billingAddressId: "",
|
|
62
63
|
shouldCreateAccount: !1
|
|
63
64
|
};
|
|
64
65
|
},
|
|
65
|
-
initialize: (
|
|
66
|
+
initialize: (I, d, S) => {
|
|
66
67
|
const {
|
|
67
|
-
defaultCountry:
|
|
68
|
-
formatCountryAsOption:
|
|
68
|
+
defaultCountry: R,
|
|
69
|
+
formatCountryAsOption: f,
|
|
69
70
|
getCountryByCode: s,
|
|
70
|
-
settings:
|
|
71
|
-
step:
|
|
72
|
-
} =
|
|
71
|
+
settings: v,
|
|
72
|
+
step: D
|
|
73
|
+
} = S || {}, { defaultValues: m } = D || {}, { addressOptions: p } = d || {}, { countryCode: C } = p || {}, { isB2bExcluded: U, isB2cExcluded: $ } = v || {}, n = typeof m == "function" ? m(S) : m, {
|
|
73
74
|
billing: M,
|
|
74
75
|
customer: e,
|
|
75
|
-
delivery:
|
|
76
|
-
expressPayment:
|
|
76
|
+
delivery: b,
|
|
77
|
+
expressPayment: h,
|
|
77
78
|
options: i,
|
|
78
79
|
phoneNumber: o
|
|
79
|
-
} =
|
|
80
|
+
} = I || {}, {
|
|
80
81
|
contact: t,
|
|
81
|
-
countryCode:
|
|
82
|
+
countryCode: l,
|
|
82
83
|
organisation: r
|
|
83
|
-
} = e || {}, { address:
|
|
84
|
+
} = e || {}, { address: N } = M || {}, { address: P } = b || {}, { address: E, customer: c } = h?.details?.express || {}, { shipping: x } = i || {}, { countries: V } = x || {}, A = s(C) || R, B = s(l), g = !!r?.id && !U || $, _ = g ? r?.phoneNumbers?.primary : t?.phoneNumbers?.primary, w = s(
|
|
84
85
|
o?.countryCode || _?.countryCode
|
|
85
|
-
) ||
|
|
86
|
+
) || B || A || null, [L] = w?.callingCodes || [], k = (O(o?.number) ? o.number : _?.number || n.phoneNumber).replace(`+${L}`, ""), T = g ? r?.addressing?.shipping?.primary : t?.addressing?.shipping?.primary, u = j(
|
|
86
87
|
P?.addressLine1 ? P : E || T || {}
|
|
87
88
|
);
|
|
88
89
|
let G = null;
|
|
89
|
-
if (
|
|
90
|
-
G =
|
|
91
|
-
else if (
|
|
92
|
-
G =
|
|
90
|
+
if (B && V?.includes(B?.alpha2Code))
|
|
91
|
+
G = B;
|
|
92
|
+
else if (A && V?.includes(A?.alpha2Code))
|
|
93
|
+
G = A;
|
|
93
94
|
else {
|
|
94
95
|
const [ei] = V || [];
|
|
95
96
|
G = s(ei);
|
|
96
97
|
}
|
|
97
|
-
const J = s(
|
|
98
|
+
const J = s(u?.countryCode) || G, F = O(J) ? f(J) : n.shipping.country, z = u?.administrativeArea || n.shipping.administrativeArea, Y = z && typeof z == "string" ? {
|
|
98
99
|
code: z,
|
|
99
100
|
label: z,
|
|
100
101
|
value: z
|
|
101
|
-
} : z, Z =
|
|
102
|
-
|
|
103
|
-
), K = s(
|
|
102
|
+
} : z, Z = g ? r?.addressing?.billing?.primary : t?.addressing?.billing?.primary, y = j(
|
|
103
|
+
N?.addressLine1 ? N : Z || {}
|
|
104
|
+
), K = s(y?.countryCode) || A, Q = O(K) ? f(K) : n.billing.country, H = y?.administrativeArea || n.billing.administrativeArea, ii = H && typeof H == "string" ? {
|
|
104
105
|
code: H,
|
|
105
106
|
label: H,
|
|
106
107
|
value: H
|
|
107
108
|
} : H;
|
|
108
109
|
return {
|
|
109
110
|
...n,
|
|
110
|
-
defaultCountry:
|
|
111
|
-
type:
|
|
111
|
+
defaultCountry: f(A),
|
|
112
|
+
type: g ? "business" : "private",
|
|
112
113
|
contact: t || null,
|
|
113
|
-
email:
|
|
114
|
+
email: g ? r?.administration?.email || t?.email || c?.email || n.email : t?.email || c?.email || n.email,
|
|
114
115
|
organisation: {
|
|
115
116
|
...n.organisation,
|
|
116
|
-
...
|
|
117
|
+
...g ? {
|
|
117
118
|
id: r?.id || n.organisation.id,
|
|
118
119
|
name: r?.name || n.organisation.name,
|
|
119
120
|
cocNumber: r?.cocNumber || n.organisation.cocNumber,
|
|
120
121
|
type: r?.type || n.organisation.type,
|
|
121
122
|
vatNumber: r?.vatNumber || n.organisation.vatNumber,
|
|
122
|
-
vatNumberCountry:
|
|
123
|
-
s(r?.registration?.countryCode) ||
|
|
123
|
+
vatNumberCountry: f(
|
|
124
|
+
s(r?.registration?.countryCode) || A
|
|
124
125
|
)
|
|
125
126
|
} : {
|
|
126
|
-
vatNumberCountry:
|
|
127
|
+
vatNumberCountry: f(A)
|
|
127
128
|
}
|
|
128
129
|
},
|
|
129
130
|
phoneNumber: k,
|
|
130
|
-
phoneNumberCountry:
|
|
131
|
+
phoneNumberCountry: O(w) ? f(w) : n.phoneNumberCountry,
|
|
131
132
|
phoneNumberId: o?.id || _?.id || n.phoneNumberId,
|
|
132
133
|
shipping: {
|
|
133
134
|
...n.shipping,
|
|
134
|
-
givenName:
|
|
135
|
-
additionalName:
|
|
136
|
-
familyName:
|
|
137
|
-
address_line_1:
|
|
138
|
-
address_line_2:
|
|
139
|
-
addressLine1:
|
|
140
|
-
addressLine2:
|
|
135
|
+
givenName: u?.givenName || (g ? void 0 : t?.givenName) || n.shipping.givenName,
|
|
136
|
+
additionalName: u?.additionalName || (g ? void 0 : t?.additionalName) || n.shipping.additionalName,
|
|
137
|
+
familyName: u?.familyName || (g ? void 0 : t?.familyName) || n.shipping.familyName,
|
|
138
|
+
address_line_1: u?.address_line_1 || n.shipping.address_line_1,
|
|
139
|
+
address_line_2: u?.address_line_2 || n.shipping.address_line_2,
|
|
140
|
+
addressLine1: u?.addressLine1 || n.shipping.addressLine1,
|
|
141
|
+
addressLine2: u?.addressLine2 || n.shipping.addressLine2,
|
|
141
142
|
country: F,
|
|
142
143
|
countryCode: F?.value || n.shipping.countryCode,
|
|
143
|
-
organisation:
|
|
144
|
-
postalCode:
|
|
145
|
-
premiseNumber:
|
|
146
|
-
premiseNumberSuffix:
|
|
147
|
-
thoroughfare:
|
|
148
|
-
locality:
|
|
144
|
+
organisation: u?.organisation || n.shipping.organisation,
|
|
145
|
+
postalCode: u?.postalCode || n.shipping.postalCode,
|
|
146
|
+
premiseNumber: u?.premiseNumber || n.shipping.premiseNumber,
|
|
147
|
+
premiseNumberSuffix: u?.premiseNumberSuffix || n.shipping.premiseNumberSuffix,
|
|
148
|
+
thoroughfare: u?.thoroughfare || n.shipping.thoroughfare,
|
|
149
|
+
locality: u?.locality || n.shipping.locality,
|
|
149
150
|
administrativeArea: Y
|
|
150
151
|
},
|
|
151
|
-
shippingAddressId:
|
|
152
|
+
shippingAddressId: u?.id || n.shippingAddressId,
|
|
152
153
|
billing: {
|
|
153
154
|
...n.billing,
|
|
154
|
-
givenName:
|
|
155
|
-
additionalName:
|
|
156
|
-
familyName:
|
|
157
|
-
address_line_1:
|
|
158
|
-
address_line_2:
|
|
159
|
-
addressLine1:
|
|
160
|
-
addressLine2:
|
|
155
|
+
givenName: y?.givenName || n.billing.givenName,
|
|
156
|
+
additionalName: y?.additionalName || n.billing.additionalName,
|
|
157
|
+
familyName: y?.familyName || n.billing.familyName,
|
|
158
|
+
address_line_1: y?.address_line_1 || n.billing.address_line_1,
|
|
159
|
+
address_line_2: y?.address_line_2 || n.billing.address_line_2,
|
|
160
|
+
addressLine1: y?.addressLine1 || n.billing.addressLine1,
|
|
161
|
+
addressLine2: y?.addressLine2 || n.billing.addressLine2,
|
|
161
162
|
country: Q,
|
|
162
163
|
countryCode: Q?.value || n.billing.countryCode,
|
|
163
|
-
organisation:
|
|
164
|
-
postalCode:
|
|
165
|
-
premiseNumber:
|
|
166
|
-
premiseNumberSuffix:
|
|
167
|
-
thoroughfare:
|
|
168
|
-
locality:
|
|
164
|
+
organisation: y?.organisation || n.billing.organisation,
|
|
165
|
+
postalCode: y?.postalCode || n.billing.postalCode,
|
|
166
|
+
premiseNumber: y?.premiseNumber || n.billing.premiseNumber,
|
|
167
|
+
premiseNumberSuffix: y?.premiseNumberSuffix || n.billing.premiseNumberSuffix,
|
|
168
|
+
thoroughfare: y?.thoroughfare || n.billing.thoroughfare,
|
|
169
|
+
locality: y?.locality || n.billing.locality,
|
|
169
170
|
administrativeArea: ii
|
|
170
171
|
},
|
|
171
|
-
billingAddressId:
|
|
172
|
-
sameBillingAsShippingAddress:
|
|
172
|
+
billingAddressId: y?.id || n.billingAddressId,
|
|
173
|
+
sameBillingAsShippingAddress: O(y?.id) && O(u?.id) ? y?.id === u?.id : n.sameBillingAsShippingAddress
|
|
173
174
|
};
|
|
174
175
|
},
|
|
175
|
-
isComplete: (
|
|
176
|
-
const { step:
|
|
177
|
-
return
|
|
176
|
+
isComplete: (I, d) => {
|
|
177
|
+
const { step: S } = d || {};
|
|
178
|
+
return S.validationSchema(d).isValidSync(I);
|
|
178
179
|
},
|
|
179
|
-
onEvent: async (
|
|
180
|
-
const { step:
|
|
181
|
-
activeStep:
|
|
182
|
-
addCustomer:
|
|
183
|
-
formRef:
|
|
184
|
-
formatCountryAsOption:
|
|
185
|
-
getCountryByCode:
|
|
180
|
+
onEvent: async (I, d, S, R) => {
|
|
181
|
+
const { step: f, stepIndex: s } = S || {}, {
|
|
182
|
+
activeStep: v,
|
|
183
|
+
addCustomer: D,
|
|
184
|
+
formRef: m,
|
|
185
|
+
formatCountryAsOption: p,
|
|
186
|
+
getCountryByCode: C,
|
|
186
187
|
settings: U
|
|
187
|
-
} =
|
|
188
|
-
if (
|
|
189
|
-
const { user:
|
|
188
|
+
} = R || {}, { isB2bExcluded: $, isB2cExcluded: n } = U || {}, M = m.current?.formProps?.data || [], e = v === s ? m.current?.getValues() : M[s] ?? {}, b = typeof f.defaultValues == "function" ? f.defaultValues(R) : f.defaultValues;
|
|
189
|
+
if (I === "signedIn") {
|
|
190
|
+
const { user: h, account: i } = d || {};
|
|
190
191
|
let o = e?.contact;
|
|
191
|
-
|
|
192
|
+
h?.id && e?.contact?.id !== h?.id && (o = (await D({
|
|
192
193
|
customer: {
|
|
193
|
-
contactId:
|
|
194
|
+
contactId: h.id
|
|
194
195
|
}
|
|
195
196
|
}))?.customer?.contact);
|
|
196
|
-
const [t] = i?.billing || [], [
|
|
197
|
+
const [t] = i?.billing || [], [l] = i?.shipping || [], [r] = i?.organisations || [], [N] = i?.phoneNumbers || [], P = C(N?.countryCode) || e?.defaultCountry, [E] = P?.callingCodes || [], c = l ? j(l) : null, {
|
|
197
198
|
id: x,
|
|
198
199
|
isValid: V,
|
|
199
|
-
...
|
|
200
|
-
} =
|
|
200
|
+
...A
|
|
201
|
+
} = c || {}, B = A?.countryCode ? p(C(A.countryCode)) : e?.defaultCountry, g = t ? j(t) : null, {
|
|
201
202
|
id: _,
|
|
202
203
|
isValid: w,
|
|
203
204
|
...L
|
|
204
|
-
} =
|
|
205
|
+
} = g || {}, k = L?.countryCode ? p(C(L.countryCode)) : e?.defaultCountry, T = !$ && r?.id || n, u = T && r?.administration?.email || i?.email, J = {
|
|
205
206
|
...e,
|
|
206
|
-
...
|
|
207
|
+
...b || {},
|
|
207
208
|
contact: o,
|
|
208
|
-
email:
|
|
209
|
+
email: u,
|
|
209
210
|
type: T ? "business" : "private",
|
|
210
|
-
...
|
|
211
|
-
phoneNumber:
|
|
211
|
+
...N ? {
|
|
212
|
+
phoneNumber: N.number?.replace(
|
|
212
213
|
`+${E}`,
|
|
213
214
|
""
|
|
214
215
|
),
|
|
215
216
|
phoneNumberCountry: P,
|
|
216
|
-
phoneNumberId:
|
|
217
|
+
phoneNumberId: N?.id || ""
|
|
217
218
|
} : {
|
|
218
219
|
phoneNumberCountry: e.defaultCountry
|
|
219
220
|
},
|
|
220
221
|
organisation: T ? {
|
|
221
222
|
...e?.organisation || {},
|
|
222
|
-
...
|
|
223
|
+
...b?.organisation || {},
|
|
223
224
|
id: r?.id || "",
|
|
224
225
|
name: r?.name || "",
|
|
225
226
|
cocNumber: r?.cocNumber || "",
|
|
@@ -227,14 +228,14 @@ const ai = {
|
|
|
227
228
|
isVatNumberRequired: e?.organisation?.isVatNumberRequired ?? !1,
|
|
228
229
|
type: r?.type || "DEFAULT",
|
|
229
230
|
vatNumber: r?.registration?.number || "",
|
|
230
|
-
vatNumberCountry:
|
|
231
|
-
|
|
231
|
+
vatNumberCountry: p(
|
|
232
|
+
C(
|
|
232
233
|
r?.registration?.countryCode
|
|
233
234
|
) || e?.defaultCountry
|
|
234
235
|
)
|
|
235
236
|
} : {
|
|
236
237
|
...e?.organisation || {},
|
|
237
|
-
...
|
|
238
|
+
...b?.organisation || {},
|
|
238
239
|
isCocNumberRequired: e?.organisation?.isCocNumberRequired ?? !1,
|
|
239
240
|
isVatNumberRequired: e?.organisation?.isVatNumberRequired ?? !1,
|
|
240
241
|
vatNumberCountry: e.defaultCountry
|
|
@@ -250,91 +251,91 @@ const ai = {
|
|
|
250
251
|
country: e.defaultCountry
|
|
251
252
|
},
|
|
252
253
|
billingAddressId: _ || "",
|
|
253
|
-
shipping:
|
|
254
|
+
shipping: l ? {
|
|
254
255
|
...e.shipping,
|
|
255
256
|
...q,
|
|
256
|
-
...
|
|
257
|
-
country:
|
|
257
|
+
...A,
|
|
258
|
+
country: B
|
|
258
259
|
} : {
|
|
259
260
|
...e.shipping,
|
|
260
261
|
...q,
|
|
261
262
|
country: e.defaultCountry
|
|
262
263
|
},
|
|
263
264
|
shippingAddressId: x || "",
|
|
264
|
-
sameBillingAsShippingAddress:
|
|
265
|
+
sameBillingAsShippingAddress: O(_) || O(_) && _ === x
|
|
265
266
|
};
|
|
266
|
-
i && (
|
|
267
|
+
i && (v === s && m.current?.reset({
|
|
267
268
|
...e,
|
|
268
269
|
...J
|
|
269
|
-
}),
|
|
270
|
+
}), m.current?.formProps?.setData((F) => (F.splice(s, 1, {
|
|
270
271
|
...F[s],
|
|
271
272
|
...J
|
|
272
273
|
}), F)));
|
|
273
274
|
}
|
|
274
|
-
if (
|
|
275
|
-
const { sessionExpired:
|
|
275
|
+
if (I === "clearSession") {
|
|
276
|
+
const { sessionExpired: h, shouldCreateAccount: i } = d || {}, o = {
|
|
276
277
|
...e,
|
|
277
|
-
...
|
|
278
|
+
...h ? b || {} : {},
|
|
278
279
|
shouldCreateAccount: i ?? !1
|
|
279
280
|
};
|
|
280
|
-
|
|
281
|
+
v === s && m.current?.reset({
|
|
281
282
|
...e,
|
|
282
283
|
...o
|
|
283
|
-
}),
|
|
284
|
+
}), m.current?.formProps?.setData((t) => (t.splice(s, 1, {
|
|
284
285
|
...t[s],
|
|
285
286
|
...o
|
|
286
287
|
}), t));
|
|
287
288
|
}
|
|
288
|
-
if (
|
|
289
|
-
const { account:
|
|
290
|
-
id:
|
|
289
|
+
if (I === "accountSelected") {
|
|
290
|
+
const { account: h, user: i } = d || {}, [o] = h?.billing || [], [t] = h?.shipping || [], [l] = h?.organisations || [], [r] = h?.phoneNumbers || [], N = C(r?.countryCode) || e?.defaultCountry, [P] = N?.callingCodes || [], E = t ? j(t) : null, {
|
|
291
|
+
id: c,
|
|
291
292
|
isValid: x,
|
|
292
293
|
...V
|
|
293
|
-
} = E || {},
|
|
294
|
-
id:
|
|
294
|
+
} = E || {}, A = V?.countryCode ? p(C(V.countryCode)) : e?.defaultCountry, B = o ? j(o) : null, {
|
|
295
|
+
id: g,
|
|
295
296
|
isValid: _,
|
|
296
297
|
...w
|
|
297
|
-
} =
|
|
298
|
-
await
|
|
298
|
+
} = B || {}, L = w?.countryCode ? p(C(w.countryCode)) : e?.defaultCountry, k = !$ && l?.id || n;
|
|
299
|
+
await D({
|
|
299
300
|
customer: {
|
|
300
301
|
contactId: i.id,
|
|
301
|
-
...k &&
|
|
302
|
+
...k && l?.id ? { organisationId: l?.id } : {}
|
|
302
303
|
}
|
|
303
304
|
});
|
|
304
305
|
const T = {
|
|
305
306
|
...e,
|
|
306
|
-
...
|
|
307
|
+
...b || {},
|
|
307
308
|
contact: e?.contact,
|
|
308
|
-
email: k &&
|
|
309
|
+
email: k && l?.administration?.email || h?.email,
|
|
309
310
|
type: k ? "business" : "private",
|
|
310
311
|
...r ? {
|
|
311
312
|
phoneNumber: r.number?.replace(
|
|
312
313
|
`+${P}`,
|
|
313
314
|
""
|
|
314
315
|
),
|
|
315
|
-
phoneNumberCountry:
|
|
316
|
+
phoneNumberCountry: N,
|
|
316
317
|
phoneNumberId: r?.id || ""
|
|
317
318
|
} : {
|
|
318
319
|
phoneNumberCountry: e.defaultCountry
|
|
319
320
|
},
|
|
320
321
|
organisation: k ? {
|
|
321
322
|
...e?.organisation || {},
|
|
322
|
-
...
|
|
323
|
-
id:
|
|
324
|
-
name:
|
|
325
|
-
cocNumber:
|
|
323
|
+
...b?.organisation || {},
|
|
324
|
+
id: l?.id || "",
|
|
325
|
+
name: l?.name || "",
|
|
326
|
+
cocNumber: l?.cocNumber || "",
|
|
326
327
|
isCocNumberRequired: e?.organisation?.isCocNumberRequired ?? !1,
|
|
327
328
|
isVatNumberRequired: e?.organisation?.isVatNumberRequired ?? !1,
|
|
328
|
-
type:
|
|
329
|
-
vatNumber:
|
|
330
|
-
vatNumberCountry:
|
|
331
|
-
|
|
332
|
-
|
|
329
|
+
type: l?.type || "DEFAULT",
|
|
330
|
+
vatNumber: l?.registration?.number || "",
|
|
331
|
+
vatNumberCountry: p(
|
|
332
|
+
C(
|
|
333
|
+
l?.registration?.countryCode
|
|
333
334
|
) || e?.defaultCountry
|
|
334
335
|
)
|
|
335
336
|
} : {
|
|
336
337
|
...e?.organisation || {},
|
|
337
|
-
...
|
|
338
|
+
...b?.organisation || {},
|
|
338
339
|
isCocNumberRequired: e?.organisation?.isCocNumberRequired ?? !1,
|
|
339
340
|
isVatNumberRequired: e?.organisation?.isVatNumberRequired ?? !1,
|
|
340
341
|
vatNumberCountry: e.defaultCountry
|
|
@@ -349,71 +350,71 @@ const ai = {
|
|
|
349
350
|
...q,
|
|
350
351
|
country: e.defaultCountry
|
|
351
352
|
},
|
|
352
|
-
billingAddressId:
|
|
353
|
+
billingAddressId: g || "",
|
|
353
354
|
shipping: t ? {
|
|
354
355
|
...e.shipping,
|
|
355
356
|
...q,
|
|
356
357
|
...V,
|
|
357
|
-
country:
|
|
358
|
+
country: A
|
|
358
359
|
} : {
|
|
359
360
|
...e.shipping,
|
|
360
361
|
...q,
|
|
361
362
|
country: e.defaultCountry
|
|
362
363
|
},
|
|
363
|
-
shippingAddressId:
|
|
364
|
-
sameBillingAsShippingAddress: !
|
|
364
|
+
shippingAddressId: c || "",
|
|
365
|
+
sameBillingAsShippingAddress: !O(g) || O(g) && g === c
|
|
365
366
|
};
|
|
366
|
-
|
|
367
|
+
v === s && m.current?.reset({
|
|
367
368
|
...e,
|
|
368
369
|
...T
|
|
369
|
-
}),
|
|
370
|
-
...
|
|
370
|
+
}), m.current?.formProps?.setData((u) => (u.splice(s, 1, {
|
|
371
|
+
...u[s],
|
|
371
372
|
...T
|
|
372
|
-
}),
|
|
373
|
+
}), u));
|
|
373
374
|
}
|
|
374
|
-
if (
|
|
375
|
-
const { account:
|
|
376
|
-
await
|
|
375
|
+
if (I === "businessAccountSelected") {
|
|
376
|
+
const { account: h, organisation: i, user: o } = d || {};
|
|
377
|
+
await D({
|
|
377
378
|
customer: {
|
|
378
379
|
contactId: o.id,
|
|
379
380
|
organisationId: i?.id
|
|
380
381
|
}
|
|
381
382
|
});
|
|
382
383
|
const t = i?.addressing?.billing?.primary ? j(i?.addressing?.billing?.primary) : null, {
|
|
383
|
-
id:
|
|
384
|
+
id: l,
|
|
384
385
|
isValid: r,
|
|
385
|
-
...
|
|
386
|
-
} = t || {}, P =
|
|
387
|
-
N
|
|
386
|
+
...N
|
|
387
|
+
} = t || {}, P = N?.countryCode ? p(
|
|
388
|
+
C(N.countryCode)
|
|
388
389
|
) : e?.defaultCountry, E = i?.addressing?.shipping?.primary ? j(i?.addressing?.shipping?.primary) : null, {
|
|
389
|
-
id:
|
|
390
|
+
id: c,
|
|
390
391
|
isValid: x,
|
|
391
392
|
...V
|
|
392
|
-
} = E || {},
|
|
393
|
-
|
|
394
|
-
) : e?.defaultCountry,
|
|
393
|
+
} = E || {}, A = V?.countryCode ? p(
|
|
394
|
+
C(V.countryCode)
|
|
395
|
+
) : e?.defaultCountry, B = i?.phoneNumbers?.primary, g = C(B?.countryCode) || e?.defaultCountry, [_] = g?.callingCodes || [], w = {
|
|
395
396
|
...e,
|
|
396
|
-
...
|
|
397
|
+
...b || {}
|
|
397
398
|
};
|
|
398
|
-
|
|
399
|
+
v === s && m.current?.reset({
|
|
399
400
|
...e,
|
|
400
401
|
...w,
|
|
401
402
|
contact: e?.contact,
|
|
402
|
-
email: i?.administration?.email ||
|
|
403
|
+
email: i?.administration?.email || h?.email || "",
|
|
403
404
|
type: "business",
|
|
404
|
-
...
|
|
405
|
-
phoneNumber:
|
|
405
|
+
...B ? {
|
|
406
|
+
phoneNumber: B?.number?.replace(
|
|
406
407
|
`+${_}`,
|
|
407
408
|
""
|
|
408
409
|
),
|
|
409
|
-
phoneNumberCountry:
|
|
410
|
-
phoneNumberId:
|
|
410
|
+
phoneNumberCountry: g,
|
|
411
|
+
phoneNumberId: B?.id || ""
|
|
411
412
|
} : {
|
|
412
413
|
phoneNumberCountry: e.defaultCountry
|
|
413
414
|
},
|
|
414
415
|
organisation: i ? {
|
|
415
416
|
...e?.organisation || {},
|
|
416
|
-
...
|
|
417
|
+
...b?.organisation || {},
|
|
417
418
|
id: i?.id || "",
|
|
418
419
|
name: i?.name || "",
|
|
419
420
|
cocNumber: i?.cocNumber || "",
|
|
@@ -421,12 +422,12 @@ const ai = {
|
|
|
421
422
|
isVatNumberRequired: e?.organisation?.isVatNumberRequired ?? !1,
|
|
422
423
|
type: i?.type || "SHARED",
|
|
423
424
|
vatNumber: i?.registration?.number || "",
|
|
424
|
-
vatNumberCountry:
|
|
425
|
-
|
|
425
|
+
vatNumberCountry: p(
|
|
426
|
+
C(i?.registration?.countryCode) || e?.defaultCountry
|
|
426
427
|
)
|
|
427
428
|
} : {
|
|
428
429
|
...e?.organisation || {},
|
|
429
|
-
...
|
|
430
|
+
...b?.organisation || {},
|
|
430
431
|
isCocNumberRequired: e?.organisation?.isCocNumberRequired ?? !1,
|
|
431
432
|
isVatNumberRequired: e?.organisation?.isVatNumberRequired ?? !1,
|
|
432
433
|
vatNumberCountry: e.defaultCountry
|
|
@@ -434,59 +435,59 @@ const ai = {
|
|
|
434
435
|
billing: t ? {
|
|
435
436
|
...e.billing,
|
|
436
437
|
...q,
|
|
437
|
-
...
|
|
438
|
+
...N,
|
|
438
439
|
country: P
|
|
439
440
|
} : {
|
|
440
441
|
...e.billing,
|
|
441
442
|
...q,
|
|
442
443
|
country: e.defaultCountry
|
|
443
444
|
},
|
|
444
|
-
billingAddressId:
|
|
445
|
+
billingAddressId: l || "",
|
|
445
446
|
shipping: E ? {
|
|
446
447
|
...e.shipping,
|
|
447
448
|
...q,
|
|
448
449
|
...V,
|
|
449
|
-
country:
|
|
450
|
+
country: A
|
|
450
451
|
} : {
|
|
451
452
|
...e.shipping,
|
|
452
453
|
...q,
|
|
453
454
|
country: e.defaultCountry
|
|
454
455
|
},
|
|
455
|
-
shippingAddressId:
|
|
456
|
-
sameBillingAsShippingAddress: !
|
|
457
|
-
}),
|
|
456
|
+
shippingAddressId: c || "",
|
|
457
|
+
sameBillingAsShippingAddress: !O(l) || O(l) && l === c
|
|
458
|
+
}), m.current?.formProps?.setData((L) => (L.splice(s, 1, {
|
|
458
459
|
...L[s],
|
|
459
460
|
...w
|
|
460
461
|
}), L));
|
|
461
462
|
}
|
|
462
463
|
},
|
|
463
|
-
submit: async (
|
|
464
|
+
submit: async (I, d, S) => {
|
|
464
465
|
const {
|
|
465
|
-
activeStep:
|
|
466
|
-
addInformation:
|
|
466
|
+
activeStep: R,
|
|
467
|
+
addInformation: f,
|
|
467
468
|
currentOrganisation: s,
|
|
468
|
-
formRef:
|
|
469
|
-
getCountryByCode:
|
|
470
|
-
getUser:
|
|
471
|
-
isSignedIn:
|
|
472
|
-
setCurrentOrganisation:
|
|
469
|
+
formRef: v,
|
|
470
|
+
getCountryByCode: D,
|
|
471
|
+
getUser: m,
|
|
472
|
+
isSignedIn: p,
|
|
473
|
+
setCurrentOrganisation: C,
|
|
473
474
|
setErrorMessage: U,
|
|
474
475
|
signUp: $,
|
|
475
476
|
translations: n = {},
|
|
476
477
|
updateAccountInformation: M,
|
|
477
478
|
updateOrganisationOnAccount: e
|
|
478
|
-
} =
|
|
479
|
+
} = S || {}, b = {
|
|
479
480
|
...ai,
|
|
480
481
|
...n.feedback || {}
|
|
481
|
-
}, { shouldCreateAccount:
|
|
482
|
+
}, { shouldCreateAccount: h } = I || {};
|
|
482
483
|
try {
|
|
483
484
|
U(null);
|
|
484
|
-
const i = oi(
|
|
485
|
+
const i = oi(I, {
|
|
485
486
|
currentOrganisation: s,
|
|
486
|
-
isSignedIn:
|
|
487
|
-
}), o =
|
|
488
|
-
if (
|
|
489
|
-
const
|
|
487
|
+
isSignedIn: p
|
|
488
|
+
}), o = m();
|
|
489
|
+
if (h) {
|
|
490
|
+
const c = await $({
|
|
490
491
|
givenName: i?.shipping?.givenName,
|
|
491
492
|
additionalName: i?.shipping?.additionalName,
|
|
492
493
|
familyName: i?.shipping?.familyName,
|
|
@@ -500,25 +501,25 @@ const ai = {
|
|
|
500
501
|
}).catch((x) => {
|
|
501
502
|
const V = W(x);
|
|
502
503
|
return U({
|
|
503
|
-
title:
|
|
504
|
-
description: V ? X(V) :
|
|
504
|
+
title: b.feedback?.signUpFailedTitle,
|
|
505
|
+
description: V ? X(V) : b.feedback?.signUpFailedDescription,
|
|
505
506
|
action: {
|
|
506
|
-
label:
|
|
507
|
+
label: b.feedback?.signUpFailedActionLabel,
|
|
507
508
|
onClick: () => {
|
|
508
|
-
U(null),
|
|
509
|
-
...
|
|
509
|
+
U(null), v.current?.reset({
|
|
510
|
+
...v.current?.getValues() || {},
|
|
510
511
|
shouldCreateAccount: !1
|
|
511
|
-
}),
|
|
512
|
+
}), v.current?.submitForm();
|
|
512
513
|
}
|
|
513
514
|
}
|
|
514
515
|
}), Promise.reject(x);
|
|
515
516
|
});
|
|
516
|
-
if (!
|
|
517
|
+
if (!c)
|
|
517
518
|
return Promise.reject();
|
|
518
|
-
delete i.customer.contact, i.customer.contactId =
|
|
519
|
+
delete i.customer.contact, i.customer.contactId = c.id, v.current?.setValue("shouldCreateAccount", !1);
|
|
519
520
|
}
|
|
520
521
|
if (o && !o?.organisation?.id) {
|
|
521
|
-
const
|
|
522
|
+
const c = si(
|
|
522
523
|
{
|
|
523
524
|
billingAddress: i.billingAddress,
|
|
524
525
|
billingAddressId: i.billingAddressId,
|
|
@@ -535,14 +536,14 @@ const ai = {
|
|
|
535
536
|
user: o
|
|
536
537
|
},
|
|
537
538
|
{
|
|
538
|
-
getCountryByCode:
|
|
539
|
+
getCountryByCode: D
|
|
539
540
|
}
|
|
540
541
|
);
|
|
541
|
-
|
|
542
|
+
c && await M(c).catch(() => {
|
|
542
543
|
});
|
|
543
544
|
}
|
|
544
545
|
if (o?.organisation?.id && o?.organisation?.role?.toLowerCase() === "admin") {
|
|
545
|
-
const
|
|
546
|
+
const c = ri(
|
|
546
547
|
{
|
|
547
548
|
billingAddress: i.billingAddress,
|
|
548
549
|
billingAddressId: i.billingAddressId,
|
|
@@ -559,77 +560,80 @@ const ai = {
|
|
|
559
560
|
user: o
|
|
560
561
|
},
|
|
561
562
|
{
|
|
562
|
-
getCountryByCode:
|
|
563
|
+
getCountryByCode: D
|
|
563
564
|
}
|
|
564
565
|
);
|
|
565
|
-
|
|
566
|
+
c && await e(c).catch(
|
|
566
567
|
() => {
|
|
567
568
|
}
|
|
568
569
|
);
|
|
569
570
|
}
|
|
570
|
-
const t = await
|
|
571
|
+
const t = await f({
|
|
571
572
|
billingAddress: i.billingAddress,
|
|
572
573
|
customer: i.customer,
|
|
573
574
|
phoneNumber: i.phoneNumber,
|
|
574
575
|
shippingAddress: i.shippingAddress
|
|
575
|
-
}), { customer:
|
|
576
|
-
return
|
|
577
|
-
...
|
|
578
|
-
contact:
|
|
576
|
+
}), { customer: l, billing: r, delivery: N, phoneNumber: P } = t || {}, { organisation: E } = l || {};
|
|
577
|
+
return v.current?.formProps?.setData((c) => (c.splice(R, 1, {
|
|
578
|
+
...c[R],
|
|
579
|
+
contact: l?.contact,
|
|
579
580
|
billingAddressId: r?.address?.id,
|
|
580
|
-
shippingAddressId:
|
|
581
|
+
shippingAddressId: N?.address?.id,
|
|
581
582
|
phoneNumberId: P?.id,
|
|
582
583
|
phoneNumberIsDirty: !1
|
|
583
|
-
}),
|
|
584
|
+
}), c)), C(E), t;
|
|
584
585
|
} catch (i) {
|
|
585
586
|
const o = W(i);
|
|
586
587
|
return U({
|
|
587
|
-
title:
|
|
588
|
-
description: o ? X(o) :
|
|
588
|
+
title: b.feedback?.informationStepErrorTitle,
|
|
589
|
+
description: o ? X(o) : b.feedback?.informationStepErrorDescription
|
|
589
590
|
}), Promise.reject(i);
|
|
590
591
|
}
|
|
591
592
|
},
|
|
592
|
-
validationSchema: (
|
|
593
|
+
validationSchema: (I) => {
|
|
593
594
|
const {
|
|
594
|
-
billingAddressValidationSchema:
|
|
595
|
-
shippingAddressValidationSchema:
|
|
596
|
-
settings:
|
|
597
|
-
} =
|
|
598
|
-
isCocNumberRequired:
|
|
595
|
+
billingAddressValidationSchema: d,
|
|
596
|
+
shippingAddressValidationSchema: S,
|
|
597
|
+
settings: R
|
|
598
|
+
} = I || {}, {
|
|
599
|
+
isCocNumberRequired: f,
|
|
599
600
|
isPhoneNumberRequired: s,
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
601
|
+
isSalutationRequired: v,
|
|
602
|
+
isVatNumberRequired: D,
|
|
603
|
+
salutation: m
|
|
604
|
+
} = R || {};
|
|
605
|
+
return a.object().shape({
|
|
606
|
+
type: a.string().oneOf(["business", "private"]).required(),
|
|
607
|
+
contact: a.object().nullable(),
|
|
608
|
+
email: a.string().trim().email().required(),
|
|
609
|
+
emailOptIn: a.boolean().nullable(),
|
|
610
|
+
salutation: m && v ? a.string().nullable().required() : a.string().nullable(),
|
|
611
|
+
shouldCreateAccount: a.boolean().nullable(),
|
|
612
|
+
password: a.string().nullable().when("shouldCreateAccount", {
|
|
609
613
|
is: !0,
|
|
610
|
-
then: (
|
|
614
|
+
then: (p) => p.required()
|
|
611
615
|
}),
|
|
612
|
-
passwordConfirm:
|
|
616
|
+
passwordConfirm: a.string().when("shouldCreateAccount", {
|
|
613
617
|
is: !0,
|
|
614
|
-
then: (
|
|
618
|
+
then: (p) => p.required().equalPassword()
|
|
615
619
|
}),
|
|
616
|
-
phoneNumber: s ?
|
|
617
|
-
phoneNumberCountry: s ?
|
|
618
|
-
organisation:
|
|
619
|
-
is: (
|
|
620
|
-
then: (
|
|
621
|
-
id:
|
|
622
|
-
name:
|
|
623
|
-
cocNumber:
|
|
624
|
-
vatNumber:
|
|
625
|
-
vatNumberCountry:
|
|
620
|
+
phoneNumber: s ? a.string().phoneNumber().nullable().required() : a.string().phoneNumber().nullable(),
|
|
621
|
+
phoneNumberCountry: s ? a.object().nullable().required() : a.object().nullable(),
|
|
622
|
+
organisation: a.object().nullable().when("type", {
|
|
623
|
+
is: (p) => p === "business",
|
|
624
|
+
then: (p) => p.shape({
|
|
625
|
+
id: a.string().nullable(),
|
|
626
|
+
name: a.string().required(),
|
|
627
|
+
cocNumber: f ? a.string().trim().required() : a.string().trim().nullable(),
|
|
628
|
+
vatNumber: D ? a.string().trim().required() : a.string().trim().nullable(),
|
|
629
|
+
vatNumberCountry: D ? a.object().nullable().required() : a.object().nullable()
|
|
626
630
|
})
|
|
627
631
|
}),
|
|
628
|
-
sameBillingAsShippingAddress:
|
|
629
|
-
shipping:
|
|
630
|
-
billing:
|
|
632
|
+
sameBillingAsShippingAddress: a.boolean().nullable(),
|
|
633
|
+
shipping: a.object().nullable().shape(S),
|
|
634
|
+
billing: a.object().nullable().when("sameBillingAsShippingAddress", {
|
|
631
635
|
is: !1,
|
|
632
|
-
then: (
|
|
636
|
+
then: (p) => p.shape(d)
|
|
633
637
|
})
|
|
634
638
|
});
|
|
635
639
|
}
|