@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.
@@ -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 D } from "@afosto/utils";
6
- import * as u from "yup";
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: (S) => {
29
- const { defaultCountry: a, formatCountryAsOption: v, settings: O } = S || {}, { isB2cExcluded: y, isSharedOrganisationRequired: s } = O || {};
28
+ defaultValues: (I) => {
29
+ const { defaultCountry: d, formatCountryAsOption: S, settings: R } = I || {}, { isB2cExcluded: f, isSharedOrganisationRequired: s } = R || {};
30
30
  return {
31
- type: y ? "business" : "private",
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: y && a ? v(a) : null
41
+ vatNumberCountry: f && d ? S(d) : null
42
42
  },
43
43
  password: "",
44
44
  passwordConfirm: "",
45
45
  phoneNumber: "",
46
- phoneNumberCountry: a ? v(a) : null,
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: a ? v(a) : null,
53
- countryCode: a ? a.alpha2Code : ""
53
+ country: d ? S(d) : null,
54
+ countryCode: d ? d.alpha2Code : ""
54
55
  },
55
56
  shippingAddressId: "",
56
57
  billing: {
57
58
  ...q,
58
- country: a ? v(a) : null,
59
- countryCode: a ? a.alpha2Code : ""
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: (S, a, v) => {
66
+ initialize: (I, d, S) => {
66
67
  const {
67
- defaultCountry: O,
68
- formatCountryAsOption: y,
68
+ defaultCountry: R,
69
+ formatCountryAsOption: f,
69
70
  getCountryByCode: s,
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, {
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: m,
76
- expressPayment: b,
76
+ delivery: b,
77
+ expressPayment: h,
77
78
  options: i,
78
79
  phoneNumber: o
79
- } = S || {}, {
80
+ } = I || {}, {
80
81
  contact: t,
81
- countryCode: d,
82
+ countryCode: l,
82
83
  organisation: r
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(
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
- ) || 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(
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 (R && V?.includes(R?.alpha2Code))
90
- G = R;
91
- else if (I && V?.includes(I?.alpha2Code))
92
- G = I;
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(l?.countryCode) || G, F = D(J) ? y(J) : n.shipping.country, z = l?.administrativeArea || n.shipping.administrativeArea, Y = z && typeof z == "string" ? {
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 = 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" ? {
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: y(I),
111
- type: c ? "business" : "private",
111
+ defaultCountry: f(A),
112
+ type: g ? "business" : "private",
112
113
  contact: t || null,
113
- email: c ? r?.administration?.email || t?.email || p?.email || n.email : t?.email || p?.email || n.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
- ...c ? {
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: y(
123
- s(r?.registration?.countryCode) || I
123
+ vatNumberCountry: f(
124
+ s(r?.registration?.countryCode) || A
124
125
  )
125
126
  } : {
126
- vatNumberCountry: y(I)
127
+ vatNumberCountry: f(A)
127
128
  }
128
129
  },
129
130
  phoneNumber: k,
130
- phoneNumberCountry: D(w) ? y(w) : n.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: 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,
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: 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,
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: l?.id || n.shippingAddressId,
152
+ shippingAddressId: u?.id || n.shippingAddressId,
152
153
  billing: {
153
154
  ...n.billing,
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,
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: 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,
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: h?.id || n.billingAddressId,
172
- sameBillingAsShippingAddress: D(h?.id) && D(l?.id) ? h?.id === l?.id : n.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: (S, a) => {
176
- const { step: v } = a || {};
177
- return v.validationSchema(a).isValidSync(S);
176
+ isComplete: (I, d) => {
177
+ const { step: S } = d || {};
178
+ return S.validationSchema(d).isValidSync(I);
178
179
  },
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,
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
- } = 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 || {};
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
- b?.id && e?.contact?.id !== b?.id && (o = (await g({
192
+ h?.id && e?.contact?.id !== h?.id && (o = (await D({
192
193
  customer: {
193
- contactId: b.id
194
+ contactId: h.id
194
195
  }
195
196
  }))?.customer?.contact);
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, {
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
- ...I
200
- } = p || {}, R = I?.countryCode ? B(N(I.countryCode)) : e?.defaultCountry, c = t ? j(t) : null, {
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
- } = c || {}, k = L?.countryCode ? B(N(L.countryCode)) : e?.defaultCountry, T = !$ && r?.id || n, l = T && r?.administration?.email || i?.email, J = {
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
- ...m || {},
207
+ ...b || {},
207
208
  contact: o,
208
- email: l,
209
+ email: u,
209
210
  type: T ? "business" : "private",
210
- ...A ? {
211
- phoneNumber: A.number?.replace(
211
+ ...N ? {
212
+ phoneNumber: N.number?.replace(
212
213
  `+${E}`,
213
214
  ""
214
215
  ),
215
216
  phoneNumberCountry: P,
216
- phoneNumberId: A?.id || ""
217
+ phoneNumberId: N?.id || ""
217
218
  } : {
218
219
  phoneNumberCountry: e.defaultCountry
219
220
  },
220
221
  organisation: T ? {
221
222
  ...e?.organisation || {},
222
- ...m?.organisation || {},
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: B(
231
- N(
231
+ vatNumberCountry: p(
232
+ C(
232
233
  r?.registration?.countryCode
233
234
  ) || e?.defaultCountry
234
235
  )
235
236
  } : {
236
237
  ...e?.organisation || {},
237
- ...m?.organisation || {},
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: d ? {
254
+ shipping: l ? {
254
255
  ...e.shipping,
255
256
  ...q,
256
- ...I,
257
- country: R
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: D(_) || D(_) && _ === x
265
+ sameBillingAsShippingAddress: O(_) || O(_) && _ === x
265
266
  };
266
- i && (f === s && C.current?.reset({
267
+ i && (v === s && m.current?.reset({
267
268
  ...e,
268
269
  ...J
269
- }), C.current?.formProps?.setData((F) => (F.splice(s, 1, {
270
+ }), m.current?.formProps?.setData((F) => (F.splice(s, 1, {
270
271
  ...F[s],
271
272
  ...J
272
273
  }), F)));
273
274
  }
274
- if (S === "clearSession") {
275
- const { sessionExpired: b, shouldCreateAccount: i } = a || {}, o = {
275
+ if (I === "clearSession") {
276
+ const { sessionExpired: h, shouldCreateAccount: i } = d || {}, o = {
276
277
  ...e,
277
- ...b ? m || {} : {},
278
+ ...h ? b || {} : {},
278
279
  shouldCreateAccount: i ?? !1
279
280
  };
280
- f === s && C.current?.reset({
281
+ v === s && m.current?.reset({
281
282
  ...e,
282
283
  ...o
283
- }), C.current?.formProps?.setData((t) => (t.splice(s, 1, {
284
+ }), m.current?.formProps?.setData((t) => (t.splice(s, 1, {
284
285
  ...t[s],
285
286
  ...o
286
287
  }), t));
287
288
  }
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,
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 || {}, I = V?.countryCode ? B(N(V.countryCode)) : e?.defaultCountry, R = o ? j(o) : null, {
294
- id: c,
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
- } = R || {}, L = w?.countryCode ? B(N(w.countryCode)) : e?.defaultCountry, k = !$ && d?.id || n;
298
- await g({
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 && d?.id ? { organisationId: d?.id } : {}
302
+ ...k && l?.id ? { organisationId: l?.id } : {}
302
303
  }
303
304
  });
304
305
  const T = {
305
306
  ...e,
306
- ...m || {},
307
+ ...b || {},
307
308
  contact: e?.contact,
308
- email: k && d?.administration?.email || b?.email,
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: A,
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
- ...m?.organisation || {},
323
- id: d?.id || "",
324
- name: d?.name || "",
325
- cocNumber: d?.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: d?.type || "DEFAULT",
329
- vatNumber: d?.registration?.number || "",
330
- vatNumberCountry: B(
331
- N(
332
- d?.registration?.countryCode
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
- ...m?.organisation || {},
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: c || "",
353
+ billingAddressId: g || "",
353
354
  shipping: t ? {
354
355
  ...e.shipping,
355
356
  ...q,
356
357
  ...V,
357
- country: I
358
+ country: A
358
359
  } : {
359
360
  ...e.shipping,
360
361
  ...q,
361
362
  country: e.defaultCountry
362
363
  },
363
- shippingAddressId: p || "",
364
- sameBillingAsShippingAddress: !D(c) || D(c) && c === p
364
+ shippingAddressId: c || "",
365
+ sameBillingAsShippingAddress: !O(g) || O(g) && g === c
365
366
  };
366
- f === s && C.current?.reset({
367
+ v === s && m.current?.reset({
367
368
  ...e,
368
369
  ...T
369
- }), C.current?.formProps?.setData((l) => (l.splice(s, 1, {
370
- ...l[s],
370
+ }), m.current?.formProps?.setData((u) => (u.splice(s, 1, {
371
+ ...u[s],
371
372
  ...T
372
- }), l));
373
+ }), u));
373
374
  }
374
- if (S === "businessAccountSelected") {
375
- const { account: b, organisation: i, user: o } = a || {};
376
- await g({
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: d,
384
+ id: l,
384
385
  isValid: r,
385
- ...A
386
- } = t || {}, P = A?.countryCode ? B(
387
- N(A.countryCode)
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: p,
390
+ id: c,
390
391
  isValid: x,
391
392
  ...V
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 = {
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
- ...m || {}
397
+ ...b || {}
397
398
  };
398
- f === s && C.current?.reset({
399
+ v === s && m.current?.reset({
399
400
  ...e,
400
401
  ...w,
401
402
  contact: e?.contact,
402
- email: i?.administration?.email || b?.email || "",
403
+ email: i?.administration?.email || h?.email || "",
403
404
  type: "business",
404
- ...R ? {
405
- phoneNumber: R?.number?.replace(
405
+ ...B ? {
406
+ phoneNumber: B?.number?.replace(
406
407
  `+${_}`,
407
408
  ""
408
409
  ),
409
- phoneNumberCountry: c,
410
- phoneNumberId: R?.id || ""
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
- ...m?.organisation || {},
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: B(
425
- N(i?.registration?.countryCode) || e?.defaultCountry
425
+ vatNumberCountry: p(
426
+ C(i?.registration?.countryCode) || e?.defaultCountry
426
427
  )
427
428
  } : {
428
429
  ...e?.organisation || {},
429
- ...m?.organisation || {},
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
- ...A,
438
+ ...N,
438
439
  country: P
439
440
  } : {
440
441
  ...e.billing,
441
442
  ...q,
442
443
  country: e.defaultCountry
443
444
  },
444
- billingAddressId: d || "",
445
+ billingAddressId: l || "",
445
446
  shipping: E ? {
446
447
  ...e.shipping,
447
448
  ...q,
448
449
  ...V,
449
- country: I
450
+ country: A
450
451
  } : {
451
452
  ...e.shipping,
452
453
  ...q,
453
454
  country: e.defaultCountry
454
455
  },
455
- shippingAddressId: p || "",
456
- sameBillingAsShippingAddress: !D(d) || D(d) && d === p
457
- }), C.current?.formProps?.setData((L) => (L.splice(s, 1, {
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 (S, a, v) => {
464
+ submit: async (I, d, S) => {
464
465
  const {
465
- activeStep: O,
466
- addInformation: y,
466
+ activeStep: R,
467
+ addInformation: f,
467
468
  currentOrganisation: s,
468
- formRef: f,
469
- getCountryByCode: g,
470
- getUser: C,
471
- isSignedIn: B,
472
- setCurrentOrganisation: N,
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
- } = v || {}, m = {
479
+ } = S || {}, b = {
479
480
  ...ai,
480
481
  ...n.feedback || {}
481
- }, { shouldCreateAccount: b } = S || {};
482
+ }, { shouldCreateAccount: h } = I || {};
482
483
  try {
483
484
  U(null);
484
- const i = oi(S, {
485
+ const i = oi(I, {
485
486
  currentOrganisation: s,
486
- isSignedIn: B
487
- }), o = C();
488
- if (b) {
489
- const p = await $({
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: m.feedback?.signUpFailedTitle,
504
- description: V ? X(V) : m.feedback?.signUpFailedDescription,
504
+ title: b.feedback?.signUpFailedTitle,
505
+ description: V ? X(V) : b.feedback?.signUpFailedDescription,
505
506
  action: {
506
- label: m.feedback?.signUpFailedActionLabel,
507
+ label: b.feedback?.signUpFailedActionLabel,
507
508
  onClick: () => {
508
- U(null), f.current?.reset({
509
- ...f.current?.getValues() || {},
509
+ U(null), v.current?.reset({
510
+ ...v.current?.getValues() || {},
510
511
  shouldCreateAccount: !1
511
- }), f.current?.submitForm();
512
+ }), v.current?.submitForm();
512
513
  }
513
514
  }
514
515
  }), Promise.reject(x);
515
516
  });
516
- if (!p)
517
+ if (!c)
517
518
  return Promise.reject();
518
- delete i.customer.contact, i.customer.contactId = p.id, f.current?.setValue("shouldCreateAccount", !1);
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 p = si(
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: g
539
+ getCountryByCode: D
539
540
  }
540
541
  );
541
- p && await M(p).catch(() => {
542
+ c && await M(c).catch(() => {
542
543
  });
543
544
  }
544
545
  if (o?.organisation?.id && o?.organisation?.role?.toLowerCase() === "admin") {
545
- const p = ri(
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: g
563
+ getCountryByCode: D
563
564
  }
564
565
  );
565
- p && await e(p).catch(
566
+ c && await e(c).catch(
566
567
  () => {
567
568
  }
568
569
  );
569
570
  }
570
- const t = await y({
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: 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,
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: A?.address?.id,
581
+ shippingAddressId: N?.address?.id,
581
582
  phoneNumberId: P?.id,
582
583
  phoneNumberIsDirty: !1
583
- }), p)), N(E), t;
584
+ }), c)), C(E), t;
584
585
  } catch (i) {
585
586
  const o = W(i);
586
587
  return U({
587
- title: m.feedback?.informationStepErrorTitle,
588
- description: o ? X(o) : m.feedback?.informationStepErrorDescription
588
+ title: b.feedback?.informationStepErrorTitle,
589
+ description: o ? X(o) : b.feedback?.informationStepErrorDescription
589
590
  }), Promise.reject(i);
590
591
  }
591
592
  },
592
- validationSchema: (S) => {
593
+ validationSchema: (I) => {
593
594
  const {
594
- billingAddressValidationSchema: a,
595
- shippingAddressValidationSchema: v,
596
- settings: O
597
- } = S || {}, {
598
- isCocNumberRequired: y,
595
+ billingAddressValidationSchema: d,
596
+ shippingAddressValidationSchema: S,
597
+ settings: R
598
+ } = I || {}, {
599
+ isCocNumberRequired: f,
599
600
  isPhoneNumberRequired: s,
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", {
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: (g) => g.required()
614
+ then: (p) => p.required()
611
615
  }),
612
- passwordConfirm: u.string().when("shouldCreateAccount", {
616
+ passwordConfirm: a.string().when("shouldCreateAccount", {
613
617
  is: !0,
614
- then: (g) => g.required().equalPassword()
618
+ then: (p) => p.required().equalPassword()
615
619
  }),
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()
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: u.boolean().nullable(),
629
- shipping: u.object().nullable().shape(v),
630
- billing: u.object().nullable().when("sameBillingAsShippingAddress", {
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: (g) => g.shape(a)
636
+ then: (p) => p.shape(d)
633
637
  })
634
638
  });
635
639
  }