@tallyui/components 3.20.1 → 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
|
@@ -2,28 +2,19 @@
|
|
|
2
2
|
// reducer.ts), lib/decimal-entry.ts and keypad/index.tsx's decimalRow, as the cart cells open them
|
|
3
3
|
// (packages/core/src/screens/main/pos/cart/cells/quantity-keypad.tsx and cells/price.tsx); MIT, WCPOS.
|
|
4
4
|
import { useEffect, useId, useRef, useState, type ReactNode, type RefObject } from 'react';
|
|
5
|
-
import { Platform, Pressable, StyleSheet, Text, View } from 'react-native';
|
|
6
|
-
import {
|
|
5
|
+
import { Animated, Platform, Pressable, StyleSheet, Text, View } from 'react-native';
|
|
6
|
+
import { useFormatMoney, minorUnitDigits } from '@tallyui/core';
|
|
7
7
|
import { Popover } from '@tallyui/primitives';
|
|
8
8
|
import { cn } from '@tallyui/theme';
|
|
9
|
-
import {
|
|
9
|
+
import { decimalRows, typeDecimal } from '../input/decimal-entry';
|
|
10
|
+
import { Keypad } from '../input/keypad';
|
|
11
|
+
import { POPOVER_MOTION, useOverlayMotion } from '../ui/dialog/motion';
|
|
10
12
|
import { lessPercent, parsePrice, QuickDiscountKeys, quickKeys } from './price-form';
|
|
11
13
|
|
|
12
14
|
/** nav-drawer.tsx's focus targets. */
|
|
13
15
|
const FOCUSABLE = 'button, [href], input, [tabindex]:not([tabindex="-1"])';
|
|
14
|
-
const BACKSPACE: KeypadKey = { name: 'backspace', label: 'Delete last digit', text: '⌫' };
|
|
15
16
|
const button = 'min-h-11 flex-1 items-center justify-center rounded-md border border-border px-3 py-2';
|
|
16
17
|
|
|
17
|
-
/** v2's typeDecimal: `.` once and only with places, a digit past the places refused, a lone 0 replaced. */
|
|
18
|
-
function typeDecimal(buffer: string, key: string, places: number): string {
|
|
19
|
-
if (key === 'backspace') return buffer.slice(0, -1);
|
|
20
|
-
if (key === 'decimal') return places > 0 && !buffer.includes('.') ? `${buffer || '0'}.` : buffer;
|
|
21
|
-
if (!/^[0-9]$/.test(key)) return buffer;
|
|
22
|
-
const point = buffer.indexOf('.');
|
|
23
|
-
if (point >= 0) return buffer.length - point > places ? buffer : buffer + key;
|
|
24
|
-
return buffer === '0' ? key : buffer + key;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
18
|
export interface LinePopoverProps {
|
|
28
19
|
/** `quantity` takes whole numbers only, with no decimal key (decimal quantities need an ADR first, TallyUI#486). */
|
|
29
20
|
kind: 'quantity' | 'price';
|
|
@@ -43,15 +34,26 @@ export interface LinePopoverProps {
|
|
|
43
34
|
/** Buttons drawn in the open panel above Apply / Cancel, e.g. the cart line's Discount and Remove. Pressing one closes
|
|
44
35
|
* the popover, then calls its `onPress`. `destructive` draws it in the destructive colour. */
|
|
45
36
|
actions?: ReadonlyArray<{ id: string; label: string; onPress: () => void; destructive?: boolean }>;
|
|
37
|
+
/** `apply` (default): today's Apply / Cancel. `close`: v2's grow keypad. There is no Apply or Cancel, and a full-width
|
|
38
|
+
* Done writes what was typed. Escape closes without writing, and any other close (a press outside, the overlay) writes
|
|
39
|
+
* it; a refusal on that path goes to `onCloseRefused`, as the popover is already closing. A quantity also gets v2's − / +
|
|
40
|
+
* steppers, which write at once. */
|
|
41
|
+
commit?: 'apply' | 'close';
|
|
42
|
+
/** `commit="close"` only: called with the refusal when the write on a close other than Done is refused; the popover is already closing, so the host shows it. */
|
|
43
|
+
onCloseRefused?: (message: string) => void;
|
|
44
|
+
/** Quantity with `commit="close"` only: − becomes Remove at a shown quantity of 1 or less, closes without writing and calls this. */
|
|
45
|
+
onRemove?: () => void;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* A cart line's quantity or price that opens v2's keypad: the cashier types (or picks a quick discount),
|
|
50
|
-
* Apply writes through `onApply`, and Cancel, Escape or a press outside close without writing.
|
|
50
|
+
* Apply writes through `onApply`, and Cancel, Escape or a press outside close without writing (`commit="close"` differs).
|
|
51
51
|
*/
|
|
52
52
|
export function LinePopover({ kind, lineName, currency, value, onApply, quickDiscounts, textClassName, regularValue,
|
|
53
|
-
actions }: LinePopoverProps) {
|
|
53
|
+
actions, commit = 'apply', onRemove, onCloseRefused }: LinePopoverProps) {
|
|
54
|
+
const formatMoney = useFormatMoney();
|
|
54
55
|
const [open, setOpen] = useState(false);
|
|
56
|
+
const { mounted, panel } = useOverlayMotion(open, true, POPOVER_MOTION);
|
|
55
57
|
// v2's entry: the typed buffer (`.` as its separator), or the lit quick key, a percentage off `value`.
|
|
56
58
|
const [entry, setEntry] = useState<{ buffer: string; percent?: number }>({ buffer: '' });
|
|
57
59
|
const [error, setError] = useState<string | null>(null);
|
|
@@ -67,12 +69,20 @@ export function LinePopover({ kind, lineName, currency, value, onApply, quickDis
|
|
|
67
69
|
const draft = !price ? (Number.parseInt(typed, 10) > 0 ? Number.parseInt(typed, 10) : undefined)
|
|
68
70
|
: percent !== undefined ? lessPercent(value, percent) : typed ? parsePrice(typed, currency) : undefined;
|
|
69
71
|
const title = `${price ? 'Price' : 'Quantity'} for ${lineName}`;
|
|
70
|
-
const rows =
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
const rows = decimalRows(places);
|
|
73
|
+
const close = commit === 'close';
|
|
74
|
+
const shown = typeof draft === 'number' ? draft : value;
|
|
75
|
+
// v2's trash: at 1 or less, − removes the line when the host can; without onRemove it stops at 1.
|
|
76
|
+
const trash = shown <= 1 && onRemove !== undefined;
|
|
77
|
+
// Set by Escape and Remove: the close that follows writes nothing.
|
|
78
|
+
const discard = useRef(false);
|
|
73
79
|
|
|
74
80
|
const openChange = (next: boolean) => {
|
|
75
|
-
if (next) { setEntry({ buffer: '' }); setError(null); }
|
|
81
|
+
if (next) { setEntry({ buffer: '' }); setError(null); discard.current = false; }
|
|
82
|
+
else if (close && !discard.current && typeof draft === 'number' && draft !== value) {
|
|
83
|
+
const refused = onApply(draft);
|
|
84
|
+
if (refused) onCloseRefused?.(refused);
|
|
85
|
+
}
|
|
76
86
|
setOpen(next);
|
|
77
87
|
};
|
|
78
88
|
const press = (name: string) => {
|
|
@@ -89,8 +99,18 @@ export function LinePopover({ kind, lineName, currency, value, onApply, quickDis
|
|
|
89
99
|
setError(refused);
|
|
90
100
|
if (refused === null) setOpen(false);
|
|
91
101
|
}
|
|
102
|
+
// A step writes at once; the display then follows `value`, or shows it again after a refusal.
|
|
103
|
+
const step = (to: number) => {
|
|
104
|
+
setError(onApply(to));
|
|
105
|
+
setEntry({ buffer: '' });
|
|
106
|
+
};
|
|
107
|
+
const remove = () => {
|
|
108
|
+
discard.current = true;
|
|
109
|
+
setOpen(false);
|
|
110
|
+
onRemove?.();
|
|
111
|
+
};
|
|
92
112
|
const onKey = (key: string) => {
|
|
93
|
-
if (key === 'Escape') setOpen(false);
|
|
113
|
+
if (key === 'Escape') { discard.current = true; setOpen(false); }
|
|
94
114
|
else if (/^[0-9]$/.test(key)) press(key);
|
|
95
115
|
else if (key === 'Backspace') press('backspace');
|
|
96
116
|
else if ((key === '.' || key === ',') && places) press('decimal');
|
|
@@ -101,20 +121,32 @@ export function LinePopover({ kind, lineName, currency, value, onApply, quickDis
|
|
|
101
121
|
className="min-h-11 justify-center rounded-md px-1">
|
|
102
122
|
<Text className={cn('text-sm tabular-nums text-foreground', textClassName)}>{format(value)}</Text>
|
|
103
123
|
</Popover.Trigger>
|
|
104
|
-
<Popover.Portal>
|
|
105
|
-
<Popover.Overlay style={StyleSheet.absoluteFill} />
|
|
106
|
-
<Popover.Content testID={`${kind}-popover`} align={price ? 'end' : 'start'} sideOffset={4}
|
|
107
|
-
aria-labelledby={titleId} aria-describedby={undefined}
|
|
108
|
-
className="w-64 rounded-md border border-border bg-popover p-4 shadow-md"
|
|
109
|
-
|
|
124
|
+
{mounted ? <Popover.Portal forceMount>
|
|
125
|
+
<Popover.Overlay testID={`${kind}-popover-overlay`} style={StyleSheet.absoluteFill} />
|
|
126
|
+
<Popover.Content forceMount testID={`${kind}-popover`} align={price ? 'end' : 'start'} sideOffset={4}
|
|
127
|
+
aria-labelledby={titleId} aria-describedby={undefined} onEscapeKeyDown={() => { discard.current = true; }}>
|
|
128
|
+
<Animated.View className="w-64 rounded-md border border-border bg-popover p-4 shadow-md"
|
|
129
|
+
style={{ opacity: panel, transform: Platform.OS === 'web' ? [{ translateY: panel.interpolate({ inputRange: [0, 1], outputRange: [-6, 0] }) }] : undefined }}
|
|
130
|
+
pointerEvents={open ? 'auto' : 'none'}>
|
|
131
|
+
<Panel onKey={onKey} active={open}>
|
|
110
132
|
<Text nativeID={titleId} className="font-semibold text-popover-foreground">{title}</Text>
|
|
111
133
|
<View className="items-end">
|
|
112
134
|
{regular ? <Text accessibilityLabel={`Regular price ${regular}`} style={{ textDecorationLine: 'line-through' }}
|
|
113
135
|
className="text-sm tabular-nums text-muted-foreground line-through">{regular}</Text> : null}
|
|
114
136
|
{percent !== undefined ? <Text className="text-sm text-muted-foreground">{`${format(value)} −${percent}%`}</Text> : null}
|
|
115
137
|
<Text testID={`${kind}-popover-value`} numberOfLines={1} className="text-2xl font-semibold tabular-nums text-popover-foreground">
|
|
116
|
-
{buffer || format(
|
|
138
|
+
{buffer || format(shown)}</Text>
|
|
117
139
|
</View>
|
|
140
|
+
{close && !price ? <View className="flex-row items-center gap-2">
|
|
141
|
+
{trash ? <Pressable testID="quantity-popover-remove" accessibilityRole="button" accessibilityLabel="Remove"
|
|
142
|
+
onPress={remove} className={`${button} bg-card`}><Text className="text-destructive">Remove</Text></Pressable>
|
|
143
|
+
: <Pressable testID="quantity-popover-step-down" accessibilityRole="button" accessibilityLabel="One fewer"
|
|
144
|
+
disabled={shown <= 1} accessibilityState={{ disabled: shown <= 1 }} onPress={() => { if (shown > 1) step(shown - 1); }}
|
|
145
|
+
className={cn(button, 'bg-card', shown <= 1 && 'opacity-50')}><Text className="text-foreground">−</Text></Pressable>}
|
|
146
|
+
<Text className="flex-1 text-center tabular-nums text-popover-foreground">{format(shown)}</Text>
|
|
147
|
+
<Pressable testID="quantity-popover-step-up" accessibilityRole="button" accessibilityLabel="One more"
|
|
148
|
+
onPress={() => step(shown + 1)} className={`${button} bg-card`}><Text className="text-foreground">+</Text></Pressable>
|
|
149
|
+
</View> : null}
|
|
118
150
|
{keys.length ? <QuickDiscountKeys keys={keys} percent={percent} onPress={quick} /> : null}
|
|
119
151
|
<Keypad testID={`${kind}-popover-keypad`} rows={rows} onPress={press} />
|
|
120
152
|
{error ? <Text accessibilityRole="alert" className="text-destructive">{error}</Text> : null}
|
|
@@ -125,30 +157,34 @@ export function LinePopover({ kind, lineName, currency, value, onApply, quickDis
|
|
|
125
157
|
<Text className={action.destructive ? 'text-destructive' : 'text-foreground'}>{action.label}</Text>
|
|
126
158
|
</Pressable>)}
|
|
127
159
|
</View> : null}
|
|
128
|
-
<View className="flex-row
|
|
160
|
+
{close ? <View className="flex-row">
|
|
161
|
+
<Pressable testID={`${kind}-popover-done`} accessibilityRole="button" onPress={apply} className={`${button} bg-primary`}>
|
|
162
|
+
<Text className="font-semibold text-primary-foreground">Done</Text></Pressable>
|
|
163
|
+
</View> : <View className="flex-row gap-2">
|
|
129
164
|
<Pressable testID={`${kind}-popover-apply`} accessibilityRole="button" onPress={apply} className={`${button} bg-primary`}>
|
|
130
165
|
<Text className="font-semibold text-primary-foreground">Apply</Text></Pressable>
|
|
131
166
|
<Pressable testID={`${kind}-popover-cancel`} accessibilityRole="button" onPress={() => setOpen(false)} className={`${button} bg-card`}>
|
|
132
167
|
<Text className="text-foreground">Cancel</Text></Pressable>
|
|
133
|
-
</View>
|
|
168
|
+
</View>}
|
|
134
169
|
</Panel>
|
|
170
|
+
</Animated.View>
|
|
135
171
|
</Popover.Content>
|
|
136
|
-
</Popover.Portal>
|
|
172
|
+
</Popover.Portal> : null}
|
|
137
173
|
</Popover.Root>;
|
|
138
174
|
}
|
|
139
175
|
|
|
140
176
|
/** The open panel. Web: focus moves into it and back to where it was on close; keys go to `onKey` (nav-drawer's pattern). */
|
|
141
|
-
function Panel({ onKey, children }: { onKey: (key: string) => void; children: ReactNode }) {
|
|
177
|
+
function Panel({ onKey, active, children }: { onKey: (key: string) => void; active: boolean; children: ReactNode }) {
|
|
142
178
|
const panel = useRef<View>(null);
|
|
143
|
-
useKeys(panel, onKey);
|
|
179
|
+
useKeys(panel, onKey, active);
|
|
144
180
|
return <View ref={panel} className="gap-3">{children}</View>;
|
|
145
181
|
}
|
|
146
182
|
|
|
147
|
-
function useKeys(panel: RefObject<View | null>, onKey: (key: string) => void) {
|
|
183
|
+
function useKeys(panel: RefObject<View | null>, onKey: (key: string) => void, active: boolean) {
|
|
148
184
|
const latest = useRef(onKey);
|
|
149
185
|
latest.current = onKey;
|
|
150
186
|
useEffect(() => {
|
|
151
|
-
if (Platform.OS !== 'web' || typeof document === 'undefined') return;
|
|
187
|
+
if (!active || Platform.OS !== 'web' || typeof document === 'undefined') return;
|
|
152
188
|
const previous = document.activeElement as HTMLElement | null;
|
|
153
189
|
(panel.current as unknown as HTMLElement | null)?.querySelector<HTMLElement>(FOCUSABLE)?.focus();
|
|
154
190
|
const onKeyDown = (event: KeyboardEvent) => latest.current(event.key);
|
|
@@ -157,5 +193,5 @@ function useKeys(panel: RefObject<View | null>, onKey: (key: string) => void) {
|
|
|
157
193
|
document.removeEventListener('keydown', onKeyDown);
|
|
158
194
|
previous?.focus?.();
|
|
159
195
|
};
|
|
160
|
-
}, [panel]);
|
|
196
|
+
}, [panel, active]);
|
|
161
197
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defaultPaymentMethods, wireMethodOf, type PaymentMethodDescriptor, type PaymentMethodKind } from '@tallyui/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The methods the tender pane offers: the host's (else today's two defaults) whose capture is `manual`. Only manual
|
|
5
|
+
* capture records a leg here, the cashier saying the money is taken; a device, gateway, webview, server or stored-value
|
|
6
|
+
* method takes its money elsewhere, so recording its leg here would mark a sale paid that nobody has charged.
|
|
7
|
+
*/
|
|
8
|
+
export function offeredMethods(methods?: PaymentMethodDescriptor[]): PaymentMethodDescriptor[] {
|
|
9
|
+
return (methods ?? defaultPaymentMethods()).filter((method) => method.capture.mode === 'manual');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The leg a descriptor records: its wire method (`wireMethodOf`), plus its own id as `methodId` when that differs. */
|
|
13
|
+
export function tenderOf(descriptor: PaymentMethodDescriptor): { method: PaymentMethodKind; methodId?: string } {
|
|
14
|
+
const method = wireMethodOf(descriptor);
|
|
15
|
+
return { method, ...(descriptor.id !== method ? { methodId: descriptor.id } : {}) };
|
|
16
|
+
}
|
|
@@ -1,15 +1,37 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { Pressable, ScrollView, View } from 'react-native';
|
|
3
|
-
import {
|
|
4
|
-
import type
|
|
1
|
+
import { useEffect, useRef, useState, type JSX } from 'react';
|
|
2
|
+
import { Platform, Pressable, ScrollView, View } from 'react-native';
|
|
3
|
+
import { useFormatMoney } from '@tallyui/core';
|
|
4
|
+
import { isPartlyPaid, type OpenSale } from '@tallyui/pos';
|
|
5
|
+
import { cn } from '@tallyui/theme';
|
|
5
6
|
import { Text } from '../ui/text';
|
|
6
7
|
|
|
8
|
+
const AGE_TICK_MS = 60_000; // Ages tick once a minute (v2).
|
|
9
|
+
const STALE_AFTER_MS = 60 * 60_000; // A sale parked for an hour is one somebody forgot (v2).
|
|
10
|
+
|
|
11
|
+
function useNowMs(intervalMs: number): number {
|
|
12
|
+
const [now, setNow] = useState(() => Date.now());
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const timer = setInterval(() => setNow(Date.now()), intervalMs);
|
|
15
|
+
return () => clearInterval(timer);
|
|
16
|
+
}, [intervalMs]);
|
|
17
|
+
return now;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function staleAge(parkedAt: string | undefined, nowMs: number): string | null {
|
|
21
|
+
if (!parkedAt) return null;
|
|
22
|
+
const parsed = Date.parse(parkedAt);
|
|
23
|
+
if (Number.isNaN(parsed) || nowMs - parsed < STALE_AFTER_MS) return null;
|
|
24
|
+
return `${Math.round((nowMs - parsed) / 3_600_000)} h`;
|
|
25
|
+
}
|
|
26
|
+
|
|
7
27
|
/** Pass `openSales(sale.order, useParkedSales(drafts).parked)`; `onSelect` and `onNew` call `sale.switchSale(id)` and `sale.switchSale(null)`. */
|
|
8
28
|
export interface OpenSaleTabsProps {
|
|
9
29
|
sales: OpenSale[];
|
|
10
30
|
currency: string;
|
|
11
31
|
onSelect: (id: string) => void;
|
|
12
32
|
onNew: () => void;
|
|
33
|
+
/** Merged onto the bar's root, after its own classes, so an app can restyle it (for example `border-t-0 border-b` at the top). */
|
|
34
|
+
className?: string;
|
|
13
35
|
}
|
|
14
36
|
|
|
15
37
|
/** v2 cart/tab-who.ts: the customer, or what is in the cart when the customer is a guest. */
|
|
@@ -23,17 +45,42 @@ function who(sale: OpenSale): string {
|
|
|
23
45
|
* The open sales as cart tabs (v2 cart/tabs.tsx): who, then the Partly paid chip or else the total. The open sale's
|
|
24
46
|
* tab is underlined even when it is the only one; a blank cart has no tab, the + cell is its tab and reads "New".
|
|
25
47
|
*/
|
|
26
|
-
export function OpenSaleTabs({ sales, currency, onSelect, onNew }: OpenSaleTabsProps): JSX.Element {
|
|
48
|
+
export function OpenSaleTabs({ sales, currency, onSelect, onNew, className }: OpenSaleTabsProps): JSX.Element {
|
|
49
|
+
const formatMoney = useFormatMoney();
|
|
50
|
+
const now = useNowMs(AGE_TICK_MS);
|
|
27
51
|
const blank = !sales.some((sale) => sale.current);
|
|
52
|
+
// v2 cart/tabs.tsx: on a blank cart the active position is the + cell, just past the last sale; no wrap.
|
|
53
|
+
const activeIndex = blank ? sales.length : sales.findIndex((sale) => sale.current);
|
|
54
|
+
const focusPending = useRef(false);
|
|
55
|
+
const step = (delta: number) => {
|
|
56
|
+
const at = activeIndex + delta;
|
|
57
|
+
if (at < 0 || at > sales.length) return;
|
|
58
|
+
focusPending.current = true;
|
|
59
|
+
if (at === sales.length) onNew(); else onSelect(sales[at].id);
|
|
60
|
+
};
|
|
61
|
+
// Once a key step's tab renders active, it takes focus; a press leaves focus where it is (v2).
|
|
62
|
+
const follow = (active: boolean) => (node: View | null) => {
|
|
63
|
+
if (node && active && focusPending.current) { focusPending.current = false; node.focus?.(); }
|
|
64
|
+
};
|
|
65
|
+
// The arrow keys step from any tab, + included: the strip is their one ancestor (v2, web only).
|
|
66
|
+
const onKeyDown = Platform.OS === 'web' ? (event: { nativeEvent: { key: string }; target: unknown; defaultPrevented: boolean; preventDefault: () => void }) => {
|
|
67
|
+
const key = event.nativeEvent.key;
|
|
68
|
+
const from = (event.target as { getAttribute?: (n: string) => string | null })?.getAttribute?.('role');
|
|
69
|
+
if (from === 'tab' && (key === 'ArrowLeft' || key === 'ArrowRight') && !event.defaultPrevented) {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
step(key === 'ArrowLeft' ? -1 : 1);
|
|
72
|
+
}
|
|
73
|
+
} : undefined;
|
|
28
74
|
return (
|
|
29
|
-
<View testID="open-sale-tabs" className=
|
|
75
|
+
<View testID="open-sale-tabs" className={cn('h-14 flex-row items-stretch border-t border-border bg-card', className)}
|
|
76
|
+
{...{ onKeyDown } /* RN's View types lack onKeyDown; react-native-web passes it to the div. */}>
|
|
30
77
|
<ScrollView horizontal accessibilityRole="tablist" showsHorizontalScrollIndicator={false} className="min-w-0 flex-1">
|
|
31
78
|
{sales.map((sale) => {
|
|
32
|
-
|
|
33
|
-
const
|
|
79
|
+
const partly = isPartlyPaid(sale);
|
|
80
|
+
const age = staleAge(sale.parkedAt, now);
|
|
34
81
|
const status = `Partly paid · ${formatMoney({ amount: sale.balanceDueMinor, currency })} due`;
|
|
35
82
|
return (
|
|
36
|
-
<Pressable key={sale.id} testID={`open-sale-tab-${sale.id}`} accessibilityRole="tab"
|
|
83
|
+
<Pressable key={sale.id} testID={`open-sale-tab-${sale.id}`} ref={follow(sale.current)} accessibilityRole="tab"
|
|
37
84
|
accessibilityState={{ selected: sale.current }} aria-selected={sale.current} onPress={() => onSelect(sale.id)}
|
|
38
85
|
className={`h-full justify-center border-b-2 px-3 ${sale.current ? 'border-primary' : 'border-transparent'}`}>
|
|
39
86
|
<Text testID={`open-sale-tab-${sale.id}-who`} numberOfLines={1}
|
|
@@ -49,13 +96,14 @@ export function OpenSaleTabs({ sales, currency, onSelect, onNew }: OpenSaleTabsP
|
|
|
49
96
|
) : (
|
|
50
97
|
<Text testID={`open-sale-tab-${sale.id}-amount`} className="text-xs text-muted-foreground tabular-nums">
|
|
51
98
|
{formatMoney({ amount: sale.totalMinor, currency })}
|
|
99
|
+
{age !== null && <> · <Text testID={`open-sale-tab-${sale.id}-age`} className="text-xs font-semibold text-warning-text">{age}</Text></>}
|
|
52
100
|
</Text>
|
|
53
101
|
)}
|
|
54
102
|
</Pressable>
|
|
55
103
|
);
|
|
56
104
|
})}
|
|
57
105
|
</ScrollView>
|
|
58
|
-
<Pressable testID="new-sale-tab" accessibilityRole="tab" accessibilityLabel="New order" accessibilityState={{ selected: blank }} aria-selected={blank}
|
|
106
|
+
<Pressable testID="new-sale-tab" ref={follow(blank)} accessibilityRole="tab" accessibilityLabel="New order" accessibilityState={{ selected: blank }} aria-selected={blank}
|
|
59
107
|
// Already on the blank cart: + is a place, not an action (v2).
|
|
60
108
|
onPress={() => { if (!blank) onNew(); }}
|
|
61
109
|
className={`h-full flex-row items-center justify-center gap-1.5 px-3 ${blank ? 'border-b-2 border-primary' : ''}`}>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Port of WCPOS v2's Order details note field, MIT, WCPOS:
|
|
2
|
+
// packages/core/src/screens/main/pos/cart/foot.tsx, note-row.tsx, order-sheet.tsx,
|
|
3
|
+
// and buttons/edit-order-meta/form.tsx:431-444 (paths relative to that cart directory).
|
|
4
|
+
import type { JSX } from 'react';
|
|
5
|
+
import { Dialog, DialogContent, DialogTitle } from '../ui/dialog';
|
|
6
|
+
import { Textarea } from '../ui/textarea';
|
|
7
|
+
import { Label } from '../ui/label';
|
|
8
|
+
import { Button } from '../ui/button';
|
|
9
|
+
import { Text } from '../ui/text';
|
|
10
|
+
|
|
11
|
+
export interface OrderNoteSheetProps {
|
|
12
|
+
/** The note as it stands; the sheet edits it live, as v2's autosaved field does. */
|
|
13
|
+
value: string;
|
|
14
|
+
onChangeText: (text: string) => void;
|
|
15
|
+
onOpenChange: (open: boolean) => void;
|
|
16
|
+
/** The note's name: the field's label and accessible name, and "Add <label lower-cased>" as its placeholder.
|
|
17
|
+
* Default "Customer note" (WooCommerce's customer_note, which the customer sees). */
|
|
18
|
+
label?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function OrderNoteSheet({ value, onChangeText, onOpenChange, label = 'Customer note' }: OrderNoteSheetProps): JSX.Element {
|
|
22
|
+
return (
|
|
23
|
+
<Dialog open onOpenChange={onOpenChange}>
|
|
24
|
+
{/* v2 opens the order sheet away from the cart so the cart's note row stays in view. */}
|
|
25
|
+
<DialogContent side="left" testID="order-note-sheet">
|
|
26
|
+
<DialogTitle>Order details</DialogTitle>
|
|
27
|
+
<Label nativeID="order-note-label">{label}</Label>
|
|
28
|
+
<Textarea testID="order-note-input" value={value} onChangeText={onChangeText}
|
|
29
|
+
accessibilityLabel={label} accessibilityLabelledBy="order-note-label"
|
|
30
|
+
placeholder={`Add ${label.toLowerCase()}`} />
|
|
31
|
+
<Button testID="order-note-close" onPress={() => onOpenChange(false)}>
|
|
32
|
+
<Text>Close</Text>
|
|
33
|
+
</Button>
|
|
34
|
+
</DialogContent>
|
|
35
|
+
</Dialog>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -7,3 +7,6 @@ export function orderReference(order: { id: string; serverRefs?: { displayId?: s
|
|
|
7
7
|
|
|
8
8
|
/** The receipt and Orders say this under a note that went below order.create 7 (ADR-083 condition 2). */
|
|
9
9
|
export const NOTE_NOT_SENT = "The customer note couldn't be sent to the store.";
|
|
10
|
+
/** Orders says these when a sale's tax ids or custom fields went below order.create 12 (ADR-092 condition 1). */
|
|
11
|
+
export const TAX_IDS_NOT_SENT = "The customer's tax IDs couldn't be sent to the store.";
|
|
12
|
+
export const META_NOT_SENT = "The order's custom fields couldn't be sent to the store.";
|
package/src/sale/orders-list.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
1
|
+
import { useEffect, useId, useRef, useState, type ReactNode } from 'react';
|
|
2
2
|
import { Pressable, ScrollView, Text, View } from 'react-native';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { NOTE_NOT_SENT, orderReference } from './order-reference';
|
|
3
|
+
import { useFormatMoney, knownWarnings } from '@tallyui/core';
|
|
4
|
+
import { extrasNotSent, isRequeueableOrder, needsAttention, noteDelivery, refundDueOf, UPDATE_UNSENDABLE, UPDATE_UNSENDABLE_MESSAGE, type OutboxState, type PosOrder } from '@tallyui/pos';
|
|
5
|
+
import { META_NOT_SENT, NOTE_NOT_SENT, orderReference, TAX_IDS_NOT_SENT } from './order-reference';
|
|
6
6
|
import { sinceText } from './since-text';
|
|
7
7
|
|
|
8
8
|
/** One order from the store's own history (ADR-052 amendment 1), mapped by the app from its platform. */
|
|
@@ -32,6 +32,7 @@ const REFUSAL_SENTENCES = new Map([
|
|
|
32
32
|
]);
|
|
33
33
|
// Any other code, or none: platform_error's sentence, as the generic fallback (approved by the Front desk, 2026-09-30).
|
|
34
34
|
const refusalSentence = (code: string | undefined) => REFUSAL_SENTENCES.get(code ?? '') ?? REFUSAL_SENTENCES.get('platform_error')!;
|
|
35
|
+
const REOPEN_AGAIN_SENTENCE = "This order was changed in the online store after it was reopened here, so your change wasn't sent. Reopen the order and make the change again.";
|
|
35
36
|
|
|
36
37
|
/** Keeps an unparseable value as is, like medusapos's date util, since `Intl` throws on an invalid date. */
|
|
37
38
|
function defaultFormatDate(iso: string) {
|
|
@@ -39,6 +40,64 @@ function defaultFormatDate(iso: string) {
|
|
|
39
40
|
return Number.isNaN(date.getTime()) ? iso : new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' }).format(date);
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
export type OrderSyncNoticesProps = {
|
|
44
|
+
order: PosOrder;
|
|
45
|
+
/** The outbox's `state.stuck`, as OrdersList takes it. */
|
|
46
|
+
stuck?: OutboxState['stuck'];
|
|
47
|
+
/** Rendered between the notes (note not sent) and the store's warnings: OrdersList's Retry goes here. */
|
|
48
|
+
children?: ReactNode;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** The per-sale sync notices OrdersList shows under each order, for an app's own order screen. */
|
|
52
|
+
export function OrderSyncNotices({ order, stuck, children }: OrderSyncNoticesProps) {
|
|
53
|
+
const formatMoney = useFormatMoney();
|
|
54
|
+
// The order's own stuck entry: its clock and latest reason, not the earliest across all stuck orders.
|
|
55
|
+
const stuckEntry = order.syncStatus === 'pending' ? stuck?.orders.find((entry) => entry.commandId === order.commandId) : undefined;
|
|
56
|
+
const sentence = order.syncStatus === 'rejected'
|
|
57
|
+
? order.storeOrderId !== undefined && ['reopen_required', 'revision_conflict'].includes(order.error?.code ?? '')
|
|
58
|
+
? REOPEN_AGAIN_SENTENCE : refusalSentence(order.error?.code)
|
|
59
|
+
: order.syncStatus === 'pending' && order.error?.code === UPDATE_UNSENDABLE ? UPDATE_UNSENDABLE_MESSAGE : undefined;
|
|
60
|
+
const extras = extrasNotSent(order);
|
|
61
|
+
return <>
|
|
62
|
+
{stuckEntry ? <Text className="text-destructive">
|
|
63
|
+
{/* The same words for any reason, with no reason code; the hour as the status line has it (numeric, #245). */}
|
|
64
|
+
{`Hasn't reached the online store since ${sinceText(stuckEntry)}.`}
|
|
65
|
+
</Text> : null}
|
|
66
|
+
{/* The code's sentence alone: the cashier sees no error code and never the store's message. */}
|
|
67
|
+
{sentence ? <Text className="text-destructive">{sentence}</Text> : null}
|
|
68
|
+
{/* A late sale (ADR-032) needs no Retry of its own; a rejected one still gets its Retry below. */}
|
|
69
|
+
{order.lateSessionId !== undefined ? <Text className="text-foreground">Taken after the register closed. It is not in that register's closure.</Text> : null}
|
|
70
|
+
{order.countedInClosureOf !== undefined ? <Text className="text-foreground">Recorded after the register closed. Its payment is in that register's closure.</Text> : null}
|
|
71
|
+
{order.localWarnings?.map((warning, index) => <Text key={index} className="text-foreground">
|
|
72
|
+
{warning.code === 'customer_omitted'
|
|
73
|
+
? `The customer's ${warning.field} couldn't be sent to the store, so the order isn't linked to them.`
|
|
74
|
+
: "The terminal's payment reference couldn't be kept; the payment is recorded without it."}
|
|
75
|
+
</Text>)}
|
|
76
|
+
{noteDelivery(order) === 'not_sent' ? <Text testID={`order-note-not-sent-${order.id}`} className="text-foreground">{NOTE_NOT_SENT}</Text> : null}
|
|
77
|
+
{extras.taxIds ? <Text testID={`order-tax-ids-not-sent-${order.id}`} className="text-foreground">{TAX_IDS_NOT_SENT}</Text> : null}
|
|
78
|
+
{extras.meta ? <Text testID={`order-meta-not-sent-${order.id}`} className="text-foreground">{META_NOT_SENT}</Text> : null}
|
|
79
|
+
{extras.skuLineIds.length ? <Text testID={`order-sku-not-sent-${order.id}`} className="text-foreground">
|
|
80
|
+
{((ids) => `The edited ${ids.length === 1 ? 'SKU' : 'SKUs'} of ${order.lines.filter((line) => ids.includes(line.id)).map((line) => line.name).join(', ')} couldn't be sent to the store.`)(extras.skuLineIds)}
|
|
81
|
+
</Text> : null}
|
|
82
|
+
{children}
|
|
83
|
+
{knownWarnings(order.warnings).filter((warning) => warning.code !== 'register_session_unknown').map((warning, index) => <View key={index} className="border-l-4 border-warning pl-2"><Text className="text-foreground">
|
|
84
|
+
{warning.code === 'insufficient_stock'
|
|
85
|
+
? `${warning.quantity} sold without stock: ${order.lines.find((line) => line.variantId === warning.variantId)?.name}`
|
|
86
|
+
: warning.code === 'tax_rate_mismatch'
|
|
87
|
+
? `Tax at ${(warning.ratePpm / 10000).toLocaleString(undefined, { maximumFractionDigits: 4 })}%: store ${formatMoney({ amount: warning.serverMinor, currency: order.currency })} vs POS ${formatMoney({ amount: warning.expectedMinor, currency: order.currency })}`
|
|
88
|
+
: warning.code === 'customer_ignored'
|
|
89
|
+
? `The online store didn't recognise the customer on this sale, so it was saved as a guest sale. Customer id: ${warning.customerId}.`
|
|
90
|
+
: warning.code === 'figures_mismatch'
|
|
91
|
+
? `The online store worked out different figures for this sale. ${warning.fields.map(({ field, tillMinor, serverMinor }) => `${FIGURE_LABELS.get(field) ?? field}: till ${formatMoney({ amount: tillMinor, currency: order.currency })}, store ${formatMoney({ amount: serverMinor, currency: order.currency })}.`).join(' ')}`
|
|
92
|
+
: warning.code === 'line_figures_mismatch'
|
|
93
|
+
? ((n) => `The online store worked out different figures for ${n === 1 ? 'one line' : `${n} lines`} of this sale.`)(new Set(warning.lines.map((line) => line.lineId)).size)
|
|
94
|
+
: warning.bridgeMinor !== undefined
|
|
95
|
+
? `Store calculated ${formatMoney({ amount: warning.serverMinor, currency: order.currency })}; a rounding line of ${warning.bridgeMinor > 0 ? '+' : ''}${formatMoney({ amount: warning.bridgeMinor, currency: order.currency })} brought it to ${formatMoney({ amount: warning.expectedMinor, currency: order.currency })}`
|
|
96
|
+
: `Store total ${formatMoney({ amount: warning.serverMinor, currency: order.currency })} vs POS ${formatMoney({ amount: warning.expectedMinor, currency: order.currency })}`}
|
|
97
|
+
</Text></View>)}
|
|
98
|
+
</>;
|
|
99
|
+
}
|
|
100
|
+
|
|
42
101
|
/** The "Needs attention" (when not empty) and "Recent" orders, lifted from medusapos/app's orders screen (ADR-052).
|
|
43
102
|
* `onRetry` is the outbox's `requeue`; `formatDate` replaces the app's date util; `footer` is the app's own content
|
|
44
103
|
* (medusapos: the feedback link). The router and session redirect stay in the app. `stuck` is the outbox's
|
|
@@ -51,6 +110,8 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
51
110
|
history?: OrderHistoryRow[];
|
|
52
111
|
onOpen?: (row: PosOrder | OrderHistoryRow) => void;
|
|
53
112
|
}) {
|
|
113
|
+
const formatMoney = useFormatMoney();
|
|
114
|
+
const hintId = useId();
|
|
54
115
|
const retrying = useRef(new Set<string>());
|
|
55
116
|
const [retryingIds, setRetryingIds] = useState(new Set<string>());
|
|
56
117
|
const [expanded, setExpanded] = useState(new Set<string>());
|
|
@@ -69,7 +130,7 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
69
130
|
return bTime - aTime;
|
|
70
131
|
});
|
|
71
132
|
return <ScrollView className="flex-1 bg-background p-4">
|
|
72
|
-
{[{ title: 'Needs attention', orders: needsAttention(orders, { stuckCommandIds: stuck?.commandIds }) }, { title: 'Recent', orders: recent }].filter((section) => section.title === 'Recent' || section.orders.length > 0).map((section) => (
|
|
133
|
+
{[{ title: 'Needs attention', orders: needsAttention(orders, { stuckCommandIds: stuck?.commandIds }) }, { title: 'Recent', orders: recent }].filter((section) => section.title === 'Recent' || section.orders.length > 0).map((section, sectionIndex) => (
|
|
73
134
|
<View key={section.title} className="mb-6 gap-3">
|
|
74
135
|
<Text accessibilityRole="header" className="text-xl font-semibold text-foreground">{section.title}</Text>
|
|
75
136
|
{section.title === 'Recent' && orders.length === 0 && shown.length === 0 ? <Text testID="orders-empty" className="text-muted-foreground">No sales yet. Completed sales appear here.</Text> : null}
|
|
@@ -87,13 +148,14 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
87
148
|
</View>;
|
|
88
149
|
}
|
|
89
150
|
const count = order.lines.reduce((sum, line) => sum + line.quantity, 0);
|
|
151
|
+
const refundDueMinor = refundDueOf(order);
|
|
90
152
|
const key = `${section.title}:${order.id}`;
|
|
91
153
|
const isExpanded = expanded.has(key);
|
|
92
|
-
// The order's own stuck entry: its clock and latest reason, not the earliest across all stuck orders.
|
|
93
|
-
const stuckEntry = order.syncStatus === 'pending' ? stuck?.orders.find((entry) => entry.commandId === order.commandId) : undefined;
|
|
94
154
|
return (
|
|
95
155
|
<View key={order.id} className="gap-1 rounded-md border border-border bg-card p-3">
|
|
96
|
-
|
|
156
|
+
{/* RN-web drops accessibilityHint; aria-describedby carries it on web. */}
|
|
157
|
+
<Text id={`${hintId}-${sectionIndex}-${order.id}`} className="hidden">Shows the items and payments of this sale</Text>
|
|
158
|
+
<Pressable accessibilityRole="button" aria-expanded={isExpanded} aria-describedby={`${hintId}-${sectionIndex}-${order.id}`}
|
|
97
159
|
accessibilityHint="Shows the items and payments of this sale" testID={`order-row-${order.id}`} className="gap-1"
|
|
98
160
|
onPress={() => setExpanded((current) => {
|
|
99
161
|
const next = new Set(current);
|
|
@@ -113,24 +175,13 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
113
175
|
{order.payments.map((payment) => <Text key={payment.id} className="text-muted-foreground">
|
|
114
176
|
{`${payment.method === 'cash' ? 'Cash' : 'Card terminal'} ${formatMoney({ amount: payment.amountMinor, currency: order.currency })}${payment.reference ? ` · ${payment.reference}` : ''}`}
|
|
115
177
|
</Text>)}
|
|
178
|
+
{refundDueMinor > 0 ? <Text testID={`order-refund-due-${order.id}`} className="text-foreground">
|
|
179
|
+
{`Refund due ${formatMoney({ amount: refundDueMinor, currency: order.currency })}`}</Text> : null}
|
|
116
180
|
{order.note ? <Text testID={`order-note-${order.id}`} className="text-foreground">{`Customer note: ${order.note}`}</Text> : null}
|
|
117
181
|
</View> : null}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
</Text> : null}
|
|
122
|
-
{/* The code's sentence alone: the cashier sees no error code and never the store's message. */}
|
|
123
|
-
{order.syncStatus === 'rejected' ? <Text className="text-destructive">{refusalSentence(order.error?.code)}</Text> : null}
|
|
124
|
-
{/* A late sale (ADR-032) needs no Retry of its own; a rejected one still gets its Retry below. */}
|
|
125
|
-
{order.lateSessionId !== undefined ? <Text className="text-foreground">Taken after the register closed. It is not in that register's closure.</Text> : null}
|
|
126
|
-
{order.localWarnings?.map((warning, index) => <Text key={index} className="text-foreground">
|
|
127
|
-
{warning.code === 'customer_omitted'
|
|
128
|
-
? `The customer's ${warning.field} couldn't be sent to the store, so the order isn't linked to them.`
|
|
129
|
-
: "The terminal's payment reference couldn't be kept; the payment is recorded without it."}
|
|
130
|
-
</Text>)}
|
|
131
|
-
{noteDelivery(order) === 'not_sent' ? <Text testID={`order-note-not-sent-${order.id}`} className="text-foreground">{NOTE_NOT_SENT}</Text> : null}
|
|
132
|
-
{/* Retry is offered only for a code the outbox resends (isRequeueable). */}
|
|
133
|
-
{section.title === 'Needs attention' && order.syncStatus === 'rejected' && isRequeueable(order.error?.code)
|
|
182
|
+
<OrderSyncNotices order={order} stuck={stuck}>
|
|
183
|
+
{/* Retry is offered only for an order the outbox resends (isRequeueableOrder). */}
|
|
184
|
+
{section.title === 'Needs attention' && isRequeueableOrder(order)
|
|
134
185
|
? <Pressable accessibilityRole="button" disabled={retryingIds.has(order.id)} onPress={async () => {
|
|
135
186
|
if (retrying.current.has(order.id)) return;
|
|
136
187
|
retrying.current.add(order.id);
|
|
@@ -142,19 +193,7 @@ export function OrdersList({ orders, onRetry, formatDate = defaultFormatDate, fo
|
|
|
142
193
|
}} className="rounded-md bg-primary px-4 py-2">
|
|
143
194
|
<Text className="text-center font-semibold text-primary-foreground">Retry</Text>
|
|
144
195
|
</Pressable> : null}
|
|
145
|
-
|
|
146
|
-
{warning.code === 'insufficient_stock'
|
|
147
|
-
? `${warning.quantity} sold without stock: ${order.lines.find((line) => line.variantId === warning.variantId)?.name}`
|
|
148
|
-
: warning.code === 'tax_rate_mismatch'
|
|
149
|
-
? `Tax at ${(warning.ratePpm / 10000).toLocaleString(undefined, { maximumFractionDigits: 4 })}%: store ${formatMoney({ amount: warning.serverMinor, currency: order.currency })} vs POS ${formatMoney({ amount: warning.expectedMinor, currency: order.currency })}`
|
|
150
|
-
: warning.code === 'customer_ignored'
|
|
151
|
-
? `The online store didn't recognise the customer on this sale, so it was saved as a guest sale. Customer id: ${warning.customerId}.`
|
|
152
|
-
: warning.code === 'figures_mismatch'
|
|
153
|
-
? `The online store worked out different figures for this sale. ${warning.fields.map(({ field, tillMinor, serverMinor }) => `${FIGURE_LABELS.get(field) ?? field}: till ${formatMoney({ amount: tillMinor, currency: order.currency })}, store ${formatMoney({ amount: serverMinor, currency: order.currency })}.`).join(' ')}`
|
|
154
|
-
: warning.bridgeMinor !== undefined
|
|
155
|
-
? `Store calculated ${formatMoney({ amount: warning.serverMinor, currency: order.currency })}; a rounding line of ${warning.bridgeMinor > 0 ? '+' : ''}${formatMoney({ amount: warning.bridgeMinor, currency: order.currency })} brought it to ${formatMoney({ amount: warning.expectedMinor, currency: order.currency })}`
|
|
156
|
-
: `Store total ${formatMoney({ amount: warning.serverMinor, currency: order.currency })} vs POS ${formatMoney({ amount: warning.expectedMinor, currency: order.currency })}`}
|
|
157
|
-
</Text></View>)}
|
|
196
|
+
</OrderSyncNotices>
|
|
158
197
|
</View>
|
|
159
198
|
);
|
|
160
199
|
})}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState, type JSX } from 'react';
|
|
2
2
|
import { ScrollView, useWindowDimensions, View } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { useFormatMoney } from '@tallyui/core';
|
|
4
4
|
import type { ParkedOrderSummary, useSale } from '@tallyui/pos';
|
|
5
5
|
import { errorText } from '../lib/error-text';
|
|
6
6
|
import { Button } from '../ui/button';
|
|
@@ -24,6 +24,7 @@ export interface ParkedSalesProps {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export function ParkedSales({ sale, parked, onDiscard, onPark, onResume, currency, open, onOpenChange, hour12 }: ParkedSalesProps): JSX.Element {
|
|
27
|
+
const formatMoney = useFormatMoney();
|
|
27
28
|
const { height: windowHeight } = useWindowDimensions();
|
|
28
29
|
const maxHeight = Math.max(280, windowHeight - 64);
|
|
29
30
|
const [confirming, setConfirming] = useState<string | null>(null);
|
package/src/sale/price-form.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useState, type JSX } from 'react';
|
|
2
2
|
import { Pressable, Text, TextInput, View } from 'react-native';
|
|
3
|
-
import {
|
|
3
|
+
import { useFormatMoney, useMoneyFormat, minorUnitDigits, moneyFromDecimalString, normalizeMoneyText, type MoneyFormat } from '@tallyui/core';
|
|
4
4
|
|
|
5
5
|
/** The cashier's entry as integer minor units of `currency` (0 allowed), or the inline error to show. */
|
|
6
|
-
export function parsePrice(text: string, currency: string): number | string {
|
|
7
|
-
const raw = text.trim();
|
|
8
|
-
const trimmed = raw.split(',').length === 2 ? raw.replace(',', '.') : raw;
|
|
6
|
+
export function parsePrice(text: string, currency: string, format?: MoneyFormat): number | string {
|
|
7
|
+
const raw = normalizeMoneyText(text, format).trim();
|
|
8
|
+
const trimmed = !format?.decimalSeparator && !format?.thousandSeparator && raw.split(',').length === 2 ? raw.replace(',', '.') : raw;
|
|
9
9
|
if (!trimmed) return 'Enter a price.';
|
|
10
10
|
if (!/^-?\d+(\.\d+)?$/.test(trimmed)) return 'Enter a number.';
|
|
11
11
|
if (Number(trimmed) < 0) return 'Enter a price of 0 or more.';
|
|
@@ -44,6 +44,8 @@ export function PriceForm({ lineName, currency, currentMinor, onApply, onClose,
|
|
|
44
44
|
/** Percentages off the current price, as v2's price-keypad keys; the first three valid ones (0 < n ≤ 100) are drawn. */
|
|
45
45
|
quickDiscounts?: readonly number[];
|
|
46
46
|
}): JSX.Element {
|
|
47
|
+
const formatMoney = useFormatMoney();
|
|
48
|
+
const format = useMoneyFormat();
|
|
47
49
|
const [text, setText] = useState('');
|
|
48
50
|
const [reason, setReason] = useState('');
|
|
49
51
|
const [error, setError] = useState<string | null>(null);
|
|
@@ -54,7 +56,7 @@ export function PriceForm({ lineName, currency, currentMinor, onApply, onClose,
|
|
|
54
56
|
const current = formatMoney({ amount: currentMinor, currency });
|
|
55
57
|
const draft = percent === undefined ? undefined : lessPercent(currentMinor, percent);
|
|
56
58
|
function apply() {
|
|
57
|
-
const parsed = draft ?? parsePrice(text, currency);
|
|
59
|
+
const parsed = draft ?? parsePrice(text, currency, format);
|
|
58
60
|
const refused = typeof parsed === 'string' ? parsed : onApply(parsed, reason.trim() || undefined);
|
|
59
61
|
setError(refused);
|
|
60
62
|
if (refused === null) onClose();
|