@velion-la/onboarding-sdk-react-native 1.3.0-beta.24 → 1.3.0-beta.26

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