@quantaroute/checkout 1.4.1 → 1.4.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.
- package/CHANGELOG.md +12 -0
- package/README.md +9 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/quantaroute-checkout.es.js +18 -17
- package/dist/lib/quantaroute-checkout.umd.js +43 -42
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/AddressForm.native.tsx +55 -1
- package/src/components/AddressForm.tsx +39 -1
- package/src/components/CheckoutWidget.tsx +4 -1
- package/src/core/types.ts +9 -0
- package/src/index.ts +2 -0
- package/src/styles/checkout.css +42 -0
- package/src/styles/checkout.native.ts +48 -0
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from '../core/api';
|
|
9
9
|
import type {
|
|
10
10
|
AddressFormProps,
|
|
11
|
+
AddressLabel,
|
|
11
12
|
AdministrativeInfo,
|
|
12
13
|
CompleteAddress,
|
|
13
14
|
LocationAlternative,
|
|
@@ -30,6 +31,7 @@ type FormState =
|
|
|
30
31
|
adminInfo: AdministrativeInfo;
|
|
31
32
|
alternatives: LocationAlternative[];
|
|
32
33
|
selectedLocality: string; // Selected locality name (from adminInfo or alternatives)
|
|
34
|
+
selectedLabel: AddressLabel;
|
|
33
35
|
fields: ManualFields;
|
|
34
36
|
submitting: boolean;
|
|
35
37
|
/** At least one India Post office with "Delivery" (not only "Non Delivery") */
|
|
@@ -48,6 +50,7 @@ type FormAction =
|
|
|
48
50
|
| { type: 'LOAD_ERROR'; message: string }
|
|
49
51
|
| { type: 'SET_FIELD'; key: keyof ManualFields; value: string }
|
|
50
52
|
| { type: 'SET_LOCALITY'; locality: string }
|
|
53
|
+
| { type: 'SET_LABEL'; label: AddressLabel }
|
|
51
54
|
| { type: 'SUBMIT_START' }
|
|
52
55
|
| { type: 'SUBMIT_END' };
|
|
53
56
|
|
|
@@ -103,6 +106,7 @@ function reducer(state: FormState, action: FormAction): FormState {
|
|
|
103
106
|
adminInfo: action.adminInfo,
|
|
104
107
|
alternatives: action.alternatives || [],
|
|
105
108
|
selectedLocality: action.adminInfo.locality,
|
|
109
|
+
selectedLabel: 'home',
|
|
106
110
|
fields: { ...INITIAL_FIELDS, ...preFilled },
|
|
107
111
|
submitting: false,
|
|
108
112
|
pincodeHasDelivery: action.pincodeHasDelivery,
|
|
@@ -116,6 +120,9 @@ function reducer(state: FormState, action: FormAction): FormState {
|
|
|
116
120
|
case 'SET_LOCALITY':
|
|
117
121
|
if (state.status !== 'ready') return state;
|
|
118
122
|
return { ...state, selectedLocality: action.locality };
|
|
123
|
+
case 'SET_LABEL':
|
|
124
|
+
if (state.status !== 'ready') return state;
|
|
125
|
+
return { ...state, selectedLabel: action.label };
|
|
119
126
|
case 'SUBMIT_START':
|
|
120
127
|
if (state.status !== 'ready') return state;
|
|
121
128
|
return { ...state, submitting: true };
|
|
@@ -202,7 +209,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
202
209
|
e.preventDefault();
|
|
203
210
|
if (state.status !== 'ready') return;
|
|
204
211
|
|
|
205
|
-
const { adminInfo, selectedLocality, fields } = state;
|
|
212
|
+
const { adminInfo, selectedLocality, selectedLabel, fields } = state;
|
|
206
213
|
|
|
207
214
|
const parts: string[] = [
|
|
208
215
|
fields.flatNumber,
|
|
@@ -228,6 +235,7 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
228
235
|
country: adminInfo.country ?? 'India',
|
|
229
236
|
...fields,
|
|
230
237
|
formattedAddress: parts.join(', '),
|
|
238
|
+
label: selectedLabel,
|
|
231
239
|
};
|
|
232
240
|
|
|
233
241
|
dispatch({ type: 'SUBMIT_START' });
|
|
@@ -387,6 +395,36 @@ const AddressForm: React.FC<AddressFormProps> = ({
|
|
|
387
395
|
</div>
|
|
388
396
|
)}
|
|
389
397
|
|
|
398
|
+
{/* Address label */}
|
|
399
|
+
<fieldset className="qr-fieldset">
|
|
400
|
+
<legend className="qr-fieldset__legend">Save as</legend>
|
|
401
|
+
<div className="qr-label-picker" role="radiogroup" aria-label="Address label">
|
|
402
|
+
{(
|
|
403
|
+
[
|
|
404
|
+
{ value: 'home' as const, title: 'Home', icon: '🏠' },
|
|
405
|
+
{ value: 'work' as const, title: 'Work', icon: '💼' },
|
|
406
|
+
{ value: 'other' as const, title: 'Other', icon: '📍' },
|
|
407
|
+
] as const
|
|
408
|
+
).map(({ value, title, icon }) => (
|
|
409
|
+
<button
|
|
410
|
+
key={value}
|
|
411
|
+
type="button"
|
|
412
|
+
role="radio"
|
|
413
|
+
aria-checked={state.selectedLabel === value}
|
|
414
|
+
className={`qr-label-picker__option${
|
|
415
|
+
state.selectedLabel === value ? ' qr-label-picker__option--active' : ''
|
|
416
|
+
}`}
|
|
417
|
+
onClick={() => dispatch({ type: 'SET_LABEL', label: value })}
|
|
418
|
+
>
|
|
419
|
+
<span className="qr-label-picker__icon" aria-hidden="true">
|
|
420
|
+
{icon}
|
|
421
|
+
</span>
|
|
422
|
+
<span>{title}</span>
|
|
423
|
+
</button>
|
|
424
|
+
))}
|
|
425
|
+
</div>
|
|
426
|
+
</fieldset>
|
|
427
|
+
|
|
390
428
|
{/* Manual entry section */}
|
|
391
429
|
<fieldset className="qr-fieldset">
|
|
392
430
|
<legend className="qr-fieldset__legend">
|
|
@@ -376,6 +376,9 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
376
376
|
]
|
|
377
377
|
.filter(Boolean)
|
|
378
378
|
.join(', '),
|
|
379
|
+
label: (saved.label === 'work' || saved.label === 'other'
|
|
380
|
+
? saved.label
|
|
381
|
+
: 'home') as CompleteAddress['label'],
|
|
379
382
|
};
|
|
380
383
|
void finishAddress(complete);
|
|
381
384
|
};
|
|
@@ -426,7 +429,7 @@ const CheckoutWidget: React.FC<CheckoutWidgetProps> = ({
|
|
|
426
429
|
building_name: address.buildingName,
|
|
427
430
|
street_name: address.streetName,
|
|
428
431
|
full_address_json: address as unknown as Record<string, unknown>,
|
|
429
|
-
label: 'home',
|
|
432
|
+
label: address.label ?? 'home',
|
|
430
433
|
is_default: true,
|
|
431
434
|
});
|
|
432
435
|
} catch {
|
package/src/core/types.ts
CHANGED
|
@@ -49,6 +49,13 @@ export interface LocationLookupResponse {
|
|
|
49
49
|
message?: string;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
// ─── Address labels (saved-address book) ─────────────────────────────────────
|
|
53
|
+
|
|
54
|
+
/** Label for a saved buyer address — stored in checkout-addresses API. */
|
|
55
|
+
export type AddressLabel = 'home' | 'work' | 'other';
|
|
56
|
+
|
|
57
|
+
export const ADDRESS_LABELS: AddressLabel[] = ['home', 'work', 'other'];
|
|
58
|
+
|
|
52
59
|
// ─── Complete Address (output) ───────────────────────────────────────────────
|
|
53
60
|
|
|
54
61
|
export interface CompleteAddress {
|
|
@@ -82,6 +89,8 @@ export interface CompleteAddress {
|
|
|
82
89
|
streetName: string;
|
|
83
90
|
/** Combined formatted address string */
|
|
84
91
|
formattedAddress: string;
|
|
92
|
+
/** Buyer-chosen label for saved-address book (defaults to home) */
|
|
93
|
+
label?: AddressLabel;
|
|
85
94
|
}
|
|
86
95
|
|
|
87
96
|
// ─── Checkout event (client-side analytics hook) ─────────────────────────────
|
package/src/index.ts
CHANGED
package/src/styles/checkout.css
CHANGED
|
@@ -814,6 +814,47 @@
|
|
|
814
814
|
font-size: 14px;
|
|
815
815
|
}
|
|
816
816
|
|
|
817
|
+
.qr-label-picker {
|
|
818
|
+
display: grid;
|
|
819
|
+
grid-template-columns: repeat(3, 1fr);
|
|
820
|
+
gap: 8px;
|
|
821
|
+
padding: 0 16px 12px;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
.qr-label-picker__option {
|
|
825
|
+
display: flex;
|
|
826
|
+
flex-direction: column;
|
|
827
|
+
align-items: center;
|
|
828
|
+
justify-content: center;
|
|
829
|
+
gap: 4px;
|
|
830
|
+
min-height: 72px;
|
|
831
|
+
padding: 10px 8px;
|
|
832
|
+
border: 1.5px solid var(--qr-border);
|
|
833
|
+
border-radius: 10px;
|
|
834
|
+
background: var(--qr-bg, #fff);
|
|
835
|
+
color: var(--qr-text-muted);
|
|
836
|
+
font-family: inherit;
|
|
837
|
+
font-size: 13px;
|
|
838
|
+
font-weight: 500;
|
|
839
|
+
cursor: pointer;
|
|
840
|
+
transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
.qr-label-picker__option:hover:not(.qr-label-picker__option--active) {
|
|
844
|
+
border-color: color-mix(in srgb, var(--qr-accent, var(--qr-navy)) 35%, var(--qr-border));
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
.qr-label-picker__option--active {
|
|
848
|
+
border-color: var(--qr-accent, var(--qr-navy));
|
|
849
|
+
background: color-mix(in srgb, var(--qr-accent, var(--qr-navy)) 10%, var(--qr-bg, #fff));
|
|
850
|
+
color: var(--qr-text);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
.qr-label-picker__icon {
|
|
854
|
+
font-size: 18px;
|
|
855
|
+
line-height: 1;
|
|
856
|
+
}
|
|
857
|
+
|
|
817
858
|
/* ── Auto-filled grid ────────────────────────────────────── */
|
|
818
859
|
.qr-auto-grid {
|
|
819
860
|
display: grid;
|
|
@@ -1375,6 +1416,7 @@
|
|
|
1375
1416
|
|
|
1376
1417
|
/* ── Focus visible (keyboard nav) ────────────────────────── */
|
|
1377
1418
|
.qr-btn:focus-visible,
|
|
1419
|
+
.qr-label-picker__option:focus-visible,
|
|
1378
1420
|
.qr-back-btn:focus-visible,
|
|
1379
1421
|
.qr-locate-btn:focus-visible {
|
|
1380
1422
|
outline: 2px solid var(--qr-primary);
|
|
@@ -721,6 +721,54 @@ export const styles = StyleSheet.create({
|
|
|
721
721
|
fontWeight: '700',
|
|
722
722
|
},
|
|
723
723
|
|
|
724
|
+
// ── Address label picker ────────────────────────────────────────────────────
|
|
725
|
+
labelPicker: {
|
|
726
|
+
flexDirection: 'row',
|
|
727
|
+
gap: 8,
|
|
728
|
+
paddingHorizontal: 16,
|
|
729
|
+
paddingBottom: 12,
|
|
730
|
+
},
|
|
731
|
+
labelPickerOption: {
|
|
732
|
+
flex: 1,
|
|
733
|
+
alignItems: 'center',
|
|
734
|
+
justifyContent: 'center',
|
|
735
|
+
gap: 4,
|
|
736
|
+
minHeight: 72,
|
|
737
|
+
paddingVertical: 10,
|
|
738
|
+
paddingHorizontal: 8,
|
|
739
|
+
borderWidth: 1.5,
|
|
740
|
+
borderColor: COLORS.border,
|
|
741
|
+
borderRadius: 10,
|
|
742
|
+
backgroundColor: COLORS.bg,
|
|
743
|
+
},
|
|
744
|
+
labelPickerOptionDark: {
|
|
745
|
+
borderColor: COLORS.borderDark,
|
|
746
|
+
backgroundColor: COLORS.bgDark,
|
|
747
|
+
},
|
|
748
|
+
labelPickerOptionActive: {
|
|
749
|
+
borderColor: COLORS.primary,
|
|
750
|
+
backgroundColor: COLORS.primaryLight,
|
|
751
|
+
},
|
|
752
|
+
labelPickerOptionActiveDark: {
|
|
753
|
+
borderColor: COLORS.primary,
|
|
754
|
+
backgroundColor: '#0c4a6e33',
|
|
755
|
+
},
|
|
756
|
+
labelPickerIcon: {
|
|
757
|
+
fontSize: 18,
|
|
758
|
+
},
|
|
759
|
+
labelPickerText: {
|
|
760
|
+
fontSize: 13,
|
|
761
|
+
fontWeight: '500',
|
|
762
|
+
color: COLORS.textMuted,
|
|
763
|
+
},
|
|
764
|
+
labelPickerTextDark: {
|
|
765
|
+
color: COLORS.textMutedDark,
|
|
766
|
+
},
|
|
767
|
+
labelPickerTextActive: {
|
|
768
|
+
color: COLORS.text,
|
|
769
|
+
fontWeight: '600',
|
|
770
|
+
},
|
|
771
|
+
|
|
724
772
|
// ── Manual fields ───────────────────────────────────────────────────────────
|
|
725
773
|
fieldsGrid: {
|
|
726
774
|
paddingHorizontal: 16,
|