@quantaroute/checkout 1.4.3 → 1.4.5

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.
@@ -6,6 +6,7 @@ import {
6
6
  pincodeHasDeliveryOffice,
7
7
  type AddressComponents,
8
8
  } from '../core/api';
9
+ import { checkServiceability, type ServiceabilityResult } from '../core/checkout-api';
9
10
  import type {
10
11
  AddressFormProps,
11
12
  AddressLabel,
@@ -13,6 +14,7 @@ import type {
13
14
  CompleteAddress,
14
15
  LocationAlternative,
15
16
  } from '../core/types';
17
+ import { AddressLabelIcon } from './AddressLabelIcons';
16
18
 
17
19
  // ─── State ────────────────────────────────────────────────────────────────────
18
20
 
@@ -32,10 +34,12 @@ type FormState =
32
34
  alternatives: LocationAlternative[];
33
35
  selectedLocality: string; // Selected locality name (from adminInfo or alternatives)
34
36
  selectedLabel: AddressLabel;
37
+ labelText: string;
35
38
  fields: ManualFields;
36
39
  submitting: boolean;
37
40
  /** At least one India Post office with "Delivery" (not only "Non Delivery") */
38
41
  pincodeHasDelivery: boolean;
42
+ serviceabilityResult: ServiceabilityResult | null;
39
43
  };
40
44
 
41
45
  type FormAction =
@@ -46,11 +50,13 @@ type FormAction =
46
50
  alternatives: LocationAlternative[];
47
51
  addressComponents: AddressComponents;
48
52
  pincodeHasDelivery: boolean;
53
+ serviceabilityResult: ServiceabilityResult | null;
49
54
  }
50
55
  | { type: 'LOAD_ERROR'; message: string }
51
56
  | { type: 'SET_FIELD'; key: keyof ManualFields; value: string }
52
57
  | { type: 'SET_LOCALITY'; locality: string }
53
58
  | { type: 'SET_LABEL'; label: AddressLabel }
59
+ | { type: 'SET_LABEL_TEXT'; value: string }
54
60
  | { type: 'SUBMIT_START' }
55
61
  | { type: 'SUBMIT_END' };
56
62
 
@@ -107,9 +113,11 @@ function reducer(state: FormState, action: FormAction): FormState {
107
113
  alternatives: action.alternatives || [],
108
114
  selectedLocality: action.adminInfo.locality,
109
115
  selectedLabel: 'home',
116
+ labelText: '',
110
117
  fields: { ...INITIAL_FIELDS, ...preFilled },
111
118
  submitting: false,
112
119
  pincodeHasDelivery: action.pincodeHasDelivery,
120
+ serviceabilityResult: action.serviceabilityResult,
113
121
  };
114
122
  }
115
123
  case 'LOAD_ERROR':
@@ -122,7 +130,14 @@ function reducer(state: FormState, action: FormAction): FormState {
122
130
  return { ...state, selectedLocality: action.locality };
123
131
  case 'SET_LABEL':
124
132
  if (state.status !== 'ready') return state;
125
- return { ...state, selectedLabel: action.label };
133
+ return {
134
+ ...state,
135
+ selectedLabel: action.label,
136
+ labelText: action.label === 'other' ? state.labelText : '',
137
+ };
138
+ case 'SET_LABEL_TEXT':
139
+ if (state.status !== 'ready') return state;
140
+ return { ...state, labelText: action.value.slice(0, 64) };
126
141
  case 'SUBMIT_START':
127
142
  if (state.status !== 'ready') return state;
128
143
  return { ...state, submitting: true };
@@ -145,6 +160,12 @@ const AddressForm: React.FC<AddressFormProps> = ({
145
160
  onAddressComplete,
146
161
  onBack,
147
162
  onError,
163
+ checkoutConfig,
164
+ serviceabilitySessionToken,
165
+ enableServiceabilityCheck = false,
166
+ showIndiaPostDeliveryWarning = false,
167
+ serviceabilityBlockCheckout,
168
+ onServiceabilityResult,
148
169
  }) => {
149
170
  const [state, dispatch] = useReducer(reducer, { status: 'loading' });
150
171
 
@@ -184,6 +205,27 @@ const AddressForm: React.FC<AddressFormProps> = ({
184
205
  }
185
206
 
186
207
  const hasDelivery = pincodeHasDeliveryOffice(pinValidation.offices);
208
+ let serviceabilityResult: ServiceabilityResult | null = null;
209
+
210
+ if (
211
+ enableServiceabilityCheck
212
+ && checkoutConfig?.functionBaseUrl
213
+ && checkoutConfig.merchantId
214
+ && serviceabilitySessionToken
215
+ ) {
216
+ try {
217
+ serviceabilityResult = await checkServiceability(
218
+ checkoutConfig,
219
+ serviceabilitySessionToken,
220
+ pincode,
221
+ { lat, lng }
222
+ );
223
+ onServiceabilityResult?.(serviceabilityResult);
224
+ } catch {
225
+ // Fail open: merchant serviceability should never block address entry
226
+ // when the checkout-addresses function itself is unreachable.
227
+ }
228
+ }
187
229
 
188
230
  dispatch({
189
231
  type: 'LOAD_SUCCESS',
@@ -191,13 +233,25 @@ const AddressForm: React.FC<AddressFormProps> = ({
191
233
  alternatives: adminRes.data.alternatives || [],
192
234
  addressComponents: reverseRes.data.addressComponents,
193
235
  pincodeHasDelivery: hasDelivery,
236
+ serviceabilityResult,
194
237
  });
195
238
  } catch (err) {
196
239
  const msg = err instanceof Error ? err.message : 'Failed to fetch address data.';
197
240
  dispatch({ type: 'LOAD_ERROR', message: msg });
198
241
  onError?.(err instanceof Error ? err : new Error(msg));
199
242
  }
200
- }, [digipin, lat, lng, apiKey, apiBaseUrl, onError]);
243
+ }, [
244
+ digipin,
245
+ lat,
246
+ lng,
247
+ apiKey,
248
+ apiBaseUrl,
249
+ onError,
250
+ checkoutConfig,
251
+ serviceabilitySessionToken,
252
+ enableServiceabilityCheck,
253
+ onServiceabilityResult,
254
+ ]);
201
255
 
202
256
  useEffect(() => {
203
257
  void fetchAdminInfo();
@@ -209,7 +263,14 @@ const AddressForm: React.FC<AddressFormProps> = ({
209
263
  e.preventDefault();
210
264
  if (state.status !== 'ready') return;
211
265
 
212
- const { adminInfo, selectedLocality, selectedLabel, fields } = state;
266
+ const { adminInfo, selectedLocality, selectedLabel, labelText, fields } = state;
267
+
268
+ if (selectedLabel === 'other' && !labelText.trim()) return;
269
+ const serviceabilityBlocked =
270
+ state.serviceabilityResult?.checked
271
+ && state.serviceabilityResult.serviceable === false
272
+ && (serviceabilityBlockCheckout ?? state.serviceabilityResult.block_checkout);
273
+ if (serviceabilityBlocked) return;
213
274
 
214
275
  const parts: string[] = [
215
276
  fields.flatNumber,
@@ -236,6 +297,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
236
297
  ...fields,
237
298
  formattedAddress: parts.join(', '),
238
299
  label: selectedLabel,
300
+ ...(selectedLabel === 'other' ? { labelText: labelText.trim() } : {}),
239
301
  };
240
302
 
241
303
  dispatch({ type: 'SUBMIT_START' });
@@ -245,9 +307,27 @@ const AddressForm: React.FC<AddressFormProps> = ({
245
307
  dispatch({ type: 'SUBMIT_END' });
246
308
  }
247
309
  },
248
- [state, digipin, lat, lng, onAddressComplete]
310
+ [state, digipin, lat, lng, onAddressComplete, serviceabilityBlockCheckout]
249
311
  );
250
312
 
313
+ const serviceabilityBlocked =
314
+ state.status === 'ready'
315
+ && state.serviceabilityResult?.checked
316
+ && state.serviceabilityResult.serviceable === false
317
+ && (serviceabilityBlockCheckout ?? state.serviceabilityResult.block_checkout);
318
+
319
+ const showMerchantServiceability =
320
+ state.status === 'ready'
321
+ && state.serviceabilityResult?.checked
322
+ && state.serviceabilityResult.serviceable === false;
323
+
324
+ const showIndiaPostInfo =
325
+ state.status === 'ready'
326
+ && !state.pincodeHasDelivery
327
+ && state.serviceabilityResult?.serviceable !== true
328
+ && !showMerchantServiceability
329
+ && (state.serviceabilityResult?.show_india_post_delivery_warning ?? showIndiaPostDeliveryWarning);
330
+
251
331
  return (
252
332
  <div className="qr-form-wrapper">
253
333
  {/* ── Step header ── */}
@@ -325,7 +405,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
325
405
  <fieldset className="qr-fieldset">
326
406
  <legend className="qr-fieldset__legend">
327
407
  <span className="qr-fieldset__icon" aria-hidden="true">📍</span>
328
- Auto-detected from your pin
408
+ Auto-detected from your digipin
329
409
  </legend>
330
410
 
331
411
  <div className="qr-auto-grid">
@@ -377,19 +457,44 @@ const AddressForm: React.FC<AddressFormProps> = ({
377
457
  </div>
378
458
  </fieldset>
379
459
 
380
- {/* Serviceability: India Post "Non Delivery" only — warn (still allow save) */}
381
- {!state.pincodeHasDelivery && (
460
+ {showMerchantServiceability && state.serviceabilityResult && (
382
461
  <div
383
- className="qr-pincode-banner qr-pincode-banner--warning"
462
+ className={`qr-pincode-banner ${
463
+ serviceabilityBlocked
464
+ ? 'qr-pincode-banner--error'
465
+ : 'qr-pincode-banner--warning'
466
+ }`}
467
+ role={serviceabilityBlocked ? 'alert' : 'status'}
468
+ aria-live="polite"
469
+ >
470
+ <span className="qr-pincode-banner__icon" aria-hidden="true">
471
+ {serviceabilityBlocked ? '!' : '⚠'}
472
+ </span>
473
+ <div className="qr-pincode-banner__text">
474
+ <strong>
475
+ {serviceabilityBlocked ? 'Delivery unavailable' : 'Delivery may be limited'}
476
+ </strong>
477
+ <span>
478
+ {state.serviceabilityResult.message
479
+ ?? (serviceabilityBlocked
480
+ ? 'This seller does not currently deliver to this pincode.'
481
+ : 'This seller recommends confirming delivery availability for this pincode.')}
482
+ </span>
483
+ </div>
484
+ </div>
485
+ )}
486
+
487
+ {showIndiaPostInfo && (
488
+ <div
489
+ className="qr-pincode-banner qr-pincode-banner--info"
384
490
  role="status"
385
491
  aria-live="polite"
386
492
  >
387
- <span className="qr-pincode-banner__icon" aria-hidden="true">⚠</span>
493
+ <span className="qr-pincode-banner__icon" aria-hidden="true">i</span>
388
494
  <div className="qr-pincode-banner__text">
389
- <strong>Non-delivery area</strong>
495
+ <strong>India Post: no home-delivery office</strong>
390
496
  <span>
391
- This pincode has no India Post home-delivery office. Courier delivery may be limited —
392
- confirm with your seller before placing the order.
497
+ Courier partners may still deliver to this pincode.
393
498
  </span>
394
499
  </div>
395
500
  </div>
@@ -397,15 +502,15 @@ const AddressForm: React.FC<AddressFormProps> = ({
397
502
 
398
503
  {/* Address label */}
399
504
  <fieldset className="qr-fieldset">
400
- <legend className="qr-fieldset__legend">Save as</legend>
505
+ <legend className="qr-fieldset__legend qr-fieldset__legend--compact">Save as</legend>
401
506
  <div className="qr-label-picker" role="radiogroup" aria-label="Address label">
402
507
  {(
403
508
  [
404
- { value: 'home' as const, title: 'Home', icon: '🏠' },
405
- { value: 'work' as const, title: 'Work', icon: '💼' },
406
- { value: 'other' as const, title: 'Other', icon: '📍' },
509
+ { value: 'home' as const, title: 'Home' },
510
+ { value: 'work' as const, title: 'Work' },
511
+ { value: 'other' as const, title: 'Other' },
407
512
  ] as const
408
- ).map(({ value, title, icon }) => (
513
+ ).map(({ value, title }) => (
409
514
  <button
410
515
  key={value}
411
516
  type="button"
@@ -416,13 +521,35 @@ const AddressForm: React.FC<AddressFormProps> = ({
416
521
  }`}
417
522
  onClick={() => dispatch({ type: 'SET_LABEL', label: value })}
418
523
  >
419
- <span className="qr-label-picker__icon" aria-hidden="true">
420
- {icon}
524
+ <span className="qr-label-picker__icon">
525
+ <AddressLabelIcon label={value} />
421
526
  </span>
422
527
  <span>{title}</span>
423
528
  </button>
424
529
  ))}
425
530
  </div>
531
+ {state.selectedLabel === 'other' && (
532
+ <div className="qr-label-text-field">
533
+ <label className="qr-field__label" htmlFor="qr-labelText">
534
+ Label name
535
+ <span className="qr-required" aria-hidden="true">*</span>
536
+ </label>
537
+ <input
538
+ id="qr-labelText"
539
+ type="text"
540
+ className="qr-field__input"
541
+ placeholder="e.g. Friend's home, Gym"
542
+ value={state.labelText}
543
+ onChange={(e) =>
544
+ dispatch({ type: 'SET_LABEL_TEXT', value: e.target.value })
545
+ }
546
+ maxLength={64}
547
+ required
548
+ aria-required="true"
549
+ autoComplete="off"
550
+ />
551
+ </div>
552
+ )}
426
553
  </fieldset>
427
554
 
428
555
  {/* Manual entry section */}
@@ -535,7 +662,12 @@ const AddressForm: React.FC<AddressFormProps> = ({
535
662
  <button
536
663
  type="submit"
537
664
  className="qr-btn qr-btn--primary qr-btn--grow"
538
- disabled={state.submitting || !state.fields.flatNumber.trim()}
665
+ disabled={
666
+ state.submitting
667
+ || !state.fields.flatNumber.trim()
668
+ || (state.selectedLabel === 'other' && !state.labelText.trim())
669
+ || Boolean(serviceabilityBlocked)
670
+ }
539
671
  >
540
672
  {state.submitting ? (
541
673
  <>
@@ -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
+ }
@@ -97,6 +97,9 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
97
97
  merchantId = '',
98
98
  supabaseFunctionBaseUrl = '',
99
99
  enableCod = false,
100
+ enableServiceabilityCheck = false,
101
+ showIndiaPostDeliveryWarning = false,
102
+ serviceabilityBlockCheckout,
100
103
  codCartTotalPaise,
101
104
  codSessionToken = '',
102
105
  }) => {
@@ -243,6 +246,11 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
243
246
  onBack={handleBack}
244
247
  onError={onError}
245
248
  theme={theme}
249
+ checkoutConfig={checkoutConfig}
250
+ serviceabilitySessionToken={codSession}
251
+ enableServiceabilityCheck={enableServiceabilityCheck}
252
+ showIndiaPostDeliveryWarning={showIndiaPostDeliveryWarning}
253
+ serviceabilityBlockCheckout={serviceabilityBlockCheckout}
246
254
  />
247
255
  ) : null}
248
256
 
@@ -159,6 +159,9 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
159
159
  headerBanner,
160
160
  onCheckoutEvent,
161
161
  enableCod = false,
162
+ enableServiceabilityCheck = false,
163
+ showIndiaPostDeliveryWarning = false,
164
+ serviceabilityBlockCheckout,
162
165
  codCartTotalPaise,
163
166
  codSessionToken = '',
164
167
  enableEmailAuth = false,
@@ -380,6 +383,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
380
383
  label: (saved.label === 'work' || saved.label === 'other'
381
384
  ? saved.label
382
385
  : 'home') as CompleteAddress['label'],
386
+ labelText: saved.label_text?.trim() || undefined,
383
387
  addressId: saved.id,
384
388
  };
385
389
  void finishAddress(complete);
@@ -433,6 +437,8 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
433
437
  street_name: address.streetName,
434
438
  full_address_json: address as unknown as Record<string, unknown>,
435
439
  label: address.label ?? 'home',
440
+ label_text:
441
+ address.label === 'other' ? (address.labelText?.trim() || null) : null,
436
442
  is_default: false,
437
443
  });
438
444
  } catch {
@@ -715,6 +721,11 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
715
721
  onBack={handleBack}
716
722
  onError={onError}
717
723
  theme={theme}
724
+ checkoutConfig={checkoutConfig}
725
+ serviceabilitySessionToken={codSession}
726
+ enableServiceabilityCheck={enableServiceabilityCheck}
727
+ showIndiaPostDeliveryWarning={showIndiaPostDeliveryWarning}
728
+ serviceabilityBlockCheckout={serviceabilityBlockCheckout}
718
729
  />
719
730
  )}
720
731
 
@@ -13,7 +13,7 @@ import { OSMView, LocationButton } from 'expo-osm-sdk';
13
13
  import type { OSMViewRef, MarkerConfig } from 'expo-osm-sdk';
14
14
  import * as Location from 'expo-location';
15
15
  import { getDigiPin, getLatLngFromDigiPin, formatDigiPin, isWithinIndia } from '../core/digipin';
16
- import { autocompleteAddress, looksLikeDigiPin } from '../core/api';
16
+ import { autocompleteAddress, looksLikeDigiPin, couldBeDigiPinInput } from '../core/api';
17
17
  import type { AutocompleteSuggestion } from '../core/api';
18
18
  import type { MapPinSelectorProps } from '../core/types';
19
19
  import { styles, COLORS } from '../styles/checkout.native';
@@ -150,6 +150,13 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
150
150
  return;
151
151
  }
152
152
 
153
+ // Partial DigiPin — wait for full code, skip autocomplete
154
+ if (couldBeDigiPinInput(trimmed)) {
155
+ setSuggestions([]);
156
+ setSearchLoading(false);
157
+ return;
158
+ }
159
+
153
160
  if (trimmed.length < 3) {
154
161
  setSuggestions([]);
155
162
  return;
@@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState, useCallback, useId } from 'react';
2
2
  import maplibregl from 'maplibre-gl';
3
3
  import 'maplibre-gl/dist/maplibre-gl.css';
4
4
  import { getDigiPin, getLatLngFromDigiPin, formatDigiPin, isWithinIndia } from '../core/digipin';
5
- import { autocompleteAddress, looksLikeDigiPin } from '../core/api';
5
+ import { autocompleteAddress, looksLikeDigiPin, couldBeDigiPinInput } from '../core/api';
6
6
  import type { AutocompleteSuggestion } from '../core/api';
7
7
  import { useGeolocation } from '../hooks/useGeolocation';
8
8
  import type { MapPinSelectorProps } from '../core/types';
@@ -190,6 +190,14 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
190
190
  return;
191
191
  }
192
192
 
193
+ // Partial DigiPin (compact/spaced/dashed) — wait for full code, skip autocomplete
194
+ if (couldBeDigiPinInput(trimmed)) {
195
+ setSuggestions([]);
196
+ setDropdownOpen(false);
197
+ setSearchLoading(false);
198
+ return;
199
+ }
200
+
193
201
  // Address search — debounce 400 ms, need ≥ 3 chars
194
202
  if (trimmed.length < 3) {
195
203
  setSuggestions([]);
@@ -32,6 +32,12 @@ function LabelIcon({ label }: { label: string }) {
32
32
  return <PinIcon />;
33
33
  }
34
34
 
35
+ function formatAddressLabel(address: SavedAddress): string {
36
+ const custom = address.label_text?.trim();
37
+ if (address.label === 'other' && custom) return custom;
38
+ return address.label.charAt(0).toUpperCase() + address.label.slice(1);
39
+ }
40
+
35
41
  // ─── Address card ─────────────────────────────────────────────────────────────
36
42
 
37
43
  interface AddressCardProps {
@@ -64,7 +70,7 @@ function AddressCard({ address, onUse, onDelete, onSetDefault, deleting }: Addre
64
70
  <LabelIcon label={address.label} />
65
71
  </div>
66
72
  <span className="qr-addr-card__label">
67
- {address.label.charAt(0).toUpperCase() + address.label.slice(1)}
73
+ {formatAddressLabel(address)}
68
74
  </span>
69
75
  {address.is_default && (
70
76
  <span className="qr-addr-card__default-badge">Default</span>
package/src/core/api.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { LocationLookupResponse } from './types';
2
- import { isCompleteDigiPinInput } from './digipin';
2
+ import { isCompleteDigiPinInput, isPotentialDigiPinInput } from './digipin';
3
3
 
4
4
  const DEFAULT_BASE_URL = 'https://api.quantaroute.com';
5
5
 
@@ -235,6 +235,14 @@ export function looksLikeDigiPin(input: string): boolean {
235
235
  return isCompleteDigiPinInput(input);
236
236
  }
237
237
 
238
+ /**
239
+ * Returns true while the user is typing a DigiPin (compact, dashed, or spaced).
240
+ * Used to suppress address autocomplete until the code is complete or abandoned.
241
+ */
242
+ export function couldBeDigiPinInput(input: string): boolean {
243
+ return isPotentialDigiPinInput(input);
244
+ }
245
+
238
246
  /**
239
247
  * Call QuantaRoute's autocomplete API.
240
248
  * Minimum 3 characters required; max 10 suggestions.