@tallyui/components 3.18.0 → 3.20.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 +473 -37
- package/dist/index.js +3656 -1905
- package/package.json +9 -9
- package/src/cart/cart-columns.tsx +42 -4
- package/src/cart/cart-foot.tsx +2 -2
- package/src/cart/cart-line.tsx +42 -18
- package/src/cart/cart-note-input.tsx +10 -2
- package/src/cart/cart-panel.tsx +4 -1
- package/src/cart/cart-total.tsx +8 -5
- package/src/cart/index.ts +1 -1
- package/src/customer/customer-select.tsx +21 -3
- package/src/index.ts +27 -0
- package/src/input/search-input.tsx +1 -1
- package/src/order/index.ts +1 -0
- package/src/order/order-filter-bar.tsx +247 -0
- package/src/product/camera-scan-button.tsx +28 -0
- package/src/product/camera-scanner-panel.tsx +156 -0
- package/src/product/index.ts +5 -0
- package/src/product/product-table.tsx +14 -4
- package/src/product/scanner-viewfinder.tsx +76 -0
- package/src/product/variation-picker.tsx +128 -0
- package/src/register/register-bar.tsx +2 -6
- package/src/register/register-panel.tsx +47 -24
- package/src/register/register-side-sheet.tsx +175 -0
- package/src/reports/date-range-menu.tsx +109 -0
- package/src/reports/filters-bar.tsx +11 -21
- package/src/reports/hero.tsx +8 -4
- package/src/reports/index.ts +1 -0
- package/src/sale/cart.tsx +49 -10
- package/src/sale/catalogue.tsx +98 -21
- package/src/sale/charge-form.tsx +12 -6
- package/src/sale/customer-display-pairing.tsx +111 -0
- package/src/sale/index.ts +1 -0
- package/src/sale/line-popover.tsx +17 -1
- package/src/sale/order-reference.ts +1 -1
- package/src/sale/orders-list.tsx +1 -1
- package/src/settings/customer-display-settings.tsx +163 -0
- package/src/settings/index.ts +2 -0
- package/src/settings/tax-calculation-settings.tsx +97 -0
- package/src/shell/nav-drawer.tsx +1 -1
- package/src/tax/index.ts +1 -0
- package/src/tax/tax-based-on.tsx +196 -0
- package/src/ui/alert-dialog/index.tsx +1 -1
- package/src/ui/avatar/index.tsx +22 -4
- package/src/ui/button/index.tsx +1 -1
- package/src/ui/calendar/index.tsx +119 -0
- package/src/ui/calendar/month-grid.ts +40 -0
- package/src/ui/combobox/index.tsx +1 -1
- package/src/ui/dialog/index.tsx +21 -9
- package/src/ui/icon/chevron-down-icon.tsx +4 -0
- package/src/ui/icon/grip-icon.tsx +10 -0
- package/src/ui/icon/scan-icon.tsx +13 -0
- package/src/ui/icon/shopping-cart-icon.tsx +10 -0
- package/src/ui/icon-button/index.tsx +1 -1
- package/src/ui/index.ts +11 -1
- package/src/ui/input/index.tsx +1 -1
- package/src/ui/select/index.tsx +22 -4
- package/src/ui/slider/index.tsx +2 -2
- package/src/ui/switch/index.tsx +19 -8
- package/src/ui/textarea/index.tsx +1 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings › Customer display (ADR-085 U5, d4, d5, d11, d13): the till's paired displays, pairing one with a code and
|
|
3
|
+
* its "wants to pair" check (#705), and forgetting one. Props only; the app passes `useTillPairing(pairing)` and
|
|
4
|
+
* `useTillDisplays(service)` and wires the callbacks to the same `TillPairing`.
|
|
5
|
+
*/
|
|
6
|
+
import { useRef, type JSX } from 'react';
|
|
7
|
+
import { View } from 'react-native';
|
|
8
|
+
import type { PairingError, PairingPhase, TillDisplayEntry, TillDisplayStatus } from '@tallyui/pos';
|
|
9
|
+
import { cn } from '@tallyui/theme';
|
|
10
|
+
import {
|
|
11
|
+
AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter,
|
|
12
|
+
AlertDialogTitle, AlertDialogTrigger,
|
|
13
|
+
} from '../ui/alert-dialog';
|
|
14
|
+
import { Button } from '../ui/button';
|
|
15
|
+
import { Loader } from '../ui/loader';
|
|
16
|
+
import { Text } from '../ui/text';
|
|
17
|
+
import { SettingsGroup } from './settings-group';
|
|
18
|
+
|
|
19
|
+
export interface CustomerDisplaySettingsProps {
|
|
20
|
+
/** `useTillPairing(pairing)`. */
|
|
21
|
+
pairing: { phase: PairingPhase; forgetError: PairingError | null };
|
|
22
|
+
/** `useTillDisplays(service)`. */
|
|
23
|
+
displays: { status: TillDisplayStatus; displays: readonly TillDisplayEntry[] };
|
|
24
|
+
onStartPairing: () => void;
|
|
25
|
+
onConfirm: (claimId: string) => void;
|
|
26
|
+
onDecline: (claimId: string) => void;
|
|
27
|
+
onCancelPairing: () => void;
|
|
28
|
+
onForget: (displayId: string) => void;
|
|
29
|
+
/** Formats the code's expiry; default: the device's locale, hours and minutes. */
|
|
30
|
+
formatTime?: (iso: string) => string;
|
|
31
|
+
className?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const PAIRING_ERRORS: Record<PairingError, string> = {
|
|
35
|
+
forbidden: 'Sign in as a cashier who can pair customer displays.',
|
|
36
|
+
limit: 'Too many pairing attempts. Try again in a few minutes.',
|
|
37
|
+
expired: 'The code expired. Start again for a new code.',
|
|
38
|
+
not_found: 'That display is no longer waiting. Ask it to enter the code again.',
|
|
39
|
+
network: "Can't reach the store. Check the connection and try again.",
|
|
40
|
+
server: "The store couldn't finish that. Try again.",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const STATUS_LINES: Partial<Record<TillDisplayStatus, string>> = {
|
|
44
|
+
offline: "Can't reach the store. Open displays keep showing the sale; new connections wait.",
|
|
45
|
+
paused: 'Sign in as a cashier who can pair customer displays.',
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type CodePhase = Extract<PairingPhase, { phase: 'code' }>;
|
|
49
|
+
|
|
50
|
+
const defaultFormatTime = (iso: string) => new Date(iso).toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' });
|
|
51
|
+
|
|
52
|
+
function stateOf({ display, link }: TillDisplayEntry): string {
|
|
53
|
+
if (link === 'open') return 'Connected';
|
|
54
|
+
if (link === 'connecting') return 'Connecting…';
|
|
55
|
+
return display.connected ? 'Waiting for the display' : 'Offline';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function DisplayRow({ entry, onForget }: { entry: TillDisplayEntry; onForget: (displayId: string) => void }): JSX.Element {
|
|
59
|
+
const { displayId, name } = entry.display;
|
|
60
|
+
return (
|
|
61
|
+
<View testID={`display-${displayId}`} className="flex-row items-center gap-3 px-4 py-3">
|
|
62
|
+
<View className="flex-1 gap-0.5">
|
|
63
|
+
<Text className="text-sm font-medium text-foreground">{name}</Text>
|
|
64
|
+
<Text testID={`display-state-${displayId}`} className="text-xs text-muted-foreground">{stateOf(entry)}</Text>
|
|
65
|
+
</View>
|
|
66
|
+
<AlertDialog>
|
|
67
|
+
<AlertDialogTrigger asChild>
|
|
68
|
+
<Button testID={`forget-${displayId}`} variant="outline" className="min-h-11"><Text>Forget</Text></Button>
|
|
69
|
+
</AlertDialogTrigger>
|
|
70
|
+
<AlertDialogContent>
|
|
71
|
+
<AlertDialogTitle>{`Forget ${name}?`}</AlertDialogTitle>
|
|
72
|
+
<AlertDialogDescription>It will need a new code to pair again.</AlertDialogDescription>
|
|
73
|
+
<AlertDialogFooter>
|
|
74
|
+
<AlertDialogCancel asChild>
|
|
75
|
+
<Button testID={`forget-cancel-${displayId}`} variant="outline" className="min-h-11"><Text>Cancel</Text></Button>
|
|
76
|
+
</AlertDialogCancel>
|
|
77
|
+
<AlertDialogAction asChild>
|
|
78
|
+
<Button testID={`forget-confirm-${displayId}`} variant="destructive" className="min-h-11" onPress={() => onForget(displayId)}>
|
|
79
|
+
<Text>Forget</Text>
|
|
80
|
+
</Button>
|
|
81
|
+
</AlertDialogAction>
|
|
82
|
+
</AlertDialogFooter>
|
|
83
|
+
</AlertDialogContent>
|
|
84
|
+
</AlertDialog>
|
|
85
|
+
</View>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function CustomerDisplaySettings({
|
|
90
|
+
pairing, displays, onStartPairing, onConfirm, onDecline, onCancelPairing, onForget, formatTime = defaultFormatTime, className,
|
|
91
|
+
}: CustomerDisplaySettingsProps): JSX.Element {
|
|
92
|
+
const { phase, forgetError } = pairing;
|
|
93
|
+
// `confirming` carries only the claim id, so the code and its claims stay on screen from the last `code` phase.
|
|
94
|
+
const lastCode = useRef<CodePhase | null>(null);
|
|
95
|
+
if (phase.phase === 'code') lastCode.current = phase;
|
|
96
|
+
else if (phase.phase !== 'confirming') lastCode.current = null;
|
|
97
|
+
const shown = phase.phase === 'code' ? phase : phase.phase === 'confirming' ? lastCode.current : null;
|
|
98
|
+
const busy = phase.phase === 'confirming';
|
|
99
|
+
const statusLine = STATUS_LINES[displays.status];
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<View className={cn('gap-6', className)}>
|
|
103
|
+
{statusLine && <Text testID="customer-display-status" className="px-4 text-sm text-muted-foreground">{statusLine}</Text>}
|
|
104
|
+
|
|
105
|
+
<SettingsGroup title="Paired displays">
|
|
106
|
+
{displays.displays.length === 0
|
|
107
|
+
? <Text className="px-4 py-3 text-sm text-muted-foreground">No displays paired yet.</Text>
|
|
108
|
+
: displays.displays.map((entry) => <DisplayRow key={entry.display.displayId} entry={entry} onForget={onForget} />)}
|
|
109
|
+
{forgetError && (
|
|
110
|
+
<Text testID="forget-error" className="px-4 py-3 text-sm text-destructive">{PAIRING_ERRORS[forgetError]}</Text>
|
|
111
|
+
)}
|
|
112
|
+
</SettingsGroup>
|
|
113
|
+
|
|
114
|
+
<SettingsGroup title="Pair a display">
|
|
115
|
+
{shown ? (
|
|
116
|
+
<View className="gap-4 p-4">
|
|
117
|
+
<View className="items-center gap-1">
|
|
118
|
+
<Text testID="pairing-code" className="text-4xl font-bold tabular-nums text-foreground">{shown.code}</Text>
|
|
119
|
+
<Text className="text-center text-sm text-muted-foreground">
|
|
120
|
+
{`Enter this code on the display. Expires at ${formatTime(shown.expiresAt)}.`}
|
|
121
|
+
</Text>
|
|
122
|
+
</View>
|
|
123
|
+
{shown.claims.length === 0 ? (
|
|
124
|
+
<Text className="text-center text-sm text-muted-foreground">Waiting for a display…</Text>
|
|
125
|
+
) : (
|
|
126
|
+
<View className="gap-2">
|
|
127
|
+
<Text className="text-sm text-muted-foreground">Confirm only if the display shows the same check code.</Text>
|
|
128
|
+
{shown.claims.map(({ claimId, displayName, checkCode }) => (
|
|
129
|
+
<View key={claimId} testID={`claim-${claimId}`} className="gap-3 rounded-md border border-border p-3 sm:flex-row sm:items-center">
|
|
130
|
+
<View className="flex-1 gap-1">
|
|
131
|
+
<Text className="text-sm text-foreground">{`${displayName} wants to pair. Check code`}</Text>
|
|
132
|
+
<Text testID={`check-${claimId}`} className="text-3xl font-bold tabular-nums text-foreground">{checkCode}</Text>
|
|
133
|
+
</View>
|
|
134
|
+
<View className="flex-row gap-2">
|
|
135
|
+
<Button testID={`decline-${claimId}`} variant="outline" className="min-h-11" disabled={busy} onPress={() => onDecline(claimId)}>
|
|
136
|
+
<Text>Decline</Text>
|
|
137
|
+
</Button>
|
|
138
|
+
<Button testID={`confirm-${claimId}`} className="min-h-11" disabled={busy} onPress={() => onConfirm(claimId)}>
|
|
139
|
+
{phase.phase === 'confirming' && phase.claimId === claimId ?<Loader size="sm" /> : null}
|
|
140
|
+
<Text>Confirm</Text>
|
|
141
|
+
</Button>
|
|
142
|
+
</View>
|
|
143
|
+
</View>
|
|
144
|
+
))}
|
|
145
|
+
</View>
|
|
146
|
+
)}
|
|
147
|
+
<Button testID="pairing-cancel" variant="outline" className="min-h-11" onPress={onCancelPairing}><Text>Cancel</Text></Button>
|
|
148
|
+
</View>
|
|
149
|
+
) : (
|
|
150
|
+
<View className="gap-3 p-4">
|
|
151
|
+
{phase.phase === 'idle' && phase.error && (
|
|
152
|
+
<Text testID="pairing-error" className="text-sm text-destructive">{PAIRING_ERRORS[phase.error]}</Text>
|
|
153
|
+
)}
|
|
154
|
+
<Button testID="pairing-start" className="min-h-11" disabled={phase.phase !== 'idle'} onPress={onStartPairing}>
|
|
155
|
+
{phase.phase === 'idle' ? null : <Loader size="sm" />}
|
|
156
|
+
<Text>Pair a display</Text>
|
|
157
|
+
</Button>
|
|
158
|
+
</View>
|
|
159
|
+
)}
|
|
160
|
+
</SettingsGroup>
|
|
161
|
+
</View>
|
|
162
|
+
);
|
|
163
|
+
}
|
package/src/settings/index.ts
CHANGED
|
@@ -2,3 +2,5 @@ export { SettingsRow, type SettingsRowProps } from './settings-row';
|
|
|
2
2
|
export { SettingsGroup, type SettingsGroupProps } from './settings-group';
|
|
3
3
|
export { ConnectorStatus, type ConnectorStatusProps, type ConnectionStatus } from './connector-status';
|
|
4
4
|
export { DisplaySettings, type DisplaySettingsProps } from './display-settings';
|
|
5
|
+
export { TaxCalculationSettings, type TaxCalculationSettingsProps } from './tax-calculation-settings';
|
|
6
|
+
export { CustomerDisplaySettings, type CustomerDisplaySettingsProps } from './customer-display-settings';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Settings › Tax › Calculation: "Calculate tax based on", and read-only rows for the settings that live in WooCommerce.
|
|
3
|
+
* Port of WCPOS v2 `packages/core/src/screens/main/settings/tax.tsx:139-183` and `option-lists.ts` `taxBasedOn`;
|
|
4
|
+
* the labels are v2's English strings from core.json. StoreSettings has no `calcTaxes`, so v2's "Enable taxes" row is left out.
|
|
5
|
+
*/
|
|
6
|
+
import { View } from 'react-native';
|
|
7
|
+
import type { woocommerceTax } from '@tallyui/core';
|
|
8
|
+
import { cn } from '@tallyui/theme';
|
|
9
|
+
import { Button } from '../ui/button';
|
|
10
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select';
|
|
11
|
+
import { Text } from '../ui/text';
|
|
12
|
+
import { SettingsGroup } from './settings-group';
|
|
13
|
+
import { SettingsRow } from './settings-row';
|
|
14
|
+
|
|
15
|
+
type TaxBasedOn = woocommerceTax.TaxBasedOn;
|
|
16
|
+
|
|
17
|
+
export interface TaxCalculationSettingsProps {
|
|
18
|
+
taxBasedOn: TaxBasedOn;
|
|
19
|
+
onTaxBasedOnChange?: (value: TaxBasedOn) => void;
|
|
20
|
+
pricesIncludeTax?: boolean;
|
|
21
|
+
shippingTaxClass?: string;
|
|
22
|
+
taxRoundAtSubtotal?: boolean;
|
|
23
|
+
/** "Set in WooCommerce": a link when given, plain text otherwise. */
|
|
24
|
+
onOpenStoreTaxSettings?: () => void;
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const OPTIONS: { value: TaxBasedOn; label: string }[] = [
|
|
29
|
+
{ value: 'shipping', label: 'Customer shipping address' },
|
|
30
|
+
{ value: 'billing', label: 'Customer billing address' },
|
|
31
|
+
{ value: 'base', label: 'Shop base address' },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
/** The class name rule of @tallyui/pos `taxDerivation` (re-implemented here: components import only types from pos). */
|
|
35
|
+
function classLabel(slug: string): string {
|
|
36
|
+
if (slug === '' || slug === 'standard') return 'Standard';
|
|
37
|
+
const words = slug.replace(/-/g, ' ');
|
|
38
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const yesNo = (value: boolean) => (value ? 'Yes' : 'No');
|
|
42
|
+
|
|
43
|
+
/** A SettingsRow whose description, "Set in WooCommerce", is a link when `onOpen` is given. */
|
|
44
|
+
function LockedRow({ id, label, value, onOpen }: { id: string; label: string; value: string; onOpen?: () => void }) {
|
|
45
|
+
return (
|
|
46
|
+
<View testID={`settings-tax-locked-${id}`} className="flex-row items-center gap-3 px-4 py-3">
|
|
47
|
+
<View className="flex-1 gap-0.5">
|
|
48
|
+
<Text className="text-sm font-medium text-foreground">{label}</Text>
|
|
49
|
+
{onOpen ? (
|
|
50
|
+
<Button variant="link" size="sm" role="link" onPress={onOpen} className="h-11 self-start px-0">
|
|
51
|
+
<Text className="text-xs">Set in WooCommerce</Text>
|
|
52
|
+
</Button>
|
|
53
|
+
) : <Text className="text-xs text-muted-foreground">Set in WooCommerce</Text>}
|
|
54
|
+
</View>
|
|
55
|
+
<Text testID={`settings-tax-locked-${id}-value`} className="text-sm text-foreground">{value}</Text>
|
|
56
|
+
</View>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function TaxCalculationSettings({ taxBasedOn, onTaxBasedOnChange, pricesIncludeTax, shippingTaxClass,
|
|
61
|
+
taxRoundAtSubtotal, onOpenStoreTaxSettings, className }: TaxCalculationSettingsProps) {
|
|
62
|
+
const value = OPTIONS.find((option) => option.value === taxBasedOn);
|
|
63
|
+
const disabled = !onTaxBasedOnChange;
|
|
64
|
+
return (
|
|
65
|
+
<SettingsGroup title="Calculation" className={className}>
|
|
66
|
+
<SettingsRow
|
|
67
|
+
label="Calculate tax based on"
|
|
68
|
+
action={(
|
|
69
|
+
<Select value={value} disabled={disabled}
|
|
70
|
+
onValueChange={(option) => { if (option && option.value !== taxBasedOn) onTaxBasedOnChange?.(option.value as TaxBasedOn); }}>
|
|
71
|
+
<SelectTrigger testID="settings-tax-based-on" accessibilityLabel="Calculate tax based on"
|
|
72
|
+
className={cn('h-11 w-56 gap-2', disabled && 'opacity-50')}>
|
|
73
|
+
<SelectValue placeholder="Select tax based on" className="shrink text-sm text-foreground" numberOfLines={1} />
|
|
74
|
+
<Text className="text-xs text-muted-foreground">▼</Text>
|
|
75
|
+
</SelectTrigger>
|
|
76
|
+
<SelectContent className="w-56">
|
|
77
|
+
{OPTIONS.map((option) => (
|
|
78
|
+
<SelectItem key={option.value} value={option.value} label={option.label}
|
|
79
|
+
testID={`settings-tax-based-on-${option.value}`} className="min-h-11">
|
|
80
|
+
<Text className="text-sm">{option.label}</Text>
|
|
81
|
+
</SelectItem>
|
|
82
|
+
))}
|
|
83
|
+
</SelectContent>
|
|
84
|
+
</Select>
|
|
85
|
+
)}
|
|
86
|
+
/>
|
|
87
|
+
{pricesIncludeTax === undefined ? null
|
|
88
|
+
: <LockedRow id="prices_include_tax" label="Prices entered with tax" value={yesNo(pricesIncludeTax)} onOpen={onOpenStoreTaxSettings} />}
|
|
89
|
+
{shippingTaxClass === undefined ? null : (
|
|
90
|
+
<LockedRow id="shipping_tax_class" label="Shipping tax class" onOpen={onOpenStoreTaxSettings}
|
|
91
|
+
value={shippingTaxClass === 'inherit' ? 'Based on cart items' : classLabel(shippingTaxClass)} />
|
|
92
|
+
)}
|
|
93
|
+
{taxRoundAtSubtotal === undefined ? null
|
|
94
|
+
: <LockedRow id="tax_round_at_subtotal" label="Round tax at subtotal level" value={yesNo(taxRoundAtSubtotal)} onOpen={onOpenStoreTaxSettings} />}
|
|
95
|
+
</SettingsGroup>
|
|
96
|
+
);
|
|
97
|
+
}
|
package/src/shell/nav-drawer.tsx
CHANGED
|
@@ -106,7 +106,7 @@ export function NavDrawer({ open, onOpenChange, items, activeId, onNavigate, hea
|
|
|
106
106
|
<Pressable
|
|
107
107
|
testID={`${testID}-backdrop`}
|
|
108
108
|
accessibilityLabel="Close menu"
|
|
109
|
-
className="flex-1 bg-
|
|
109
|
+
className="flex-1 bg-scrim"
|
|
110
110
|
onPress={close}
|
|
111
111
|
/>
|
|
112
112
|
</Animated.View>
|
package/src/tax/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TaxBasedOn, type TaxBasedOnProps } from './tax-based-on';
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// Port of WCPOS v2 (monorepo next) packages/core/src/components/product/tax-based-on/ (index.tsx and
|
|
2
|
+
// display-current-tax-rates.tsx) and packages/components/src/derivation/; MIT, WCPOS. The copy is v2's core.json English.
|
|
3
|
+
import { useState, type ReactNode } from 'react';
|
|
4
|
+
import { ScrollView, StyleSheet, View } from 'react-native';
|
|
5
|
+
import type { woocommerceTax } from '@tallyui/core';
|
|
6
|
+
import type { TaxDerivation, TaxRateWhy } from '@tallyui/pos';
|
|
7
|
+
import { Popover } from '@tallyui/primitives';
|
|
8
|
+
import { cn } from '@tallyui/theme';
|
|
9
|
+
import { Button } from '../ui/button';
|
|
10
|
+
import { XIcon } from '../ui/icon/x-icon';
|
|
11
|
+
import { Text } from '../ui/text';
|
|
12
|
+
|
|
13
|
+
type TaxBasedOn = woocommerceTax.TaxBasedOn;
|
|
14
|
+
type StepState = 'fact' | 'result' | 'failed' | 'quiet';
|
|
15
|
+
|
|
16
|
+
export interface TaxBasedOnProps {
|
|
17
|
+
derivation: TaxDerivation;
|
|
18
|
+
/** "Change in Settings › Tax"; the link shows only when given. */
|
|
19
|
+
onChangeSetting?: () => void;
|
|
20
|
+
/** "View all tax rates"; the footer shows only when given. */
|
|
21
|
+
onViewAllRates?: () => void;
|
|
22
|
+
/** Country code to display name; defaults to Intl.DisplayNames('en', region) as "{Name} ({CODE})", the code alone if Intl lacks it. */
|
|
23
|
+
countryName?: (code: string) => string;
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const SETTING_LABEL: Record<TaxBasedOn, string> = {
|
|
28
|
+
shipping: 'Customer shipping address', billing: 'Customer billing address', base: 'Shop base address',
|
|
29
|
+
};
|
|
30
|
+
const VALUE_LABEL: Record<TaxBasedOn, string> = { ...SETTING_LABEL, base: 'Shop base' };
|
|
31
|
+
const FALLBACK_NOTE: Record<NonNullable<TaxDerivation['fallback']>, string> = {
|
|
32
|
+
'shipping-to-billing': 'This order has no shipping address, so tax uses the billing address',
|
|
33
|
+
'shipping-to-shop': 'This order has no shipping or billing address, so tax uses the shop address',
|
|
34
|
+
'billing-to-shop': 'This order has no billing address, so tax uses the shop address',
|
|
35
|
+
};
|
|
36
|
+
const BEAD: Record<StepState, string> = {
|
|
37
|
+
fact: 'bg-muted-foreground', result: 'bg-foreground', failed: 'bg-destructive', quiet: 'border-2 border-border',
|
|
38
|
+
};
|
|
39
|
+
/** v2's TABLE_HEAD_TEXT, as cart-columns' heads draw it. */
|
|
40
|
+
const CAPTION = 'text-xs font-medium uppercase tracking-wide text-muted-foreground';
|
|
41
|
+
const FIELDS = [['country', 'Country'], ['state', 'State'], ['city', 'City'], ['postcode', 'Postcode']] as const;
|
|
42
|
+
|
|
43
|
+
function intlCountryName(code: string): string {
|
|
44
|
+
try {
|
|
45
|
+
const name = new Intl.DisplayNames(['en'], { type: 'region' }).of(code.toUpperCase());
|
|
46
|
+
return name && name !== code.toUpperCase() ? `${name} (${code.toUpperCase()})` : code;
|
|
47
|
+
} catch {
|
|
48
|
+
return code;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function whyText(why: TaxRateWhy, countryName: (code: string) => string): string {
|
|
53
|
+
switch (why.field) {
|
|
54
|
+
case 'postcode': return `postcode ${why.pattern}`;
|
|
55
|
+
case 'country': return `anywhere in ${countryName(why.country)}`;
|
|
56
|
+
case 'anywhere': return 'anywhere';
|
|
57
|
+
default: return why.field;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function postalLine(location: woocommerceTax.TaxAddress, countryName: (code: string) => string): string {
|
|
62
|
+
const local = [location.city, location.state, location.postcode].filter(Boolean).join(' ');
|
|
63
|
+
return [local, location.country ? countryName(location.country) : ''].filter(Boolean).join(', ') || '—';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function Step({ n, state, label, title, detail, last, children }: { n: number; state: StepState; label: string;
|
|
67
|
+
title?: string; detail?: string; last?: boolean; children?: ReactNode }) {
|
|
68
|
+
return (
|
|
69
|
+
<View testID={`tax-based-on-step-${n}`} dataSet={{ state }} className="flex-row gap-3">
|
|
70
|
+
<View className="items-center pt-0.5">
|
|
71
|
+
<View className={cn('size-4 items-center justify-center rounded-full', BEAD[state])}>
|
|
72
|
+
{state === 'failed' ? <View className="text-destructive-foreground"><XIcon size={10} strokeWidth={3} /></View> : null}
|
|
73
|
+
</View>
|
|
74
|
+
{last ? null : <View className={cn('mt-1 w-0.5 flex-1 bg-border', (state === 'failed' || state === 'quiet') && 'opacity-50')} />}
|
|
75
|
+
</View>
|
|
76
|
+
<View className={cn('min-w-0 flex-1 gap-0.5', !last && 'pb-4')}>
|
|
77
|
+
<Text className={CAPTION}>{label}</Text>
|
|
78
|
+
{title ? <Text className="text-base font-semibold text-foreground">{title}</Text> : null}
|
|
79
|
+
{detail ? <Text className="text-sm text-muted-foreground">{detail}</Text> : null}
|
|
80
|
+
{children}
|
|
81
|
+
</View>
|
|
82
|
+
</View>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function RateLine({ testID, name, why, percent, strong }: { testID: string; name: string; why?: string; percent: string; strong?: boolean }) {
|
|
87
|
+
return (
|
|
88
|
+
<View testID={testID} className={cn('flex-row items-baseline gap-3', strong ? 'min-h-8' : 'min-h-6')}>
|
|
89
|
+
<Text className={cn('min-w-0 flex-1 text-base', strong ? 'font-semibold text-foreground' : 'pl-3 text-muted-foreground')}>
|
|
90
|
+
{name}{why ? <Text className="text-muted-foreground">{` · ${why}`}</Text> : null}
|
|
91
|
+
</Text>
|
|
92
|
+
<Text className={cn('w-16 text-right text-base tabular-nums', strong ? 'font-semibold text-foreground' : 'text-muted-foreground')}>{percent}</Text>
|
|
93
|
+
</View>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* v2's "Tax based on" trigger under the product table, and its popover: how the cart's tax rates were derived, from the
|
|
99
|
+
* setting, through the address used, to the rates that match it. A popover, not a hover card: a touch screen has no hover.
|
|
100
|
+
* Rate names show as the store gives them (this package has no HTML-entity decoder yet).
|
|
101
|
+
*/
|
|
102
|
+
export function TaxBasedOn({ derivation, onChangeSetting, onViewAllRates, countryName = intlCountryName, className }: TaxBasedOnProps) {
|
|
103
|
+
const [open, setOpen] = useState(false);
|
|
104
|
+
const { taxBasedOn, failure, classes, location } = derivation;
|
|
105
|
+
const setting = SETTING_LABEL[taxBasedOn];
|
|
106
|
+
const none = classes.length === 0;
|
|
107
|
+
const country = () => countryName(location.country);
|
|
108
|
+
const ratesTitle = derivation.noRateCause === 'not-covered' ? `The store's rates for ${country()} don't cover this address`
|
|
109
|
+
: derivation.noRateCause === 'no-rate-for-country' ? `The store has no tax rate for ${country()}`
|
|
110
|
+
: 'The store has no tax rate for this address';
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<Popover.Root open={open} onOpenChange={setOpen}>
|
|
114
|
+
<Popover.Trigger testID="tax-based-on-trigger" dataSet={{ tone: none ? 'bad' : 'normal' }} accessibilityLabel={`Tax based on: ${setting}`}
|
|
115
|
+
className={cn('min-h-11 min-w-0 shrink flex-row items-center gap-1 rounded-md px-1', className)}>
|
|
116
|
+
{none
|
|
117
|
+
? <Text testID="tax-based-on-warning" className="text-sm font-bold text-destructive">!</Text>
|
|
118
|
+
: <Text testID="tax-based-on-percent" className="text-sm text-muted-foreground">%</Text>}
|
|
119
|
+
<Text testID="tax-based-on-value" numberOfLines={1} className={cn('shrink text-sm', none ? 'text-destructive' : 'text-foreground')}>
|
|
120
|
+
{VALUE_LABEL[taxBasedOn]}
|
|
121
|
+
</Text>
|
|
122
|
+
<Text className="text-xs text-muted-foreground">▼</Text>
|
|
123
|
+
</Popover.Trigger>
|
|
124
|
+
<Popover.Portal>
|
|
125
|
+
<Popover.Overlay style={StyleSheet.absoluteFill} />
|
|
126
|
+
<Popover.Content testID="tax-based-on-content" side="top" align="start" sideOffset={4}
|
|
127
|
+
aria-label="Tax based on" aria-labelledby={undefined} aria-describedby={undefined}
|
|
128
|
+
className="max-h-full w-96 max-w-full rounded-md border border-border bg-popover p-2 shadow-md">
|
|
129
|
+
<ScrollView className="min-h-0 shrink" contentContainerClassName="p-2">
|
|
130
|
+
<Step n={1} state="fact" label="Calculated from" title={setting}>
|
|
131
|
+
{onChangeSetting ? (
|
|
132
|
+
<Button variant="link" size="sm" role="link" testID="tax-based-on-change-setting" onPress={onChangeSetting}
|
|
133
|
+
className="h-11 self-start px-0">
|
|
134
|
+
<Text>Change in Settings › Tax</Text>
|
|
135
|
+
</Button>
|
|
136
|
+
) : null}
|
|
137
|
+
</Step>
|
|
138
|
+
{failure === 'address' ? (
|
|
139
|
+
<Step n={2} state="failed" label="No address on the order"
|
|
140
|
+
title={`This order has no ${taxBasedOn === 'billing' ? 'billing' : 'shipping'} address, so no rate can match`}
|
|
141
|
+
detail="Add a customer with an address, or change the setting">
|
|
142
|
+
<AddressFields location={location} />
|
|
143
|
+
</Step>
|
|
144
|
+
) : (
|
|
145
|
+
<Step n={2} state="fact" label={derivation.fromOrder ? 'Address on the order' : 'Shop address'}
|
|
146
|
+
title={postalLine(location, countryName)} detail={derivation.fallback ? FALLBACK_NOTE[derivation.fallback] : undefined}>
|
|
147
|
+
<AddressFields location={location} />
|
|
148
|
+
</Step>
|
|
149
|
+
)}
|
|
150
|
+
{failure === 'address' ? <Step n={3} last state="quiet" label="Rates that match it" detail="None" />
|
|
151
|
+
: failure === 'rates' ? <Step n={3} last state="failed" label="No rate matches it" title={ratesTitle}
|
|
152
|
+
detail="Add one in WooCommerce › Tax, or change the setting" />
|
|
153
|
+
: (
|
|
154
|
+
<Step n={3} last state="result" label="Rates that match it">
|
|
155
|
+
<View className="mt-2">
|
|
156
|
+
{classes.map((group, index) => (
|
|
157
|
+
<View key={group.slug} className={index > 0 ? 'mt-1' : undefined}>
|
|
158
|
+
<RateLine strong testID={`tax-based-on-class-${group.slug}`} name={group.name} percent={group.percent} />
|
|
159
|
+
{group.rates.map((rate) => (
|
|
160
|
+
<RateLine key={rate.id} testID={`tax-based-on-rate-${rate.id}`} name={rate.name}
|
|
161
|
+
why={whyText(rate.why, countryName)} percent={rate.percent} />
|
|
162
|
+
))}
|
|
163
|
+
</View>
|
|
164
|
+
))}
|
|
165
|
+
</View>
|
|
166
|
+
</Step>
|
|
167
|
+
)}
|
|
168
|
+
</ScrollView>
|
|
169
|
+
{onViewAllRates ? (
|
|
170
|
+
<View className="mt-1 border-t border-border pt-1">
|
|
171
|
+
<Button variant="ghost" testID="tax-based-on-view-all" className="h-11 w-full justify-between px-2"
|
|
172
|
+
onPress={() => { setOpen(false); onViewAllRates(); }}>
|
|
173
|
+
<Text>View all tax rates</Text>
|
|
174
|
+
<Text className="text-muted-foreground">›</Text>
|
|
175
|
+
</Button>
|
|
176
|
+
</View>
|
|
177
|
+
) : null}
|
|
178
|
+
</Popover.Content>
|
|
179
|
+
</Popover.Portal>
|
|
180
|
+
</Popover.Root>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function AddressFields({ location }: { location: woocommerceTax.TaxAddress }) {
|
|
185
|
+
return (
|
|
186
|
+
<View className="mt-2 flex-row gap-3">
|
|
187
|
+
{FIELDS.map(([field, label]) => (
|
|
188
|
+
<View key={field} className="min-w-0 flex-1">
|
|
189
|
+
<Text className={CAPTION} numberOfLines={1}>{label}</Text>
|
|
190
|
+
<Text testID={`tax-based-on-field-${field}`} numberOfLines={1}
|
|
191
|
+
className={cn('text-base', location[field] ? 'text-foreground' : 'text-muted-foreground')}>{location[field] || '—'}</Text>
|
|
192
|
+
</View>
|
|
193
|
+
))}
|
|
194
|
+
</View>
|
|
195
|
+
);
|
|
196
|
+
}
|
package/src/ui/avatar/index.tsx
CHANGED
|
@@ -17,13 +17,31 @@ const avatarVariants = cva('relative overflow-hidden rounded-full', {
|
|
|
17
17
|
},
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
const avatarFallbackVariants = cva('flex h-full w-full items-center justify-center', {
|
|
21
|
+
variants: { tone: { muted: 'bg-muted', primary: 'bg-primary' } },
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const avatarFallbackTextVariants = cva('text-sm font-medium', {
|
|
25
|
+
variants: { tone: { muted: 'text-muted-foreground', primary: 'text-primary-foreground' } },
|
|
26
|
+
});
|
|
27
|
+
|
|
20
28
|
type AvatarProps = ViewProps & VariantProps<typeof avatarVariants> & {
|
|
21
29
|
src?: string;
|
|
22
30
|
alt?: string;
|
|
23
31
|
fallback?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The fallback's colours. `'primary'` is v2's look (light initials on a solid primary circle),
|
|
34
|
+
* used by the Customers table and the customer dropdown.
|
|
35
|
+
*/
|
|
36
|
+
tone?: 'muted' | 'primary';
|
|
24
37
|
};
|
|
25
38
|
|
|
26
|
-
|
|
39
|
+
/** Up to two words of `name`, the first letter of each, upper case. */
|
|
40
|
+
function avatarInitials(name: string): string {
|
|
41
|
+
return name.split(/\s+/).filter(Boolean).slice(0, 2).map((word) => word[0].toUpperCase()).join('');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function Avatar({ className, size, src, alt, fallback, tone = 'muted', ...props }: AvatarProps) {
|
|
27
45
|
const [hasError, setHasError] = React.useState(false);
|
|
28
46
|
|
|
29
47
|
return (
|
|
@@ -36,8 +54,8 @@ function Avatar({ className, size, src, alt, fallback, ...props }: AvatarProps)
|
|
|
36
54
|
className="h-full w-full"
|
|
37
55
|
/>
|
|
38
56
|
) : (
|
|
39
|
-
<View className=
|
|
40
|
-
<Text className=
|
|
57
|
+
<View className={avatarFallbackVariants({ tone })}>
|
|
58
|
+
<Text className={avatarFallbackTextVariants({ tone })}>
|
|
41
59
|
{fallback ?? alt?.charAt(0)?.toUpperCase() ?? '?'}
|
|
42
60
|
</Text>
|
|
43
61
|
</View>
|
|
@@ -46,5 +64,5 @@ function Avatar({ className, size, src, alt, fallback, ...props }: AvatarProps)
|
|
|
46
64
|
);
|
|
47
65
|
}
|
|
48
66
|
|
|
49
|
-
export { Avatar, avatarVariants };
|
|
67
|
+
export { Avatar, avatarVariants, avatarInitials };
|
|
50
68
|
export type { AvatarProps };
|
package/src/ui/button/index.tsx
CHANGED
|
@@ -11,7 +11,7 @@ const buttonVariants = cva(
|
|
|
11
11
|
variant: {
|
|
12
12
|
default: 'bg-primary active:opacity-90',
|
|
13
13
|
destructive: 'bg-destructive active:opacity-90',
|
|
14
|
-
outline: 'border border-input bg-
|
|
14
|
+
outline: 'border border-input bg-card active:bg-accent',
|
|
15
15
|
secondary: 'bg-secondary active:opacity-80',
|
|
16
16
|
ghost: 'active:bg-accent',
|
|
17
17
|
link: 'web:underline-offset-4 web:hover:underline',
|