@velion-la/onboarding-sdk-react-native 1.3.0-beta.24 → 1.3.0-beta.25
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/lib/commonjs/i18n/strings/en.js +1 -0
- package/lib/commonjs/i18n/strings/en.js.map +1 -1
- package/lib/commonjs/i18n/strings/es.js +1 -0
- package/lib/commonjs/i18n/strings/es.js.map +1 -1
- package/lib/commonjs/steps/AddressInfoStep.js +315 -275
- package/lib/commonjs/steps/AddressInfoStep.js.map +1 -1
- package/lib/commonjs/utils/addressForm.js +77 -0
- package/lib/commonjs/utils/addressForm.js.map +1 -0
- package/lib/module/i18n/strings/en.js +1 -0
- package/lib/module/i18n/strings/en.js.map +1 -1
- package/lib/module/i18n/strings/es.js +1 -0
- package/lib/module/i18n/strings/es.js.map +1 -1
- package/lib/module/steps/AddressInfoStep.js +317 -277
- package/lib/module/steps/AddressInfoStep.js.map +1 -1
- package/lib/module/utils/addressForm.js +72 -0
- package/lib/module/utils/addressForm.js.map +1 -0
- package/lib/typescript/i18n/strings/en.d.ts.map +1 -1
- package/lib/typescript/i18n/strings/es.d.ts +1 -0
- package/lib/typescript/i18n/strings/es.d.ts.map +1 -1
- package/lib/typescript/steps/AddressInfoStep.d.ts +2 -0
- package/lib/typescript/steps/AddressInfoStep.d.ts.map +1 -1
- package/lib/typescript/utils/addressForm.d.ts +51 -0
- package/lib/typescript/utils/addressForm.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/i18n/strings/en.ts +1 -0
- package/src/i18n/strings/es.ts +1 -0
- package/src/steps/AddressInfoStep.tsx +395 -298
- package/src/utils/addressForm.ts +122 -0
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* 1. **Assisted** (when `VelionConfig.googleMapsApiKey` is set, or on iOS
|
|
9
9
|
* where Apple Maps needs no key): intro → map picker → details (floor /
|
|
10
10
|
* apartment / references) → submit. Lat/Lng are included in the payload.
|
|
11
|
+
* The details screen shows the resolved address as a summary; "Edit
|
|
12
|
+
* address" opens the manual form's address fields to correct it (OSDKR-43).
|
|
11
13
|
* 2. **Manual** (default fallback): the structured form — country, state,
|
|
12
14
|
* city, district, neighborhood, street, number, zip, plus the same
|
|
13
15
|
* details fields. No lat/lng.
|
|
@@ -39,9 +41,10 @@ import { getStrings } from '../i18n';
|
|
|
39
41
|
import { MapAddressPicker } from '../camera/MapAddressPicker';
|
|
40
42
|
import { isReactNativeMapsAvailable, isAndroidGoogleMapsKeyInManifest } from '../utils/googleMapsPreflight';
|
|
41
43
|
import { log } from '../utils/log';
|
|
42
|
-
import { keepStateIfValid, listStateOptions
|
|
44
|
+
import { keepStateIfValid, listStateOptions } from '../utils/subdivisions';
|
|
45
|
+
import { addressFormFromParsed, addressRequirements, validateAddressForm } from '../utils/addressForm';
|
|
43
46
|
import { prefillString, toSubmissionError } from './_shared';
|
|
44
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
47
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
45
48
|
const ADDRESS_TYPE_HOME = 'HOME';
|
|
46
49
|
export class AddressInfoStep {
|
|
47
50
|
destroyed = false;
|
|
@@ -154,16 +157,8 @@ function AssistedAddressFlow({
|
|
|
154
157
|
const theme = useTheme();
|
|
155
158
|
const [phase, setPhase] = useState('intro');
|
|
156
159
|
const [parsed, setParsed] = useState(null);
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
return {
|
|
160
|
-
state: f?.state?.required !== false,
|
|
161
|
-
city: f?.city?.required !== false,
|
|
162
|
-
street: f?.street?.required !== false,
|
|
163
|
-
number: f?.number?.required !== false,
|
|
164
|
-
postal: f?.postal_code?.required !== false
|
|
165
|
-
};
|
|
166
|
-
}, [stepConfig?.fields]);
|
|
160
|
+
const requirements = useMemo(() => addressRequirements(stepConfig?.fields), [stepConfig?.fields]);
|
|
161
|
+
const allowedCodes = useMemo(() => allowedCountries(stepConfig?.country_allow), [stepConfig?.country_allow]);
|
|
167
162
|
if (phase === 'intro') {
|
|
168
163
|
return /*#__PURE__*/_jsx(View, {
|
|
169
164
|
style: {
|
|
@@ -203,7 +198,10 @@ function AssistedAddressFlow({
|
|
|
203
198
|
// phase, so a geocoder result without a region must not block here.
|
|
204
199
|
,
|
|
205
200
|
requiredFields: {
|
|
206
|
-
|
|
201
|
+
city: requirements.city,
|
|
202
|
+
street: requirements.street,
|
|
203
|
+
number: requirements.number,
|
|
204
|
+
postal: requirements.zip,
|
|
207
205
|
state: false
|
|
208
206
|
},
|
|
209
207
|
countryAllow: stepConfig?.country_allow,
|
|
@@ -224,7 +222,8 @@ function AssistedAddressFlow({
|
|
|
224
222
|
sessionId: sessionId,
|
|
225
223
|
locale: locale,
|
|
226
224
|
parsed: parsed,
|
|
227
|
-
|
|
225
|
+
requirements: requirements,
|
|
226
|
+
allowedCodes: allowedCodes,
|
|
228
227
|
addressType: stepConfig?.address_type?.id ?? ADDRESS_TYPE_HOME,
|
|
229
228
|
prefill: prefill,
|
|
230
229
|
onComplete: onComplete,
|
|
@@ -234,12 +233,21 @@ function AssistedAddressFlow({
|
|
|
234
233
|
}
|
|
235
234
|
/** Visual order of the assisted flow's detail inputs, for "next" chaining. */
|
|
236
235
|
const DETAILS_FIELD_ORDER = ['floor', 'apartment', 'details'];
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Details screen of the assisted flow: floor, apartment and references, with
|
|
239
|
+
* the address the map resolved as a summary. "Edit address" opens the manual
|
|
240
|
+
* form's address fields, prefilled, to fix what the geocoder read (OSDKR-43).
|
|
241
|
+
* The state picker lives in that section, unless the state could not be
|
|
242
|
+
* resolved: then it is shown right away, since the user has to pick it.
|
|
243
|
+
*/
|
|
237
244
|
function AddressDetailsForm({
|
|
238
245
|
api,
|
|
239
246
|
sessionId,
|
|
240
247
|
locale,
|
|
241
248
|
parsed,
|
|
242
|
-
|
|
249
|
+
requirements,
|
|
250
|
+
allowedCodes,
|
|
243
251
|
addressType,
|
|
244
252
|
prefill,
|
|
245
253
|
onComplete,
|
|
@@ -248,51 +256,35 @@ function AddressDetailsForm({
|
|
|
248
256
|
}) {
|
|
249
257
|
const t = getStrings(locale);
|
|
250
258
|
const theme = useTheme();
|
|
259
|
+
const [form, setForm] = useState(() => addressFormFromParsed(parsed, prefill, prefillString));
|
|
260
|
+
// Decided once, from what the map resolved: picking a state afterwards must
|
|
261
|
+
// not hide the picker the user is using.
|
|
262
|
+
const [stateResolved] = useState(() => form.state !== '');
|
|
263
|
+
const [editing, setEditing] = useState(false);
|
|
251
264
|
const {
|
|
252
265
|
field
|
|
253
|
-
} = useFieldChain(DETAILS_FIELD_ORDER);
|
|
254
|
-
const
|
|
255
|
-
// The pin the user just confirmed wins over a state saved by a previous visit.
|
|
256
|
-
const [state, setState] = useState(() => suggestState(parsed.country, parsed.state) || keepStateIfValid(parsed.country, prefillString(prefill, 'state')));
|
|
257
|
-
const [stateError, setStateError] = useState(null);
|
|
258
|
-
const [floor, setFloor] = useState(() => prefillString(prefill, 'floor'));
|
|
259
|
-
const [apartment, setApartment] = useState(() => prefillString(prefill, 'apartment'));
|
|
260
|
-
const [details, setDetails] = useState(() => prefillString(prefill, 'details'));
|
|
266
|
+
} = useFieldChain(editing ? MANUAL_FIELD_ORDER : DETAILS_FIELD_ORDER);
|
|
267
|
+
const [errors, setErrors] = useState({});
|
|
261
268
|
const [bannerError, setBannerError] = useState(null);
|
|
262
269
|
const [submitting, setSubmitting] = useState(false);
|
|
263
270
|
const [retry, setRetry] = useState(null);
|
|
271
|
+
const stateOptions = useMemo(() => listStateOptions(form.country, locale), [form.country, locale]);
|
|
272
|
+
const stateLabel = stateOptions.find(o => o.value === form.state)?.label;
|
|
273
|
+
const setField = useFieldSetter(setForm, setErrors);
|
|
264
274
|
const handleSubmit = useCallback(async () => {
|
|
265
275
|
setBannerError(null);
|
|
266
|
-
|
|
267
|
-
|
|
276
|
+
const next = validateAddressForm(form, requirements, stateOptions.length > 0, t.address_info);
|
|
277
|
+
setErrors(next);
|
|
278
|
+
if (Object.keys(next).length > 0) {
|
|
279
|
+
// An error outside the state picker is on a field only the edit section shows.
|
|
280
|
+
if (Object.keys(next).some(key => key !== 'state')) setEditing(true);
|
|
268
281
|
setBannerError(t.address_info.fillAllRequired);
|
|
269
282
|
return;
|
|
270
283
|
}
|
|
271
284
|
const payload = {
|
|
272
|
-
|
|
273
|
-
country: parsed.country,
|
|
274
|
-
state,
|
|
275
|
-
city: parsed.city,
|
|
276
|
-
street: parsed.street,
|
|
277
|
-
number: parsed.number,
|
|
278
|
-
zip_code: parsed.zip_code,
|
|
285
|
+
...addressPayload(form, addressType),
|
|
279
286
|
latitude: parsed.latitude,
|
|
280
|
-
longitude: parsed.longitude
|
|
281
|
-
...(parsed.district && {
|
|
282
|
-
district: parsed.district
|
|
283
|
-
}),
|
|
284
|
-
...(parsed.neighborhood && {
|
|
285
|
-
neighborhood: parsed.neighborhood
|
|
286
|
-
}),
|
|
287
|
-
...(floor.trim() && {
|
|
288
|
-
floor: floor.trim()
|
|
289
|
-
}),
|
|
290
|
-
...(apartment.trim() && {
|
|
291
|
-
apartment: apartment.trim()
|
|
292
|
-
}),
|
|
293
|
-
...(details.trim() && {
|
|
294
|
-
details: details.trim()
|
|
295
|
-
})
|
|
287
|
+
longitude: parsed.longitude
|
|
296
288
|
};
|
|
297
289
|
setSubmitting(true);
|
|
298
290
|
try {
|
|
@@ -307,7 +299,7 @@ function AddressDetailsForm({
|
|
|
307
299
|
message: sdkErr.message
|
|
308
300
|
});
|
|
309
301
|
}
|
|
310
|
-
}, [addressType, api,
|
|
302
|
+
}, [addressType, api, form, onComplete, parsed.latitude, parsed.longitude, requirements, sessionId, stateOptions.length, t]);
|
|
311
303
|
if (retry) {
|
|
312
304
|
return /*#__PURE__*/_jsx(RetryDialog, {
|
|
313
305
|
title: t.common.submissionTitle,
|
|
@@ -324,59 +316,49 @@ function AddressDetailsForm({
|
|
|
324
316
|
}
|
|
325
317
|
});
|
|
326
318
|
}
|
|
319
|
+
const streetLine = [form.street, form.number].filter(Boolean).join(' ');
|
|
320
|
+
const placeLine = [form.city, stateLabel].filter(Boolean).join(', ');
|
|
327
321
|
return /*#__PURE__*/_jsxs(View, {
|
|
328
322
|
style: {
|
|
329
323
|
flex: 1
|
|
330
324
|
},
|
|
331
325
|
children: [/*#__PURE__*/_jsxs(StepShell, {
|
|
332
326
|
title: t.address_info.detailsTitle,
|
|
333
|
-
subtitle:
|
|
327
|
+
subtitle: streetLine || undefined,
|
|
334
328
|
iconNode: /*#__PURE__*/_jsx(HomeHeartIcon, {}),
|
|
335
|
-
children: [/*#__PURE__*/
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
})
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
onChangeText: setApartment,
|
|
369
|
-
...field('apartment')
|
|
370
|
-
})
|
|
371
|
-
})]
|
|
372
|
-
}), /*#__PURE__*/_jsx(Input, {
|
|
373
|
-
label: t.address_info.references,
|
|
374
|
-
autoCorrect: true,
|
|
375
|
-
multiline: true,
|
|
376
|
-
numberOfLines: 3,
|
|
377
|
-
value: details,
|
|
378
|
-
onChangeText: setDetails,
|
|
379
|
-
...field('details')
|
|
329
|
+
children: [editing ? /*#__PURE__*/_jsx(AddressFields, {
|
|
330
|
+
locale: locale,
|
|
331
|
+
form: form,
|
|
332
|
+
errors: errors,
|
|
333
|
+
requirements: requirements,
|
|
334
|
+
stateOptions: stateOptions,
|
|
335
|
+
allowedCodes: allowedCodes,
|
|
336
|
+
setField: setField,
|
|
337
|
+
field: field
|
|
338
|
+
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
|
339
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
340
|
+
style: [styles.summary, {
|
|
341
|
+
color: theme.textSecondaryColor
|
|
342
|
+
}],
|
|
343
|
+
children: placeLine ? `${placeLine} (${form.country})` : form.country
|
|
344
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
345
|
+
variant: "ghost",
|
|
346
|
+
label: t.address_info.editAddress,
|
|
347
|
+
onPress: () => setEditing(true),
|
|
348
|
+
disabled: submitting
|
|
349
|
+
}), !stateResolved && stateOptions.length > 0 ? /*#__PURE__*/_jsx(StateSelect, {
|
|
350
|
+
locale: locale,
|
|
351
|
+
form: form,
|
|
352
|
+
errors: errors,
|
|
353
|
+
required: requirements.state,
|
|
354
|
+
stateOptions: stateOptions,
|
|
355
|
+
setField: setField
|
|
356
|
+
}) : null]
|
|
357
|
+
}), /*#__PURE__*/_jsx(DetailsFields, {
|
|
358
|
+
form: form,
|
|
359
|
+
setField: setField,
|
|
360
|
+
field: field,
|
|
361
|
+
locale: locale
|
|
380
362
|
}), bannerError ? /*#__PURE__*/_jsx(Banner, {
|
|
381
363
|
message: bannerError
|
|
382
364
|
}) : null, /*#__PURE__*/_jsxs(View, {
|
|
@@ -403,13 +385,225 @@ function AddressDetailsForm({
|
|
|
403
385
|
}
|
|
404
386
|
|
|
405
387
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
406
|
-
//
|
|
407
|
-
//
|
|
388
|
+
// SHARED FIELDS — the address inputs of the manual form, reused by the assisted
|
|
389
|
+
// flow's "edit address" section so both validate and look the same (OSDKR-43).
|
|
408
390
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
409
391
|
|
|
410
392
|
/** Visual order of the manual form's text inputs, for keyboard "next" chaining.
|
|
411
393
|
* Module-level so the chain callback stays stable across renders. */
|
|
412
394
|
const MANUAL_FIELD_ORDER = ['city', 'district', 'neighborhood', 'street', 'number', 'zip_code', 'floor', 'apartment', 'details'];
|
|
395
|
+
|
|
396
|
+
/** Updates one field and clears its error. */
|
|
397
|
+
function useFieldSetter(setForm, setErrors) {
|
|
398
|
+
return useCallback((key, value) => {
|
|
399
|
+
setForm(prev => ({
|
|
400
|
+
...prev,
|
|
401
|
+
[key]: value
|
|
402
|
+
}));
|
|
403
|
+
setErrors(prev => {
|
|
404
|
+
if (!(key in prev)) return prev;
|
|
405
|
+
const next = {
|
|
406
|
+
...prev
|
|
407
|
+
};
|
|
408
|
+
delete next[key];
|
|
409
|
+
return next;
|
|
410
|
+
});
|
|
411
|
+
}, [setErrors, setForm]);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** The fields both flows send, trimmed; optional ones only when filled. */
|
|
415
|
+
function addressPayload(form, addressType) {
|
|
416
|
+
return {
|
|
417
|
+
type: addressType,
|
|
418
|
+
country: form.country.toUpperCase(),
|
|
419
|
+
state: form.state,
|
|
420
|
+
city: form.city.trim(),
|
|
421
|
+
street: form.street.trim(),
|
|
422
|
+
number: form.number.trim(),
|
|
423
|
+
zip_code: form.zip_code.trim(),
|
|
424
|
+
...(form.district.trim() && {
|
|
425
|
+
district: form.district.trim()
|
|
426
|
+
}),
|
|
427
|
+
...(form.neighborhood.trim() && {
|
|
428
|
+
neighborhood: form.neighborhood.trim()
|
|
429
|
+
}),
|
|
430
|
+
...(form.floor.trim() && {
|
|
431
|
+
floor: form.floor.trim()
|
|
432
|
+
}),
|
|
433
|
+
...(form.apartment.trim() && {
|
|
434
|
+
apartment: form.apartment.trim()
|
|
435
|
+
}),
|
|
436
|
+
...(form.details.trim() && {
|
|
437
|
+
details: form.details.trim()
|
|
438
|
+
})
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
function StateSelect({
|
|
442
|
+
locale,
|
|
443
|
+
form,
|
|
444
|
+
errors,
|
|
445
|
+
required,
|
|
446
|
+
stateOptions,
|
|
447
|
+
setField
|
|
448
|
+
}) {
|
|
449
|
+
const t = getStrings(locale);
|
|
450
|
+
return /*#__PURE__*/_jsx(Select, {
|
|
451
|
+
label: t.address_info.state,
|
|
452
|
+
required: required,
|
|
453
|
+
options: stateOptions,
|
|
454
|
+
value: form.state || null,
|
|
455
|
+
onChange: v => setField('state', v),
|
|
456
|
+
placeholder: t.address_info.statePlaceholder,
|
|
457
|
+
errorMessage: errors.state ?? null
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
/** Country, state, city, district, neighborhood, street, number and zip code. */
|
|
461
|
+
function AddressFields({
|
|
462
|
+
locale,
|
|
463
|
+
form,
|
|
464
|
+
errors,
|
|
465
|
+
requirements,
|
|
466
|
+
stateOptions,
|
|
467
|
+
allowedCodes,
|
|
468
|
+
setField,
|
|
469
|
+
field
|
|
470
|
+
}) {
|
|
471
|
+
const t = getStrings(locale);
|
|
472
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
473
|
+
children: [/*#__PURE__*/_jsx(CountrySelect, {
|
|
474
|
+
label: t.address_info.country,
|
|
475
|
+
required: true,
|
|
476
|
+
value: form.country || null,
|
|
477
|
+
onChange: v => {
|
|
478
|
+
setField('country', v);
|
|
479
|
+
// A state of the previous country would be rejected by the backend.
|
|
480
|
+
if (v !== form.country) setField('state', '');
|
|
481
|
+
},
|
|
482
|
+
locale: locale,
|
|
483
|
+
allowedCodes: allowedCodes,
|
|
484
|
+
placeholder: t.address_info.countryPlaceholder,
|
|
485
|
+
searchPlaceholder: t.address_info.countryPlaceholder,
|
|
486
|
+
errorMessage: errors.country ?? null
|
|
487
|
+
}), stateOptions.length > 0 ? /*#__PURE__*/_jsx(StateSelect, {
|
|
488
|
+
locale: locale,
|
|
489
|
+
form: form,
|
|
490
|
+
errors: errors,
|
|
491
|
+
required: requirements.state,
|
|
492
|
+
stateOptions: stateOptions,
|
|
493
|
+
setField: setField
|
|
494
|
+
}) : null, /*#__PURE__*/_jsx(Input, {
|
|
495
|
+
label: t.address_info.city,
|
|
496
|
+
required: requirements.city,
|
|
497
|
+
autoCapitalize: "words",
|
|
498
|
+
autoCorrect: false,
|
|
499
|
+
value: form.city,
|
|
500
|
+
onChangeText: v => setField('city', v),
|
|
501
|
+
errorMessage: errors.city ?? null,
|
|
502
|
+
...field('city')
|
|
503
|
+
}), /*#__PURE__*/_jsx(Input, {
|
|
504
|
+
label: t.address_info.district,
|
|
505
|
+
required: requirements.district,
|
|
506
|
+
autoCapitalize: "words",
|
|
507
|
+
autoCorrect: false,
|
|
508
|
+
value: form.district,
|
|
509
|
+
onChangeText: v => setField('district', v),
|
|
510
|
+
errorMessage: errors.district ?? null,
|
|
511
|
+
...field('district')
|
|
512
|
+
}), /*#__PURE__*/_jsx(Input, {
|
|
513
|
+
label: t.address_info.neighborhood,
|
|
514
|
+
required: requirements.neighborhood,
|
|
515
|
+
autoCapitalize: "words",
|
|
516
|
+
autoCorrect: false,
|
|
517
|
+
value: form.neighborhood,
|
|
518
|
+
onChangeText: v => setField('neighborhood', v),
|
|
519
|
+
errorMessage: errors.neighborhood ?? null,
|
|
520
|
+
...field('neighborhood')
|
|
521
|
+
}), /*#__PURE__*/_jsx(Input, {
|
|
522
|
+
label: t.address_info.street,
|
|
523
|
+
required: requirements.street,
|
|
524
|
+
autoCapitalize: "words",
|
|
525
|
+
autoCorrect: false,
|
|
526
|
+
value: form.street,
|
|
527
|
+
onChangeText: v => setField('street', v),
|
|
528
|
+
errorMessage: errors.street ?? null,
|
|
529
|
+
...field('street')
|
|
530
|
+
}), /*#__PURE__*/_jsxs(View, {
|
|
531
|
+
style: styles.row,
|
|
532
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
533
|
+
style: styles.col,
|
|
534
|
+
children: /*#__PURE__*/_jsx(Input, {
|
|
535
|
+
label: t.address_info.number,
|
|
536
|
+
required: requirements.number,
|
|
537
|
+
keyboardType: "number-pad",
|
|
538
|
+
autoCorrect: false,
|
|
539
|
+
value: form.number,
|
|
540
|
+
onChangeText: v => setField('number', v),
|
|
541
|
+
errorMessage: errors.number ?? null,
|
|
542
|
+
...field('number')
|
|
543
|
+
})
|
|
544
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
545
|
+
style: styles.col,
|
|
546
|
+
children: /*#__PURE__*/_jsx(Input, {
|
|
547
|
+
label: t.address_info.zipCode,
|
|
548
|
+
required: requirements.zip,
|
|
549
|
+
autoCapitalize: "characters",
|
|
550
|
+
autoCorrect: false,
|
|
551
|
+
value: form.zip_code,
|
|
552
|
+
onChangeText: v => setField('zip_code', v),
|
|
553
|
+
errorMessage: errors.zip_code ?? null,
|
|
554
|
+
...field('zip_code')
|
|
555
|
+
})
|
|
556
|
+
})]
|
|
557
|
+
})]
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
/** Floor, apartment and references: optional in both flows. */
|
|
561
|
+
function DetailsFields({
|
|
562
|
+
locale,
|
|
563
|
+
form,
|
|
564
|
+
setField,
|
|
565
|
+
field
|
|
566
|
+
}) {
|
|
567
|
+
const t = getStrings(locale);
|
|
568
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
569
|
+
children: [/*#__PURE__*/_jsxs(View, {
|
|
570
|
+
style: styles.row,
|
|
571
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
572
|
+
style: styles.col,
|
|
573
|
+
children: /*#__PURE__*/_jsx(Input, {
|
|
574
|
+
label: t.address_info.floor,
|
|
575
|
+
autoCorrect: false,
|
|
576
|
+
value: form.floor,
|
|
577
|
+
onChangeText: v => setField('floor', v),
|
|
578
|
+
...field('floor')
|
|
579
|
+
})
|
|
580
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
581
|
+
style: styles.col,
|
|
582
|
+
children: /*#__PURE__*/_jsx(Input, {
|
|
583
|
+
label: t.address_info.apartment,
|
|
584
|
+
autoCorrect: false,
|
|
585
|
+
value: form.apartment,
|
|
586
|
+
onChangeText: v => setField('apartment', v),
|
|
587
|
+
...field('apartment')
|
|
588
|
+
})
|
|
589
|
+
})]
|
|
590
|
+
}), /*#__PURE__*/_jsx(Input, {
|
|
591
|
+
label: t.address_info.references,
|
|
592
|
+
autoCorrect: true,
|
|
593
|
+
multiline: true,
|
|
594
|
+
numberOfLines: 3,
|
|
595
|
+
value: form.details,
|
|
596
|
+
onChangeText: v => setField('details', v),
|
|
597
|
+
...field('details')
|
|
598
|
+
})]
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
603
|
+
// MANUAL FLOW — structured form, kept side-by-side with the assisted flow so
|
|
604
|
+
// consumers without a Maps key still get a full onboarding experience.
|
|
605
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
606
|
+
|
|
413
607
|
function ManualAddressForm({
|
|
414
608
|
api,
|
|
415
609
|
sessionId,
|
|
@@ -421,27 +615,14 @@ function ManualAddressForm({
|
|
|
421
615
|
onCancel
|
|
422
616
|
}) {
|
|
423
617
|
const t = getStrings(locale);
|
|
424
|
-
const f = stepConfig?.fields;
|
|
425
618
|
// "Next" on the keyboard walks down the form (and the scroll follows the
|
|
426
619
|
// focused input); only the last field closes it, which is what brings the
|
|
427
620
|
// submit button back into reach (OSDKR-14).
|
|
428
621
|
const {
|
|
429
622
|
field
|
|
430
623
|
} = useFieldChain(MANUAL_FIELD_ORDER);
|
|
431
|
-
const allowedCodes = useMemo(() =>
|
|
432
|
-
|
|
433
|
-
if (!Array.isArray(allow) || allow.length === 0) return undefined;
|
|
434
|
-
return allow.map(c => c.toUpperCase());
|
|
435
|
-
}, [stepConfig?.country_allow]);
|
|
436
|
-
const requirements = useMemo(() => ({
|
|
437
|
-
state: f?.state?.required !== false,
|
|
438
|
-
city: f?.city?.required !== false,
|
|
439
|
-
district: f?.district?.required === true,
|
|
440
|
-
neighborhood: f?.neighborhood?.required === true,
|
|
441
|
-
street: f?.street?.required !== false,
|
|
442
|
-
number: f?.number?.required !== false,
|
|
443
|
-
zip: f?.postal_code?.required !== false
|
|
444
|
-
}), [f]);
|
|
624
|
+
const allowedCodes = useMemo(() => allowedCountries(stepConfig?.country_allow), [stepConfig?.country_allow]);
|
|
625
|
+
const requirements = useMemo(() => addressRequirements(stepConfig?.fields), [stepConfig?.fields]);
|
|
445
626
|
const [form, setForm] = useState(() => {
|
|
446
627
|
// Seed from prefill first (reverse navigation re-opened this step), then
|
|
447
628
|
// fall back to a single allowed country. Prefill takes precedence.
|
|
@@ -478,63 +659,16 @@ function ManualAddressForm({
|
|
|
478
659
|
const [submitting, setSubmitting] = useState(false);
|
|
479
660
|
const [retry, setRetry] = useState(null);
|
|
480
661
|
const stateOptions = useMemo(() => listStateOptions(form.country, locale), [form.country, locale]);
|
|
481
|
-
const setField =
|
|
482
|
-
setForm(prev => ({
|
|
483
|
-
...prev,
|
|
484
|
-
[key]: value
|
|
485
|
-
}));
|
|
486
|
-
setErrors(prev => {
|
|
487
|
-
if (!(key in prev)) return prev;
|
|
488
|
-
const next = {
|
|
489
|
-
...prev
|
|
490
|
-
};
|
|
491
|
-
delete next[key];
|
|
492
|
-
return next;
|
|
493
|
-
});
|
|
494
|
-
}, []);
|
|
495
|
-
const validate = useCallback(() => {
|
|
496
|
-
const next = {};
|
|
497
|
-
if (!form.country) next.country = t.address_info.requiredCountry;
|
|
498
|
-
if (requirements.state && stateOptions.length > 0 && !form.state) next.state = t.address_info.requiredState;
|
|
499
|
-
if (requirements.city && !form.city.trim()) next.city = t.address_info.requiredCity;
|
|
500
|
-
if (requirements.district && !form.district.trim()) next.district = t.address_info.requiredDistrict;
|
|
501
|
-
if (requirements.neighborhood && !form.neighborhood.trim()) next.neighborhood = t.address_info.requiredNeighborhood;
|
|
502
|
-
if (requirements.street && !form.street.trim()) next.street = t.address_info.requiredStreet;
|
|
503
|
-
if (requirements.number && !form.number.trim()) next.number = t.address_info.requiredNumber;
|
|
504
|
-
if (requirements.zip && !form.zip_code.trim()) next.zip_code = t.address_info.requiredZip;
|
|
505
|
-
setErrors(next);
|
|
506
|
-
return Object.keys(next).length === 0;
|
|
507
|
-
}, [form, requirements, stateOptions.length, t.address_info]);
|
|
662
|
+
const setField = useFieldSetter(setForm, setErrors);
|
|
508
663
|
const handleSubmit = useCallback(async () => {
|
|
509
664
|
setBannerError(null);
|
|
510
|
-
|
|
665
|
+
const next = validateAddressForm(form, requirements, stateOptions.length > 0, t.address_info);
|
|
666
|
+
setErrors(next);
|
|
667
|
+
if (Object.keys(next).length > 0) {
|
|
511
668
|
setBannerError(t.address_info.fillAllRequired);
|
|
512
669
|
return;
|
|
513
670
|
}
|
|
514
|
-
const payload =
|
|
515
|
-
type: stepConfig?.address_type?.id ?? ADDRESS_TYPE_HOME,
|
|
516
|
-
country: form.country.toUpperCase(),
|
|
517
|
-
state: form.state,
|
|
518
|
-
city: form.city.trim(),
|
|
519
|
-
street: form.street.trim(),
|
|
520
|
-
number: form.number.trim(),
|
|
521
|
-
zip_code: form.zip_code.trim(),
|
|
522
|
-
...(form.district.trim() && {
|
|
523
|
-
district: form.district.trim()
|
|
524
|
-
}),
|
|
525
|
-
...(form.neighborhood.trim() && {
|
|
526
|
-
neighborhood: form.neighborhood.trim()
|
|
527
|
-
}),
|
|
528
|
-
...(form.floor.trim() && {
|
|
529
|
-
floor: form.floor.trim()
|
|
530
|
-
}),
|
|
531
|
-
...(form.apartment.trim() && {
|
|
532
|
-
apartment: form.apartment.trim()
|
|
533
|
-
}),
|
|
534
|
-
...(form.details.trim() && {
|
|
535
|
-
details: form.details.trim()
|
|
536
|
-
})
|
|
537
|
-
};
|
|
671
|
+
const payload = addressPayload(form, stepConfig?.address_type?.id ?? ADDRESS_TYPE_HOME);
|
|
538
672
|
setSubmitting(true);
|
|
539
673
|
try {
|
|
540
674
|
await api.post(`/sessions/${sessionId}/address-info`, payload);
|
|
@@ -548,7 +682,7 @@ function ManualAddressForm({
|
|
|
548
682
|
message: sdkErr.message
|
|
549
683
|
});
|
|
550
684
|
}
|
|
551
|
-
}, [api, form, onComplete, sessionId, stepConfig?.address_type?.id, t
|
|
685
|
+
}, [api, form, onComplete, requirements, sessionId, stateOptions.length, stepConfig?.address_type?.id, t]);
|
|
552
686
|
if (retry) {
|
|
553
687
|
return /*#__PURE__*/_jsx(RetryDialog, {
|
|
554
688
|
title: t.common.submissionTitle,
|
|
@@ -576,120 +710,20 @@ function ManualAddressForm({
|
|
|
576
710
|
onBack: onBack,
|
|
577
711
|
backLabel: t.common.back,
|
|
578
712
|
backDisabled: submitting,
|
|
579
|
-
children: [/*#__PURE__*/_jsx(
|
|
580
|
-
label: t.address_info.country,
|
|
581
|
-
required: true,
|
|
582
|
-
value: form.country || null,
|
|
583
|
-
onChange: v => {
|
|
584
|
-
setField('country', v);
|
|
585
|
-
// A state of the previous country would be rejected by the backend.
|
|
586
|
-
if (v !== form.country) setField('state', '');
|
|
587
|
-
},
|
|
713
|
+
children: [/*#__PURE__*/_jsx(AddressFields, {
|
|
588
714
|
locale: locale,
|
|
715
|
+
form: form,
|
|
716
|
+
errors: errors,
|
|
717
|
+
requirements: requirements,
|
|
718
|
+
stateOptions: stateOptions,
|
|
589
719
|
allowedCodes: allowedCodes,
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
value: form.state || null,
|
|
598
|
-
onChange: v => setField('state', v),
|
|
599
|
-
placeholder: t.address_info.statePlaceholder,
|
|
600
|
-
errorMessage: errors.state ?? null
|
|
601
|
-
}) : null, /*#__PURE__*/_jsx(Input, {
|
|
602
|
-
label: t.address_info.city,
|
|
603
|
-
required: requirements.city,
|
|
604
|
-
autoCapitalize: "words",
|
|
605
|
-
autoCorrect: false,
|
|
606
|
-
value: form.city,
|
|
607
|
-
onChangeText: v => setField('city', v),
|
|
608
|
-
errorMessage: errors.city ?? null,
|
|
609
|
-
...field('city')
|
|
610
|
-
}), /*#__PURE__*/_jsx(Input, {
|
|
611
|
-
label: t.address_info.district,
|
|
612
|
-
required: requirements.district,
|
|
613
|
-
autoCapitalize: "words",
|
|
614
|
-
autoCorrect: false,
|
|
615
|
-
value: form.district,
|
|
616
|
-
onChangeText: v => setField('district', v),
|
|
617
|
-
errorMessage: errors.district ?? null,
|
|
618
|
-
...field('district')
|
|
619
|
-
}), /*#__PURE__*/_jsx(Input, {
|
|
620
|
-
label: t.address_info.neighborhood,
|
|
621
|
-
required: requirements.neighborhood,
|
|
622
|
-
autoCapitalize: "words",
|
|
623
|
-
autoCorrect: false,
|
|
624
|
-
value: form.neighborhood,
|
|
625
|
-
onChangeText: v => setField('neighborhood', v),
|
|
626
|
-
errorMessage: errors.neighborhood ?? null,
|
|
627
|
-
...field('neighborhood')
|
|
628
|
-
}), /*#__PURE__*/_jsx(Input, {
|
|
629
|
-
label: t.address_info.street,
|
|
630
|
-
required: requirements.street,
|
|
631
|
-
autoCapitalize: "words",
|
|
632
|
-
autoCorrect: false,
|
|
633
|
-
value: form.street,
|
|
634
|
-
onChangeText: v => setField('street', v),
|
|
635
|
-
errorMessage: errors.street ?? null,
|
|
636
|
-
...field('street')
|
|
637
|
-
}), /*#__PURE__*/_jsxs(View, {
|
|
638
|
-
style: styles.row,
|
|
639
|
-
children: [/*#__PURE__*/_jsx(View, {
|
|
640
|
-
style: styles.col,
|
|
641
|
-
children: /*#__PURE__*/_jsx(Input, {
|
|
642
|
-
label: t.address_info.number,
|
|
643
|
-
required: requirements.number,
|
|
644
|
-
keyboardType: "number-pad",
|
|
645
|
-
autoCorrect: false,
|
|
646
|
-
value: form.number,
|
|
647
|
-
onChangeText: v => setField('number', v),
|
|
648
|
-
errorMessage: errors.number ?? null,
|
|
649
|
-
...field('number')
|
|
650
|
-
})
|
|
651
|
-
}), /*#__PURE__*/_jsx(View, {
|
|
652
|
-
style: styles.col,
|
|
653
|
-
children: /*#__PURE__*/_jsx(Input, {
|
|
654
|
-
label: t.address_info.zipCode,
|
|
655
|
-
required: requirements.zip,
|
|
656
|
-
autoCapitalize: "characters",
|
|
657
|
-
autoCorrect: false,
|
|
658
|
-
value: form.zip_code,
|
|
659
|
-
onChangeText: v => setField('zip_code', v),
|
|
660
|
-
errorMessage: errors.zip_code ?? null,
|
|
661
|
-
...field('zip_code')
|
|
662
|
-
})
|
|
663
|
-
})]
|
|
664
|
-
}), /*#__PURE__*/_jsxs(View, {
|
|
665
|
-
style: styles.row,
|
|
666
|
-
children: [/*#__PURE__*/_jsx(View, {
|
|
667
|
-
style: styles.col,
|
|
668
|
-
children: /*#__PURE__*/_jsx(Input, {
|
|
669
|
-
label: t.address_info.floor,
|
|
670
|
-
autoCorrect: false,
|
|
671
|
-
value: form.floor,
|
|
672
|
-
onChangeText: v => setField('floor', v),
|
|
673
|
-
...field('floor')
|
|
674
|
-
})
|
|
675
|
-
}), /*#__PURE__*/_jsx(View, {
|
|
676
|
-
style: styles.col,
|
|
677
|
-
children: /*#__PURE__*/_jsx(Input, {
|
|
678
|
-
label: t.address_info.apartment,
|
|
679
|
-
autoCorrect: false,
|
|
680
|
-
value: form.apartment,
|
|
681
|
-
onChangeText: v => setField('apartment', v),
|
|
682
|
-
...field('apartment')
|
|
683
|
-
})
|
|
684
|
-
})]
|
|
685
|
-
}), /*#__PURE__*/_jsx(Input, {
|
|
686
|
-
label: t.address_info.references,
|
|
687
|
-
autoCorrect: true,
|
|
688
|
-
multiline: true,
|
|
689
|
-
numberOfLines: 3,
|
|
690
|
-
value: form.details,
|
|
691
|
-
onChangeText: v => setField('details', v),
|
|
692
|
-
...field('details')
|
|
720
|
+
setField: setField,
|
|
721
|
+
field: field
|
|
722
|
+
}), /*#__PURE__*/_jsx(DetailsFields, {
|
|
723
|
+
form: form,
|
|
724
|
+
setField: setField,
|
|
725
|
+
field: field,
|
|
726
|
+
locale: locale
|
|
693
727
|
}), bannerError ? /*#__PURE__*/_jsx(Banner, {
|
|
694
728
|
message: bannerError
|
|
695
729
|
}) : null, /*#__PURE__*/_jsx(Button, {
|
|
@@ -703,6 +737,12 @@ function ManualAddressForm({
|
|
|
703
737
|
}) : null]
|
|
704
738
|
});
|
|
705
739
|
}
|
|
740
|
+
|
|
741
|
+
/** The `country_allow` of the step config, upper-cased, or `undefined` for every country. */
|
|
742
|
+
function allowedCountries(allow) {
|
|
743
|
+
if (!Array.isArray(allow) || allow.length === 0) return undefined;
|
|
744
|
+
return allow.map(c => c.toUpperCase());
|
|
745
|
+
}
|
|
706
746
|
const styles = StyleSheet.create({
|
|
707
747
|
row: {
|
|
708
748
|
flexDirection: 'row',
|