@tallyui/components 3.18.0 → 3.19.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 +460 -34
- package/dist/index.js +3632 -1898
- package/package.json +9 -9
- package/src/cart/cart-columns.tsx +42 -4
- package/src/cart/cart-line.tsx +42 -18
- package/src/cart/cart-note-input.tsx +10 -2
- package/src/cart/index.ts +1 -1
- package/src/customer/customer-select.tsx +21 -3
- package/src/index.ts +27 -0
- 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/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 +44 -8
- 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/tax/index.ts +1 -0
- package/src/tax/tax-based-on.tsx +196 -0
- 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 +20 -8
- 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/switch/index.tsx +18 -7
- package/src/ui/textarea/index.tsx +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { View } from 'react-native';
|
|
2
|
+
import { IconButton } from '../ui/icon-button';
|
|
3
|
+
import { ScanIcon } from '../ui/icon/scan-icon';
|
|
4
|
+
import { Text } from '../ui/text';
|
|
5
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip';
|
|
6
|
+
|
|
7
|
+
export interface CameraScanButtonProps {
|
|
8
|
+
/** The camera scanner is showing: the button then closes it. */
|
|
9
|
+
open: boolean;
|
|
10
|
+
onPress: () => void;
|
|
11
|
+
testID?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Opens and closes the camera scanner panel (v2 pos/products/camera-scan-button.tsx). */
|
|
15
|
+
export function CameraScanButton({ open, onPress, testID = 'camera-scan-button' }: CameraScanButtonProps) {
|
|
16
|
+
const label = open ? 'Close barcode scanner' : 'Scan barcode with camera';
|
|
17
|
+
return (
|
|
18
|
+
<Tooltip>
|
|
19
|
+
<TooltipTrigger asChild>
|
|
20
|
+
<IconButton variant={open ? 'secondary' : 'ghost'} testID={testID} accessibilityLabel={label}
|
|
21
|
+
accessibilityState={{ expanded: open }} onPress={onPress}>
|
|
22
|
+
<View className={open ? 'text-secondary-foreground' : 'text-foreground'}><ScanIcon size={20} /></View>
|
|
23
|
+
</IconButton>
|
|
24
|
+
</TooltipTrigger>
|
|
25
|
+
<TooltipContent><Text>{label}</Text></TooltipContent>
|
|
26
|
+
</Tooltip>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { useEffect, useRef, useState, type ComponentType } from 'react';
|
|
2
|
+
import { Platform, View, type AccessibilityActionEvent } from 'react-native';
|
|
3
|
+
import type { CameraDecoder, ViewfinderStatus } from '@tallyui/pos';
|
|
4
|
+
import { Button } from '../ui/button';
|
|
5
|
+
import { IconButton } from '../ui/icon-button';
|
|
6
|
+
import { GripIcon } from '../ui/icon/grip-icon';
|
|
7
|
+
import { XIcon } from '../ui/icon/x-icon';
|
|
8
|
+
import { Text } from '../ui/text';
|
|
9
|
+
import { VStack } from '../ui/vstack';
|
|
10
|
+
import { ScannerViewfinder, type ViewfinderProps } from './scanner-viewfinder';
|
|
11
|
+
|
|
12
|
+
// v2 pos/products/camera-scanner-panel.tsx:24-36.
|
|
13
|
+
export const FLASH_DURATION_MS = 350;
|
|
14
|
+
export const SCANNER_MIN_HEIGHT = 96;
|
|
15
|
+
export const SCANNER_MAX_HEIGHT = 480;
|
|
16
|
+
export const SCANNER_DEFAULT_HEIGHT = 176;
|
|
17
|
+
const STEP = 16;
|
|
18
|
+
const RESIZE_HANDLE_HEIGHT = 20;
|
|
19
|
+
const HANDLE_SLOP = (44 - RESIZE_HANDLE_HEIGHT) / 2;
|
|
20
|
+
|
|
21
|
+
const STATUS_TEXT: Record<ViewfinderStatus, string | undefined> = {
|
|
22
|
+
initializing: 'Starting camera…',
|
|
23
|
+
scanning: undefined,
|
|
24
|
+
'camera-denied': 'Camera access was denied — allow it in the browser settings and reopen the scanner.',
|
|
25
|
+
'camera-unavailable': 'Camera unavailable — check that no other app is using it.',
|
|
26
|
+
'decoder-error': 'Barcode decoding is failing — close the scanner and try again.',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const clampHeight = (height: number) => Math.min(SCANNER_MAX_HEIGHT, Math.max(SCANNER_MIN_HEIGHT, Math.round(height)));
|
|
30
|
+
|
|
31
|
+
export interface CameraScannerPanelProps {
|
|
32
|
+
onClose: () => void;
|
|
33
|
+
/** Panel height; clamped to [96, 480]. Default 176. The app persists it from onHeightChange. */
|
|
34
|
+
height?: number;
|
|
35
|
+
onHeightChange?: (height: number) => void;
|
|
36
|
+
/** Native permission flow; omit on web, where the browser asks on getUserMedia. */
|
|
37
|
+
permission?: { granted: boolean; request: () => void };
|
|
38
|
+
/** Default ScannerViewfinder; a native app passes its own (for example one built on expo-camera). */
|
|
39
|
+
viewfinder?: ComponentType<ViewfinderProps>;
|
|
40
|
+
decoder?: CameraDecoder;
|
|
41
|
+
/** v2's readiness note (storage, offline, sync starting): the app picks the copy; shown under the status. */
|
|
42
|
+
readiness?: string;
|
|
43
|
+
/** Each decode, passed straight to the viewfinder: the app passes its useCameraScan offer. */
|
|
44
|
+
onDetected: (code: string, symbology?: string) => void;
|
|
45
|
+
/** Called once on mount (the scanner opened): the app passes its useCameraScan reset. */
|
|
46
|
+
onOpen?: () => void;
|
|
47
|
+
/** The app's useCameraScan scanCount: each change after mount flashes the panel. */
|
|
48
|
+
scanCount?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The inline camera scanner (v2 camera-scanner-panel.tsx). It calls no pos hook: the app owns useCameraScan (and
|
|
52
|
+
* its ScanHubProvider) and passes { onDetected: camera.offer, onOpen: camera.reset, scanCount: camera.scanCount },
|
|
53
|
+
* so accepted decodes reach the app's useBarcodeScanner like any device scan. */
|
|
54
|
+
export function CameraScannerPanel({ onClose, height: heightProp = SCANNER_DEFAULT_HEIGHT, onHeightChange, permission,
|
|
55
|
+
viewfinder: Viewfinder = ScannerViewfinder, decoder, readiness, onDetected, onOpen, scanCount }: CameraScannerPanelProps) {
|
|
56
|
+
const [status, setStatus] = useState<ViewfinderStatus>('initializing');
|
|
57
|
+
const [height, setHeight] = useState(() => clampHeight(heightProp));
|
|
58
|
+
useEffect(() => { setHeight(clampHeight(heightProp)); }, [heightProp]);
|
|
59
|
+
const heightRef = useRef(height);
|
|
60
|
+
heightRef.current = height;
|
|
61
|
+
const onHeightChangeRef = useRef(onHeightChange);
|
|
62
|
+
onHeightChangeRef.current = onHeightChange;
|
|
63
|
+
|
|
64
|
+
// Opening the scanner mounts the panel: a code scanned before it was closed may be scanned again at once.
|
|
65
|
+
const onOpenRef = useRef(onOpen);
|
|
66
|
+
onOpenRef.current = onOpen;
|
|
67
|
+
useEffect(() => { onOpenRef.current?.(); }, []);
|
|
68
|
+
|
|
69
|
+
// Each scanCount change after mount (re)starts the flash; the value at mount never flashes.
|
|
70
|
+
const [flashing, setFlashing] = useState(false);
|
|
71
|
+
const seenCount = useRef(scanCount);
|
|
72
|
+
const flashTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (scanCount === seenCount.current) return;
|
|
75
|
+
seenCount.current = scanCount;
|
|
76
|
+
if (flashTimer.current !== undefined) clearTimeout(flashTimer.current);
|
|
77
|
+
setFlashing(true);
|
|
78
|
+
flashTimer.current = setTimeout(() => { flashTimer.current = undefined; setFlashing(false); }, FLASH_DURATION_MS);
|
|
79
|
+
}, [scanCount]);
|
|
80
|
+
useEffect(() => () => { if (flashTimer.current !== undefined) clearTimeout(flashTimer.current); }, []);
|
|
81
|
+
|
|
82
|
+
const adjust = (delta: number) => {
|
|
83
|
+
const next = clampHeight(heightRef.current + delta);
|
|
84
|
+
setHeight(next);
|
|
85
|
+
onHeightChangeRef.current?.(next);
|
|
86
|
+
};
|
|
87
|
+
const onAccessibilityAction = ({ nativeEvent }: AccessibilityActionEvent) => {
|
|
88
|
+
if (nativeEvent.actionName === 'increment') adjust(STEP);
|
|
89
|
+
else if (nativeEvent.actionName === 'decrement') adjust(-STEP);
|
|
90
|
+
};
|
|
91
|
+
// Web pointer drag: the height follows the pointer and is reported once, when the drag ends.
|
|
92
|
+
const dragCleanup = useRef<(() => void) | undefined>(undefined);
|
|
93
|
+
useEffect(() => () => dragCleanup.current?.(), []);
|
|
94
|
+
const startDrag = (startY: number) => {
|
|
95
|
+
if (Platform.OS !== 'web' || typeof window === 'undefined') return;
|
|
96
|
+
dragCleanup.current?.();
|
|
97
|
+
const startHeight = heightRef.current;
|
|
98
|
+
let last = startHeight;
|
|
99
|
+
const move = (event: PointerEvent) => {
|
|
100
|
+
last = clampHeight(startHeight + event.clientY - startY);
|
|
101
|
+
setHeight(last);
|
|
102
|
+
};
|
|
103
|
+
const end = () => {
|
|
104
|
+
dragCleanup.current?.();
|
|
105
|
+
if (last !== startHeight) onHeightChangeRef.current?.(last);
|
|
106
|
+
};
|
|
107
|
+
window.addEventListener('pointermove', move);
|
|
108
|
+
window.addEventListener('pointerup', end);
|
|
109
|
+
window.addEventListener('pointercancel', end);
|
|
110
|
+
dragCleanup.current = () => {
|
|
111
|
+
dragCleanup.current = undefined;
|
|
112
|
+
window.removeEventListener('pointermove', move);
|
|
113
|
+
window.removeEventListener('pointerup', end);
|
|
114
|
+
window.removeEventListener('pointercancel', end);
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
if (permission && !permission.granted) {
|
|
119
|
+
return (
|
|
120
|
+
<VStack space="md" className="border-border items-center rounded-md border p-4" testID="camera-permission-request">
|
|
121
|
+
<Text className="text-center text-sm">Camera access is needed to scan barcodes.</Text>
|
|
122
|
+
<Button onPress={permission.request}><Text>Allow camera</Text></Button>
|
|
123
|
+
</VStack>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const statusText = STATUS_TEXT[status];
|
|
128
|
+
return (
|
|
129
|
+
<View>
|
|
130
|
+
<View className="relative w-full overflow-hidden rounded-md bg-black" style={{ height }} testID="camera-scanner-panel">
|
|
131
|
+
<Viewfinder onDetected={onDetected} onStatus={setStatus} decoder={decoder} />
|
|
132
|
+
{flashing ? <View className="border-success pointer-events-none absolute inset-0 rounded-md border-4"
|
|
133
|
+
testID="camera-scanner-flash" /> : null}
|
|
134
|
+
<View className="absolute top-1 right-1">
|
|
135
|
+
<IconButton size="sm" onPress={onClose} accessibilityLabel="Close barcode scanner" testID="camera-scanner-close">
|
|
136
|
+
<View className="text-white"><XIcon size={16} /></View>
|
|
137
|
+
</IconButton>
|
|
138
|
+
</View>
|
|
139
|
+
{statusText || readiness ? (
|
|
140
|
+
<View className="absolute inset-x-0 bottom-0 gap-1 bg-black/60 p-2">
|
|
141
|
+
{statusText ? <Text className="text-center text-xs text-white" testID="camera-scanner-status">{statusText}</Text> : null}
|
|
142
|
+
{readiness ? <Text className="text-center text-xs text-white/80" testID="camera-scanner-readiness">{readiness}</Text> : null}
|
|
143
|
+
</View>
|
|
144
|
+
) : null}
|
|
145
|
+
</View>
|
|
146
|
+
<View className="web:cursor-ns-resize web:hover:opacity-100 items-center justify-center opacity-40"
|
|
147
|
+
style={{ height: RESIZE_HANDLE_HEIGHT }} hitSlop={{ top: HANDLE_SLOP, bottom: HANDLE_SLOP }}
|
|
148
|
+
accessible accessibilityRole="adjustable" accessibilityLabel="Drag to resize the camera view"
|
|
149
|
+
accessibilityValue={{ min: SCANNER_MIN_HEIGHT, max: SCANNER_MAX_HEIGHT, now: height }}
|
|
150
|
+
accessibilityActions={[{ name: 'increment' }, { name: 'decrement' }]} onAccessibilityAction={onAccessibilityAction}
|
|
151
|
+
onPointerDown={(event) => startDrag(event.nativeEvent.clientY)} testID="camera-scanner-resize-handle">
|
|
152
|
+
<View className="-my-0.5 text-foreground"><GripIcon size={16} /></View>
|
|
153
|
+
</View>
|
|
154
|
+
</View>
|
|
155
|
+
);
|
|
156
|
+
}
|
package/src/product/index.ts
CHANGED
|
@@ -11,4 +11,9 @@ export { ProductList, type ProductListProps } from './product-list';
|
|
|
11
11
|
export { CategoryNav, type CategoryNavProps, type CategoryItem } from './category-nav';
|
|
12
12
|
export { ProductVariantPicker, type ProductVariantPickerProps, type VariantOption } from './product-variant-picker';
|
|
13
13
|
export { InCartBadge, type InCartBadgeProps } from './in-cart-badge';
|
|
14
|
+
export { VariationPicker, type VariationPickerProps } from './variation-picker';
|
|
14
15
|
export { CategoryTile, type CategoryTileProps } from './category-tile';
|
|
16
|
+
export { CameraScanButton, type CameraScanButtonProps } from './camera-scan-button';
|
|
17
|
+
export { CameraScannerPanel, FLASH_DURATION_MS, SCANNER_MIN_HEIGHT, SCANNER_MAX_HEIGHT, SCANNER_DEFAULT_HEIGHT,
|
|
18
|
+
type CameraScannerPanelProps } from './camera-scanner-panel';
|
|
19
|
+
export { ScannerViewfinder, type ViewfinderProps } from './scanner-viewfinder';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { Platform, View } from 'react-native';
|
|
3
|
+
import { CAMERA_CONSTRAINTS, cameraErrorStatus, nativeBarcodeDetector, startDecodeLoop,
|
|
4
|
+
type CameraDecoder, type ViewfinderStatus } from '@tallyui/pos';
|
|
5
|
+
|
|
6
|
+
export interface ViewfinderProps {
|
|
7
|
+
onDetected: (code: string, symbology?: string) => void;
|
|
8
|
+
onStatus: (status: ViewfinderStatus) => void;
|
|
9
|
+
/** Defaults to the BarcodeDetector global where it exists; an app may pass a ponyfill with the same detect. */
|
|
10
|
+
decoder?: CameraDecoder;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function canUseCamera(): boolean {
|
|
14
|
+
return Platform.OS === 'web' && typeof navigator !== 'undefined' && typeof navigator.mediaDevices?.getUserMedia === 'function';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function stopTracks(stream: MediaStream) {
|
|
18
|
+
for (const track of stream.getTracks()) track.stop();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The web camera view: getUserMedia into a <video>, decoded by startDecodeLoop (v2 scanner-viewfinder.web.tsx).
|
|
22
|
+
* Elsewhere it reports 'camera-unavailable' and renders an empty view; a native app passes its own viewfinder
|
|
23
|
+
* (for example one built on expo-camera) to CameraScannerPanel. */
|
|
24
|
+
export function ScannerViewfinder(props: ViewfinderProps) {
|
|
25
|
+
const latest = useRef(props);
|
|
26
|
+
latest.current = props;
|
|
27
|
+
const videoRef = useRef<HTMLVideoElement | null>(null);
|
|
28
|
+
const web = canUseCamera();
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!web) {
|
|
32
|
+
latest.current.onStatus('camera-unavailable');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
let cancelled = false;
|
|
36
|
+
let stream: MediaStream | undefined;
|
|
37
|
+
let loop: { stop(): void } | undefined;
|
|
38
|
+
latest.current.onStatus('initializing');
|
|
39
|
+
navigator.mediaDevices.getUserMedia(CAMERA_CONSTRAINTS).then((media) => {
|
|
40
|
+
// Unmounted before the camera answered: release the late stream at once.
|
|
41
|
+
if (cancelled) {
|
|
42
|
+
stopTracks(media);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
stream = media;
|
|
46
|
+
const video = videoRef.current;
|
|
47
|
+
if (video) video.srcObject = media;
|
|
48
|
+
const decoder = latest.current.decoder ?? nativeBarcodeDetector();
|
|
49
|
+
if (!decoder) {
|
|
50
|
+
latest.current.onStatus('decoder-error');
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
latest.current.onStatus('scanning');
|
|
54
|
+
loop = startDecodeLoop({
|
|
55
|
+
decoder,
|
|
56
|
+
source: video,
|
|
57
|
+
onDetected: (code, symbology) => latest.current.onDetected(code, symbology),
|
|
58
|
+
onStatus: (status) => latest.current.onStatus(status),
|
|
59
|
+
});
|
|
60
|
+
}, (error: unknown) => {
|
|
61
|
+
if (!cancelled) latest.current.onStatus(cameraErrorStatus(error));
|
|
62
|
+
});
|
|
63
|
+
return () => {
|
|
64
|
+
cancelled = true;
|
|
65
|
+
loop?.stop();
|
|
66
|
+
if (stream) stopTracks(stream);
|
|
67
|
+
};
|
|
68
|
+
}, [web]);
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<View className="h-full w-full" testID="scanner-viewfinder">
|
|
72
|
+
{web ? <video ref={videoRef} autoPlay playsInline muted
|
|
73
|
+
style={{ width: '100%', height: '100%', objectFit: 'cover' }} /> : null}
|
|
74
|
+
</View>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Port of WCPOS v2 (monorepo next) packages/core/src/screens/main/pos/products/variations-popover/ (variations.tsx,
|
|
2
|
+
// buttons.tsx, select.tsx, stock-status.tsx): one option per attribute group, the match's stock, and Add; MIT, WCPOS.
|
|
3
|
+
import { useMemo, useState } from 'react';
|
|
4
|
+
import { Pressable, ScrollView, View } from 'react-native';
|
|
5
|
+
import type { StockLevel, VariantOptionGroup, VariantSummary } from '@tallyui/core';
|
|
6
|
+
import { disabledOptions, matchVariant, variantPriceLabel } from '@tallyui/pos';
|
|
7
|
+
import { cn } from '@tallyui/theme';
|
|
8
|
+
import { Button } from '../ui/button';
|
|
9
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select';
|
|
10
|
+
import { Text } from '../ui/text';
|
|
11
|
+
|
|
12
|
+
export interface VariationPickerProps {
|
|
13
|
+
/** The product name. */
|
|
14
|
+
title: string;
|
|
15
|
+
groups: VariantOptionGroup[];
|
|
16
|
+
variants: VariantSummary[];
|
|
17
|
+
currency: string;
|
|
18
|
+
/** Called with the matched variant and the picks for the variant's "Any" groups (empty when it has none). */
|
|
19
|
+
onAdd: (variant: VariantSummary, anyPicks: Record<string, string>) => void | Promise<void>;
|
|
20
|
+
/** Stock refuses Add when the variant is out of stock and this is true (v2 preventOverselling). Default false. */
|
|
21
|
+
preventOverselling?: boolean;
|
|
22
|
+
testID?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// v2 shows buttons when a group's values total fewer than this many characters, a Select otherwise.
|
|
26
|
+
const CHIP_CHARACTERS = 15;
|
|
27
|
+
|
|
28
|
+
// ProductStockBadge's label vocabulary; v2 shows nothing for stock it does not track.
|
|
29
|
+
function stockLabel({ status, quantity }: StockLevel): string | null {
|
|
30
|
+
if (status === 'out_of_stock') return 'Out of Stock';
|
|
31
|
+
if (status === 'backorder') return 'On Backorder';
|
|
32
|
+
if (status === 'in_stock' && quantity != null) return `In Stock (${quantity})`;
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* v2's variations popover body: the cashier picks one value per option group (values no variant allows are
|
|
38
|
+
* dimmed), sees the matched variant's stock, and presses Add; a full match never adds on its own.
|
|
39
|
+
*/
|
|
40
|
+
export function VariationPicker({ title, groups, variants, currency, onAdd, preventOverselling = false,
|
|
41
|
+
testID = 'variation-popover' }: VariationPickerProps) {
|
|
42
|
+
const [picks, setPicks] = useState<Record<string, string>>({});
|
|
43
|
+
const [adding, setAdding] = useState(false);
|
|
44
|
+
const disabled = useMemo(() => disabledOptions(variants, groups, picks), [variants, groups, picks]);
|
|
45
|
+
const complete = groups.every(({ name }) => picks[name] !== undefined);
|
|
46
|
+
const variant = complete ? matchVariant(variants, groups, picks) : undefined;
|
|
47
|
+
const stock = variant ? stockLabel(variant.stock) : null;
|
|
48
|
+
const price = variant ? variantPriceLabel(variant, currency) : undefined;
|
|
49
|
+
const refused = preventOverselling && variant?.stock.status === 'out_of_stock';
|
|
50
|
+
|
|
51
|
+
const pick = (name: string, value: string, toggle: boolean) => {
|
|
52
|
+
if (disabled[name]?.has(value)) return;
|
|
53
|
+
setPicks((current) => {
|
|
54
|
+
const { [name]: previous, ...rest } = current;
|
|
55
|
+
return toggle && previous === value ? rest : { ...rest, [name]: value };
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const add = async () => {
|
|
60
|
+
if (!variant || adding || refused) return;
|
|
61
|
+
const anyPicks = Object.fromEntries(groups.filter(({ name }) =>
|
|
62
|
+
!Object.prototype.hasOwnProperty.call(variant.options ?? {}, name)).map(({ name }) => [name, picks[name]]));
|
|
63
|
+
const pending = onAdd(variant, anyPicks);
|
|
64
|
+
if (!(pending instanceof Promise)) return;
|
|
65
|
+
setAdding(true);
|
|
66
|
+
try {
|
|
67
|
+
await pending;
|
|
68
|
+
} finally {
|
|
69
|
+
setAdding(false);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<View testID={testID} className="min-h-0 min-w-52 shrink gap-3">
|
|
75
|
+
<Text className="text-sm font-semibold">{title}</Text>
|
|
76
|
+
<ScrollView testID="variation-popover-options" className="shrink grow-0" contentContainerClassName="gap-3">
|
|
77
|
+
{groups.map(({ name, values }) => (
|
|
78
|
+
<View key={name} className="gap-1.5">
|
|
79
|
+
<Text className="text-xs font-semibold text-muted-foreground">{name}</Text>
|
|
80
|
+
{values.join('').length < CHIP_CHARACTERS ? (
|
|
81
|
+
<View className="flex-row flex-wrap gap-2">
|
|
82
|
+
{values.map((value) => {
|
|
83
|
+
const active = picks[name] === value;
|
|
84
|
+
const off = disabled[name]?.has(value) ?? false;
|
|
85
|
+
return (
|
|
86
|
+
<Pressable key={value} testID={`variation-option-${value}`} accessibilityRole="button"
|
|
87
|
+
accessibilityState={{ selected: active, disabled: off }} disabled={off}
|
|
88
|
+
onPress={() => pick(name, value, true)}
|
|
89
|
+
className={cn('rounded-lg border px-3 py-1.5', active ? 'border-primary bg-primary/10' : 'border-border bg-card',
|
|
90
|
+
off && 'opacity-40')}>
|
|
91
|
+
<Text className={cn('text-sm font-medium', active ? 'text-primary' : 'text-foreground')}>{value}</Text>
|
|
92
|
+
</Pressable>
|
|
93
|
+
);
|
|
94
|
+
})}
|
|
95
|
+
</View>
|
|
96
|
+
) : (
|
|
97
|
+
<Select value={picks[name] ? { value: picks[name], label: picks[name] } : undefined}
|
|
98
|
+
onValueChange={(option) => { if (option) pick(name, option.value, false); }}>
|
|
99
|
+
<SelectTrigger testID={`variation-select-${name}`} accessibilityLabel={name}>
|
|
100
|
+
<SelectValue placeholder="Select an option" className="text-sm text-foreground" />
|
|
101
|
+
</SelectTrigger>
|
|
102
|
+
<SelectContent>
|
|
103
|
+
{values.map((value) => (
|
|
104
|
+
<SelectItem key={value} value={value} label={value} disabled={disabled[name]?.has(value)}
|
|
105
|
+
className={cn(disabled[name]?.has(value) && 'opacity-40')}>
|
|
106
|
+
<Text className="text-sm">{value}</Text>
|
|
107
|
+
</SelectItem>
|
|
108
|
+
))}
|
|
109
|
+
</SelectContent>
|
|
110
|
+
</Select>
|
|
111
|
+
)}
|
|
112
|
+
</View>
|
|
113
|
+
))}
|
|
114
|
+
</ScrollView>
|
|
115
|
+
{complete && !variant ? (
|
|
116
|
+
<Text testID="variation-popover-unavailable" className="text-sm text-muted-foreground">Variant not available</Text>
|
|
117
|
+
) : null}
|
|
118
|
+
{variant ? (
|
|
119
|
+
<View className="gap-2">
|
|
120
|
+
{stock ? <Text testID="variation-popover-stock-badge" className="self-start text-xs font-semibold">{stock}</Text> : null}
|
|
121
|
+
<Button testID="variation-popover-add-to-cart" disabled={adding || refused} onPress={() => { void add(); }}>
|
|
122
|
+
<Text>{price ? `Add to Cart: ${price}` : 'Add to Cart'}</Text>
|
|
123
|
+
</Button>
|
|
124
|
+
</View>
|
|
125
|
+
) : null}
|
|
126
|
+
</View>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
@@ -4,7 +4,7 @@ import type { useRegisterSession } from '@tallyui/pos';
|
|
|
4
4
|
|
|
5
5
|
import { cn } from '@tallyui/theme';
|
|
6
6
|
import { useShell } from '../shell/shell-context';
|
|
7
|
-
import { Avatar } from '../ui/avatar';
|
|
7
|
+
import { Avatar, avatarInitials } from '../ui/avatar';
|
|
8
8
|
import { Badge } from '../ui/badge';
|
|
9
9
|
import { Button } from '../ui/button';
|
|
10
10
|
import { HStack } from '../ui/hstack';
|
|
@@ -37,10 +37,6 @@ export interface RegisterBarProps {
|
|
|
37
37
|
className?: string;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
function initials(name: string): string {
|
|
41
|
-
return name.split(/\s+/).filter(Boolean).slice(0, 2).map((word) => word[0].toUpperCase()).join('');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
40
|
/**
|
|
45
41
|
* The till's one status bar: the menu (phones), the place (the store, and the register for
|
|
46
42
|
* multi-register stores), one status pill (LEDGER 48), the sync state, the button that opens the
|
|
@@ -123,7 +119,7 @@ export function RegisterBar({
|
|
|
123
119
|
disabled={!cashier.onPress}
|
|
124
120
|
onPress={cashier.onPress}
|
|
125
121
|
>
|
|
126
|
-
<Avatar size="sm" fallback={
|
|
122
|
+
<Avatar size="sm" fallback={avatarInitials(cashier.name)} />
|
|
127
123
|
</Pressable>
|
|
128
124
|
)}
|
|
129
125
|
</HStack>
|
|
@@ -11,6 +11,7 @@ import { XIcon } from '../ui/icon/x-icon';
|
|
|
11
11
|
import { Text } from '../ui/text';
|
|
12
12
|
import { MovementSheet } from './movement-sheet';
|
|
13
13
|
import { tenderLabel } from './register-count';
|
|
14
|
+
import { RegisterSideFooter, RegisterSideHeader, RegisterSideHero, RegisterSideLedger } from './register-side-sheet';
|
|
14
15
|
|
|
15
16
|
/** Margin kept clear above and below the dialog (LEDGER-free layout fix, 2026-09-28 review):
|
|
16
17
|
* a phone-height viewport must never let the panel's top go under the page header. */
|
|
@@ -32,19 +33,34 @@ export interface RegisterPanelProps {
|
|
|
32
33
|
*/
|
|
33
34
|
reapprove?: (needed: ApprovalNeeded) => Promise<{ approvedBy: string; approval: string } | null>;
|
|
34
35
|
className?: string;
|
|
36
|
+
/**
|
|
37
|
+
* `'dialog'` (the default) is the centred panel; `'side'` is WCPOS v2's right-hand sheet (Paul,
|
|
38
|
+
* 2026-10-30: "Cashier and Register modal come from the right"): the cash expected, session
|
|
39
|
+
* sales, the drawer ledger, Other tenders, and a Print X-report / Close register footer.
|
|
40
|
+
*/
|
|
41
|
+
presentation?: 'dialog' | 'side';
|
|
42
|
+
/** `'side'`: the store's name, first in the header line. */
|
|
43
|
+
storeName?: string;
|
|
44
|
+
/** `'side'`: builds and prints the X-report (`buildXReportDocument`); a rejection shows "Printing failed. Try again.". Without it, there is no button. */
|
|
45
|
+
onPrintXReport?: () => void | Promise<void>;
|
|
46
|
+
/** `'side'`: the clock for the session's age; defaults to `new Date()`. */
|
|
47
|
+
now?: () => Date;
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
/**
|
|
38
51
|
* The register's drawer panel: expected figures, cash movements with Undo, and Close register.
|
|
39
52
|
* Port provenance (ADR-032 amendment 1): WCPOS `next` `3b5331b5c` `register-panel.tsx` (LEDGER
|
|
40
|
-
* 54, 56, 58).
|
|
53
|
+
* 54, 56, 58); `presentation="side"` follows WCPOS v2's side sheet (TallyUI#716).
|
|
41
54
|
*
|
|
42
55
|
* Leaves out (registers job c2 or a later job, per `useRegisterSession`'s own "Not ported"
|
|
43
56
|
* note): refused-movement Retry and "Unsynced" (no outbox here to refuse a movement), the
|
|
44
|
-
*
|
|
57
|
+
* Z, reprint and the print sheet, the last-closure badge, and the Reports deep link.
|
|
45
58
|
*/
|
|
46
|
-
export function RegisterPanel({
|
|
47
|
-
|
|
59
|
+
export function RegisterPanel({
|
|
60
|
+
register, currency, registerName, open, onOpenChange, reapprove, className, presentation = 'dialog', storeName, onPrintXReport, now,
|
|
61
|
+
}: RegisterPanelProps) {
|
|
62
|
+
const { session, expected, salesCount, blind, movements, lastClosure, approvalNeeded, actions, terms } = register;
|
|
63
|
+
const side = presentation === 'side';
|
|
48
64
|
const [reapproving, setReapproving] = useState(false);
|
|
49
65
|
const otherTenders = Object.entries(expected).filter(([method, amount]) => method !== 'cash' && amount !== 0);
|
|
50
66
|
const { height: windowHeight } = useWindowDimensions();
|
|
@@ -67,25 +83,36 @@ export function RegisterPanel({ register, currency, registerName, open, onOpenCh
|
|
|
67
83
|
const activeMovements = movements.filter(
|
|
68
84
|
(row) => row.type !== 'void' && !row.voided_by && !movements.some((entry) => entry.voids === row.id),
|
|
69
85
|
);
|
|
86
|
+
const closeRegister = () =>
|
|
87
|
+
attempt(async () => {
|
|
88
|
+
await actions.startCounting();
|
|
89
|
+
onOpenChange(false);
|
|
90
|
+
});
|
|
91
|
+
// The side sheet is full height, so it needs no cap; its header and footer stay put, and only the body scrolls.
|
|
70
92
|
return (
|
|
71
93
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
72
94
|
<DialogContent
|
|
73
95
|
testID="register-panel"
|
|
96
|
+
side={side ? 'right' : 'center'}
|
|
74
97
|
className={`flex-col overflow-hidden ${className ?? ''}`}
|
|
75
|
-
style={{ maxHeight }}
|
|
98
|
+
style={side ? undefined : { maxHeight }}
|
|
76
99
|
>
|
|
77
100
|
{/* The heading stays visible; a phone-height viewport must never push it under the page
|
|
78
101
|
header (the Front desk review, 2026-09-28) — only the body below it scrolls. */}
|
|
79
102
|
<View className="flex-row items-center justify-between gap-2">
|
|
80
|
-
|
|
103
|
+
{side ? (
|
|
104
|
+
<RegisterSideHeader session={session} registerName={registerName} storeName={storeName} now={now} />
|
|
105
|
+
) : (
|
|
106
|
+
<DialogTitle testID="register-panel-amount">{registerName ?? 'Register'}</DialogTitle>
|
|
107
|
+
)}
|
|
81
108
|
<DialogClose asChild>
|
|
82
109
|
<IconButton variant="ghost" size="sm" testID="register-panel-dismiss" accessibilityLabel="Close panel">
|
|
83
110
|
<XIcon size={16} />
|
|
84
111
|
</IconButton>
|
|
85
112
|
</DialogClose>
|
|
86
113
|
</View>
|
|
87
|
-
<Text testID="register-panel-sales-count">{salesCount} sale{salesCount === 1 ? '' : 's'} this session</Text>
|
|
88
|
-
<ScrollView testID="register-panel-body" className="flex-1" contentContainerClassName=
|
|
114
|
+
{!side && <Text testID="register-panel-sales-count">{salesCount} sale{salesCount === 1 ? '' : 's'} this session</Text>}
|
|
115
|
+
<ScrollView testID="register-panel-body" className="flex-1" contentContainerClassName={side ? 'gap-4' : 'gap-3'}>
|
|
89
116
|
{/* Here, not in RegisterCount: a refused closure's session is already closed, and the
|
|
90
117
|
panel is what still shows once a closure exists. Title and button: WCPOS v2's
|
|
91
118
|
`register.approval_needed` and `register.approve` (monorepo core.json:2974-2976). */}
|
|
@@ -119,6 +146,7 @@ export function RegisterPanel({ register, currency, registerName, open, onOpenCh
|
|
|
119
146
|
)}
|
|
120
147
|
</View>
|
|
121
148
|
)}
|
|
149
|
+
{side && <RegisterSideHero terms={terms} blind={blind} currency={currency} salesCount={salesCount} />}
|
|
122
150
|
<View className="flex-row gap-2">
|
|
123
151
|
{(['paid_in', 'paid_out', 'no_sale'] as const).map((type) => (
|
|
124
152
|
<Button
|
|
@@ -133,7 +161,8 @@ export function RegisterPanel({ register, currency, registerName, open, onOpenCh
|
|
|
133
161
|
</Button>
|
|
134
162
|
))}
|
|
135
163
|
</View>
|
|
136
|
-
{
|
|
164
|
+
{side && <RegisterSideLedger terms={terms} blind={blind} currency={currency} />}
|
|
165
|
+
{!side && !blind && (
|
|
137
166
|
<View testID="register-panel-expected" className="gap-1">
|
|
138
167
|
<Text className="text-muted-foreground text-sm font-semibold">Expected in the drawer</Text>
|
|
139
168
|
{Object.entries(expected).filter(([method]) => method === 'cash').map(([method, amount]) => (
|
|
@@ -144,7 +173,7 @@ export function RegisterPanel({ register, currency, registerName, open, onOpenCh
|
|
|
144
173
|
))}
|
|
145
174
|
</View>
|
|
146
175
|
)}
|
|
147
|
-
{!blind && otherTenders.length > 0 && (
|
|
176
|
+
{!side && !blind && otherTenders.length > 0 && (
|
|
148
177
|
<View testID="register-panel-other-tenders" className="gap-1">
|
|
149
178
|
<Text className="text-muted-foreground text-sm font-semibold">Other tenders</Text>
|
|
150
179
|
{otherTenders.map(([method, amount]) => (
|
|
@@ -182,21 +211,15 @@ export function RegisterPanel({ register, currency, registerName, open, onOpenCh
|
|
|
182
211
|
</View>
|
|
183
212
|
))}
|
|
184
213
|
{!!error && <Text className="text-destructive">{error}</Text>}
|
|
185
|
-
|
|
186
|
-
testID="register-panel-close"
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
onPress={() =>
|
|
191
|
-
attempt(async () => {
|
|
192
|
-
await actions.startCounting();
|
|
193
|
-
onOpenChange(false);
|
|
194
|
-
})
|
|
195
|
-
}
|
|
196
|
-
>
|
|
197
|
-
<Text>Close register</Text>
|
|
198
|
-
</Button>
|
|
214
|
+
{!side && (
|
|
215
|
+
<Button testID="register-panel-close" disabled={!session} variant="outline" className="min-h-14" onPress={closeRegister}>
|
|
216
|
+
<Text>Close register</Text>
|
|
217
|
+
</Button>
|
|
218
|
+
)}
|
|
199
219
|
</ScrollView>
|
|
220
|
+
{side && (
|
|
221
|
+
<RegisterSideFooter canPrint={!blind && !!session} onPrintXReport={onPrintXReport} canClose={!!session} onClose={closeRegister} />
|
|
222
|
+
)}
|
|
200
223
|
{movementType && (
|
|
201
224
|
<MovementSheet
|
|
202
225
|
register={register}
|