@quantaroute/checkout 1.4.2 → 1.4.4

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.
@@ -26,6 +26,7 @@ import type {
26
26
  LocationAlternative,
27
27
  } from '../core/types';
28
28
  import { styles, COLORS } from '../styles/checkout.native';
29
+ import { AddressDetailsIcon, AddressLabelIcon } from './AddressLabelIcons.native';
29
30
 
30
31
  // ─── State (identical logic to web AddressForm) ───────────────────────────────
31
32
 
@@ -45,6 +46,7 @@ type FormState =
45
46
  alternatives: LocationAlternative[];
46
47
  selectedLocality: string;
47
48
  selectedLabel: AddressLabel;
49
+ labelText: string;
48
50
  fields: ManualFields;
49
51
  submitting: boolean;
50
52
  pincodeHasDelivery: boolean;
@@ -63,6 +65,7 @@ type FormAction =
63
65
  | { type: 'SET_FIELD'; key: keyof ManualFields; value: string }
64
66
  | { type: 'SET_LOCALITY'; locality: string }
65
67
  | { type: 'SET_LABEL'; label: AddressLabel }
68
+ | { type: 'SET_LABEL_TEXT'; value: string }
66
69
  | { type: 'SUBMIT_START' }
67
70
  | { type: 'SUBMIT_END' };
68
71
 
@@ -106,6 +109,7 @@ function reducer(state: FormState, action: FormAction): FormState {
106
109
  alternatives: action.alternatives || [],
107
110
  selectedLocality: action.adminInfo.locality,
108
111
  selectedLabel: 'home',
112
+ labelText: '',
109
113
  fields: { ...INITIAL_FIELDS, ...preFilled },
110
114
  submitting: false,
111
115
  pincodeHasDelivery: action.pincodeHasDelivery,
@@ -121,7 +125,14 @@ function reducer(state: FormState, action: FormAction): FormState {
121
125
  return { ...state, selectedLocality: action.locality };
122
126
  case 'SET_LABEL':
123
127
  if (state.status !== 'ready') return state;
124
- return { ...state, selectedLabel: action.label };
128
+ return {
129
+ ...state,
130
+ selectedLabel: action.label,
131
+ labelText: action.label === 'other' ? state.labelText : '',
132
+ };
133
+ case 'SET_LABEL_TEXT':
134
+ if (state.status !== 'ready') return state;
135
+ return { ...state, labelText: action.value.slice(0, 64) };
125
136
  case 'SUBMIT_START':
126
137
  if (state.status !== 'ready') return state;
127
138
  return { ...state, submitting: true };
@@ -214,8 +225,9 @@ const AddressForm: React.FC<AddressFormProps> = ({
214
225
  const handleSubmit = useCallback(() => {
215
226
  if (state.status !== 'ready') return;
216
227
  if (!state.fields.flatNumber.trim()) return;
228
+ if (state.selectedLabel === 'other' && !state.labelText.trim()) return;
217
229
 
218
- const { adminInfo, selectedLocality, selectedLabel, fields } = state;
230
+ const { adminInfo, selectedLocality, selectedLabel, labelText, fields } = state;
219
231
 
220
232
  const parts: string[] = [
221
233
  fields.flatNumber,
@@ -242,6 +254,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
242
254
  ...fields,
243
255
  formattedAddress: parts.join(', '),
244
256
  label: selectedLabel,
257
+ ...(selectedLabel === 'other' ? { labelText: labelText.trim() } : {}),
245
258
  };
246
259
 
247
260
  dispatch({ type: 'SUBMIT_START' });
@@ -368,7 +381,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
368
381
  <View style={styles.sectionHeader}>
369
382
  <Text style={styles.sectionHeaderIcon}>📍</Text>
370
383
  <Text style={[styles.sectionHeaderText, isDark && styles.sectionHeaderTextDark]}>
371
- Auto-detected from your pin
384
+ Auto-detected from your digipin
372
385
  </Text>
373
386
  </View>
374
387
 
@@ -457,20 +470,27 @@ const AddressForm: React.FC<AddressFormProps> = ({
457
470
 
458
471
  {/* Address label */}
459
472
  <View style={[styles.sectionDivider, isDark && styles.sectionDividerDark]} />
460
- <View style={styles.sectionHeader}>
461
- <Text style={[styles.sectionHeaderText, isDark && styles.sectionHeaderTextDark]}>
473
+ <View style={[styles.sectionHeader, styles.sectionHeaderCompact]}>
474
+ <Text
475
+ style={[
476
+ styles.sectionHeaderText,
477
+ styles.sectionHeaderTextCompact,
478
+ isDark && styles.sectionHeaderTextDark,
479
+ ]}
480
+ >
462
481
  Save as
463
482
  </Text>
464
483
  </View>
465
484
  <View style={styles.labelPicker}>
466
485
  {(
467
486
  [
468
- { value: 'home' as const, title: 'Home', icon: '🏠' },
469
- { value: 'work' as const, title: 'Work', icon: '💼' },
470
- { value: 'other' as const, title: 'Other', icon: '📍' },
487
+ { value: 'home' as const, title: 'Home' },
488
+ { value: 'work' as const, title: 'Work' },
489
+ { value: 'other' as const, title: 'Other' },
471
490
  ] as const
472
- ).map(({ value, title, icon }) => {
491
+ ).map(({ value, title }) => {
473
492
  const active = state.selectedLabel === value;
493
+ const iconColor = active ? COLORS.primary : COLORS.textMuted;
474
494
  return (
475
495
  <TouchableOpacity
476
496
  key={value}
@@ -484,9 +504,12 @@ const AddressForm: React.FC<AddressFormProps> = ({
484
504
  accessibilityRole="radio"
485
505
  accessibilityState={{ checked: active }}
486
506
  accessibilityLabel={title}
487
- activeOpacity={0.8}
507
+ activeOpacity={0.97}
488
508
  >
489
- <Text style={styles.labelPickerIcon}>{icon}</Text>
509
+ <AddressLabelIcon
510
+ label={value}
511
+ color={isDark && !active ? COLORS.textMutedDark : iconColor}
512
+ />
490
513
  <Text
491
514
  style={[
492
515
  styles.labelPickerText,
@@ -500,11 +523,39 @@ const AddressForm: React.FC<AddressFormProps> = ({
500
523
  );
501
524
  })}
502
525
  </View>
526
+ {state.selectedLabel === 'other' ? (
527
+ <View style={styles.labelTextField}>
528
+ <View style={styles.fieldLabel}>
529
+ <Text style={[styles.fieldLabelText, isDark && styles.fieldLabelTextDark]}>
530
+ Label name
531
+ </Text>
532
+ <Text style={styles.fieldRequired}>*</Text>
533
+ </View>
534
+ <TextInput
535
+ style={[
536
+ styles.fieldInput,
537
+ isDark && styles.fieldInputDark,
538
+ ]}
539
+ placeholder="e.g. Friend's home, Gym"
540
+ placeholderTextColor={isDark ? COLORS.textFaintDark : COLORS.textFaint}
541
+ value={state.labelText}
542
+ onChangeText={(value) =>
543
+ dispatch({ type: 'SET_LABEL_TEXT', value })
544
+ }
545
+ maxLength={64}
546
+ autoCapitalize="words"
547
+ returnKeyType="next"
548
+ />
549
+ </View>
550
+ ) : null}
503
551
 
504
552
  {/* Manual entry section */}
505
553
  <View style={[styles.sectionDivider, isDark && styles.sectionDividerDark]} />
506
554
  <View style={styles.sectionHeader}>
507
- <Text style={styles.sectionHeaderIcon}>🏠</Text>
555
+ <AddressDetailsIcon
556
+ color={isDark ? COLORS.textMutedDark : COLORS.textMuted}
557
+ size={14}
558
+ />
508
559
  <Text style={[styles.sectionHeaderText, isDark && styles.sectionHeaderTextDark]}>
509
560
  Your details
510
561
  </Text>
@@ -560,10 +611,15 @@ const AddressForm: React.FC<AddressFormProps> = ({
560
611
  style={[
561
612
  styles.btnPrimary,
562
613
  { flex: 1 },
563
- (state.submitting || !state.fields.flatNumber.trim()) && styles.btnDisabled,
614
+ (state.submitting || !state.fields.flatNumber.trim()
615
+ || (state.selectedLabel === 'other' && !state.labelText.trim())) && styles.btnDisabled,
564
616
  ]}
565
617
  onPress={handleSubmit}
566
- disabled={state.submitting || !state.fields.flatNumber.trim()}
618
+ disabled={
619
+ state.submitting
620
+ || !state.fields.flatNumber.trim()
621
+ || (state.selectedLabel === 'other' && !state.labelText.trim())
622
+ }
567
623
  activeOpacity={0.8}
568
624
  accessibilityRole="button"
569
625
  accessibilityLabel="Save address"
@@ -13,6 +13,7 @@ import type {
13
13
  CompleteAddress,
14
14
  LocationAlternative,
15
15
  } from '../core/types';
16
+ import { AddressLabelIcon } from './AddressLabelIcons';
16
17
 
17
18
  // ─── State ────────────────────────────────────────────────────────────────────
18
19
 
@@ -32,6 +33,7 @@ type FormState =
32
33
  alternatives: LocationAlternative[];
33
34
  selectedLocality: string; // Selected locality name (from adminInfo or alternatives)
34
35
  selectedLabel: AddressLabel;
36
+ labelText: string;
35
37
  fields: ManualFields;
36
38
  submitting: boolean;
37
39
  /** At least one India Post office with "Delivery" (not only "Non Delivery") */
@@ -51,6 +53,7 @@ type FormAction =
51
53
  | { type: 'SET_FIELD'; key: keyof ManualFields; value: string }
52
54
  | { type: 'SET_LOCALITY'; locality: string }
53
55
  | { type: 'SET_LABEL'; label: AddressLabel }
56
+ | { type: 'SET_LABEL_TEXT'; value: string }
54
57
  | { type: 'SUBMIT_START' }
55
58
  | { type: 'SUBMIT_END' };
56
59
 
@@ -107,6 +110,7 @@ function reducer(state: FormState, action: FormAction): FormState {
107
110
  alternatives: action.alternatives || [],
108
111
  selectedLocality: action.adminInfo.locality,
109
112
  selectedLabel: 'home',
113
+ labelText: '',
110
114
  fields: { ...INITIAL_FIELDS, ...preFilled },
111
115
  submitting: false,
112
116
  pincodeHasDelivery: action.pincodeHasDelivery,
@@ -122,7 +126,14 @@ function reducer(state: FormState, action: FormAction): FormState {
122
126
  return { ...state, selectedLocality: action.locality };
123
127
  case 'SET_LABEL':
124
128
  if (state.status !== 'ready') return state;
125
- return { ...state, selectedLabel: action.label };
129
+ return {
130
+ ...state,
131
+ selectedLabel: action.label,
132
+ labelText: action.label === 'other' ? state.labelText : '',
133
+ };
134
+ case 'SET_LABEL_TEXT':
135
+ if (state.status !== 'ready') return state;
136
+ return { ...state, labelText: action.value.slice(0, 64) };
126
137
  case 'SUBMIT_START':
127
138
  if (state.status !== 'ready') return state;
128
139
  return { ...state, submitting: true };
@@ -209,7 +220,9 @@ const AddressForm: React.FC<AddressFormProps> = ({
209
220
  e.preventDefault();
210
221
  if (state.status !== 'ready') return;
211
222
 
212
- const { adminInfo, selectedLocality, selectedLabel, fields } = state;
223
+ const { adminInfo, selectedLocality, selectedLabel, labelText, fields } = state;
224
+
225
+ if (selectedLabel === 'other' && !labelText.trim()) return;
213
226
 
214
227
  const parts: string[] = [
215
228
  fields.flatNumber,
@@ -236,6 +249,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
236
249
  ...fields,
237
250
  formattedAddress: parts.join(', '),
238
251
  label: selectedLabel,
252
+ ...(selectedLabel === 'other' ? { labelText: labelText.trim() } : {}),
239
253
  };
240
254
 
241
255
  dispatch({ type: 'SUBMIT_START' });
@@ -325,7 +339,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
325
339
  <fieldset className="qr-fieldset">
326
340
  <legend className="qr-fieldset__legend">
327
341
  <span className="qr-fieldset__icon" aria-hidden="true">📍</span>
328
- Auto-detected from your pin
342
+ Auto-detected from your digipin
329
343
  </legend>
330
344
 
331
345
  <div className="qr-auto-grid">
@@ -397,15 +411,15 @@ const AddressForm: React.FC<AddressFormProps> = ({
397
411
 
398
412
  {/* Address label */}
399
413
  <fieldset className="qr-fieldset">
400
- <legend className="qr-fieldset__legend">Save as</legend>
414
+ <legend className="qr-fieldset__legend qr-fieldset__legend--compact">Save as</legend>
401
415
  <div className="qr-label-picker" role="radiogroup" aria-label="Address label">
402
416
  {(
403
417
  [
404
- { value: 'home' as const, title: 'Home', icon: '🏠' },
405
- { value: 'work' as const, title: 'Work', icon: '💼' },
406
- { value: 'other' as const, title: 'Other', icon: '📍' },
418
+ { value: 'home' as const, title: 'Home' },
419
+ { value: 'work' as const, title: 'Work' },
420
+ { value: 'other' as const, title: 'Other' },
407
421
  ] as const
408
- ).map(({ value, title, icon }) => (
422
+ ).map(({ value, title }) => (
409
423
  <button
410
424
  key={value}
411
425
  type="button"
@@ -416,13 +430,35 @@ const AddressForm: React.FC<AddressFormProps> = ({
416
430
  }`}
417
431
  onClick={() => dispatch({ type: 'SET_LABEL', label: value })}
418
432
  >
419
- <span className="qr-label-picker__icon" aria-hidden="true">
420
- {icon}
433
+ <span className="qr-label-picker__icon">
434
+ <AddressLabelIcon label={value} />
421
435
  </span>
422
436
  <span>{title}</span>
423
437
  </button>
424
438
  ))}
425
439
  </div>
440
+ {state.selectedLabel === 'other' && (
441
+ <div className="qr-label-text-field">
442
+ <label className="qr-field__label" htmlFor="qr-labelText">
443
+ Label name
444
+ <span className="qr-required" aria-hidden="true">*</span>
445
+ </label>
446
+ <input
447
+ id="qr-labelText"
448
+ type="text"
449
+ className="qr-field__input"
450
+ placeholder="e.g. Friend's home, Gym"
451
+ value={state.labelText}
452
+ onChange={(e) =>
453
+ dispatch({ type: 'SET_LABEL_TEXT', value: e.target.value })
454
+ }
455
+ maxLength={64}
456
+ required
457
+ aria-required="true"
458
+ autoComplete="off"
459
+ />
460
+ </div>
461
+ )}
426
462
  </fieldset>
427
463
 
428
464
  {/* Manual entry section */}
@@ -535,7 +571,11 @@ const AddressForm: React.FC<AddressFormProps> = ({
535
571
  <button
536
572
  type="submit"
537
573
  className="qr-btn qr-btn--primary qr-btn--grow"
538
- disabled={state.submitting || !state.fields.flatNumber.trim()}
574
+ disabled={
575
+ state.submitting
576
+ || !state.fields.flatNumber.trim()
577
+ || (state.selectedLabel === 'other' && !state.labelText.trim())
578
+ }
539
579
  >
540
580
  {state.submitting ? (
541
581
  <>
@@ -0,0 +1,144 @@
1
+ import { View, StyleSheet } from 'react-native';
2
+ import type { AddressLabel } from '../core/types';
3
+
4
+ interface AddressLabelIconProps {
5
+ label: AddressLabel;
6
+ color: string;
7
+ size?: number;
8
+ }
9
+
10
+ const STROKE = 1.5;
11
+
12
+ /** Minimal View-drawn icons for Home / Work / Other (no react-native-svg). */
13
+ export function AddressLabelIcon({ label, color, size = 16 }: AddressLabelIconProps) {
14
+ switch (label) {
15
+ case 'home':
16
+ return (
17
+ <View style={[styles.wrap, { width: size, height: size }]}>
18
+ <View
19
+ style={{
20
+ width: 0,
21
+ height: 0,
22
+ borderLeftWidth: size * 0.5,
23
+ borderRightWidth: size * 0.5,
24
+ borderBottomWidth: size * 0.38,
25
+ borderLeftColor: 'transparent',
26
+ borderRightColor: 'transparent',
27
+ borderBottomColor: color,
28
+ marginBottom: -STROKE,
29
+ }}
30
+ />
31
+ <View
32
+ style={{
33
+ width: size * 0.68,
34
+ height: size * 0.48,
35
+ borderWidth: STROKE,
36
+ borderColor: color,
37
+ borderRadius: 1,
38
+ }}
39
+ />
40
+ </View>
41
+ );
42
+ case 'work':
43
+ return (
44
+ <View style={[styles.wrap, { width: size, height: size }]}>
45
+ <View
46
+ style={{
47
+ width: size * 0.42,
48
+ height: size * 0.22,
49
+ borderWidth: STROKE,
50
+ borderColor: color,
51
+ borderBottomWidth: 0,
52
+ borderTopLeftRadius: 2,
53
+ borderTopRightRadius: 2,
54
+ marginBottom: -STROKE,
55
+ }}
56
+ />
57
+ <View
58
+ style={{
59
+ width: size * 0.85,
60
+ height: size * 0.55,
61
+ borderWidth: STROKE,
62
+ borderColor: color,
63
+ borderRadius: 2,
64
+ }}
65
+ />
66
+ </View>
67
+ );
68
+ case 'other':
69
+ return (
70
+ <View style={[styles.wrap, { width: size, height: size }]}>
71
+ <View
72
+ style={{
73
+ width: size * 0.55,
74
+ height: size * 0.55,
75
+ borderWidth: STROKE,
76
+ borderColor: color,
77
+ borderRadius: size * 0.275,
78
+ }}
79
+ />
80
+ <View
81
+ style={{
82
+ width: 0,
83
+ height: 0,
84
+ borderLeftWidth: size * 0.22,
85
+ borderRightWidth: size * 0.22,
86
+ borderTopWidth: size * 0.32,
87
+ borderLeftColor: 'transparent',
88
+ borderRightColor: 'transparent',
89
+ borderTopColor: color,
90
+ marginTop: -STROKE * 2,
91
+ }}
92
+ />
93
+ </View>
94
+ );
95
+ }
96
+ }
97
+
98
+ /** Map-pin icon for address / location detail sections (section headers). */
99
+ export function AddressDetailsIcon({ color, size = 14 }: { color: string; size?: number }) {
100
+ return (
101
+ <View style={[styles.wrap, { width: size, height: size }]}>
102
+ <View
103
+ style={{
104
+ width: size * 0.52,
105
+ height: size * 0.52,
106
+ borderWidth: STROKE,
107
+ borderColor: color,
108
+ borderRadius: size * 0.26,
109
+ alignItems: 'center',
110
+ justifyContent: 'center',
111
+ }}
112
+ >
113
+ <View
114
+ style={{
115
+ width: size * 0.14,
116
+ height: size * 0.14,
117
+ borderRadius: size * 0.07,
118
+ backgroundColor: color,
119
+ }}
120
+ />
121
+ </View>
122
+ <View
123
+ style={{
124
+ width: 0,
125
+ height: 0,
126
+ borderLeftWidth: size * 0.22,
127
+ borderRightWidth: size * 0.22,
128
+ borderTopWidth: size * 0.28,
129
+ borderLeftColor: 'transparent',
130
+ borderRightColor: 'transparent',
131
+ borderTopColor: color,
132
+ marginTop: -STROKE * 2,
133
+ }}
134
+ />
135
+ </View>
136
+ );
137
+ }
138
+
139
+ const styles = StyleSheet.create({
140
+ wrap: {
141
+ alignItems: 'center',
142
+ justifyContent: 'center',
143
+ },
144
+ });
@@ -0,0 +1,46 @@
1
+ import type { AddressLabel } from '../core/types';
2
+
3
+ interface AddressLabelIconProps {
4
+ label: AddressLabel;
5
+ className?: string;
6
+ /** Native only — web uses `currentColor` via CSS */
7
+ color?: string;
8
+ }
9
+
10
+ /** Subtle stroke icons for Home / Work / Other address labels (web). */
11
+ export function AddressLabelIcon({ label, className }: AddressLabelIconProps) {
12
+ const shared = {
13
+ className,
14
+ 'aria-hidden': true as const,
15
+ viewBox: '0 0 24 24',
16
+ fill: 'none',
17
+ stroke: 'currentColor',
18
+ strokeWidth: 2,
19
+ strokeLinecap: 'round' as const,
20
+ strokeLinejoin: 'round' as const,
21
+ };
22
+
23
+ switch (label) {
24
+ case 'home':
25
+ return (
26
+ <svg {...shared}>
27
+ <path d="M3 9.5L12 3l9 6.5V20a1 1 0 01-1 1H5a1 1 0 01-1-1V9.5z" />
28
+ <path d="M9 21V12h6v9" />
29
+ </svg>
30
+ );
31
+ case 'work':
32
+ return (
33
+ <svg {...shared}>
34
+ <rect x="2" y="7" width="20" height="14" rx="2" />
35
+ <path d="M16 7V5a2 2 0 00-2-2h-4a2 2 0 00-2 2v2" />
36
+ </svg>
37
+ );
38
+ case 'other':
39
+ return (
40
+ <svg {...shared}>
41
+ <path d="M21 10c0 7-9 13-9 13S3 17 3 10a9 9 0 0118 0z" />
42
+ <circle cx="12" cy="10" r="3" />
43
+ </svg>
44
+ );
45
+ }
46
+ }
@@ -170,6 +170,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
170
170
  enablePrepaidNudge = false,
171
171
  prepaidNudgeCopy,
172
172
  prepaidNudgeCtaUrl,
173
+ registerController,
173
174
  }) => {
174
175
  const authMode: AuthMode = enablePhoneAuth ? 'phone' : enableEmailAuth ? 'email' : 'none';
175
176
  const initialStep: Step = authMode === 'phone' ? 'phone' : authMode === 'email' ? 'email' : 'map';
@@ -379,6 +380,8 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
379
380
  label: (saved.label === 'work' || saved.label === 'other'
380
381
  ? saved.label
381
382
  : 'home') as CompleteAddress['label'],
383
+ labelText: saved.label_text?.trim() || undefined,
384
+ addressId: saved.id,
382
385
  };
383
386
  void finishAddress(complete);
384
387
  };
@@ -414,26 +417,30 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
414
417
  locality: address.locality,
415
418
  }).catch(() => {/* silent */});
416
419
 
417
- try {
418
- await createAddress(checkoutConfig, auth.sessionToken, {
419
- digipin: address.digipin,
420
- lat: address.lat,
421
- lng: address.lng,
422
- state: address.state,
423
- district: address.district,
424
- locality: address.locality,
425
- pincode: address.pincode,
426
- delivery_status: address.delivery,
427
- flat_number: address.flatNumber,
428
- floor_number: address.floorNumber,
429
- building_name: address.buildingName,
430
- street_name: address.streetName,
431
- full_address_json: address as unknown as Record<string, unknown>,
432
- label: address.label ?? 'home',
433
- is_default: true,
434
- });
435
- } catch {
436
- // Silent
420
+ if (!address.addressId) {
421
+ try {
422
+ await createAddress(checkoutConfig, auth.sessionToken, {
423
+ digipin: address.digipin,
424
+ lat: address.lat,
425
+ lng: address.lng,
426
+ state: address.state,
427
+ district: address.district,
428
+ locality: address.locality,
429
+ pincode: address.pincode,
430
+ delivery_status: address.delivery,
431
+ flat_number: address.flatNumber,
432
+ floor_number: address.floorNumber,
433
+ building_name: address.buildingName,
434
+ street_name: address.streetName,
435
+ full_address_json: address as unknown as Record<string, unknown>,
436
+ label: address.label ?? 'home',
437
+ label_text:
438
+ address.label === 'other' ? (address.labelText?.trim() || null) : null,
439
+ is_default: false,
440
+ });
441
+ } catch {
442
+ // Silent
443
+ }
437
444
  }
438
445
  }
439
446
 
@@ -449,16 +456,61 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
449
456
  await finishAddress(address);
450
457
  };
451
458
 
452
- const handleBack = () => {
459
+ const handleBack = (): boolean => {
453
460
  if (step === 'form') {
454
461
  setStep('map');
455
- } else if (step === 'map' && auth?.sessionToken) {
462
+ return true;
463
+ }
464
+ if (step === 'map' && auth?.sessionToken) {
456
465
  setStep('saved');
457
- } else if (step === 'email-otp') {
466
+ return true;
467
+ }
468
+ if (step === 'email-otp') {
458
469
  setStep('email');
470
+ return true;
459
471
  }
472
+ if (step === 'otp') {
473
+ setStep('phone');
474
+ return true;
475
+ }
476
+ if (step === 'payment') {
477
+ setStep('form');
478
+ return true;
479
+ }
480
+ return false;
460
481
  };
461
482
 
483
+ useEffect(() => {
484
+ if (!registerController) return;
485
+ registerController({
486
+ goBack: () => {
487
+ const current = stepRef.current;
488
+ if (current === 'form') {
489
+ setStep('map');
490
+ return true;
491
+ }
492
+ if (current === 'map' && auth?.sessionToken) {
493
+ setStep('saved');
494
+ return true;
495
+ }
496
+ if (current === 'email-otp') {
497
+ setStep('email');
498
+ return true;
499
+ }
500
+ if (current === 'otp') {
501
+ setStep('phone');
502
+ return true;
503
+ }
504
+ if (current === 'payment') {
505
+ setStep('form');
506
+ return true;
507
+ }
508
+ return false;
509
+ },
510
+ getStep: () => stepRef.current,
511
+ });
512
+ }, [registerController, auth?.sessionToken]);
513
+
462
514
  const handleEditAddress = () => {
463
515
  emit({ type: 'widget_reset', step: initialStep });
464
516
  setStep(initialStep);
@@ -598,7 +650,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
598
650
  email={emailPending}
599
651
  codeReused={emailCodeReused}
600
652
  onVerified={handleEmailVerified}
601
- onBack={() => setStep('email')}
653
+ onBack={handleBack}
602
654
  functionBaseUrl={supabaseFunctionBaseUrl}
603
655
  merchantId={merchantId}
604
656
  sessionContext={sessionContext}
@@ -620,7 +672,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
620
672
  <OtpStep
621
673
  mobile={auth.mobile}
622
674
  onVerified={handleVerified}
623
- onBack={() => setStep('phone')}
675
+ onBack={handleBack}
624
676
  functionBaseUrl={supabaseFunctionBaseUrl}
625
677
  merchantId={merchantId}
626
678
  sessionContext={sessionContext}
@@ -680,7 +732,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
680
732
  codAllowed={codAllowed}
681
733
  theme={theme}
682
734
  onComplete={handlePaymentComplete}
683
- onBack={() => setStep('form')}
735
+ onBack={handleBack}
684
736
  onEvent={(type, paymentMethod) =>
685
737
  emit({ type, step: 'payment', paymentMethod, buyerId: auth?.buyerId })
686
738
  }