@quantaroute/checkout 1.7.0 → 1.7.2

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.
@@ -1,11 +1,17 @@
1
1
  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
+ import type { MapMouseEvent, Map as MapLibreMap, Marker as MapLibreMarker } from 'maplibre-gl';
4
5
  import { getDigiPin, getLatLngFromDigiPin, formatDigiPin, isWithinIndia } from '../core/digipin';
5
6
  import { autocompleteAddress, looksLikeDigiPin, couldBeDigiPinInput } from '../core/api';
6
7
  import type { AutocompleteSuggestion } from '../core/api';
7
8
  import { useGeolocation } from '../hooks/useGeolocation';
8
9
  import type { MapPinSelectorProps } from '../core/types';
10
+ import {
11
+ DEFAULT_MAP_STYLE_URL,
12
+ waitForExternalMapRuntime,
13
+ type MapRuntime,
14
+ } from '../core/map-runtime';
9
15
 
10
16
  // ─── Constants ───────────────────────────────────────────────────────────────
11
17
 
@@ -15,13 +21,7 @@ const MIN_ZOOM = 6; // users cannot zoom out beyond a useful India-level v
15
21
  const OVERVIEW_ZOOM = 9;
16
22
  const STREET_ZOOM = 18;
17
23
 
18
- /**
19
- * Carto Positron – free vector basemap, no API key required.
20
- * Attribution: © OpenStreetMap contributors © CARTO
21
- * Terms: https://carto.com/legal/
22
- */
23
- const CARTO_STYLE_URL =
24
- 'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json';
24
+ type MapLoadState = 'loading' | 'ready' | 'unavailable' | 'error';
25
25
 
26
26
  // ─── Pin dimensions ───────────────────────────────────────────────────────────
27
27
  // MUST match the SVG width/height exactly.
@@ -99,6 +99,149 @@ function createPinElement(brandColor: string = DEFAULT_BRAND): HTMLDivElement {
99
99
  return el;
100
100
  }
101
101
 
102
+ function collapseCompactAttribution(container: HTMLElement | null): void {
103
+ const attribEl = container?.querySelector(
104
+ '.maplibregl-ctrl-attrib.maplibregl-compact'
105
+ );
106
+ if (attribEl instanceof HTMLElement) {
107
+ attribEl.classList.remove('maplibregl-compact-show');
108
+ attribEl.setAttribute('open', '');
109
+ }
110
+ }
111
+
112
+ function initMapWithRuntime(
113
+ runtime: MapRuntime,
114
+ container: HTMLDivElement,
115
+ markerRef: React.MutableRefObject<MapLibreMarker | null>,
116
+ options: {
117
+ styleUrl: string;
118
+ initLat: number;
119
+ initLng: number;
120
+ initZoom: number;
121
+ brandColor: string;
122
+ indiaBoundaryUrl?: string;
123
+ refreshDigipin: (la: number, lo: number) => void;
124
+ onReady: () => void;
125
+ onError: (message: string) => void;
126
+ }
127
+ ): { map: MapLibreMap; cleanup: () => void } {
128
+ const {
129
+ styleUrl,
130
+ initLat,
131
+ initLng,
132
+ initZoom,
133
+ brandColor,
134
+ indiaBoundaryUrl,
135
+ refreshDigipin,
136
+ onReady,
137
+ onError,
138
+ } = options;
139
+
140
+ const boundaryPromise: Promise<unknown> = indiaBoundaryUrl
141
+ ? fetch(indiaBoundaryUrl)
142
+ .then((r) => (r.ok ? r.json() : null))
143
+ .catch(() => null)
144
+ : Promise.resolve(null);
145
+
146
+ const map = new runtime.Map({
147
+ container,
148
+ style: styleUrl,
149
+ center: [initLng, initLat],
150
+ zoom: initZoom,
151
+ minZoom: MIN_ZOOM,
152
+ attributionControl: false,
153
+ touchZoomRotate: true,
154
+ });
155
+
156
+ if (typeof runtime.AttributionControl === 'function') {
157
+ map.addControl(
158
+ new runtime.AttributionControl({
159
+ compact: true,
160
+ customAttribution:
161
+ '© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap</a> contributors &nbsp;© <a href="https://carto.com/attributions" target="_blank" rel="noopener">CARTO</a>',
162
+ }),
163
+ 'bottom-right'
164
+ );
165
+ }
166
+
167
+ if (typeof runtime.NavigationControl === 'function') {
168
+ map.addControl(
169
+ new runtime.NavigationControl({ showCompass: false }),
170
+ 'top-right'
171
+ );
172
+ }
173
+
174
+ let marker: MapLibreMarker | null = null;
175
+
176
+ map.on('load', () => {
177
+ collapseCompactAttribution(container);
178
+ onReady();
179
+
180
+ boundaryPromise.then((geoJson) => {
181
+ if (!geoJson || !map.isStyleLoaded()) return;
182
+ try {
183
+ map.addSource('india-boundary', {
184
+ type: 'geojson',
185
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
186
+ data: geoJson as any,
187
+ });
188
+ map.addLayer({
189
+ id: 'india-boundary-line',
190
+ type: 'line',
191
+ source: 'india-boundary',
192
+ paint: {
193
+ 'line-color': '#94a3b8',
194
+ 'line-width': 1.5,
195
+ 'line-opacity': 0.65,
196
+ },
197
+ });
198
+ } catch {
199
+ // Silent: duplicate source/layer on hot-reload is not an error
200
+ }
201
+ });
202
+
203
+ marker = new runtime.Marker({
204
+ element: createPinElement(brandColor),
205
+ draggable: true,
206
+ anchor: 'bottom',
207
+ })
208
+ .setLngLat([initLng, initLat])
209
+ .addTo(map);
210
+
211
+ markerRef.current = marker;
212
+
213
+ marker.on('drag', () => {
214
+ const pos = marker!.getLngLat();
215
+ refreshDigipin(pos.lat, pos.lng);
216
+ });
217
+
218
+ marker.on('dragend', () => {
219
+ const pos = marker!.getLngLat();
220
+ map.easeTo({ center: [pos.lng, pos.lat], duration: 250 });
221
+ });
222
+ });
223
+
224
+ map.on('error', () => {
225
+ onError('Map tiles could not load. Please try again.');
226
+ });
227
+
228
+ map.on('click', (e: MapMouseEvent) => {
229
+ const pos = e.lngLat;
230
+ marker?.setLngLat([pos.lng, pos.lat]);
231
+ refreshDigipin(pos.lat, pos.lng);
232
+ map.easeTo({ center: [pos.lng, pos.lat], duration: 200 });
233
+ });
234
+
235
+ return {
236
+ map,
237
+ cleanup: () => {
238
+ markerRef.current = null;
239
+ marker = null;
240
+ map.remove();
241
+ },
242
+ };
243
+ }
244
+
102
245
  // ─── Component ───────────────────────────────────────────────────────────────
103
246
 
104
247
  const MapPinSelector: React.FC<MapPinSelectorProps> = ({
@@ -112,10 +255,12 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
112
255
  apiKey,
113
256
  apiBaseUrl,
114
257
  brandColor = DEFAULT_BRAND,
258
+ mapStyle = DEFAULT_MAP_STYLE_URL,
259
+ embedMode = 'bundled',
115
260
  }) => {
116
261
  const containerRef = useRef<HTMLDivElement>(null);
117
- const mapRef = useRef<maplibregl.Map | null>(null);
118
- const markerRef = useRef<maplibregl.Marker | null>(null);
262
+ const mapRef = useRef<MapLibreMap | null>(null);
263
+ const markerRef = useRef<MapLibreMarker | null>(null);
119
264
 
120
265
  const initLat = defaultLat ?? INDIA_CENTER.lat;
121
266
  const initLng = defaultLng ?? INDIA_CENTER.lng;
@@ -127,6 +272,8 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
127
272
  computeDigiPinSafe(initLat, initLng)
128
273
  );
129
274
  const [mapLoaded, setMapLoaded] = useState(false);
275
+ const [mapState, setMapState] = useState<MapLoadState>('loading');
276
+ const [mapError, setMapError] = useState<string | null>(null);
130
277
 
131
278
  // ── Search state ─────────────────────────────────────────────────────────
132
279
  const [searchQuery, setSearchQuery] = useState('');
@@ -141,17 +288,15 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
141
288
  const { loading: geoLoading, error: geoError, locate, clearError } = useGeolocation();
142
289
 
143
290
  const refreshDigipin = useCallback((la: number, lo: number) => {
291
+ setLat(la);
292
+ setLng(lo);
144
293
  setDigipin(computeDigiPinSafe(la, lo));
145
294
  }, []);
146
295
 
147
296
  // ── Fly map + move pin to a coord ────────────────────────────────────────
148
297
  const flyToCoord = useCallback((la: number, lo: number) => {
149
- setLat(la);
150
- setLng(lo);
151
298
  refreshDigipin(la, lo);
152
- if (mapRef.current) {
153
- mapRef.current.flyTo({ center: [lo, la], zoom: STREET_ZOOM, duration: 900, essential: true });
154
- }
299
+ mapRef.current?.flyTo({ center: [lo, la], zoom: STREET_ZOOM, duration: 900, essential: true });
155
300
  markerRef.current?.setLngLat([lo, la]);
156
301
  }, [refreshDigipin]);
157
302
 
@@ -165,7 +310,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
165
310
 
166
311
  const trimmed = value.trim();
167
312
 
168
- // Empty — close dropdown
169
313
  if (!trimmed) {
170
314
  setSuggestions([]);
171
315
  setDropdownOpen(false);
@@ -173,8 +317,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
173
317
  return;
174
318
  }
175
319
 
176
- // DigiPin input — resolve 100% offline, instant, zero API cost
177
- // Keep the text in the input so the user can see what resolved.
178
320
  if (looksLikeDigiPin(trimmed)) {
179
321
  try {
180
322
  const coords = getLatLngFromDigiPin(trimmed);
@@ -190,7 +332,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
190
332
  return;
191
333
  }
192
334
 
193
- // Partial DigiPin (compact/spaced/dashed) — wait for full code, skip autocomplete
194
335
  if (couldBeDigiPinInput(trimmed)) {
195
336
  setSuggestions([]);
196
337
  setDropdownOpen(false);
@@ -198,7 +339,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
198
339
  return;
199
340
  }
200
341
 
201
- // Address search — debounce 400 ms, need ≥ 3 chars
202
342
  if (trimmed.length < 3) {
203
343
  setSuggestions([]);
204
344
  setDropdownOpen(false);
@@ -209,7 +349,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
209
349
  debounceRef.current = setTimeout(async () => {
210
350
  try {
211
351
  const key = apiKey ?? '';
212
- // Forward current pin position so the API can bias/bound results nearby
213
352
  const results = await autocompleteAddress(trimmed, key, apiBaseUrl, 5, lat, lng);
214
353
  setSuggestions(results);
215
354
  setDropdownOpen(results.length > 0);
@@ -221,9 +360,8 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
221
360
  setSearchLoading(false);
222
361
  }
223
362
  }, 400);
224
- }, [apiKey, apiBaseUrl, flyToCoord]);
363
+ }, [apiKey, apiBaseUrl, flyToCoord, lat, lng]);
225
364
 
226
- // ── Pick a suggestion from the dropdown ──────────────────────────────────
227
365
  const handleSuggestionSelect = useCallback((s: AutocompleteSuggestion) => {
228
366
  flyToCoord(s.coordinates.latitude, s.coordinates.longitude);
229
367
  setSearchQuery('');
@@ -240,150 +378,96 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
240
378
  }
241
379
  }, []);
242
380
 
243
- // ── Map initialization (runs once) ────────────────────────────────────────
381
+ // ── Map initialization ────────────────────────────────────────────────────
244
382
  useEffect(() => {
245
383
  if (!containerRef.current) return;
246
384
 
247
- // ── Fetch India boundary GeoJSON eagerly, in parallel with map style load ──
248
- // Starting the fetch here (before map fires 'load') means by the time the
249
- // map is ready the data is likely already parsed → zero perceived delay.
250
- // Silent failure: the boundary is a legal safeguard, not critical UI.
251
- const boundaryPromise: Promise<unknown> = indiaBoundaryUrl
252
- ? fetch(indiaBoundaryUrl)
253
- .then((r) => (r.ok ? r.json() : null))
254
- .catch(() => null)
255
- : Promise.resolve(null);
385
+ let cancelled = false;
386
+ let cancelWait: (() => void) | null = null;
387
+ let mapCleanup: (() => void) | null = null;
256
388
 
257
389
  const initZoom = hasDefault ? STREET_ZOOM : OVERVIEW_ZOOM;
390
+ const container = containerRef.current;
258
391
 
259
- const map = new maplibregl.Map({
260
- container: containerRef.current,
261
- style: CARTO_STYLE_URL,
262
- center: [initLng, initLat],
263
- zoom: initZoom,
264
- minZoom: MIN_ZOOM, // lock: cannot zoom out past level 7
265
- attributionControl: false,
266
- // Smooth touch gestures on mobile (tap center for zoom)
267
- touchZoomRotate: true,
268
- });
392
+ const mountMap = (runtime: MapRuntime) => {
393
+ if (cancelled || !containerRef.current) return;
269
394
 
270
- // Attribution (required by Carto & OSM terms)
271
- map.addControl(
272
- new maplibregl.AttributionControl({
273
- compact: true,
274
- customAttribution:
275
- '© <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">OpenStreetMap</a> contributors &nbsp;© <a href="https://carto.com/attributions" target="_blank" rel="noopener">CARTO</a>',
276
- }),
277
- 'bottom-right'
278
- );
279
-
280
- // Zoom +/− (hidden on small screens via CSS)
281
- map.addControl(
282
- new maplibregl.NavigationControl({ showCompass: false }),
283
- 'top-right'
284
- );
285
-
286
- map.on('load', () => {
287
- setMapLoaded(true);
288
-
289
- // ── India boundary overlay (legal compliance) ────────────────────────
290
- // Resolves instantly if the fetch finished before map loaded (typical),
291
- // or waits the remaining milliseconds if still in-flight.
292
- boundaryPromise.then((geoJson) => {
293
- if (!geoJson || !map.isStyleLoaded()) return;
294
- try {
295
- map.addSource('india-boundary', {
296
- type: 'geojson',
297
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
298
- data: geoJson as any,
299
- });
300
- map.addLayer({
301
- id: 'india-boundary-line',
302
- type: 'line',
303
- source: 'india-boundary',
304
- paint: {
305
- 'line-color': '#94a3b8', // slate-400 — subtle grey
306
- 'line-width': 1.5,
307
- 'line-opacity': 0.65,
308
- },
309
- });
310
- } catch {
311
- // Silent: duplicate source/layer on hot-reload is not an error
312
- }
313
- });
314
-
315
- // Create draggable pin marker.
316
- // anchor='bottom' → MapLibre aligns element's bottom-center with the coord.
317
- // Our SVG tip is at (20, 52) = exactly the bottom-center of the 40×52 element.
318
- // No offset needed — any offset shifts the tip away from the coordinate.
319
- const pinEl = createPinElement(brandColor);
320
- const marker = new maplibregl.Marker({
321
- element: pinEl,
322
- draggable: true,
323
- anchor: 'bottom',
324
- })
325
- .setLngLat([initLng, initLat])
326
- .addTo(map);
327
-
328
- // Live DigiPin update while dragging
329
- marker.on('drag', () => {
330
- const pos = marker.getLngLat();
331
- setLat(pos.lat);
332
- setLng(pos.lng);
333
- refreshDigipin(pos.lat, pos.lng);
334
- });
335
-
336
- // Re-center map after drag ends
337
- marker.on('dragend', () => {
338
- const pos = marker.getLngLat();
339
- map.easeTo({ center: [pos.lng, pos.lat], duration: 250 });
340
- });
395
+ try {
396
+ const { map, cleanup } = initMapWithRuntime(runtime, container, markerRef, {
397
+ styleUrl: mapStyle,
398
+ initLat,
399
+ initLng,
400
+ initZoom,
401
+ brandColor,
402
+ indiaBoundaryUrl,
403
+ refreshDigipin,
404
+ onReady: () => {
405
+ if (cancelled) return;
406
+ setMapLoaded(true);
407
+ setMapState('ready');
408
+ setMapError(null);
409
+ },
410
+ onError: (message) => {
411
+ if (cancelled) return;
412
+ setMapState((state) => (state === 'ready' ? state : 'error'));
413
+ setMapError(message);
414
+ },
415
+ });
341
416
 
342
- markerRef.current = marker;
343
- // DigiPin is already computed in useState() init; no need to recompute here.
344
- });
417
+ mapRef.current = map;
418
+ mapCleanup = cleanup;
419
+ } catch (err) {
420
+ setMapState('error');
421
+ setMapError(err instanceof Error ? err.message : 'Map failed to initialize.');
422
+ }
423
+ };
345
424
 
346
- // Tap/click map to reposition pin
347
- map.on('click', (e) => {
348
- const pos = e.lngLat;
349
- markerRef.current?.setLngLat([pos.lng, pos.lat]);
350
- setLat(pos.lat);
351
- setLng(pos.lng);
352
- refreshDigipin(pos.lat, pos.lng);
353
- map.easeTo({ center: [pos.lng, pos.lat], duration: 200 });
354
- });
425
+ const handleUnavailable = () => {
426
+ if (cancelled) return;
427
+ setMapState('unavailable');
428
+ setMapError('Map could not load. Check your connection and try again.');
429
+ };
355
430
 
356
- mapRef.current = map;
431
+ if (embedMode === 'external') {
432
+ cancelWait = waitForExternalMapRuntime(mountMap, handleUnavailable);
433
+ } else {
434
+ mountMap(maplibregl as MapRuntime);
435
+ }
357
436
 
358
437
  return () => {
359
- map.remove();
360
- mapRef.current = null;
438
+ cancelled = true;
439
+ cancelWait?.();
440
+ if (debounceRef.current) clearTimeout(debounceRef.current);
361
441
  markerRef.current = null;
442
+ mapRef.current = null;
443
+ mapCleanup?.();
362
444
  };
363
- // eslint-disable-next-line react-hooks/exhaustive-deps
364
- }, []); // intentionally empty – runs once on mount
445
+ }, [
446
+ brandColor,
447
+ embedMode,
448
+ hasDefault,
449
+ indiaBoundaryUrl,
450
+ initLat,
451
+ initLng,
452
+ mapStyle,
453
+ refreshDigipin,
454
+ ]);
365
455
 
366
456
  // ── Geolocation handler ───────────────────────────────────────────────────
367
457
  const handleLocateMe = useCallback(() => {
368
458
  clearError();
369
459
  locate((userLat, userLng) => {
370
- setLat(userLat);
371
- setLng(userLng);
372
460
  refreshDigipin(userLat, userLng);
373
-
374
- if (mapRef.current) {
375
- mapRef.current.flyTo({
376
- center: [userLng, userLat],
377
- zoom: STREET_ZOOM,
378
- duration: 1400,
379
- essential: true,
380
- });
381
- }
461
+ mapRef.current?.flyTo({
462
+ center: [userLng, userLat],
463
+ zoom: STREET_ZOOM,
464
+ duration: 1400,
465
+ essential: true,
466
+ });
382
467
  markerRef.current?.setLngLat([userLng, userLat]);
383
468
  });
384
469
  }, [locate, clearError, refreshDigipin]);
385
470
 
386
- // ── Confirm handler ───────────────────────────────────────────────────────
387
471
  const handleConfirm = useCallback(() => {
388
472
  if (digipin) {
389
473
  onLocationConfirm(lat, lng, digipin);
@@ -391,11 +475,11 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
391
475
  }, [lat, lng, digipin, onLocationConfirm]);
392
476
 
393
477
  const isInIndia = digipin !== null;
394
- const canConfirm = isInIndia && mapLoaded;
478
+ const canConfirm = isInIndia && mapLoaded && mapState === 'ready';
479
+ const showMapStatus = mapState !== 'ready';
395
480
 
396
481
  return (
397
482
  <div className="qr-map-wrapper">
398
- {/* ── Step header ── */}
399
483
  <div className="qr-step-header">
400
484
  <div className="qr-step-badge">1</div>
401
485
  <div className="qr-step-text">
@@ -406,11 +490,9 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
406
490
  </div>
407
491
  </div>
408
492
 
409
- {/* ── Search bar ── */}
410
493
  {enableSearch && (
411
494
  <div className="qr-search-bar" role="search">
412
495
  <div className="qr-search-bar__input-wrap">
413
- {/* Search icon */}
414
496
  <svg
415
497
  className="qr-search-bar__icon"
416
498
  aria-hidden="true"
@@ -443,12 +525,10 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
443
525
  aria-expanded={dropdownOpen}
444
526
  />
445
527
 
446
- {/* Inline loading spinner */}
447
528
  {searchLoading && (
448
529
  <span className="qr-search-bar__spinner qr-spinner qr-spinner--sm" aria-hidden="true" />
449
530
  )}
450
531
 
451
- {/* Clear button */}
452
532
  {searchQuery && !searchLoading && (
453
533
  <button
454
534
  type="button"
@@ -462,12 +542,10 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
462
542
  )}
463
543
  </div>
464
544
 
465
- {/* Inline error */}
466
545
  {searchError && (
467
546
  <p className="qr-search-bar__error" role="alert">{searchError}</p>
468
547
  )}
469
548
 
470
- {/* Suggestions dropdown */}
471
549
  {dropdownOpen && suggestions.length > 0 && (
472
550
  <ul
473
551
  id={listboxId}
@@ -482,7 +560,7 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
482
560
  role="option"
483
561
  aria-selected="false"
484
562
  onMouseDown={(e) => {
485
- e.preventDefault(); // keep input focus until after click
563
+ e.preventDefault();
486
564
  handleSuggestionSelect(s);
487
565
  }}
488
566
  >
@@ -510,7 +588,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
510
588
  </ul>
511
589
  )}
512
590
 
513
- {/* DigiPin hint chip */}
514
591
  <p className="qr-search-bar__hint">
515
592
  <span className="qr-search-bar__hint-chip">DigiPin</span>
516
593
  Type your DigiPin code for instant offline lookup — no API call
@@ -518,12 +595,22 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
518
595
  </div>
519
596
  )}
520
597
 
521
- {/* ── Map area ── */}
522
598
  <div className="qr-map-outer" style={{ height: mapHeight }}>
523
- {/* MapLibre GL container */}
524
599
  <div ref={containerRef} className="qr-map-canvas" />
525
600
 
526
- {/* DigiPin overlay badge – shown once inside India */}
601
+ {showMapStatus && (
602
+ <div className="qr-map-notice" role={mapState === 'loading' ? 'status' : 'alert'}>
603
+ {mapState === 'loading' ? (
604
+ <>
605
+ <span className="qr-spinner qr-spinner--sm" aria-hidden="true" />
606
+ <span>Loading map…</span>
607
+ </>
608
+ ) : (
609
+ mapError ?? 'Map is unavailable. Please try again.'
610
+ )}
611
+ </div>
612
+ )}
613
+
527
614
  {digipin && (
528
615
  <div className="qr-digipin-badge" aria-live="polite" aria-label={`DigiPin: ${digipin}`}>
529
616
  <span className="qr-digipin-badge__label">DigiPin</span>
@@ -531,18 +618,16 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
531
618
  </div>
532
619
  )}
533
620
 
534
- {/* Out-of-India notice */}
535
621
  {!isInIndia && mapLoaded && (
536
622
  <div className="qr-map-notice" role="status">
537
623
  Move map to India to get a DigiPin
538
624
  </div>
539
625
  )}
540
626
 
541
- {/* Locate-me button */}
542
627
  <button
543
628
  className={`qr-locate-btn${geoLoading ? ' qr-locate-btn--loading' : ''}`}
544
629
  onClick={handleLocateMe}
545
- disabled={geoLoading}
630
+ disabled={geoLoading || mapState !== 'ready'}
546
631
  title="Use my current location"
547
632
  aria-label="Use my current location"
548
633
  type="button"
@@ -555,23 +640,17 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
555
640
  viewBox="0 0 24 24"
556
641
  fill="none"
557
642
  stroke="currentColor"
558
- strokeWidth="2"
643
+ strokeWidth="2"
559
644
  strokeLinecap="round"
560
645
  strokeLinejoin="round"
561
646
  >
562
- {/* 1. Inner solid dot */}
563
647
  <circle cx="12" cy="12" r="3" fill="currentColor" stroke="none" />
564
-
565
- {/* 2. Outer ring */}
566
648
  <circle cx="12" cy="12" r="7" />
567
-
568
- {/* 3. Crosshair bumps attached to the ring */}
569
649
  <path d="M12 2v3M12 19v3M2 12h3M19 12h3" />
570
650
  </svg>
571
651
  )}
572
652
  </button>
573
653
 
574
- {/* Geo error toast */}
575
654
  {geoError && (
576
655
  <div className="qr-geo-error" role="alert">
577
656
  <span>{geoError}</span>
@@ -587,7 +666,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
587
666
  )}
588
667
  </div>
589
668
 
590
- {/* ── Coordinates strip ── */}
591
669
  {mapLoaded && (
592
670
  <div className="qr-coords-strip" aria-label="Current pin coordinates">
593
671
  <span>{lat.toFixed(5)}° N</span>
@@ -596,7 +674,6 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
596
674
  </div>
597
675
  )}
598
676
 
599
- {/* ── Confirm action bar ── */}
600
677
  <div className="qr-map-actions">
601
678
  <button
602
679
  type="button"
@@ -620,6 +697,13 @@ const MapPinSelector: React.FC<MapPinSelectorProps> = ({
620
697
  {!isInIndia && mapLoaded && (
621
698
  <p className="qr-map-hint">Move the pin to a location in India to continue</p>
622
699
  )}
700
+ {mapState !== 'ready' && (
701
+ <p className="qr-map-hint">
702
+ {mapState === 'loading'
703
+ ? 'Loading the map before location confirmation.'
704
+ : 'Map is unavailable, so location confirmation is paused.'}
705
+ </p>
706
+ )}
623
707
  </div>
624
708
  </div>
625
709
  );