@tallyui/components 3.20.0 → 4.0.0
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/dist/index.d.ts +1114 -90
- package/dist/index.js +8077 -3352
- package/package.json +10 -11
- package/src/cart/cart-charge-line.tsx +58 -0
- package/src/cart/cart-columns-form.tsx +98 -0
- package/src/cart/cart-columns.tsx +49 -18
- package/src/cart/cart-foot.tsx +7 -2
- package/src/cart/cart-line-strip.tsx +59 -0
- package/src/cart/cart-line.tsx +20 -8
- package/src/cart/cart-note-row.tsx +30 -0
- package/src/cart/cart-panel.tsx +9 -1
- package/src/cart/cart-row-motion.tsx +125 -0
- package/src/cart/cart-total.tsx +44 -15
- package/src/cart/index.ts +2 -1
- package/src/checkout/cash-tendered.tsx +8 -7
- package/src/checkout/change-display.tsx +2 -1
- package/src/checkout/index.ts +1 -1
- package/src/checkout/payment-selector.tsx +6 -2
- package/src/checkout/payment-types.test-d.ts +28 -0
- package/src/customer/address-editor.tsx +87 -0
- package/src/customer/address-fields.tsx +120 -0
- package/src/customer/customer-dropdown.tsx +200 -0
- package/src/customer/customer-editor.tsx +99 -0
- package/src/customer/customer-form.tsx +39 -5
- package/src/customer/customer-picker.tsx +38 -14
- package/src/customer/customers-list.tsx +83 -0
- package/src/customer/index.ts +5 -0
- package/src/filter/filter-pills.tsx +63 -0
- package/src/i18n/locales/en/components.json +85 -0
- package/src/index.ts +40 -2
- package/src/input/decimal-entry.ts +21 -0
- package/src/layout/checkout-layout.tsx +1 -1
- package/src/layout/live-tab-screen.tsx +1 -1
- package/src/layout/pos-layout.tsx +80 -4
- package/src/layout/settings-layout.tsx +1 -1
- package/src/layout/store-settings-choice-screen.tsx +1 -1
- package/src/lib/current-row.ts +13 -0
- package/src/lib/money-input.ts +16 -0
- package/src/lib/motion.ts +22 -0
- package/src/lib/use-reduced-motion.ts +20 -0
- package/src/order/index.ts +1 -1
- package/src/order/order-detail.tsx +123 -5
- package/src/order/order-filter-bar.tsx +7 -57
- package/src/order/order-status-badge.tsx +42 -19
- package/src/order/refund-form.tsx +7 -5
- package/src/product/camera-scan-button.tsx +2 -0
- package/src/product/category-nav.tsx +8 -0
- package/src/product/category-tile.tsx +65 -15
- package/src/product/in-cart-badge.tsx +55 -6
- package/src/product/index.ts +1 -0
- package/src/product/press-veil.tsx +7 -0
- package/src/product/product-card.tsx +5 -1
- package/src/product/product-grid.tsx +5 -0
- package/src/product/product-price.tsx +6 -3
- package/src/product/product-stock-badge.tsx +3 -2
- package/src/product/product-table.tsx +96 -8
- package/src/product/products-screen-columns.tsx +74 -0
- package/src/product/variant-tile.tsx +68 -0
- package/src/product/variation-picker.tsx +3 -3
- package/src/product/view-toggle.tsx +33 -4
- package/src/register/cashier-sheet.tsx +195 -0
- package/src/register/closure-sheet.tsx +54 -3
- package/src/register/handover-slip.tsx +2 -1
- package/src/register/index.ts +2 -1
- package/src/register/movement-sheet.tsx +66 -7
- package/src/register/open-register-card.tsx +11 -11
- package/src/register/register-bar.helpers.ts +17 -4
- package/src/register/register-bar.tsx +26 -5
- package/src/register/register-count.tsx +158 -24
- package/src/register/register-panel.tsx +16 -5
- package/src/register/register-side-sheet.tsx +32 -8
- package/src/register/switch-confirm.tsx +2 -2
- package/src/reports/card-panel.tsx +131 -0
- package/src/reports/cards.tsx +53 -36
- package/src/reports/hero.tsx +2 -1
- package/src/reports/index.ts +1 -0
- package/src/reports/sales-room.tsx +4 -2
- package/src/sale/breadcrumb.tsx +48 -0
- package/src/sale/cart-bar.tsx +2 -1
- package/src/sale/cart.tsx +127 -38
- package/src/sale/catalogue-settings-form.tsx +92 -0
- package/src/sale/catalogue.tsx +304 -42
- package/src/sale/category-browse.tsx +27 -0
- package/src/sale/charge-form.tsx +85 -21
- package/src/sale/customer-display-screen.tsx +22 -6
- package/src/sale/discount-form.tsx +132 -28
- package/src/sale/index.ts +6 -3
- package/src/sale/line-popover.tsx +72 -36
- package/src/sale/offered-methods.ts +16 -0
- package/src/sale/open-sale-tabs.tsx +58 -10
- package/src/sale/order-note-sheet.tsx +37 -0
- package/src/sale/order-reference.ts +3 -0
- package/src/sale/orders-list.tsx +76 -37
- package/src/sale/parked-sales.tsx +2 -1
- package/src/sale/price-form.tsx +7 -5
- package/src/sale/product-filter-bar.tsx +38 -5
- package/src/sale/receipt-sheet.tsx +243 -0
- package/src/sale/receipt.tsx +19 -9
- package/src/sale/sync-status.tsx +10 -0
- package/src/sale/tender-ledger.tsx +92 -0
- package/src/sale/tender-pane.tsx +159 -73
- package/src/sale/tender.tsx +10 -7
- package/src/sale/use-tender.ts +63 -0
- package/src/scale/min-target.tsx +36 -0
- package/src/settings/barcode-scanning-settings.tsx +164 -0
- package/src/settings/connector-status.tsx +1 -1
- package/src/settings/customer-display-settings.tsx +12 -25
- package/src/settings/index.ts +5 -0
- package/src/settings/printer-form.tsx +161 -0
- package/src/settings/printing-settings.tsx +268 -0
- package/src/settings/settings-group.tsx +2 -1
- package/src/settings/tax-calculation-settings.tsx +1 -1
- package/src/shell/added-to-cart-toast.tsx +61 -0
- package/src/shell/app-shell.tsx +5 -1
- package/src/shell/connectivity-toast.tsx +70 -0
- package/src/shell/index.ts +2 -0
- package/src/shell/nav-drawer.tsx +5 -2
- package/src/shell/nav-item.tsx +7 -4
- package/src/shell/nav-rail.tsx +9 -2
- package/src/ui/accordion/index.tsx +86 -8
- package/src/ui/alert-dialog/index.tsx +19 -5
- package/src/ui/combobox/index.tsx +21 -2
- package/src/ui/confirm-dialog/index.tsx +53 -0
- package/src/ui/dialog/index.tsx +68 -14
- package/src/ui/dialog/motion.ts +54 -0
- package/src/ui/icon/activity-heartbeat-icon.tsx +7 -0
- package/src/ui/icon/alert-circle-icon.tsx +5 -0
- package/src/ui/icon/alert-triangle-icon.tsx +7 -0
- package/src/ui/icon/banknote-icon.tsx +11 -0
- package/src/ui/icon/cash-register-icon.tsx +10 -0
- package/src/ui/icon/category-icon.tsx +7 -0
- package/src/ui/icon/chart-line-icon.tsx +5 -0
- package/src/ui/icon/check-icon.tsx +5 -0
- package/src/ui/icon/chevron-left-icon.tsx +4 -0
- package/src/ui/icon/chevron-right-icon.tsx +4 -0
- package/src/ui/icon/credit-card-icon.tsx +10 -0
- package/src/ui/icon/discount-icon.tsx +11 -0
- package/src/ui/icon/gift-icon.tsx +10 -0
- package/src/ui/icon/info-circle-icon.tsx +10 -0
- package/src/ui/icon/map-pin-icon.tsx +10 -0
- package/src/ui/icon/message-question-icon.tsx +7 -0
- package/src/ui/icon/pencil-icon.tsx +10 -0
- package/src/ui/icon/plus-icon.tsx +9 -0
- package/src/ui/icon/printer-icon.tsx +10 -0
- package/src/ui/icon/receipt-icon.tsx +7 -0
- package/src/ui/icon/settings-icon.tsx +10 -0
- package/src/ui/icon/sticky-note-icon.tsx +10 -0
- package/src/ui/icon/user-icon.tsx +4 -0
- package/src/ui/icon/users-icon.tsx +7 -0
- package/src/ui/icon/view-grid-icon.tsx +7 -0
- package/src/ui/icon/view-list-icon.tsx +7 -0
- package/src/ui/index.ts +24 -1
- package/src/ui/list-row/index.tsx +93 -0
- package/src/ui/notice/index.tsx +65 -0
- package/src/ui/select/index.tsx +2 -0
- package/src/ui/skeleton/index.tsx +37 -0
- package/src/ui/status-badge/index.tsx +43 -0
- package/src/ui/switch/index.tsx +1 -1
- package/src/ui/tabs/index.tsx +11 -2
- package/src/ui/toggle-group/index.tsx +3 -1
- package/src/ui/tone-disc/index.tsx +41 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState, type JSX, type ReactNode } from 'react';
|
|
2
|
+
import { Animated, Platform } from 'react-native';
|
|
3
|
+
import { EASE, EASE_EXIT, PANEL_SLIDE_OUT } from '../lib/motion';
|
|
4
|
+
import { useReducedMotion } from '../lib/use-reduced-motion';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A cart row's add and remove feedback: a tint laid over the row, of which only the opacity animates.
|
|
8
|
+
* An add lights green and settles back; a removal tints red, then the row's height closes to nothing.
|
|
9
|
+
*
|
|
10
|
+
* Ported from WCPOS v2 `PulseTableRow`, packages/components/src/table/pulse-row.tsx (MIT, WCPOS):
|
|
11
|
+
* timings 58-67, pulseAdd 161-179, pulseRemove 187-221, onLayout 237-243, overlays 247-254.
|
|
12
|
+
*/
|
|
13
|
+
export function CartRowMotion({ beat, leaving, onLeft, still, testID, children }: {
|
|
14
|
+
beat: number;
|
|
15
|
+
leaving: boolean;
|
|
16
|
+
onLeft: () => void;
|
|
17
|
+
/** Reduced motion, or not known yet: nothing animates. */
|
|
18
|
+
still: boolean;
|
|
19
|
+
testID?: string;
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
}): JSX.Element {
|
|
22
|
+
const added = useRef(new Animated.Value(0)).current;
|
|
23
|
+
const removed = useRef(new Animated.Value(0)).current;
|
|
24
|
+
const height = useRef(new Animated.Value(0)).current;
|
|
25
|
+
const measured = useRef(0);
|
|
26
|
+
const [closing, setClosing] = useState(false);
|
|
27
|
+
const left = useRef(onLeft);
|
|
28
|
+
left.current = onLeft;
|
|
29
|
+
const useNativeDriver = Platform.OS !== 'web';
|
|
30
|
+
useLayoutEffect(() => {
|
|
31
|
+
if (beat === 0 || still) return;
|
|
32
|
+
Animated.sequence([
|
|
33
|
+
Animated.timing(added, { toValue: 0.22, duration: 120, easing: EASE, useNativeDriver }),
|
|
34
|
+
Animated.timing(added, { toValue: 0, duration: 420, easing: EASE, useNativeDriver }),
|
|
35
|
+
]).start();
|
|
36
|
+
}, [beat, still, added, useNativeDriver]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!leaving) return;
|
|
39
|
+
Animated.timing(removed, { toValue: 0.3, duration: PANEL_SLIDE_OUT, easing: EASE_EXIT, useNativeDriver }).start(({ finished }) => {
|
|
40
|
+
if (!finished) return;
|
|
41
|
+
if (measured.current <= 0) return left.current();
|
|
42
|
+
height.setValue(measured.current);
|
|
43
|
+
setClosing(true);
|
|
44
|
+
Animated.timing(height, { toValue: 0, duration: PANEL_SLIDE_OUT, easing: EASE, useNativeDriver: false })
|
|
45
|
+
.start((end) => end.finished && left.current());
|
|
46
|
+
});
|
|
47
|
+
// A row that came back before it left gets its own height and no red.
|
|
48
|
+
return () => {
|
|
49
|
+
removed.stopAnimation();
|
|
50
|
+
height.stopAnimation();
|
|
51
|
+
removed.setValue(0);
|
|
52
|
+
setClosing(false);
|
|
53
|
+
};
|
|
54
|
+
}, [leaving, removed, height, useNativeDriver]);
|
|
55
|
+
return (
|
|
56
|
+
<Animated.View testID={testID} style={closing ? { height, overflow: 'hidden' } : undefined}
|
|
57
|
+
pointerEvents={leaving ? 'none' : undefined} aria-hidden={leaving || undefined}
|
|
58
|
+
onLayout={(event) => { if (!leaving) measured.current = event.nativeEvent.layout.height; }}>
|
|
59
|
+
{children}
|
|
60
|
+
<Animated.View pointerEvents="none" aria-hidden testID={testID && `${testID}-added`}
|
|
61
|
+
className="absolute inset-0 bg-success" style={{ opacity: added }} />
|
|
62
|
+
<Animated.View pointerEvents="none" aria-hidden testID={testID && `${testID}-removed`}
|
|
63
|
+
className="absolute inset-0 bg-destructive" style={{ opacity: removed }} />
|
|
64
|
+
</Animated.View>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface Row { key: string; pulse: string | number; beat: number; leaving: boolean }
|
|
69
|
+
|
|
70
|
+
function same(a: Row[], b: Row[]): boolean {
|
|
71
|
+
return a.length === b.length && a.every((row, i) =>
|
|
72
|
+
row.key === b[i].key && row.pulse === b[i].pulse && row.beat === b[i].beat && row.leaving === b[i].leaving);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Rows that pulse when they arrive or their `pulseKey` changes, and leave as a tinted, collapsing ghost.
|
|
77
|
+
* A change of `identity` (another order) rebaselines without a pulse, unless the list it replaces was empty.
|
|
78
|
+
* WCPOS v2 packages/core/src/screens/main/pos/hooks/utils.ts:61-77 and cart/table.tsx:221-265.
|
|
79
|
+
*/
|
|
80
|
+
export function MotionRows<T>({ items, keyOf, pulseKey, identity, renderItem, empty = null }: {
|
|
81
|
+
items: T[];
|
|
82
|
+
keyOf: (item: T, index: number) => string;
|
|
83
|
+
pulseKey: (item: T) => string | number;
|
|
84
|
+
identity?: string;
|
|
85
|
+
renderItem: (item: T, index: number) => ReactNode;
|
|
86
|
+
empty?: ReactNode;
|
|
87
|
+
}): JSX.Element {
|
|
88
|
+
const still = useReducedMotion() !== false;
|
|
89
|
+
const current = items.map((item, index) => ({ item, index, key: keyOf(item, index), pulse: pulseKey(item) }));
|
|
90
|
+
const [seen, setSeen] = useState(() => ({ identity, rows: current.map(({ key, pulse }): Row => ({ key, pulse, beat: 0, leaving: false })) }));
|
|
91
|
+
const nodes = useRef(new Map<string, ReactNode>());
|
|
92
|
+
let rows: Row[];
|
|
93
|
+
if (seen.identity !== identity) {
|
|
94
|
+
const fresh = !seen.rows.some((row) => !row.leaving);
|
|
95
|
+
rows = current.map(({ key, pulse }) => ({ key, pulse, beat: fresh ? 1 : 0, leaving: false }));
|
|
96
|
+
} else {
|
|
97
|
+
const before = new Map(seen.rows.map((row) => [row.key, row]));
|
|
98
|
+
rows = current.map(({ key, pulse }) => {
|
|
99
|
+
const was = before.get(key);
|
|
100
|
+
const beat = !was ? 1 : was.leaving || was.pulse !== pulse ? was.beat + 1 : was.beat;
|
|
101
|
+
return { key, pulse, beat, leaving: false };
|
|
102
|
+
});
|
|
103
|
+
const kept = new Set(rows.map((row) => row.key));
|
|
104
|
+
if (!still) {
|
|
105
|
+
seen.rows.forEach((row, i) => {
|
|
106
|
+
if (kept.has(row.key)) return;
|
|
107
|
+
// The ghost stays where it was: right after the row that preceded it, or first.
|
|
108
|
+
rows.splice(i === 0 ? 0 : rows.findIndex((other) => other.key === seen.rows[i - 1].key) + 1, 0, { ...row, leaving: true });
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (seen.identity !== identity || !same(seen.rows, rows)) setSeen({ identity, rows });
|
|
113
|
+
const rendered = new Map(current.map(({ item, index, key }) => [key, renderItem(item, index)]));
|
|
114
|
+
useLayoutEffect(() => {
|
|
115
|
+
for (const [key, node] of rendered) nodes.current.set(key, node);
|
|
116
|
+
for (const key of nodes.current.keys()) if (!rendered.has(key) && !rows.some((row) => row.key === key)) nodes.current.delete(key);
|
|
117
|
+
});
|
|
118
|
+
if (!rows.length) return <>{empty}</>;
|
|
119
|
+
return <>{rows.map((row) => (
|
|
120
|
+
<CartRowMotion key={row.key} testID={`cart-row-${row.key}`} beat={row.beat} leaving={row.leaving} still={still}
|
|
121
|
+
onLeft={() => setSeen((s) => ({ ...s, rows: s.rows.filter((other) => other.key !== row.key || !other.leaving) }))}>
|
|
122
|
+
{row.leaving ? nodes.current.get(row.key) : rendered.get(row.key)}
|
|
123
|
+
</CartRowMotion>
|
|
124
|
+
))}</>;
|
|
125
|
+
}
|
package/src/cart/cart-total.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useFormatMoney, type Money } from '@tallyui/core';
|
|
3
3
|
import { cn } from '@tallyui/theme';
|
|
4
4
|
import { Text, HStack, VStack, type VStackProps } from '../ui';
|
|
5
5
|
|
|
@@ -7,8 +7,12 @@ export interface CartTotalProps extends Omit<VStackProps, 'children'> {
|
|
|
7
7
|
subtotal: Money;
|
|
8
8
|
taxLines?: Array<{ label: string; amount: Money }>;
|
|
9
9
|
discount?: Money;
|
|
10
|
+
/** The fee lines' sum in the display tax mode; a "Fees" row shows when it is not 0, as WCPOS v2. */
|
|
11
|
+
fees?: Money;
|
|
12
|
+
/** The shipping lines' sum in the display tax mode; a "Shipping" row shows when it is not 0, as WCPOS v2. */
|
|
13
|
+
shipping?: Money;
|
|
10
14
|
total: Money;
|
|
11
|
-
/** The tax is already in the subtotal
|
|
15
|
+
/** The display tax mode: true tags each tax row "Including tax" (the tax is already in the subtotal), false "Excluding tax", as WCPOS v2; absent draws no tag. */
|
|
12
16
|
taxInclusive?: boolean;
|
|
13
17
|
locale?: string;
|
|
14
18
|
className?: string;
|
|
@@ -19,7 +23,8 @@ export interface CartTotalProps extends Omit<VStackProps, 'children'> {
|
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
|
-
* Displays a cart summary: subtotal, optional discount, optional tax, and an optional Total row, in the
|
|
26
|
+
* Displays a cart summary: subtotal, optional discount, fees and shipping, optional tax, and an optional Total row, in the
|
|
27
|
+
* receipt's order.
|
|
23
28
|
*
|
|
24
29
|
* ```tsx
|
|
25
30
|
* <CartTotal subtotal={subtotal} discount={discount} taxLines={taxLines} total={total} />
|
|
@@ -29,6 +34,8 @@ export function CartTotal({
|
|
|
29
34
|
subtotal,
|
|
30
35
|
taxLines,
|
|
31
36
|
discount,
|
|
37
|
+
fees,
|
|
38
|
+
shipping,
|
|
32
39
|
total,
|
|
33
40
|
taxInclusive,
|
|
34
41
|
locale,
|
|
@@ -37,27 +44,33 @@ export function CartTotal({
|
|
|
37
44
|
showTotal = true,
|
|
38
45
|
...props
|
|
39
46
|
}: CartTotalProps) {
|
|
47
|
+
const formatMoney = useFormatMoney();
|
|
40
48
|
return (
|
|
41
49
|
<VStack space="none" className={cn('gap-1.5 px-3 py-3', className)} {...props}>
|
|
42
|
-
<
|
|
43
|
-
<Text className="text-sm text-muted-foreground">Subtotal</Text>
|
|
44
|
-
<Text className="text-sm">{formatMoney(subtotal, locale) ?? '—'}</Text>
|
|
45
|
-
</HStack>
|
|
50
|
+
<Row label="Subtotal" amount={formatMoney(subtotal, locale) ?? '—'} />
|
|
46
51
|
|
|
47
52
|
{afterSubtotal}
|
|
48
53
|
|
|
49
54
|
{discount && discount.amount > 0 && (
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
<Row label="Discount" amount={`−${formatMoney(discount, locale) ?? '—'}`} />
|
|
56
|
+
)}
|
|
57
|
+
|
|
58
|
+
{fees && fees.amount !== 0 && (
|
|
59
|
+
<Row testID="cart-total-fees" label="Fees" amount={formatMoney(fees, locale) ?? '—'} />
|
|
60
|
+
)}
|
|
61
|
+
|
|
62
|
+
{shipping && shipping.amount !== 0 && (
|
|
63
|
+
<Row testID="cart-total-shipping" label="Shipping" amount={formatMoney(shipping, locale) ?? '—'} />
|
|
54
64
|
)}
|
|
55
65
|
|
|
56
66
|
{taxLines?.map((line, index) => (
|
|
57
|
-
<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
<Row
|
|
68
|
+
key={index}
|
|
69
|
+
testID={`cart-total-tax-${index}`}
|
|
70
|
+
label={line.label}
|
|
71
|
+
beside={taxInclusive === undefined ? undefined : taxInclusive ? 'Including tax' : 'Excluding tax'}
|
|
72
|
+
amount={formatMoney(line.amount, locale) ?? '—'}
|
|
73
|
+
/>
|
|
61
74
|
))}
|
|
62
75
|
|
|
63
76
|
{showTotal && <HStack space="none" className="mt-1.5 justify-between border-t border-border pt-2">
|
|
@@ -67,3 +80,19 @@ export function CartTotal({
|
|
|
67
80
|
</VStack>
|
|
68
81
|
);
|
|
69
82
|
}
|
|
83
|
+
|
|
84
|
+
/** One muted label with its amount, as every CartTotal row but Total draws it; `beside` sits next to the label at the help size. */
|
|
85
|
+
function Row({ label, amount, testID, beside }: { label: string; amount: string; testID?: string; beside?: string }) {
|
|
86
|
+
const text = <Text className="text-sm text-muted-foreground">{label}</Text>;
|
|
87
|
+
return (
|
|
88
|
+
<HStack testID={testID} space="none" className="justify-between">
|
|
89
|
+
{beside ? (
|
|
90
|
+
<HStack space="none" className="items-baseline gap-1.5">
|
|
91
|
+
{text}
|
|
92
|
+
<Text className="text-xs text-muted-foreground">{beside}</Text>
|
|
93
|
+
</HStack>
|
|
94
|
+
) : text}
|
|
95
|
+
<Text className="text-sm">{amount}</Text>
|
|
96
|
+
</HStack>
|
|
97
|
+
);
|
|
98
|
+
}
|
package/src/cart/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { CartLine, type CartLineProps } from './cart-line';
|
|
2
|
-
export { CartColumnHeads, cartColumnIds, type CartColumnHeadsProps, type CartColumnSettings } from './cart-columns';
|
|
2
|
+
export { CartColumnHeads, cartColumnIds, type CartColumnHeadsProps, type CartColumnId, type CartColumnSettings } from './cart-columns';
|
|
3
|
+
export { CartColumnsForm, type CartColumnsFormProps } from './cart-columns-form';
|
|
3
4
|
export { CartTotal, type CartTotalProps } from './cart-total';
|
|
4
5
|
export { CartPanel, type CartPanelProps } from './cart-panel';
|
|
5
6
|
export { DiscountBadge, type DiscountBadgeProps } from './discount-badge';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { Pressable, Text, TextInput, View, type ViewProps } from 'react-native';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { useFormatMoney, useMoneyFormat, minorUnitDigits, moneyFromDecimalString, normalizeMoneyText, type Money } from '@tallyui/core';
|
|
5
5
|
import { quickTenderedAmounts } from '@tallyui/pos';
|
|
6
6
|
import { cn } from '@tallyui/theme';
|
|
7
|
+
import { moneyInputText } from '../lib/money-input';
|
|
7
8
|
|
|
8
9
|
export interface CashTenderedProps extends Omit<ViewProps, 'children'> {
|
|
9
10
|
total: Money;
|
|
@@ -33,13 +34,13 @@ export function CashTendered({
|
|
|
33
34
|
className,
|
|
34
35
|
...viewProps
|
|
35
36
|
}: CashTenderedProps) {
|
|
37
|
+
const formatMoney = useFormatMoney();
|
|
38
|
+
const format = useMoneyFormat();
|
|
36
39
|
const [internalAmount, setInternalAmount] = useState(defaultAmount ?? total);
|
|
37
40
|
const amount = controlledAmount ?? internalAmount;
|
|
38
41
|
const buttons = quickAmounts ?? defaultQuickAmounts(total);
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const decimal = (amount.amount < 0 ? '-' : '') + (digits
|
|
42
|
-
? `${amountText.slice(0, -digits)}.${amountText.slice(-digits)}` : amountText);
|
|
42
|
+
const decimal = moneyInputText(amount.amount, amount.currency, format);
|
|
43
|
+
const separator = format?.decimalSeparator || '.';
|
|
43
44
|
const [text, setText] = useState(decimal);
|
|
44
45
|
const lastTextAmount = useRef(amount);
|
|
45
46
|
|
|
@@ -82,12 +83,12 @@ export function CashTendered({
|
|
|
82
83
|
<TextInput
|
|
83
84
|
value={text}
|
|
84
85
|
onChangeText={(text) => {
|
|
85
|
-
const parsed = moneyFromDecimalString(text, total.currency);
|
|
86
|
+
const parsed = moneyFromDecimalString(normalizeMoneyText(text, format), total.currency);
|
|
86
87
|
if (parsed) {
|
|
87
88
|
setText(text);
|
|
88
89
|
lastTextAmount.current = parsed;
|
|
89
90
|
handleChange(parsed);
|
|
90
|
-
} else if (text === '' || /^\d
|
|
91
|
+
} else if (text === '' || (text.endsWith(separator) && /^\d+$/.test(text.slice(0, -separator.length)))) {
|
|
91
92
|
setText(text);
|
|
92
93
|
}
|
|
93
94
|
}}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Text, View, type ViewProps } from 'react-native';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useFormatMoney, type Money } from '@tallyui/core';
|
|
4
4
|
import { cn } from '@tallyui/theme';
|
|
5
5
|
|
|
6
6
|
export interface ChangeDisplayProps extends Omit<ViewProps, 'children'> {
|
|
@@ -10,6 +10,7 @@ export interface ChangeDisplayProps extends Omit<ViewProps, 'children'> {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function ChangeDisplay({ change, locale, className, ...viewProps }: ChangeDisplayProps) {
|
|
13
|
+
const formatMoney = useFormatMoney();
|
|
13
14
|
return (
|
|
14
15
|
<View className={cn('items-center gap-1 rounded-xl bg-muted p-4', className)} {...viewProps}>
|
|
15
16
|
<Text className="text-sm text-muted-foreground">Change Due</Text>
|
package/src/checkout/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { PaymentMethodCard, type PaymentMethodCardProps } from './payment-method-card';
|
|
2
2
|
export { OrderSummaryLine, type OrderSummaryLineProps } from './order-summary-line';
|
|
3
|
-
export { PaymentSelector, type PaymentSelectorProps, type PaymentMethod } from './payment-selector';
|
|
3
|
+
export { PaymentSelector, type PaymentSelectorProps, type PaymentMethod, type PaymentSelectorMethod } from './payment-selector';
|
|
4
4
|
export { OrderSummary, type OrderSummaryProps, type OrderSummaryPayment } from './order-summary';
|
|
5
5
|
export { ChangeDisplay, type ChangeDisplayProps } from './change-display';
|
|
6
6
|
export { CashTendered, type CashTenderedProps } from './cash-tendered';
|
|
@@ -3,15 +3,19 @@ import { cn } from '@tallyui/theme';
|
|
|
3
3
|
import { VStack, type VStackProps } from '../ui';
|
|
4
4
|
import { PaymentMethodCard } from './payment-method-card';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/** One method the selector offers. */
|
|
7
|
+
export interface PaymentSelectorMethod {
|
|
7
8
|
id: string;
|
|
8
9
|
label: string;
|
|
9
10
|
icon?: ReactNode;
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
/** @deprecated Use `PaymentSelectorMethod`; `@tallyui/pos` exports a different `PaymentMethod`. */
|
|
14
|
+
export type PaymentMethod = PaymentSelectorMethod;
|
|
15
|
+
|
|
12
16
|
export interface PaymentSelectorProps extends Omit<VStackProps, 'children'> {
|
|
13
17
|
/** Available payment methods */
|
|
14
|
-
methods:
|
|
18
|
+
methods: PaymentSelectorMethod[];
|
|
15
19
|
/** ID of the currently selected method */
|
|
16
20
|
selected: string;
|
|
17
21
|
/** Called when a method is selected */
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expectTypeOf, it } from 'vitest';
|
|
2
|
+
import type { PaymentKind } from '@tallyui/core';
|
|
3
|
+
import type {
|
|
4
|
+
OrderFilterBarProps,
|
|
5
|
+
PaymentMethod,
|
|
6
|
+
PaymentMethodKind,
|
|
7
|
+
PaymentSelectorMethod,
|
|
8
|
+
PaymentSelectorProps,
|
|
9
|
+
} from '../index';
|
|
10
|
+
|
|
11
|
+
describe('component payment types', () => {
|
|
12
|
+
it('keeps PaymentMethodKind as an alias of core PaymentKind', () => {
|
|
13
|
+
expectTypeOf<PaymentMethodKind>().toEqualTypeOf<PaymentKind>();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('keeps PaymentMethod as an alias of PaymentSelectorMethod', () => {
|
|
17
|
+
expectTypeOf<PaymentMethod>().toEqualTypeOf<PaymentSelectorMethod>();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('uses PaymentSelectorMethod for selector methods', () => {
|
|
21
|
+
expectTypeOf<PaymentSelectorProps['methods']>().toEqualTypeOf<PaymentSelectorMethod[]>();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('uses core PaymentKind for optional filter kinds', () => {
|
|
25
|
+
type PaymentOption = NonNullable<NonNullable<OrderFilterBarProps['options']>['paymentMethod']>[number];
|
|
26
|
+
expectTypeOf<PaymentOption['kind']>().toEqualTypeOf<PaymentKind | undefined>();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/** An order's billing and shipping as WCPOS v2's address rows (`components/customer/address-rows.tsx:100-140`, MIT, WCPOS):
|
|
2
|
+
* an add button until the address is present, then a row with a summary, Edit and Remove, the parts opening beneath it. */
|
|
3
|
+
import { useState, type JSX } from 'react';
|
|
4
|
+
import { View } from 'react-native';
|
|
5
|
+
import type { CustomerAddress } from '@tallyui/core';
|
|
6
|
+
import { useT } from '../i18n';
|
|
7
|
+
import { Button } from '../ui/button';
|
|
8
|
+
import { Text } from '../ui/text';
|
|
9
|
+
import { AddressFields, ShippingAddressFields, type AddressFieldsProps } from './address-fields';
|
|
10
|
+
|
|
11
|
+
export interface AddressEditorValue { billing?: CustomerAddress; shipping?: CustomerAddress }
|
|
12
|
+
|
|
13
|
+
export interface AddressEditorProps {
|
|
14
|
+
value: AddressEditorValue;
|
|
15
|
+
onChange: (next: AddressEditorValue) => void;
|
|
16
|
+
countries?: AddressFieldsProps['countries'];
|
|
17
|
+
statesFor?: AddressFieldsProps['statesFor'];
|
|
18
|
+
/** The store's country: a new address starts with it (v2 address-rows.tsx:115-119). */
|
|
19
|
+
defaultCountry?: string;
|
|
20
|
+
/** Prefix for every testID. Default 'address-editor'. */
|
|
21
|
+
testID?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const SUMMARY_PARTS = ['address1', 'address2', 'city', 'state', 'postcode', 'country'] as const;
|
|
25
|
+
|
|
26
|
+
/** The set address parts joined with ", "; with none, the name, else the company, else ''. */
|
|
27
|
+
function summary(address: CustomerAddress): string {
|
|
28
|
+
const parts = SUMMARY_PARTS.map((part) => address[part]).filter(Boolean);
|
|
29
|
+
if (parts.length) return parts.join(', ');
|
|
30
|
+
return [address.firstName, address.lastName].filter(Boolean).join(' ') || address.company || '';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function AddressRow({ id, heading, address, open, onEdit, onRemove }: {
|
|
34
|
+
id: string;
|
|
35
|
+
heading: string;
|
|
36
|
+
address: CustomerAddress;
|
|
37
|
+
open: boolean;
|
|
38
|
+
onEdit: () => void;
|
|
39
|
+
onRemove: () => void;
|
|
40
|
+
}) {
|
|
41
|
+
const t = useT();
|
|
42
|
+
const text = summary(address);
|
|
43
|
+
const verb = (name: string, copy: string, onPress: () => void, expanded?: boolean) => <Button variant="link" size="sm"
|
|
44
|
+
testID={`${id}-${name}`} onPress={onPress} aria-expanded={expanded}
|
|
45
|
+
className="h-11 px-2"><Text>{copy}</Text></Button>;
|
|
46
|
+
return <View className="gap-1">
|
|
47
|
+
<Text className="text-sm font-medium text-foreground">{heading}</Text>
|
|
48
|
+
<View className="flex-row items-center gap-1">
|
|
49
|
+
<Text testID={`${id}-summary`} numberOfLines={1} className={`flex-1 text-sm ${text ? 'text-foreground' : 'text-muted-foreground'}`}>{text}</Text>
|
|
50
|
+
{verb('edit', t('common.edit'), onEdit, open)}
|
|
51
|
+
{verb('remove', t('common.remove'), onRemove)}
|
|
52
|
+
</View>
|
|
53
|
+
</View>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** A controlled editor for an order's billing and shipping. No dialog: the app places it in its own. */
|
|
57
|
+
export function AddressEditor({ value, onChange, countries, statesFor, defaultCountry, testID = 'address-editor' }: AddressEditorProps): JSX.Element {
|
|
58
|
+
const t = useT();
|
|
59
|
+
const [open, setOpen] = useState({ billing: false, shipping: false });
|
|
60
|
+
const { billing, shipping } = value;
|
|
61
|
+
const toggle = (name: 'billing' | 'shipping') => () => setOpen((current) => ({ ...current, [name]: !current[name] }));
|
|
62
|
+
const add = (name: 'billing' | 'shipping', label: string) => <Button variant="link" size="sm" testID={`${testID}-${name}-add`}
|
|
63
|
+
onPress={() => { onChange({ ...value, [name]: defaultCountry ? { country: defaultCountry } : {} }); setOpen((current) => ({ ...current, [name]: true })); }}
|
|
64
|
+
className="h-11 self-start px-0"><Text>{t('common.add_value', { label })}</Text></Button>;
|
|
65
|
+
const remove = (name: 'billing' | 'shipping') => () => {
|
|
66
|
+
onChange({ ...value, [name]: undefined });
|
|
67
|
+
setOpen((current) => ({ ...current, [name]: false }));
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return <View className="gap-4">
|
|
71
|
+
{billing ? <View className="gap-3">
|
|
72
|
+
<AddressRow id={`${testID}-billing`} heading={t('common.billing_address')} address={billing} open={open.billing}
|
|
73
|
+
onEdit={toggle('billing')} onRemove={remove('billing')} />
|
|
74
|
+
{open.billing && <AddressFields value={billing} showEmail onChange={(next) => onChange({ ...value, billing: next })}
|
|
75
|
+
countries={countries} statesFor={statesFor} testID={`${testID}-billing`} />}
|
|
76
|
+
</View> : add('billing', t('common.billing_address'))}
|
|
77
|
+
{/* Not re-keyed: ShippingAddressFields reads its link once, at mount (address-fields.tsx). */}
|
|
78
|
+
{billing ? <ShippingAddressFields billing={billing} value={shipping} onChange={(next) => onChange({ ...value, shipping: next })}
|
|
79
|
+
countries={countries} statesFor={statesFor} testID={`${testID}-shipping`} />
|
|
80
|
+
: shipping ? <View className="gap-3">
|
|
81
|
+
<AddressRow id={`${testID}-shipping`} heading={t('common.shipping_address')} address={shipping} open={open.shipping}
|
|
82
|
+
onEdit={toggle('shipping')} onRemove={remove('shipping')} />
|
|
83
|
+
{open.shipping && <AddressFields value={shipping} onChange={(next) => onChange({ ...value, shipping: next })}
|
|
84
|
+
countries={countries} statesFor={statesFor} testID={`${testID}-shipping`} />}
|
|
85
|
+
</View> : add('shipping', t('common.shipping_address'))}
|
|
86
|
+
</View>;
|
|
87
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/** A CustomerAddress's parts, and shipping linked to billing. Ported from WCPOS v2's `components/customer/address-rows.tsx` (MIT, WCPOS). */
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import type { CustomerAddress } from '@tallyui/core';
|
|
5
|
+
import { useT } from '../i18n';
|
|
6
|
+
import { Input } from '../ui/input';
|
|
7
|
+
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, ComboboxTrigger } from '../ui/combobox';
|
|
8
|
+
import { Button } from '../ui/button';
|
|
9
|
+
import { Text } from '../ui/text';
|
|
10
|
+
import { labelOf, type FilterOption } from '../filter/filter-pills';
|
|
11
|
+
type Part = keyof CustomerAddress;
|
|
12
|
+
// v2 SHIPPING_PARTS (address-rows.tsx:26, ADDRESS_PARTS :17-24); with showEmail, email follows lastName as in v2's BILLING_PARTS (:28).
|
|
13
|
+
const PARTS: readonly Part[] = ['firstName', 'lastName', 'company', 'phone', 'address1', 'address2', 'city', 'postcode', 'country', 'state'];
|
|
14
|
+
const LABELS: Record<Part, string> = { firstName: 'common.first_name', lastName: 'common.last_name', email: 'common.email',
|
|
15
|
+
company: 'common.company', phone: 'common.phone', address1: 'common.address_1', address2: 'common.address_2', city: 'common.city',
|
|
16
|
+
postcode: 'common.postcode', country: 'common.country', state: 'common.state' };
|
|
17
|
+
const KEYBOARD: Partial<Record<Part, 'email-address' | 'phone-pad'>> = { email: 'email-address', phone: 'phone-pad' };
|
|
18
|
+
|
|
19
|
+
export interface AddressFieldsProps {
|
|
20
|
+
value: CustomerAddress;
|
|
21
|
+
onChange: (next: CustomerAddress) => void;
|
|
22
|
+
/** Country options (ISO alpha-2 value, display label). Absent: Country is a text input. */
|
|
23
|
+
countries?: readonly { value: string; label: string }[];
|
|
24
|
+
/** A country's state options. Absent, or undefined/empty for that country: State is a text input. */
|
|
25
|
+
statesFor?: (country: string) => readonly { value: string; label: string }[] | undefined;
|
|
26
|
+
/** Show the Email part (billing only; v2's shipping has no email, address.tsx:30-33). Default false. */
|
|
27
|
+
showEmail?: boolean;
|
|
28
|
+
/** Prefix for every testID. Default 'address-fields'. */
|
|
29
|
+
testID?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Every part is optional (v2 address.tsx:11-28): an emptied part leaves the address, never stays as '' or undefined. */
|
|
33
|
+
function put(address: CustomerAddress, part: Part, text: string): CustomerAddress {
|
|
34
|
+
const { [part]: _emptied, ...rest } = address;
|
|
35
|
+
return text === '' ? rest : { ...address, [part]: text };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A new country drops a state its list does not have; a country without a list, or an emptied one, keeps it. */
|
|
39
|
+
function withCountry(address: CustomerAddress, next: string, statesFor: AddressFieldsProps['statesFor']): CustomerAddress {
|
|
40
|
+
const list = next ? statesFor?.(next) : undefined;
|
|
41
|
+
const stale = !!list?.length && !!address.state && !list.some((option) => option.value === address.state);
|
|
42
|
+
return put(stale ? put(address, 'state', '') : address, 'country', next);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** ui/combobox as a form field, as sale/discount-form.tsx composes it; ComboboxPill is a chip, not a field. */
|
|
46
|
+
function PartPicker({ id, label, placeholder, value, options, onPick }: {
|
|
47
|
+
id: string;
|
|
48
|
+
label: string;
|
|
49
|
+
placeholder: string;
|
|
50
|
+
value?: string;
|
|
51
|
+
options: readonly FilterOption[];
|
|
52
|
+
onPick: (text: string) => void;
|
|
53
|
+
}) {
|
|
54
|
+
const [search, setSearch] = useState('');
|
|
55
|
+
const needle = search.trim().toLowerCase();
|
|
56
|
+
const shown = needle ? options.filter((option) => option.label.toLowerCase().includes(needle)) : options;
|
|
57
|
+
const picked = value === undefined ? undefined : { value, label: labelOf([...options], value) };
|
|
58
|
+
return <Combobox value={picked} onValueChange={(next) => onPick(next?.value ?? '')} searchValue={search} onSearchValueChange={setSearch}>
|
|
59
|
+
<ComboboxTrigger testID={id}><Text className={picked ? 'text-foreground' : 'text-muted-foreground'}>{picked?.label ?? placeholder}</Text></ComboboxTrigger>
|
|
60
|
+
<ComboboxContent>
|
|
61
|
+
<View className="border-b border-border px-2 py-1.5"><ComboboxInput testID={`${id}-search`} accessibilityLabel={label} placeholder={placeholder} /></View>
|
|
62
|
+
<ComboboxList>
|
|
63
|
+
{shown.map((option) => <ComboboxItem key={option.value} testID={`${id}-${option.value}`} value={option.value} label={option.label}>
|
|
64
|
+
<Text className="text-sm text-popover-foreground">{option.label}</Text></ComboboxItem>)}
|
|
65
|
+
{shown.length ? null : <ComboboxEmpty />}
|
|
66
|
+
</ComboboxList>
|
|
67
|
+
</ComboboxContent>
|
|
68
|
+
</Combobox>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A controlled CustomerAddress form, one column. Country and State are pickers when the app passes their options. */
|
|
72
|
+
export function AddressFields({ value, onChange, countries, statesFor, showEmail = false, testID = 'address-fields' }: AddressFieldsProps) {
|
|
73
|
+
const t = useT();
|
|
74
|
+
const states = value.country ? statesFor?.(value.country) : undefined;
|
|
75
|
+
const parts: readonly Part[] = showEmail ? [...PARTS.slice(0, 2), 'email', ...PARTS.slice(2)] : PARTS;
|
|
76
|
+
return <View className="gap-3">{parts.map((part) => {
|
|
77
|
+
const label = t(LABELS[part]);
|
|
78
|
+
const placeholder = t('common.add_value', { label });
|
|
79
|
+
const write = (text: string) => onChange(part === 'country' ? withCountry(value, text, statesFor) : put(value, part, text));
|
|
80
|
+
const options = part === 'country' ? countries : part === 'state' && states?.length ? states : undefined;
|
|
81
|
+
return <View key={part} className="gap-1">
|
|
82
|
+
<Text className="text-xs font-medium text-muted-foreground">{label}</Text>
|
|
83
|
+
{options ? <PartPicker id={`${testID}-${part}`} label={label} placeholder={placeholder} value={value[part]} options={options} onPick={write} />
|
|
84
|
+
: <Input><Input.Field testID={`${testID}-${part}`} accessibilityLabel={label} value={value[part] ?? ''} placeholder={placeholder}
|
|
85
|
+
keyboardType={KEYBOARD[part]} onChangeText={write} /></Input>}
|
|
86
|
+
</View>;
|
|
87
|
+
})}</View>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface ShippingAddressFieldsProps {
|
|
91
|
+
billing: CustomerAddress | undefined;
|
|
92
|
+
value: CustomerAddress | undefined;
|
|
93
|
+
/** `undefined` is "Same as billing": shipping folds back to billing. */
|
|
94
|
+
onChange: (next: CustomerAddress | undefined) => void;
|
|
95
|
+
countries?: AddressFieldsProps['countries'];
|
|
96
|
+
statesFor?: AddressFieldsProps['statesFor'];
|
|
97
|
+
/** Default 'shipping-address'. */
|
|
98
|
+
testID?: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** v2 shipsToBilling (address-rows.tsx:41-48): no part set, or billing's copy; email is not compared, absent reads as ''. */
|
|
102
|
+
const sameAsBilling = (value: CustomerAddress | undefined, billing: CustomerAddress | undefined) =>
|
|
103
|
+
!PARTS.some((part) => value?.[part]) || PARTS.every((part) => (value?.[part] ?? '') === (billing?.[part] ?? ''));
|
|
104
|
+
|
|
105
|
+
/** Shipping reads "Same as billing" until the cashier uses a different address. The link is read once, at mount, so a copy of
|
|
106
|
+
* billing stays open: key the component by order to read it again, as v2 keys its form by the order's uuid (pos/cart/customer.tsx:59). */
|
|
107
|
+
export function ShippingAddressFields({ billing, value, onChange, countries, statesFor, testID = 'shipping-address' }: ShippingAddressFieldsProps) {
|
|
108
|
+
const t = useT();
|
|
109
|
+
const [linked, setLinked] = useState(() => sameAsBilling(value, billing));
|
|
110
|
+
const { email: _email, ...own } = billing ?? {}; // v2 asShipping: shipping has no email.
|
|
111
|
+
const link = (on: boolean) => { onChange(on ? undefined : own); setLinked(on); };
|
|
112
|
+
const button = (id: string, copy: string, on: boolean) => <Button variant="link" size="sm" testID={`${testID}-${id}`}
|
|
113
|
+
onPress={() => link(on)} className="h-11 self-start px-0"><Text>{copy}</Text></Button>;
|
|
114
|
+
return <View className="gap-3">
|
|
115
|
+
<Text className="text-sm font-medium text-foreground">{t('common.shipping_address')}</Text>
|
|
116
|
+
{linked ? <Text testID={`${testID}-linked`} className="text-sm text-muted-foreground">{t('pos_cart.same_as_billing')}</Text>
|
|
117
|
+
: <AddressFields value={value ?? {}} onChange={onChange} countries={countries} statesFor={statesFor} testID={`${testID}-fields`} />}
|
|
118
|
+
{linked ? button('different', t('pos_cart.use_different_address'), false) : button('same', t('pos_cart.same_as_billing'), true)}
|
|
119
|
+
</View>;
|
|
120
|
+
}
|