@tallyui/components 4.2.0 → 5.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tallyui/components",
3
- "version": "4.2.0",
3
+ "version": "5.1.0",
4
4
  "type": "module",
5
5
  "description": "Universal POS UI components for Tally UI",
6
6
  "main": "./dist/index.js",
@@ -19,6 +19,7 @@
19
19
  "src",
20
20
  "!src/**/*.test.ts",
21
21
  "!src/**/*.test.tsx",
22
+ "!src/**/*.test-d.ts",
22
23
  "!src/**/__tests__/**"
23
24
  ],
24
25
  "license": "MIT",
@@ -28,9 +29,9 @@
28
29
  "directory": "packages/components"
29
30
  },
30
31
  "peerDependencies": {
31
- "@tallyui/core": "^4.2.0",
32
- "@tallyui/primitives": "^4.2.0",
33
- "@tallyui/theme": "^4.2.0",
32
+ "@tallyui/core": "^5.1.0",
33
+ "@tallyui/primitives": "^5.1.0",
34
+ "@tallyui/theme": "^5.1.0",
34
35
  "react": ">=18",
35
36
  "react-native": ">=0.74",
36
37
  "react-native-svg": ">=15"
@@ -39,13 +40,13 @@
39
40
  "class-variance-authority": "^0.7.1",
40
41
  "i18next": "^26.7.1",
41
42
  "react-i18next": "^17.1.12",
42
- "@tallyui/pos": "4.2.0"
43
+ "@tallyui/pos": "5.1.0"
43
44
  },
44
45
  "devDependencies": {
45
- "@tallyui/connector-medusa": "4.2.0",
46
- "@tallyui/connector-vendure": "4.2.0",
47
- "@tallyui/connector-woocommerce": "4.2.0",
48
- "@tallyui/mock-api": "4.2.0",
46
+ "@tallyui/connector-medusa": "5.1.0",
47
+ "@tallyui/connector-vendure": "5.1.0",
48
+ "@tallyui/connector-woocommerce": "5.1.0",
49
+ "@tallyui/mock-api": "5.1.0",
49
50
  "@types/react": ">=18",
50
51
  "react": "^19.2.4",
51
52
  "react-native-svg": "15.12.1",
@@ -55,7 +55,7 @@ export function CartColumnsForm({ value = {}, onChange, showReset = false, class
55
55
  };
56
56
  return (
57
57
  <View className={cn('gap-1', className)} {...viewProps}>
58
- <Text role="heading" className="pb-1 text-base font-semibold">{t('common.columns')}</Text>
58
+ <Text role="heading" aria-level={4} className="pb-1 text-base font-semibold">{t('common.columns')}</Text>
59
59
  {order.map((id, at) => {
60
60
  const label = t(LABELS[id]);
61
61
  const show = value[id]?.show ?? CART_COLUMN_DEFAULT_SHOWN[id];
@@ -1,8 +1,8 @@
1
- // Ported from WCPOS v2 packages/core/src/screens/main/pos/cart/cells/line-strip.tsx (press to open, Remove flies the row off; no swipe or hover yet) and cells/edit-cart-item-button.tsx; MIT, WCPOS.
1
+ // Ported from WCPOS v2 packages/core/src/screens/main/pos/cart/cells/line-strip.tsx (press to open, Remove flies the row off; the Total peeks on hover; no swipe yet) and cells/edit-cart-item-button.tsx; MIT, WCPOS.
2
2
  import { useRef, useState, type JSX, type ReactNode } from 'react';
3
3
  import { Animated, Platform, Pressable, View } from 'react-native';
4
4
  import { Button, Text } from '../ui';
5
- import { ARM, EASE_EXIT, PANEL_SLIDE_OUT } from '../lib/motion';
5
+ import { ARM, EASE_EXIT, PANEL_SLIDE_OUT, PEEK, PEEK_SPRING } from '../lib/motion';
6
6
  import { useReducedMotion } from '../lib/use-reduced-motion';
7
7
 
8
8
  /** A cart row with v2's hidden strip under it: pressing the row's Total slides the row left onto a solid Edit and Remove. */
@@ -18,11 +18,14 @@ export function CartLineStrip({ name, onEdit, onRemove, children }: {
18
18
  // The row is flying off or its removal is committing: nothing else may move it.
19
19
  const leaving = useRef(false);
20
20
  const [open, setOpen] = useState(false);
21
+ // `open` at event time: react-native-web binds a Pressable's hover-out listener at hover-in and keeps that closure (modules/useHover).
22
+ const opened = useRef(false);
21
23
  const [rowWidth, setRowWidth] = useState<number>();
22
24
  const [stripWidth, setStripWidth] = useState(0);
23
25
  const settle = (next: boolean) => {
24
26
  if (leaving.current) return;
25
27
  setOpen(next);
28
+ opened.current = next;
26
29
  const target = next ? -stripWidth : 0;
27
30
  if (reduced) offset.setValue(target);
28
31
  else Animated.spring(offset, { toValue: target, overshootClamping: true, useNativeDriver: Platform.OS !== 'web' }).start();
@@ -39,9 +42,19 @@ export function CartLineStrip({ name, onEdit, onRemove, children }: {
39
42
  settle(false);
40
43
  });
41
44
  };
45
+ // v2's peek: only a closed, staying row, and only with reduced motion known to be off.
46
+ const peek = (on: boolean) => {
47
+ if (opened.current || leaving.current || reduced) return;
48
+ if (on) Animated.spring(offset, { ...PEEK_SPRING, toValue: -PEEK, useNativeDriver: Platform.OS !== 'web' }).start();
49
+ else settle(false);
50
+ };
51
+ // A peek retargeted mid-close keeps the spring's velocity (SpringAnimation.start), so the bounce could swing past 0 and bare the strip's red at the left: never right of rest.
52
+ const shown = useRef(offset.interpolate({ inputRange: [-1, 0], outputRange: [-1, 0], extrapolateRight: 'clamp' })).current;
42
53
  const wrapTotal = (content: ReactNode) => <Pressable testID="cart-line-total" accessibilityRole="button"
43
54
  accessibilityLabel={`Edit total of ${name}`} accessibilityState={{ expanded: open }} className="justify-center"
44
- onPress={() => settle(!open)}>{content}</Pressable>;
55
+ onPress={() => settle(!open)} onHoverIn={() => peek(true)} onHoverOut={() => peek(false)}>{content}
56
+ {/* v2's HOVER_REACH: past the bounce, so the Total never slides out from under a resting pointer; closed only, or it would take Edit's presses. */}
57
+ {open ? null : <View className="absolute inset-y-0 left-0" style={{ right: -PEEK * 2 }} />}</Pressable>;
45
58
  const block = 'h-auto min-w-16 rounded-none px-5';
46
59
  return <View testID="cart-line-row" className="relative overflow-hidden" onLayout={(event) => setRowWidth(event.nativeEvent.layout.width)}>
47
60
  <View testID="cart-line-strip" className="absolute inset-y-0 right-0 flex-row items-stretch justify-end bg-destructive"
@@ -54,6 +67,6 @@ export function CartLineStrip({ name, onEdit, onRemove, children }: {
54
67
  onPress={leave}><Text>Remove</Text></Button>
55
68
  </View>
56
69
  </View>
57
- <Animated.View className="bg-background" style={{ transform: [{ translateX: offset }] }}>{children(wrapTotal)}</Animated.View>
70
+ <Animated.View className="bg-background" style={{ transform: [{ translateX: shown }] }}>{children(wrapTotal)}</Animated.View>
58
71
  </View>;
59
72
  }
@@ -5,6 +5,7 @@ import { Platform, Pressable, ScrollView, StyleSheet, Text, View, type NativeScr
5
5
  import { CustomerServiceError, type Customer } from '@tallyui/core';
6
6
  import { Popover } from '@tallyui/primitives';
7
7
  import { cn } from '@tallyui/theme';
8
+ import { useT } from '../i18n';
8
9
  import { Avatar, avatarInitials, Input, UserIcon } from '../ui';
9
10
  import { MapPinIcon } from '../ui/icon/map-pin-icon';
10
11
  import { customerErrorText } from './customer-picker';
@@ -56,6 +57,9 @@ export function CustomerDropdown({ search, browse, selected, onSelect, onError,
56
57
  const canBrowse = browse !== undefined;
57
58
  const onErrorRef = useRef(onError);
58
59
  onErrorRef.current = onError;
60
+ const t = useT();
61
+ const tRef = useRef(t);
62
+ tRef.current = t;
59
63
  const chip = useRef<View>(null);
60
64
  const name = selected?.name ?? 'Guest';
61
65
  // The shown rows' paging: their generation (any newer first page makes older pages stale), query, last page loaded
@@ -80,7 +84,7 @@ export function CustomerDropdown({ search, browse, selected, onSelect, onError,
80
84
  p.done = results.length < PAGE_SIZE;
81
85
  } catch (error) {
82
86
  if (stale()) return;
83
- setError(customerErrorText(error));
87
+ setError(customerErrorText(error, tRef.current));
84
88
  if (!(error instanceof CustomerServiceError)) onErrorRef.current?.(error);
85
89
  }
86
90
  }, blank ? 0 : debounceMs);
@@ -106,7 +110,7 @@ export function CustomerDropdown({ search, browse, selected, onSelect, onError,
106
110
  if (!fresh.length) p.done = true;
107
111
  } catch (error) {
108
112
  if (paging.current.gen !== p.gen) return;
109
- setError(customerErrorText(error));
113
+ setError(customerErrorText(error, tRef.current));
110
114
  if (!(error instanceof CustomerServiceError)) onErrorRef.current?.(error);
111
115
  } finally { p.busy = false; }
112
116
  };
@@ -53,7 +53,7 @@ export function CustomerEditor({ customer, create, update, onSaved, onCancel, on
53
53
  if (disabled) return;
54
54
  const trimmed: CustomerEditValues = { ...values, firstName: values.firstName.trim(), lastName: values.lastName.trim(),
55
55
  email: values.email.trim(), phone: values.phone.trim(), company: values.company?.trim() };
56
- const error = customerEmailError(trimmed.email);
56
+ const error = customerEmailError(trimmed.email, t);
57
57
  if (error) return setEmailError(error);
58
58
  let call: Promise<Customer> | undefined;
59
59
  if (!customer) call = create?.(toCustomerInput(trimmed));
@@ -69,7 +69,7 @@ export function CustomerEditor({ customer, create, update, onSaved, onCancel, on
69
69
  const result = await call;
70
70
  if (mounted.current) onSaved(result);
71
71
  } catch (failure) {
72
- if (mounted.current) setSaveError(customerErrorText(failure));
72
+ if (mounted.current) setSaveError(customerErrorText(failure, t));
73
73
  } finally {
74
74
  if (mounted.current) setSaving(false);
75
75
  }
@@ -6,6 +6,8 @@ import { CustomerCard } from './customer-card';
6
6
  import { CustomerSelect } from './customer-select';
7
7
  import { GuestGlyph } from './customer-dropdown';
8
8
  import { CustomerForm, type CustomerFormValues } from './customer-form';
9
+ import type { TFunction } from 'i18next';
10
+ import { useT } from '../i18n';
9
11
 
10
12
  export interface CustomerPickerProps {
11
13
  /** The connector's searchCustomers, bound to its context by the app. */
@@ -34,23 +36,24 @@ const EMAIL_MAX = 254;
34
36
  /** A simple shape, not RFC 5322: one `@`, a non-empty local part, a domain with text either side of a dot, no whitespace or NUL. */
35
37
  const EMAIL_SHAPE = /^[^\s@\u0000]+@[^\s@\u0000]+\.[^\s@\u0000]+$/u;
36
38
 
37
- /** The cashier's text for an email the store's shape check would refuse, else undefined (CustomerPicker's and CustomerEditor's). */
38
- export function customerEmailError(email: string): string | undefined {
39
- return email.length > EMAIL_MAX || !EMAIL_SHAPE.test(email) ? `Enter a valid email address (up to ${EMAIL_MAX} characters)` : undefined;
39
+ /** The cashier's text, read from the `customers.invalid_email` catalogue key, for an email the store's shape check would refuse, else undefined (CustomerPicker's and CustomerEditor's). */
40
+ export function customerEmailError(email: string, t: TFunction): string | undefined {
41
+ return email.length > EMAIL_MAX || !EMAIL_SHAPE.test(email) ? t('customers.invalid_email', { max: EMAIL_MAX }) : undefined;
40
42
  }
41
43
 
42
- /** The cashier's text for a customer search or create error (CustomerPicker's and CustomerDropdown's). */
43
- export function customerErrorText(error: unknown): string {
44
+ /** The cashier's text for a customer search or create error, read from the `customers.error_*` catalogue keys; an `invalid` error keeps the store's own reason (CustomerPicker's, CustomerEditor's and CustomerDropdown's). */
45
+ export function customerErrorText(error: unknown, t: TFunction): string {
44
46
  if (error instanceof CustomerServiceError) {
45
- return error.code === 'network' ? "Couldn't reach the store. Try again."
46
- : error.code === 'server' ? "The store couldn't do that. Try again." : error.message;
47
+ return error.code === 'network' ? t('customers.error_network')
48
+ : error.code === 'server' ? t('customers.error_server') : error.message;
47
49
  }
48
- return error instanceof ConnectorUnauthorizedError && error.code === 'unauthorized' ? 'Sign in again to continue.'
49
- : error instanceof ConnectorUnauthorizedError && error.code === 'forbidden' ? "Your account isn't allowed to do this on this store. Ask the store owner."
50
- : 'Something went wrong. Try again.';
50
+ return error instanceof ConnectorUnauthorizedError && error.code === 'unauthorized' ? t('customers.error_unauthorized')
51
+ : error instanceof ConnectorUnauthorizedError && error.code === 'forbidden' ? t('customers.error_forbidden')
52
+ : t('customers.error_unknown');
51
53
  }
52
54
 
53
55
  export function CustomerPicker({ search, create, selected, onSelect, onError, online, debounceMs = 250, className, testID = 'customer-picker-search', showAvatar = false, withGuest = false }: CustomerPickerProps) {
56
+ const t = useT();
54
57
  const [query, setQuery] = useState('');
55
58
  const [customers, setCustomers] = useState<Customer[]>([]);
56
59
  const [error, setError] = useState<string | null>(null);
@@ -65,7 +68,7 @@ export function CustomerPicker({ search, create, selected, onSelect, onError, on
65
68
  useEffect(() => { mounted.current = true; return () => { mounted.current = false; }; }, []);
66
69
 
67
70
  function handleError(error: unknown) {
68
- setError(customerErrorText(error));
71
+ setError(customerErrorText(error, t));
69
72
  if (!(error instanceof CustomerServiceError)) onError?.(error);
70
73
  }
71
74
 
@@ -89,7 +92,7 @@ export function CustomerPicker({ search, create, selected, onSelect, onError, on
89
92
  const email = values.email.trim();
90
93
  if (!online || !create || creating || !email) return;
91
94
  // The till sends this email in order.create, whose shape check refuses one over 254 characters: refuse it here instead.
92
- const emailError = customerEmailError(email);
95
+ const emailError = customerEmailError(email, t);
93
96
  if (emailError) return setError(emailError);
94
97
  setCreating(true);
95
98
  setError(null);
@@ -43,6 +43,12 @@
43
43
  "customer_display.refund_due": "Refund due",
44
44
  "customers.add_customer": "Add Customer",
45
45
  "customers.clear_search": "Clear search",
46
+ "customers.error_forbidden": "Your account isn't allowed to do this on this store. Ask the store owner.",
47
+ "customers.error_network": "Couldn't reach the store. Try again.",
48
+ "customers.error_server": "The store couldn't do that. Try again.",
49
+ "customers.error_unauthorized": "Sign in again to continue.",
50
+ "customers.error_unknown": "Something went wrong. Try again.",
51
+ "customers.invalid_email": "Enter a valid email address (up to {max} characters)",
46
52
  "customers.no_customers_yet": "No customers yet",
47
53
  "customers.no_customers_yet_description": "Customers you add, and anyone who buys from you, will appear here.",
48
54
  "customers.nothing_matches_search": "No customers match your search",
@@ -61,6 +67,7 @@
61
67
  "pos_cart.use_different_address": "Use a different address",
62
68
  "pos_checkout.after_this_payment": "After this payment · {amount}",
63
69
  "pos_checkout.amount_each": "{amount} each",
70
+ "pos_checkout.cancel_and_void": "Cancel and void",
64
71
  "pos_checkout.cancel_payment": "Cancel payment",
65
72
  "pos_checkout.cancel_payment_question": "Cancel this payment?",
66
73
  "pos_checkout.cancelled": "Cancelled",
@@ -69,6 +76,7 @@
69
76
  "pos_checkout.exact_amount": "Exact {amount}",
70
77
  "pos_checkout.full_balance": "Full balance {amount}",
71
78
  "pos_checkout.full_balance_label": "Full balance",
79
+ "pos_checkout.keep_taking_payment": "Keep taking payment",
72
80
  "pos_checkout.n_of_units": "{n} of {total}",
73
81
  "pos_checkout.n_of_ways": "{n} of {ways}",
74
82
  "pos_checkout.n_ways": "{ways} ways",
@@ -81,14 +89,16 @@
81
89
  "pos_checkout.paid_of_total": "{paid} of {total} paid",
82
90
  "pos_checkout.part_payment_left": "Part payment · {left} left after this",
83
91
  "pos_checkout.pick_amount_due": "This payment is {amount} for the picked items",
92
+ "pos_checkout.pick_rounds_to_nothing": "Cash cannot pay for these items: they round to nothing. Take them by another method.",
84
93
  "pos_checkout.payments_tab": "Payments",
85
94
  "pos_checkout.pick_fewer": "One fewer {name}",
86
95
  "pos_checkout.pick_more": "One more {name}",
87
96
  "pos_checkout.refund_due": "Refund due {amount}",
97
+ "pos_checkout.refund_on_method": "Refund {amount} on {title} from the order",
88
98
  "pos_checkout.remaining": "Remaining",
89
- "pos_checkout.remove_payment": "Remove payment",
90
99
  "pos_checkout.return_cash": "Return {amount} cash to the customer",
91
100
  "pos_checkout.rounded_from": "Rounded from {amount}",
101
+ "pos_checkout.rounding": "Rounding",
92
102
  "pos_checkout.split": "Split",
93
103
  "pos_checkout.split_the_rest": "Split the rest",
94
104
  "pos_checkout.status_authorized": "Authorized",
@@ -96,11 +106,21 @@
96
106
  "pos_checkout.status_failed": "Failed",
97
107
  "pos_checkout.status_pending": "Pending",
98
108
  "pos_checkout.status_voided": "Voided",
99
- "pos_checkout.store_holds_payment": "The store already holds this sale's payment. Remove the {amount} taken here to finish.",
109
+ "pos_checkout.store_holds_park": "The store already holds this sale's payment. The {amount} taken here can only be refunded from the order, so this sale can only be parked.",
110
+ "pos_checkout.store_holds_payment": "The store already holds this sale's payment. Cancel the {amount} taken here to finish.",
100
111
  "pos_checkout.take_amount_in": "Take {amount} in {method}",
101
112
  "pos_checkout.tendered": "Tendered",
102
113
  "pos_checkout.this_payment": "This payment",
103
114
  "pos_checkout.to_pay": "To pay",
115
+ "pos_checkout.void_later_cash_first": "Void the later cash payment first.",
116
+ "pos_checkout.cash_not_payable": "Cash cannot pay that exactly. Take {below} or {above}.",
117
+ "pos_checkout.cash_not_payable_above": "Cash cannot pay that exactly. Take {above}.",
118
+ "pos_checkout.cash_not_payable_typed": "Cash cannot pay that amount: take a whole number of the smallest cash step.",
119
+ "pos_checkout.cash_waits_for_payment": "Cash cannot pay that amount while another payment is in progress: finish that payment first.",
120
+ "pos_checkout.cash_pick_limit": "Too many rounded cash payments on this sale: take the rest as one payment.",
121
+ "pos_checkout.cash_settle_limit": "Too many rounded cash payments on this sale: take the rest by another method.",
122
+ "pos_checkout.cash_settle_limit_void": "Too many rounded cash payments on this sale: void the {amount} cash payment, then take the rest again.",
123
+ "pos_checkout.cash_settle_limit_park": "Too many rounded cash payments on this sale, and the {amount} cash payment cannot be voided here, so this sale can only be parked.",
104
124
  "pos_checkout.void_on_method": "Void {amount} on {title}",
105
125
  "receipt.email_queued": "Receipt email queued",
106
126
  "receipt.email_sent": "Email sent",
package/src/index.ts CHANGED
@@ -172,6 +172,8 @@ export {
172
172
  type RefundFormValue,
173
173
  RefundModal,
174
174
  type RefundModalProps,
175
+ RefundNeedsAdminNotice,
176
+ type RefundNeedsAdminNoticeProps,
175
177
  OrderFilterBar,
176
178
  type OrderFilterBarProps,
177
179
  type OrderFilterOption,
@@ -4,12 +4,16 @@ import { Pressable, Text, View, useWindowDimensions, type ViewProps } from 'reac
4
4
  import { cn } from '@tallyui/theme';
5
5
 
6
6
  export interface SettingsLayoutProps extends Omit<ViewProps, 'children'> {
7
- navSlot: ReactNode;
7
+ /** A function receives closeNav; call it from an item's onPress so a pick shows that section's content on a narrow screen. */
8
+ navSlot: ReactNode | ((nav: { closeNav: () => void }) => ReactNode);
8
9
  contentSlot: ReactNode;
9
10
  headerSlot?: ReactNode;
10
11
  layout?: 'split' | 'stacked';
11
12
  breakpoint?: number;
12
13
  className?: string;
14
+ /** Controls the stacked menu; absent means the layout keeps its own state. */
15
+ navOpen?: boolean;
16
+ onNavOpenChange?: (open: boolean) => void;
13
17
  }
14
18
 
15
19
  export function SettingsLayout({
@@ -19,11 +23,19 @@ export function SettingsLayout({
19
23
  layout: layoutProp,
20
24
  breakpoint = 768,
21
25
  className,
26
+ navOpen,
27
+ onNavOpenChange,
22
28
  ...viewProps
23
29
  }: SettingsLayoutProps) {
24
30
  const { width } = useWindowDimensions();
25
31
  const layout = layoutProp ?? (width >= breakpoint ? 'split' : 'stacked');
26
- const [showNav, setShowNav] = useState(false);
32
+ const [innerOpen, setInnerOpen] = useState(false);
33
+ const showNav = navOpen ?? innerOpen;
34
+ const setShowNav = (open: boolean) => {
35
+ if (navOpen === undefined) setInnerOpen(open);
36
+ onNavOpenChange?.(open);
37
+ };
38
+ const renderNav = (closeNav: () => void) => (typeof navSlot === 'function' ? navSlot({ closeNav }) : navSlot);
27
39
 
28
40
  return (
29
41
  <View className={cn('flex-1 bg-background', className)} {...viewProps}>
@@ -31,14 +43,14 @@ export function SettingsLayout({
31
43
 
32
44
  {layout === 'split' ? (
33
45
  <View className="flex-1 flex-row">
34
- <View className="w-64 border-r border-border">{navSlot}</View>
46
+ <View className="w-64 border-r border-border">{renderNav(() => {})}</View>
35
47
  <View className="flex-1">{contentSlot}</View>
36
48
  </View>
37
49
  ) : (
38
50
  <View className="flex-1">
39
51
  {showNav ? (
40
52
  <View className="flex-1">
41
- {navSlot}
53
+ {renderNav(() => setShowNav(false))}
42
54
  <Pressable onPress={() => setShowNav(false)} className="border-t border-border p-3">
43
55
  <Text className="text-center text-sm font-medium text-primary">Done</Text>
44
56
  </Pressable>
package/src/lib/motion.ts CHANGED
@@ -20,3 +20,9 @@ export const EASE = Easing.bezier(...EASE_POINTS);
20
20
  export const CROSSFADE = 200;
21
21
  // Reanimated 4.7.1 withTiming's default easing (src/animation/timing.ts:91), which v2's accordion chevron uses.
22
22
  export const TIMING_EASE = Easing.inOut(Easing.quad);
23
+ export const PLUS_WIDTH = 48; // WCPOS v2 packages/core/src/screens/main/pos/cart/tab-window.ts:3.
24
+ export const NEW_TAB_WIDTH = 112; // WCPOS v2 packages/core/src/screens/main/pos/cart/tab-window.ts:5: the + cell unfolded into "+ New".
25
+ // WCPOS v2 packages/core/src/screens/main/pos/cart/cells/line-strip.tsx:49 (PEEK): how far a hovered row's Total peeks.
26
+ export const PEEK = 16;
27
+ // WCPOS v2 packages/core/src/screens/main/pos/cart/cells/line-strip.tsx:54 (PEEK_SPRING): the peek's underdamped bounce.
28
+ export const PEEK_SPRING = { mass: 1, stiffness: 380, damping: 12 };
@@ -4,4 +4,5 @@ export { OrderList, type OrderListProps } from './order-list';
4
4
  export { OrderDetail, type OrderDetailProps, type OrderDetailLineItem, type OrderDetailTaxLine } from './order-detail';
5
5
  export { RefundForm, type RefundFormProps, type RefundFormValue } from './refund-form';
6
6
  export { RefundModal, type RefundModalProps } from './refund-modal';
7
+ export { RefundNeedsAdminNotice, type RefundNeedsAdminNoticeProps } from './refund-needs-admin-notice';
7
8
  export { OrderFilterBar, type OrderFilterBarProps, type OrderFilterOption, type PaymentMethodKind } from './order-filter-bar';
@@ -29,6 +29,10 @@ export interface RefundFormProps {
29
29
  refundedMinor?: number;
30
30
  /** Shipping still refundable, with tax; 0 or absent hides the shipping field. */
31
31
  refundableShippingMinor?: number;
32
+ /** The order's cash rounding, signed (ADR-094): the sum of its entries, or a WooCommerce order's Rounding fee. The refund that takes every line's whole remaining quantity returns it through adjustmentMinor; default 0. */
33
+ cashRoundingMinor?: number;
34
+ /** The cash method's rounding increment (PaymentRounding.incrementMinor). A cash refund that is not a multiple of it shows a one-line notice; the refund itself is not rounded. */
35
+ cashIncrementMinor?: number;
32
36
  /** The sale's payment method; omit for a cash sale, which always refunds in cash. */
33
37
  originalMethod?: { title: string; available: boolean };
34
38
  /** Each line's restock starting value; default true. */
@@ -53,7 +57,7 @@ function parseAmount(text: string, currency: string, signed = false, format?: Mo
53
57
  /** Ports WCPOS v2 form.tsx, monorepo main 5ac185b0e; the till never prices lines itself (priceRefund). */
54
58
  export function RefundForm({
55
59
  lines, refunds, currency, orderReference, orderTotalMinor, refundedMinor = 0,
56
- refundableShippingMinor = 0, originalMethod, defaultRestock = true, online = true,
60
+ refundableShippingMinor = 0, cashRoundingMinor = 0, cashIncrementMinor, originalMethod, defaultRestock = true, online = true,
57
61
  error, onConfirm, onCancel,
58
62
  }: RefundFormProps): JSX.Element {
59
63
  const formatMoney = useFormatMoney();
@@ -76,11 +80,14 @@ export function RefundForm({
76
80
  restock: restock[orderLineId] ?? defaultRestock,
77
81
  })).filter(({ quantity }) => quantity > 0);
78
82
  const priced = priceRefund(lines, refunds, request);
83
+ const emptiesLines = priced.lines.length > 0 && available.every(({ orderLineId, refundableQuantity }) => (request.find((line) => line.orderLineId === orderLineId)?.quantity ?? 0) === refundableQuantity);
84
+ const roundingShareMinor = emptiesLines ? cashRoundingMinor : 0;
79
85
  const shippingMinor = refundableShippingMinor > 0 ? parseAmount(shippingText, currency, false, format) : 0;
80
86
  const adjustmentMinor = parseAmount(adjustmentText, currency, true, format);
81
87
  const totalMinor = typeof shippingMinor === 'number' && typeof adjustmentMinor === 'number'
82
- ? priced.totalMinor + shippingMinor + adjustmentMinor : undefined;
88
+ ? priced.totalMinor + shippingMinor + adjustmentMinor + roundingShareMinor : undefined;
83
89
  const destination = originalMethod?.available ? (picked ?? 'original_method') : 'cash';
90
+ const cashStep = destination === 'cash' && Number.isInteger(cashIncrementMinor) && cashIncrementMinor! > 1 && typeof totalMinor === 'number' && totalMinor > 0 && totalMinor % cashIncrementMinor! !== 0;
84
91
  const invalid = typeof shippingMinor === 'string' ? shippingMinor
85
92
  : typeof adjustmentMinor === 'string' ? adjustmentMinor
86
93
  : shippingMinor > refundableShippingMinor ? `Shipping can be at most ${fmt(refundableShippingMinor)}.`
@@ -98,7 +105,7 @@ export function RefundForm({
98
105
  const value: RefundFormValue = {
99
106
  lines: priced.lines,
100
107
  shippingMinor: shippingMinor as number,
101
- adjustmentMinor: adjustmentMinor as number,
108
+ adjustmentMinor: (adjustmentMinor as number) + roundingShareMinor,
102
109
  totalMinor: totalMinor!,
103
110
  destination,
104
111
  reason: reason.trim(),
@@ -178,10 +185,16 @@ export function RefundForm({
178
185
  Original payment method refunds are unavailable for this order.
179
186
  </Text>}
180
187
  </View>}
188
+ {roundingShareMinor !== 0 && <View className="flex-row justify-between gap-2">
189
+ <Text>Rounding</Text><Text testID="refund-rounding">{fmt(roundingShareMinor)}</Text>
190
+ </View>}
181
191
  <View className="flex-row justify-between gap-2">
182
192
  <Text className="font-semibold">Refund Total</Text>
183
193
  <Text testID="refund-total" className="font-semibold">{fmt(totalMinor ?? 0)}</Text>
184
194
  </View>
195
+ {cashStep && <Text testID="refund-cash-step" className="text-muted-foreground">
196
+ {`Cash cannot pay ${fmt(totalMinor)} exactly. The smallest cash step is ${fmt(cashIncrementMinor!)}.`}
197
+ </Text>}
185
198
  </ScrollView>
186
199
  {online === false && <Text testID="refund-offline-reason" className="text-muted-foreground">Refunds need a connection</Text>}
187
200
  {invalid && online !== false && <Text testID="refund-invalid" className="text-muted-foreground">{invalid}</Text>}
@@ -0,0 +1,29 @@
1
+ import type { JSX } from 'react';
2
+ import { View } from 'react-native';
3
+ import { NEEDS_ADMIN_MESSAGE_MAX } from '@tallyui/core';
4
+ import { refundNeedsAdminLine } from '@tallyui/pos';
5
+ import { Button } from '../ui/button';
6
+ import { Text } from '../ui/text';
7
+
8
+ export type RefundNeedsAdminNoticeProps = {
9
+ /** The server's needs_admin reason: the outcome's `reason`, or a pending record's `error.data.reason`. */
10
+ reason: string;
11
+ /** The server's message: shown under the lead line as plain text, cut to NEEDS_ADMIN_MESSAGE_MAX. */
12
+ message?: string;
13
+ /** Resends the same refund envelope (same id); omit to hide the button. */
14
+ onCheckAgain?: () => void;
15
+ };
16
+
17
+ export function RefundNeedsAdminNotice({ reason, message, onCheckAgain }: RefundNeedsAdminNoticeProps): JSX.Element {
18
+ return <View>
19
+ <Text testID="refund-needs-admin-line" accessibilityLiveRegion="polite" className="text-destructive">
20
+ {refundNeedsAdminLine(reason)}
21
+ </Text>
22
+ {message ? <Text testID="refund-needs-admin-message" className="text-muted-foreground">
23
+ {message.slice(0, NEEDS_ADMIN_MESSAGE_MAX)}
24
+ </Text> : null}
25
+ {onCheckAgain ? <Button testID="refund-needs-admin-check-again" onPress={onCheckAgain}>
26
+ <Text>Check again</Text>
27
+ </Button> : null}
28
+ </View>;
29
+ }
@@ -144,7 +144,7 @@ async function saving(call: () => Promise<unknown>) {
144
144
  await call();
145
145
  } catch (e) {
146
146
  // The hook's own refusals keep their text (by name: components import no class from pos, ADR-064).
147
- const own = e instanceof Error && (e.name === 'RegisterApprovalRequiredError' || e.name === 'RegisterTenderInProgressError');
147
+ const own = e instanceof Error && (e.name === 'RegisterApprovalRequiredError' || e.name === 'RegisterTenderInProgressError' || e.name === 'RegisterSaleSavingError');
148
148
  throw own ? e : new StoreCallFailed(e);
149
149
  }
150
150
  }
@@ -62,8 +62,10 @@ function panelCells(card: SalesPanelId, figures: SalesFigures, money: (minor: nu
62
62
  };
63
63
  case 'taxes': return {
64
64
  head: ['Rate', 'Net', 'Tax', 'Gross'],
65
- rows: figures.taxes.map((row) => [taxLabel(row), row.netMinor === null ? UNKNOWN : money(row.netMinor), money(row.taxMinor),
65
+ rows: [...figures.taxes.map((row) => [taxLabel(row), row.netMinor === null ? UNKNOWN : money(row.netMinor), money(row.taxMinor),
66
66
  row.netMinor === null ? UNKNOWN : money(row.netMinor + row.taxMinor)]),
67
+ // Rounding is in gross, in no rate's net or tax: each column sums to its total.
68
+ ...(totals.roundingMinor !== 0 ? [['Rounding', '', '', money(totals.roundingMinor)]] : [])],
67
69
  total: ['Total', money(totals.netMinor), money(totals.taxMinor), money(totals.grossMinor)],
68
70
  };
69
71
  }
@@ -194,6 +194,7 @@ export function SalesCards({ figures, currency, onOpenCard, hide }: SalesCardsPr
194
194
  <StatGrid stats={[
195
195
  { label: 'Net', value: money(totals.netMinor) },
196
196
  { label: 'Tax', value: money(totals.taxMinor) },
197
+ ...(totals.roundingMinor !== 0 ? [{ label: 'Rounding', value: money(totals.roundingMinor) }] : []),
197
198
  { label: 'Gross', value: money(totals.grossMinor) },
198
199
  ]} />
199
200
  </>
@@ -0,0 +1,102 @@
1
+ /**
2
+ * WCPOS v2's cancel-payment view (use-tender-flow.ts): before anything is voided, each payment taken here is listed as cash to
3
+ * return, a void on its method, or a refund from the order. ADR-072 d3 (amended 2026-11-22): it ends on the cart, not in
4
+ * checkout as v2 does, because park() runs only from the cart and a refund-only leg's sale must still be able to park.
5
+ */
6
+ import { useState, type ComponentProps, type JSX } from 'react';
7
+ import { Pressable, Text, View } from 'react-native';
8
+ import { useFormatMoney, wireMethodOf, type PaymentMethodDescriptor } from '@tallyui/core';
9
+ import { canVoidLeg, cashVoidRefusal, countsTowardPaid, lockedRefundDueMinor, type Order, type useSale } from '@tallyui/pos';
10
+ import { useT } from '../i18n';
11
+ import { heldTillLeg } from './held-leg';
12
+ import { offeredMethods } from './offered-methods';
13
+ import { cancelLine, type TenderLedger } from './tender-ledger';
14
+ import { claimVoid, releaseVoid } from './void-in-flight';
15
+
16
+ type Leg = Order['payments'][number];
17
+ /** tender-pane.tsx's button. */
18
+ const button = 'min-h-11 justify-center rounded-md border border-border bg-card px-4 py-2';
19
+
20
+ /** The leg's offered descriptor, as TenderLedger's: its own id and its wire method both match. */
21
+ export function legDescriptor(offered: PaymentMethodDescriptor[], leg: Leg): PaymentMethodDescriptor | undefined {
22
+ return offered.find((method) => method.id === (leg.methodId ?? leg.method) && wireMethodOf(method) === leg.method);
23
+ }
24
+
25
+ /** TenderLedger's Cancel payment rule: the offered method can void the leg, and the leg is not held. Any other leg is refund-only. */
26
+ export function voidableLeg(order: Order, offered: PaymentMethodDescriptor[], leg: Leg): boolean {
27
+ const descriptor = legDescriptor(offered, leg);
28
+ return !!descriptor && canVoidLeg(leg, descriptor) && !heldTillLeg(order, leg);
29
+ }
30
+
31
+ /** The legs the view lists: taken here, still counting, and not held. */
32
+ export function cancelLegs(order: Order): Leg[] {
33
+ return order.payments.filter((leg) => countsTowardPaid(leg) && leg.takenAt !== undefined && !heldTillLeg(order, leg));
34
+ }
35
+
36
+ /** ADR-094 item 6: the first of `voidable` the core would refuse once every other voidable leg is voided, or undefined. Checked before any beforeVoid, so a refused void is never journalled. */
37
+ export function cancelRefusedLeg(order: Order, voidable: Leg[]): Leg | undefined {
38
+ const ids = new Set(voidable.map((leg) => leg.id));
39
+ const after = { ...order, payments: order.payments.map((leg) => (ids.has(leg.id) ? { ...leg, status: 'voided' as const } : leg)) };
40
+ return voidable.find((leg) => cashVoidRefusal(after, leg.id));
41
+ }
42
+
43
+ // Row 501: a net leg (with `tenderedMinor`) returns its `amountMinor`; a leg without `tenderedMinor` is netted as finalize nets it.
44
+ // Known limitation (ADR-072 d3, amended 2026-11-22): a pre-#1214 draft's gross leg, voided later, loses its change record.
45
+ export function cashToReturnMinor(order: Pick<Order, 'payments' | 'changeDueMinor' | 'totalMinor'>, leg: Leg): number {
46
+ if (leg.tenderedMinor !== undefined) return leg.amountMinor;
47
+ let change = order.changeDueMinor - Math.min(order.changeDueMinor, lockedRefundDueMinor(order));
48
+ for (const gross of order.payments.filter(countsTowardPaid).reverse()) {
49
+ if (gross.method !== 'cash' || gross.tenderedMinor !== undefined) continue;
50
+ const share = Math.min(change, gross.amountMinor);
51
+ if (gross.id === leg.id) return leg.amountMinor - share;
52
+ change -= share;
53
+ }
54
+ return leg.amountMinor;
55
+ }
56
+
57
+ export function CancelPaymentView({ sale, methods, onClose, beforeVoid, afterVoid }: { sale: ReturnType<typeof useSale>; methods?: PaymentMethodDescriptor[]; onClose: () => void;
58
+ /** Runs before each leg this view voids, as in TenderLedger. */
59
+ beforeVoid?: ComponentProps<typeof TenderLedger>['beforeVoid'];
60
+ /** Runs after each leg this view voids, as in TenderLedger. */
61
+ afterVoid?: ComponentProps<typeof TenderLedger>['afterVoid'] }): JSX.Element {
62
+ const formatMoney = useFormatMoney();
63
+ const t = useT();
64
+ const [voiding, setVoiding] = useState(false);
65
+ const { order } = sale;
66
+ const money = (minor: number) => formatMoney({ amount: minor, currency: order.currency }) ?? '';
67
+ const offered = offeredMethods(methods);
68
+ const legs = cancelLegs(order);
69
+ const voidable = legs.filter((leg) => voidableLeg(order, offered, leg));
70
+ const latestFirst = [...voidable].reverse();
71
+ // Void latest first (ADR-094 item 6: a later cash rounding is voided before the one it was computed against). A leg the core would refuse closes the view before any beforeVoid, and the pane shows the sale's error.
72
+ const confirm = async () => {
73
+ if (voiding) return;
74
+ const refused = cancelRefusedLeg(order, voidable); if (refused) { sale.voidTender(refused.id); return onClose(); }
75
+ if (!beforeVoid) { for (const leg of latestFirst) if (!sale.voidTender(leg.id)) return onClose(); sale.cancelTender(); return; }
76
+ setVoiding(true);
77
+ try {
78
+ for (const leg of latestFirst) {
79
+ if (!claimVoid(order.id, leg.id)) return onClose(); // #1271: a ledger is journalling this leg; the view closes and leaves the leg to it
80
+ let go = false;
81
+ try { go = (await beforeVoid(leg)) !== false; } catch { /* the leg stays; the host reports its own error */ } finally { releaseVoid(order.id, leg.id); }
82
+ if (!go) return onClose();
83
+ const voided = sale.voidTender(leg.id);
84
+ try { afterVoid?.(leg, voided); } catch { /* the host reports its own error */ }
85
+ if (!voided) return onClose();
86
+ }
87
+ sale.cancelTender();
88
+ } finally { setVoiding(false); }
89
+ };
90
+ return <View testID="tender-cancel-view" className="gap-3">
91
+ <Text className="text-lg font-semibold text-foreground">{t('pos_checkout.cancel_payment')}</Text>
92
+ {legs.map((leg) => <Text key={leg.id} testID={`tender-cancel-leg-${leg.id}`} className="text-foreground">{cancelLine(t, money, leg, legDescriptor(offered, leg), voidable.includes(leg), cashToReturnMinor(order, leg))}</Text>)}
93
+ <Pressable testID="tender-cancel-keep" accessibilityRole="button" onPress={onClose} disabled={voiding} className={`rounded-md bg-primary px-4 py-3${voiding ? ' opacity-50' : ''}`}>
94
+ <Text className="text-center font-semibold text-primary-foreground">{t('pos_checkout.keep_taking_payment')}</Text>
95
+ </Pressable>
96
+ {voidable.length > 0 ? <Pressable testID="tender-cancel-confirm" accessibilityRole="button" onPress={confirm} disabled={voiding} className={`${button}${voiding ? ' opacity-50' : ''}`}>
97
+ <Text className="text-center text-destructive">{t('pos_checkout.cancel_and_void')}</Text>
98
+ </Pressable> : <Pressable testID="tender-cancel-back" accessibilityRole="button" onPress={sale.cancelTender} className={button}>
99
+ <Text className="text-center text-foreground">{t('common.back')}</Text>
100
+ </Pressable>}
101
+ </View>;
102
+ }