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