@tallyui/components 4.1.0 → 5.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.
Files changed (40) hide show
  1. package/dist/index.d.ts +133 -50
  2. package/dist/index.js +2134 -1722
  3. package/package.json +10 -9
  4. package/src/cart/cart-columns-form.tsx +1 -1
  5. package/src/cart/cart-line-strip.tsx +17 -4
  6. package/src/customer/customer-dropdown.tsx +6 -2
  7. package/src/customer/customer-editor.tsx +2 -2
  8. package/src/customer/customer-picker.tsx +15 -12
  9. package/src/i18n/locales/en/components.json +23 -2
  10. package/src/index.ts +4 -2
  11. package/src/layout/settings-layout.tsx +16 -4
  12. package/src/lib/motion.ts +6 -0
  13. package/src/order/index.ts +1 -0
  14. package/src/order/refund-form.tsx +16 -3
  15. package/src/order/refund-needs-admin-notice.tsx +29 -0
  16. package/src/product/product-table.tsx +18 -7
  17. package/src/product/product-variant-picker.tsx +4 -0
  18. package/src/register/register-count.tsx +1 -1
  19. package/src/reports/card-panel.tsx +3 -1
  20. package/src/reports/cards.tsx +1 -0
  21. package/src/sale/cancel-payment-view.tsx +102 -0
  22. package/src/sale/cart.tsx +12 -8
  23. package/src/sale/catalogue-settings-form.tsx +2 -2
  24. package/src/sale/catalogue.tsx +57 -12
  25. package/src/sale/charge-form.tsx +21 -3
  26. package/src/sale/customer-display-screen.tsx +2 -1
  27. package/src/sale/index.ts +2 -2
  28. package/src/sale/open-sale-tabs.tsx +23 -3
  29. package/src/sale/orders-list.tsx +10 -3
  30. package/src/sale/receipt-sheet.tsx +28 -8
  31. package/src/sale/receipt.tsx +1 -0
  32. package/src/sale/sale-error-text.ts +10 -0
  33. package/src/sale/since-text.ts +6 -3
  34. package/src/sale/sync-status.tsx +10 -1
  35. package/src/sale/tender-ledger.tsx +54 -11
  36. package/src/sale/tender-pane.tsx +106 -38
  37. package/src/sale/tender.tsx +7 -5
  38. package/src/sale/void-in-flight.ts +19 -0
  39. package/src/ui/tabs/index.tsx +1 -1
  40. package/src/checkout/payment-types.test-d.ts +0 -28
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react';
2
2
  import { AccessibilityInfo, Platform, Text, View } from 'react-native';
3
3
  import type { SyncNotice } from '@tallyui/core';
4
4
  import type { OutboxState } from '@tallyui/pos';
5
+ import { needsAdminReasonOf } from '@tallyui/pos';
5
6
  import { sinceText } from './since-text';
6
7
 
7
8
  /**
@@ -50,6 +51,8 @@ const PULL_NOTICE_FALLBACK: PullNoticeText = {
50
51
  const BACKEND_MISSING = "Sales aren't reaching the online store. Keep selling: they're saved on this till and will send by themselves.";
51
52
  // The same line once an order is stuck, with the store missing or not; {time} is the real first failure or about the virtual since.
52
53
  const BACKEND_MISSING_SINCE = "Sales haven't reached the online store since {time}. Keep selling: they're saved on this till and will send by themselves.";
54
+ // #1280: parked sales keep retrying while a manager finishes them in the store admin.
55
+ const NEEDS_ADMIN_SALES = (n: number) => `${n === 1 ? '1 sale needs' : `${n} sales need`} a manager in the store admin. Keep selling: new sales are saved on this till.`;
53
56
  // The line instead when no sale waits but till updates do, and its "since" variant once registerState.stuck is set.
54
57
  const TILL_UPDATES_MISSING = "Till updates aren't reaching the online store. Keep selling: they're saved on this till and will send by themselves.";
55
58
  const TILL_UPDATES_MISSING_SINCE = "Till updates haven't reached the online store since {time}. Keep selling: they're saved on this till and will send by themselves.";
@@ -71,6 +74,8 @@ const REFUSED_DETAIL = 'Refused sales stay on this till under Needs attention, e
71
74
  // on reopen and both sentences name a reopen.
72
75
  const SALES_REFUSED = 'The online store refused the last send. This till will try again with the next sale, or when the app is reopened.';
73
76
  const TILL_UPDATES_REFUSED = 'The online store refused the last send. This till will try again with the next till update, or when the app is reopened.';
77
+ // The line below the sending or retrying line while the shown outbox's lastRetryReason is store_version_unknown.
78
+ const STORE_VERSION_UNKNOWN = "The online store didn't say which POS plugin version it runs.";
74
79
 
75
80
  const count = (n: number, noun: string) => `${n} ${noun}${n === 1 ? '' : 's'}`;
76
81
  // iOS has no live region (accessibilityLiveRegion is Android-only), so there each text is announced when it changes: never on
@@ -113,16 +118,18 @@ export function SyncStatus({ state, registerState, pluginName = 'the POS plugin'
113
118
  const label = [state.pending && count(state.pending, 'sale'),
114
119
  updates && count(updates, 'till update')].filter(Boolean).join(' and ') + ' waiting to sync';
115
120
  const { stuck } = state;
121
+ const needsAdmin = stuck?.orders.filter((entry) => needsAdminReasonOf(entry.reason) !== undefined).length ?? 0;
116
122
  const backendMissing = state.backendMissing ?? registerState?.backendMissing;
117
123
  const backendMissingText = state.pending === 0 && updates > 0 ? (registerState?.stuck
118
124
  ? TILL_UPDATES_MISSING_SINCE.replace('{time}', () => sinceText(registerState.stuck!)) : TILL_UPDATES_MISSING)
119
125
  : stuck ? BACKEND_MISSING_SINCE.replace('{time}', () => sinceText(stuck)) : BACKEND_MISSING;
120
126
  const upToDate = state.pending === 0 && updates === 0;
121
127
  // The sentence shows with the store missing, or once the waiting sales (with none waiting, the till updates) are stuck, then as
122
- // its "since" variant: the same words for any reason, and no reason code.
128
+ // its "since" variant, unless a parked sale needs a manager; no reason code is shown.
123
129
  // A refused batch from the outbox shown (the sales', whenever a sale waits) replaces that sentence: it is the store's latest
124
130
  // answer, and sending waits for that outbox's next command or start.
125
131
  const sentence = outbox.refused ? ` · ${outbox === state ? SALES_REFUSED : TILL_UPDATES_REFUSED}`
132
+ : outbox === state && needsAdmin > 0 ? ` · ${NEEDS_ADMIN_SALES(needsAdmin)}`
126
133
  : backendMissing || (state.pending === 0 && updates > 0 ? registerState?.stuck : stuck) ? ` · ${backendMissingText}` : '';
127
134
  // The live region holds only the substance (counts and the sentence), so it is announced when that changes and never as sending
128
135
  // or retrying flips or the countdown ticks: those are a short line of their own below it, outside any live region.
@@ -147,6 +154,8 @@ export function SyncStatus({ state, registerState, pluginName = 'the POS plugin'
147
154
  {oneDetail ? null : <Text className="px-4 pb-2 text-xs text-muted-foreground">{notice.detail}</Text>}
148
155
  </> : null}<Text accessibilityLabel={spoken} accessibilityLiveRegion="polite" className="px-4 py-2 text-xs text-muted-foreground">{spoken}</Text>
149
156
  {doing ? <Text className="px-4 pb-2 text-xs text-muted-foreground">{doing}</Text> : null}
157
+ {doing && outbox.lastRetryReason === 'store_version_unknown'
158
+ ? <Text className="px-4 pb-2 text-xs text-muted-foreground">{STORE_VERSION_UNKNOWN}</Text> : null}
150
159
  {refused ? <Text className="px-4 pb-2 text-xs text-muted-foreground">{REFUSED_DETAIL}</Text> : null}
151
160
  {oneDetail && notice ? <Text className="px-4 pb-2 text-xs text-muted-foreground">{notice.detail}</Text>
152
161
  : backendMissing ? <Text className="px-4 pb-2 text-xs text-muted-foreground">
@@ -6,12 +6,15 @@
6
6
  import { useState, type JSX } from 'react';
7
7
  import { Pressable, Text, View } from 'react-native';
8
8
  import { useFormatMoney, wireMethodOf, type PaymentMethodDescriptor } from '@tallyui/core';
9
- import { canVoidLeg, countsTowardPaid, legStatus, type PaymentLegStatus, type useSale } from '@tallyui/pos';
9
+ import { canVoidLeg, countsTowardPaid, legStatus, type Payment, type PaymentLegStatus, type useSale } from '@tallyui/pos';
10
+ import { cashVoidRefusal } from '@tallyui/pos';
10
11
  import { cn } from '@tallyui/theme';
11
12
  import { useT } from '../i18n';
12
13
  import { ConfirmDialog } from '../ui/confirm-dialog';
13
14
  import { heldTillLeg } from './held-leg';
14
15
  import { offeredMethods } from './offered-methods';
16
+ import { shortTime } from './since-text';
17
+ import { claimVoid, releaseVoid } from './void-in-flight';
15
18
 
16
19
  /** v2 labels.ts statusLabel, as catalogue keys. */
17
20
  const STATUS_LABEL: Record<PaymentLegStatus, string> = {
@@ -23,13 +26,32 @@ const STATUS_TONE: Record<PaymentLegStatus, string> = {
23
26
  pending: 'text-muted-foreground', authorized: 'text-success', captured: 'text-success', failed: 'text-destructive', voided: 'text-muted-foreground',
24
27
  };
25
28
 
26
- export function TenderLedger({ sale, methods, closing = false, confirmVoid = false }: { sale: ReturnType<typeof useSale>; methods?: PaymentMethodDescriptor[]; closing?: boolean;
29
+ // One leg's line in v2's cancel-payment view (use-tender-flow.ts cancelOne): voidable cash not captured by the server goes back as
30
+ // `cashMinor` cash, any other voidable leg is voided on its method, and a leg the till cannot void is refunded from the order.
31
+ export function cancelLine(t: ReturnType<typeof useT>, money: (minor: number) => string, leg: ReturnType<typeof useSale>['order']['payments'][number],
32
+ descriptor: PaymentMethodDescriptor | undefined, voidable: boolean, cashMinor: number): string {
33
+ if (!voidable) return t('pos_checkout.refund_on_method', { amount: money(leg.amountMinor), title: descriptor?.title ?? leg.methodId ?? leg.method });
34
+ return descriptor?.kind === 'cash' && descriptor.capture.mode !== 'server'
35
+ ? t('pos_checkout.return_cash', { amount: money(cashMinor) })
36
+ : t('pos_checkout.void_on_method', { amount: money(leg.amountMinor), title: descriptor?.title ?? leg.methodId ?? leg.method });
37
+ }
38
+
39
+ export function TenderLedger({ sale, methods, closing = false, confirmVoid = false, beforeVoid, afterVoid }: { sale: ReturnType<typeof useSale>; methods?: PaymentMethodDescriptor[]; closing?: boolean;
27
40
  /** v2's "Cancel this payment?" before a leg is voided (use-tender-flow.ts cancelOne). Default false: Cancel payment voids at once. */
28
- confirmVoid?: boolean }): JSX.Element | null {
41
+ confirmVoid?: boolean;
42
+ /**
43
+ * Runs before Cancel payment voids the leg (a host journalling each void first, as v2's awaited cancelOnePayment); the
44
+ * void waits for it. Returning `false` or throwing keeps the leg (the host reports its own error). Absent, the void is immediate.
45
+ */
46
+ beforeVoid?: (leg: Payment) => boolean | void | Promise<boolean | void>;
47
+ /** Runs after a void that beforeVoid approved, with voidTender's result: false means the leg was kept (voided, locked or finished elsewhere meanwhile), so the host reverses what beforeVoid journalled. Not called without beforeVoid, nor when beforeVoid refuses. */
48
+ afterVoid?: (leg: Payment, voided: boolean) => void }): JSX.Element | null {
29
49
  const formatMoney = useFormatMoney();
30
50
  const t = useT();
31
51
  /** The id of the leg the one question is about (confirmVoid). */
32
52
  const [asking, setAsking] = useState<string | null>(null);
53
+ /** The ids of the legs whose beforeVoid is in flight here: drives their disabled Cancel payment. The guard is the shared set in void-in-flight.ts. */
54
+ const [voiding, setVoiding] = useState<ReadonlySet<string>>(new Set());
33
55
  const { order, stage } = sale;
34
56
  if (stage.kind !== 'tender') return null;
35
57
 
@@ -39,19 +61,33 @@ export function TenderLedger({ sale, methods, closing = false, confirmVoid = fal
39
61
  const money = (minor: number) => formatMoney({ amount: minor, currency: order.currency }) ?? '';
40
62
  const balance = order.balanceDueMinor;
41
63
  const settled = order.payments.some(countsTowardPaid);
64
+ /** v2's paid_in_full_at: the time of the last settled leg (settled.at(-1)); plain Paid in full when it has none. */
65
+ const paidAt = order.payments.filter(countsTowardPaid).at(-1)?.takenAt;
66
+ const paidInFull = paidAt ? t('pos_checkout.paid_in_full_at', { time: shortTime(paidAt) }) : t('pos_checkout.paid_in_full');
42
67
  const firstPending = order.payments.find((leg) => legStatus(leg) === 'pending');
43
68
  const askedLeg = order.payments.find((leg) => leg.id === asking);
44
69
  const asked = askedLeg && descriptorOf(askedLeg);
45
- /** v2 cancelOne's body: cash not captured by the server goes back as cash, anything else is voided on its method. */
46
- const question = askedLeg && asked ? asked.kind === 'cash' && asked.capture.mode !== 'server'
47
- ? t('pos_checkout.return_cash', { amount: money(askedLeg.amountMinor) })
48
- : t('pos_checkout.void_on_method', { amount: money(askedLeg.amountMinor), title: asked.title }) : undefined;
70
+ const question = askedLeg && asked ? cancelLine(t, money, askedLeg, asked, true, askedLeg.amountMinor) : undefined;
71
+
72
+ const cancel = async (leg: Payment) => {
73
+ if (cashVoidRefusal(order, leg.id)) { sale.voidTender(leg.id); return; } // ADR-094 item 6: the core refuses and sets the error; beforeVoid never journals a refused void
74
+ if (!beforeVoid) { sale.voidTender(leg.id); return; }
75
+ if (!claimVoid(order.id, leg.id)) return; // #1271: another view, or this ledger before a remount, is journalling this leg
76
+ setVoiding((ids) => new Set(ids).add(leg.id));
77
+ let go = false;
78
+ try { go = (await beforeVoid(leg)) !== false; } catch { /* the leg stays; the host reports its own error */ } finally { releaseVoid(order.id, leg.id); }
79
+ setVoiding((ids) => { const next = new Set(ids); next.delete(leg.id); return next; });
80
+ if (!go) return;
81
+ const voided = sale.voidTender(leg.id);
82
+ try { afterVoid?.(leg, voided); } catch { /* the host reports its own error */ }
83
+ };
49
84
 
50
85
  const legs = <View testID="tender-ledger" className="gap-1">
51
86
  {order.payments.length === 0 ? <Text className="text-muted-foreground">{t('pos_checkout.no_payments_yet')}</Text> : order.payments.map((leg) => {
52
87
  const status = legStatus(leg);
53
88
  const voided = status === 'voided';
54
89
  const descriptor = descriptorOf(leg);
90
+ const inFlight = voiding.has(leg.id);
55
91
  return <View key={leg.id} testID={`tender-leg-${leg.id}`} className="gap-1 border-b border-border py-2">
56
92
  <View className="flex-row items-center gap-2">
57
93
  <Text className={cn('flex-1 font-semibold text-foreground', voided && 'line-through')}>{descriptor?.title ?? leg.methodId ?? leg.method}</Text>
@@ -59,17 +95,24 @@ export function TenderLedger({ sale, methods, closing = false, confirmVoid = fal
59
95
  <Text testID={`tender-leg-${leg.id}-status`} className={cn('text-sm font-semibold', STATUS_TONE[status])}>{voided ? t('pos_checkout.cancelled') : t(STATUS_LABEL[status])}</Text>
60
96
  </View>
61
97
  {leg.reference ? <Text className="text-sm text-muted-foreground">{leg.reference}</Text> : null}
98
+ {leg.takenAt ? <Text testID={`tender-leg-${leg.id}-time`} className="text-sm text-muted-foreground">{shortTime(leg.takenAt)}</Text> : null}
62
99
  {leg === firstPending ? <Text className="text-sm text-muted-foreground">{t('pos_checkout.next_leg')}</Text> : null}
63
100
  {descriptor && canVoidLeg(leg, descriptor) && !heldTillLeg(order, leg) ? <Pressable testID={`tender-leg-${leg.id}-void`} accessibilityRole="button" accessibilityLabel={t('pos_checkout.cancel_payment')}
64
- onPress={() => (confirmVoid ? setAsking(leg.id) : sale.voidTender(leg.id))} className="self-start min-h-11 justify-center px-2">
101
+ disabled={inFlight} accessibilityState={{ disabled: inFlight }}
102
+ onPress={() => (confirmVoid ? setAsking(leg.id) : void cancel(leg))} className="self-start min-h-11 justify-center px-2">
65
103
  <Text className="text-destructive">{t('pos_checkout.cancel_payment')}</Text>
66
104
  </Pressable> : null}
67
105
  </View>;
68
106
  })}
69
- {!closing && balance === 0 && settled ? <Text className="text-sm text-success">{t('pos_checkout.paid_in_full')}</Text> : null}
107
+ {/* ADR-094: each live cash rounding, signed, under the legs. */}
108
+ {order.cashRoundings?.map((entry) => <View key={`rounding-${entry.paymentId}`} testID={`tender-rounding-${entry.paymentId}`} className="flex-row items-center gap-2 border-b border-border py-2">
109
+ <Text className="flex-1 text-muted-foreground">{t('pos_checkout.rounding')}</Text>
110
+ <Text className="text-foreground">{money(entry.minor)}</Text>
111
+ </View>)}
112
+ {!closing && balance === 0 && settled ? <Text className="text-sm text-success">{paidInFull}</Text> : null}
70
113
  {confirmVoid ? <ConfirmDialog testID="tender-leg-void-dialog" tone="destructive" title={t('pos_checkout.cancel_payment_question')} description={question}
71
114
  confirmLabel={t('pos_checkout.cancel_payment')} open={asking !== null} onOpenChange={(open) => { if (!open) setAsking(null); }}
72
- onConfirm={() => { if (asking) sale.voidTender(asking); }} /> : null}
115
+ onConfirm={() => { if (askedLeg) void cancel(askedLeg); }} /> : null}
73
116
  </View>;
74
117
  if (!closing) return legs;
75
118
 
@@ -83,7 +126,7 @@ export function TenderLedger({ sale, methods, closing = false, confirmVoid = fal
83
126
  {row(t('common.total'), order.totalMinor)}
84
127
  {row(t('pos_checkout.paid'), order.paidMinor)}
85
128
  <View testID="tender-ledger-lead" className="mt-1.5 flex-row justify-between border-t border-border pt-2">
86
- {balance === 0 && settled ? <Text className="font-semibold text-success">{t('pos_checkout.paid_in_full')}</Text> : <>
129
+ {balance === 0 && settled ? <Text className="font-semibold text-success">{paidInFull}</Text> : <>
87
130
  <Text className="font-semibold text-foreground">{t('pos_checkout.remaining')}</Text>
88
131
  <Text testID="tender-ledger-remaining" className="font-semibold text-foreground">{money(order.balanceDueMinor)}</Text>
89
132
  </>}
@@ -5,20 +5,22 @@
5
5
  * comes from pos (useSale's captured-only totals, tenderRounding, quickTenderedAmounts, planLegs).
6
6
  * The caption row and the hero figure follow tender-pane.tsx's caption row and AmountFigure (v2 :390-459).
7
7
  */
8
- import { useEffect, useState, type JSX } from 'react';
8
+ import { useEffect, useState, type ComponentProps, type JSX } from 'react';
9
9
  import { Pressable, ScrollView, Text, TextInput, View } from 'react-native';
10
10
  import { useFormatMoney, minorUnitDigits, wireMethodOf, type PaymentMethodDescriptor } from '@tallyui/core';
11
11
  import {
12
- activePlan, changeMinor, countsTowardPaid, evenSplitShareMinor, inMotionMinor, isInMotion, legStatus, lockedRefundDueMinor, planLegs, quickTenderedAmounts, tenderRounding, tillLegsTheStoreRefuses,
12
+ activePlan, CASH_PICK_ENTRIES_MAX, changeMinor, countsTowardPaid, evenSplitShareMinor, inMotionMinor, isInMotion, legStatus, lockedRefundDueMinor, nearestPayableCash, planLegs, quickTenderedAmounts, remainderEntriesMinor, roundedPickTarget, tenderRounding, tillLegsTheStoreRefuses,
13
13
  type TenderAction, type TenderKey, type TenderPlan, type TenderState, type useSale,
14
14
  } from '@tallyui/pos';
15
15
  import { cn } from '@tallyui/theme';
16
16
  import { QUICK_CASH_STEPS } from '../checkout/cash-tendered';
17
17
  import { useT } from '../i18n';
18
+ import { saleErrorText } from './sale-error-text';
18
19
  import { DIGIT_ROWS, Keypad } from '../input/keypad';
19
20
  import { offeredMethods, tenderOf } from './offered-methods';
20
21
  import { heldTillLeg } from './held-leg';
21
- import { TenderLedger } from './tender-ledger';
22
+ import { CancelPaymentView, cancelLegs, legDescriptor, voidableLeg } from './cancel-payment-view';
23
+ import { cancelLine, TenderLedger } from './tender-ledger';
22
24
  import { pickFigure } from './use-tender';
23
25
  import { BanknoteIcon } from '../ui/icon/banknote-icon';
24
26
  import { CreditCardIcon } from '../ui/icon/credit-card-icon';
@@ -35,9 +37,13 @@ export interface TenderPaneProps {
35
37
  methods?: PaymentMethodDescriptor[];
36
38
  /** Draws the payments ledger in the pane. Pass `false` when the host shows it in the cart column, as v2 does (Cart's `tenderLedger`). Default `true`. */
37
39
  ledger?: boolean;
38
- /** Draws the Back button (`sale.cancelTender`). Pass `false` when the host leaves the tender stage itself, as v2's phone checkout does. Default `true`. */ back?: boolean;
40
+ /** Draws the Back button: `sale.cancelTender`, or the cancel-payment view first when money was taken here. Pass `false` when the host leaves the tender stage itself, as v2's phone checkout does. Default `true`. */ back?: boolean;
39
41
  /** Passed to the ledger: v2's "Cancel this payment?" before a leg is voided. Default `false`: Cancel payment voids at once. */
40
42
  confirmVoid?: boolean;
43
+ /** Passed to the ledger: runs before Cancel payment voids a leg; the void waits for it, and `false` or a throw keeps the leg. */
44
+ beforeVoid?: ComponentProps<typeof TenderLedger>['beforeVoid'];
45
+ /** Passed to the ledger: runs after a void `beforeVoid` approved, with whether the leg was voided; `false` means the host reverses its journal entry. */
46
+ afterVoid?: ComponentProps<typeof TenderLedger>['afterVoid'];
41
47
  }
42
48
 
43
49
  /** order.create's bound on `payments[].reference`, in UTF-16 units. */
@@ -59,17 +65,22 @@ const rowsSince = (payments: readonly Leg[], plan: TenderPlan | null) => {
59
65
  .map((leg) => ({ title: leg.method, amountMinor: leg.amountMinor }));
60
66
  };
61
67
 
62
- export function TenderPane({ sale, state, dispatch, methods, ledger = true, back = true, confirmVoid }: TenderPaneProps): JSX.Element | null {
68
+ export function TenderPane({ sale, state, dispatch, methods, ledger = true, back = true, confirmVoid, beforeVoid, afterVoid }: TenderPaneProps): JSX.Element | null {
63
69
  const formatMoney = useFormatMoney();
64
70
  const { order, stage } = sale;
65
71
  const t = useT();
66
72
  const [reference, setReference] = useState('');
67
73
  const [refusal, setRefusal] = useState(false);
74
+ const [cancelling, setCancelling] = useState(false);
68
75
  const balance = order.balanceDueMinor;
76
+ // Leaving the tender stage ends the cancel-payment view (state adjusted while rendering, so it never outlives the stage).
77
+ if (stage.kind !== 'tender' && cancelling) setCancelling(false);
69
78
  // The ledger changed (a leg taken or voided) and the entry is untouched: pre-type the next leg or plan share.
70
79
  useEffect(() => {
71
80
  if (!state.entryDirty) dispatch({ type: 'tender-recorded', rowsSinceFrom: rowsSince(order.payments, state.plan), balanceMinor: balance });
72
81
  }, [order.payments, balance, state.entryDirty, state.plan, dispatch]);
82
+ const legsKey = order.payments.map((leg) => `${leg.id}:${legStatus(leg)}`).join(',');
83
+ useEffect(() => setRefusal(false), [legsKey]);
73
84
  if (stage.kind !== 'tender') return null;
74
85
 
75
86
  const offered = offeredMethods(methods);
@@ -81,14 +92,47 @@ export function TenderPane({ sale, state, dispatch, methods, ledger = true, back
81
92
  const pick = state.plan || Object.keys(state.pickedUnits).length === 0 ? null : pickFigure(order, state.pickedUnits);
82
93
  const target = pick ? Math.min(pick.minor, balance - inMotionMinor(order.payments)) : balance;
83
94
  const partPick = pick !== null && target < balance;
84
- const entry = state.entryDirty ? state.entryMinor : target;
85
- const figures = partPick ? tenderRounding({ entryMinor: entry, entryDirty: state.entryDirty }, target, null) : tenderRounding(state, balance, method);
86
- const pickRefused = (partPick && entry > 0 && (givesChange ? entry < target : entry !== target))
95
+ // ADR-094: the pane rounds exactly when addTender does: only on a store whose connector declares cashRounding, and only while no leg is in motion.
96
+ const rounds = sale.capabilities?.cashRounding === true && inMotionMinor(order.payments) === 0;
97
+ // ADR-094 (cash picks): a cash part pick rounds its own target; addTender rounds the leg, the pane shows the same figure.
98
+ const pickRounding = rounds && method !== null && wireMethodOf(method) === 'cash' && method.capture.mode === 'manual' && method.defaults.rounding ? method.defaults.rounding : null;
99
+ const pickTarget = partPick ? roundedPickTarget(target, pickRounding) : target;
100
+ const entry = state.entryDirty ? state.entryMinor : pickTarget;
101
+ const entries = remainderEntriesMinor(order);
102
+ const figures = partPick ? tenderRounding({ entryMinor: entry, entryDirty: state.entryDirty }, pickTarget, null) : tenderRounding(state, balance, rounds ? method : null, entries);
103
+ const cashNotPayable = rounds && pick === null && method !== null && wireMethodOf(method) === 'cash' && method.capture.mode === 'manual' && method.defaults.rounding
104
+ && figures.roundingMinor === 0 && figures.appliedMinor < figures.roundedDueMinor
105
+ ? nearestPayableCash(figures.entryMinor, method.defaults.rounding.incrementMinor) : null;
106
+ const cashWaits = sale.capabilities?.cashRounding === true && inMotionMinor(order.payments) > 0 && method !== null
107
+ && wireMethodOf(method) === 'cash' && method.capture.mode === 'manual' && method.defaults.rounding && (partPick
108
+ ? nearestPayableCash(target, method.defaults.rounding.incrementMinor) !== null
109
+ : figures.entryMinor > 0 && nearestPayableCash(Math.min(figures.entryMinor, balance - inMotionMinor(order.payments)), method.defaults.rounding.incrementMinor) !== null);
110
+ // order-payload-shape.ts's 16-entry cap: a pick that would add an entry is refused once the sale has CASH_PICK_ENTRIES_MAX.
111
+ const pickLimit = partPick && pickTarget !== target && (order.cashRoundings ?? []).length >= CASH_PICK_ENTRIES_MAX;
112
+ const pickRefused = (partPick && entry > 0 && (givesChange ? entry < pickTarget : entry !== pickTarget))
87
113
  || (pick !== null && !partPick && figures.appliedMinor > 0 && figures.appliedMinor < figures.roundedDueMinor);
88
- const entryChange = changeMinor(figures.entryMinor, figures.appliedMinor, givesChange);
89
- const left = balance + figures.roundingMinor - figures.appliedMinor;
114
+ // Row 500: judged against the due less the legs in motion, as addTender records the leg's change.
115
+ // ADR-094: a cash due rounded to nothing still settles the sale (v2 tender-pane.tsx:1062), where the store's connector declares cashRounding.
116
+ const zeroDue = sale.capabilities?.cashRounding === true && !partPick && figures.roundedDueMinor === 0 && figures.roundingMinor !== 0
117
+ && inMotionMinor(order.payments) === 0;
118
+ // The 16-entry cap as addTender applies it: a settle that adds an entry is refused at 16; a write-off onto a leg with one is not.
119
+ const lastCounted = order.payments.filter(countsTowardPaid).at(-1);
120
+ const settleLimit = !partPick && sale.capabilities?.cashRounding === true && figures.roundingMinor !== 0
121
+ && (order.cashRoundings ?? []).length > CASH_PICK_ENTRIES_MAX
122
+ && !(zeroDue && lastCounted !== undefined && (order.cashRoundings ?? []).some((e) => e.paymentId === lastCounted.id));
123
+ // With no other method, a cash-only store frees an entry by voiding its latest rounded cash leg, which no later cash leg's entry blocks; offered methods are all manual capture.
124
+ const otherWay = offered.some((m) => !(wireMethodOf(m) === 'cash' && m.defaults.rounding));
125
+ const lastRounded = order.payments.filter(countsTowardPaid).filter((leg) => leg.method === 'cash' && (order.cashRoundings ?? []).some((e) => e.paymentId === leg.id)).at(-1);
126
+ const entryChange = zeroDue ? 0 : partPick ? changeMinor(figures.entryMinor, figures.appliedMinor, givesChange)
127
+ : changeMinor(figures.entryMinor, Math.min(figures.appliedMinor, Math.max(0, balance - inMotionMinor(order.payments)) + figures.roundingMinor), givesChange);
128
+ // What Take can still pay: pos caps a leg at the balance less the legs in motion (use-sale.ts addTender).
129
+ const dueNow = Math.max(0, balance - inMotionMinor(order.payments));
130
+ const left = dueNow + figures.roundingMinor - figures.appliedMinor;
90
131
  const noChange = !partPick && method !== null && !givesChange && figures.entryMinor > balance;
91
- const changeLeads = !noChange && entryChange > 0;
132
+ // Take records only dueNow here (pos caps the leg), so the hint names it without blocking.
133
+ const capped = !partPick && method !== null && !givesChange && dueNow > 0 && figures.entryMinor > dueNow;
134
+ const cannotTake = (figures.appliedMinor <= 0 && !zeroDue) || (partPick && pickTarget === 0) || noChange || pickRefused || cashNotPayable !== null || cashWaits || pickLimit || settleLimit || (!partPick && balance - inMotionMinor(order.payments) <= 0);
135
+ const changeLeads = !cannotTake && entryChange > 0;
92
136
  // v2 tender-pane.tsx:405-410: the caption names the balance only when it differs from the figure shown.
93
137
  const balanceInCaption = balance === 0 || figures.entryMinor !== balance;
94
138
  const rows = rowsSince(order.payments, state.plan).map(({ title, amountMinor }) => ({ title, minor: amountMinor }));
@@ -98,30 +142,41 @@ export function TenderPane({ sale, state, dispatch, methods, ledger = true, back
98
142
  const splitOn = state.splitView || plan !== null;
99
143
  // v2 tender-figures.ts: a typed part payment comes first, and the ways divide what is left after it.
100
144
  const typed = state.entryDirty && figures.appliedMinor > 0 && figures.appliedMinor < balance;
101
- const restMinor = balance - (typed ? figures.appliedMinor : 0);
145
+ const restMinor = balance - (typed ? (partPick ? target : figures.appliedMinor) : 0);
102
146
  const thisPaymentMinor = planned ? planned.thisPaymentMinor : balance;
103
- const dueMinor = partPick ? target : planned && planned.thisPaymentMinor < balance ? planned.thisPaymentMinor : figures.roundedDueMinor;
147
+ const dueMinor = partPick ? pickTarget : planned && planned.thisPaymentMinor < balance ? planned.thisPaymentMinor : figures.roundedDueMinor;
104
148
  const chips = givesChange ? quickTenderedAmounts(dueMinor, QUICK_CASH_STEPS.map((step) => step * 10 ** minorUnitDigits(order.currency))) : [];
105
149
  // v2 tender-pane.tsx:942-954: a method that gives no change gets one chip setting the entry to the due figure; hidden in percent entry, as v2 does.
106
150
  const balanceChip = method !== null && !givesChange && state.entryMode !== 'percent' ? dueMinor : null;
107
- const [onlyLeg] = order.payments;
108
- // startTender('external') records the card leg for the total: its reference is edited in place, as before.
109
- const cardReference = order.payments.length === 1 && onlyLeg.method === 'external' && legStatus(onlyLeg) === 'captured' && balance === 0
110
- && !heldTillLeg(order, onlyLeg);
111
- const hint = partPick ? (pickRefused || entry === target ? t('pos_checkout.pick_amount_due', { amount: money(target) })
112
- : givesChange && entry > target ? t('pos_checkout.change_due', { amount: money(entry - target) }) : '')
151
+ const unstamped = order.payments.filter((leg) => leg.takenAt === undefined && !sale.tenderHeld(leg.id));
152
+ const [prefill] = unstamped;
153
+ // startTender('external')'s one unstamped card leg for the rest, beside any kept taken or voided legs: its reference is edited in place.
154
+ const cardReference = unstamped.length === 1 && prefill.method === 'external' && legStatus(prefill) === 'captured' && balance === 0;
155
+ const hint = cashNotPayable ? (cashNotPayable.belowMinor === 0 ? t('pos_checkout.cash_not_payable_above', { above: money(cashNotPayable.aboveMinor) })
156
+ : t('pos_checkout.cash_not_payable', { below: money(cashNotPayable.belowMinor), above: money(cashNotPayable.aboveMinor) }))
157
+ : cashWaits ? t('pos_checkout.cash_waits_for_payment')
158
+ : pickLimit ? t('pos_checkout.cash_pick_limit')
159
+ : settleLimit ? (otherWay ? t('pos_checkout.cash_settle_limit')
160
+ : lastRounded && voidableLeg(order, offered, lastRounded) ? t('pos_checkout.cash_settle_limit_void', { amount: money(lastRounded.amountMinor) })
161
+ : t('pos_checkout.cash_settle_limit_park', { amount: lastRounded ? money(lastRounded.amountMinor) : '' }))
162
+ : partPick ? (pickTarget === 0 ? t('pos_checkout.pick_rounds_to_nothing')
163
+ : pickRefused || entry === pickTarget ? t('pos_checkout.pick_amount_due', { amount: money(pickTarget) })
164
+ : givesChange && entry > pickTarget ? (cannotTake ? '' : t('pos_checkout.change_due', { amount: money(entry - pickTarget) })) : '')
113
165
  : pickRefused ? t('pos_checkout.pick_amount_due', { amount: money(figures.roundedDueMinor) })
114
- : noChange ? t('pos_checkout.no_change_for_method', { amount: money(balance), method: method?.title })
115
- : entryChange > 0 ? t('pos_checkout.change_due', { amount: money(entryChange) })
116
- : figures.appliedMinor < balance && figures.entryMinor > 0 ? t('pos_checkout.part_payment_left', { left: money(left) }) : '';
117
- // ADR-090 gate 36c: once the store's legs cover the total, finalize refuses every till leg; name them and offer their removal.
166
+ : capped || (noChange && dueNow === balance) ? t('pos_checkout.no_change_for_method', { amount: money(dueNow), method: method?.title })
167
+ : zeroDue ? ''
168
+ : entryChange > 0 ? (cannotTake ? '' : t('pos_checkout.change_due', { amount: money(entryChange) }))
169
+ : !cannotTake && figures.appliedMinor < dueNow && figures.entryMinor > 0 ? t('pos_checkout.part_payment_left', { left: money(left) }) : '';
170
+ // ADR-090 gate 36c: once the store's legs cover the total, finalize refuses every till leg; name them and offer their void.
118
171
  const refused = tillLegsTheStoreRefuses(order);
119
- const refusedMinor = order.payments.filter((leg) => refused.includes(leg.id)).reduce((total, leg) => total + leg.amountMinor, 0);
172
+ const refusedLegs = order.payments.filter((leg) => refused.includes(leg.id));
173
+ const refusedMinor = refusedLegs.reduce((total, leg) => total + leg.amountMinor, 0);
174
+ // A refused leg the till cannot void (held, or refund-only) leaves the sale only able to park (ADR-072 d3, amended 2026-11-22).
175
+ const kept = refusedLegs.filter((leg) => !voidableLeg(order, offered, leg));
120
176
  const canComplete = balance === 0 && !order.payments.some(isInMotion) && refused.length === 0;
121
177
  // ADR-090 gate 36 (desk Q4): changeDueMinor counts locked legs; what they hold beyond the total is the store's refund due, never till change.
122
178
  const refundDue = Math.min(order.changeDueMinor, lockedRefundDueMinor(order));
123
179
  const tillChange = order.changeDueMinor - refundDue + order.payments.reduce((sum, leg) => sum + (!leg.locked && countsTowardPaid(leg) ? leg.changeMinor ?? 0 : 0), 0);
124
- const cannotTake = figures.appliedMinor <= 0 || noChange || pickRefused;
125
180
 
126
181
  function take() {
127
182
  if (!method || pickRefused) return;
@@ -129,14 +184,20 @@ export function TenderPane({ sale, state, dispatch, methods, ledger = true, back
129
184
  // No pick stands (a plan is set, or nothing is picked): the leg carries no units. Otherwise it carries the picks that stand (pickFigure), never the raw ones.
130
185
  const units = pick === null ? {} : { units: pick.picks };
131
186
  const id = tender.method === 'cash'
132
- ? sale.addTender({ ...tender, ...units, amountMinor: partPick ? target : figures.entryMinor, ...(partPick ? { tenderedMinor: entry } : {}) })
187
+ ? sale.addTender({ ...tender, ...units, amountMinor: partPick ? target : figures.entryMinor, ...(partPick ? { tenderedMinor: entry, ...(method.capture.mode === 'manual' && method.defaults.rounding ? { rounding: method.defaults.rounding } : {}) } : {}),
188
+ ...(!partPick && method.capture.mode === 'manual' && method.defaults.rounding ? { rounding: method.defaults.rounding } : {}) })
133
189
  : sale.addTender({ ...tender, ...units, amountMinor: partPick ? target : figures.appliedMinor, ...(reference ? { reference } : {}) });
134
190
  if (id === null) { setRefusal(true); return; }
135
191
  setRefusal(false);
136
192
  setReference('');
137
- dispatch({ type: 'tender-started', paymentId: id, units: pick === null ? {} : pick.picks });
193
+ // A zero-due settle returns the leg its entry went on, which already holds its own units.
194
+ dispatch({ type: 'tender-started', paymentId: id, units: pick === null || zeroDue ? {} : pick.picks });
138
195
  }
139
196
 
197
+ if (cancelling) return <View dataSet={{ print: 'hide' }} testID="tender-pane" className="gap-4 p-4">
198
+ <CancelPaymentView sale={sale} methods={methods} beforeVoid={beforeVoid} afterVoid={afterVoid} onClose={() => setCancelling(false)} />
199
+ </View>;
200
+
140
201
  return <View dataSet={{ print: 'hide' }} testID="tender-pane" className="gap-4 p-4">
141
202
  <View testID="tender-headline" className="items-center gap-1">
142
203
  <View className="flex-row flex-wrap items-center justify-center gap-2">
@@ -167,15 +228,15 @@ export function TenderPane({ sale, state, dispatch, methods, ledger = true, back
167
228
  </> : <>
168
229
  <Text testID="tender-entry-amount" className={cn('text-4xl font-bold text-foreground', !state.entryDirty && 'opacity-70')}>{money(figures.entryMinor)}</Text>
169
230
  {figures.roundingMinor !== 0 ? <Text className="text-sm text-muted-foreground">{t('pos_checkout.rounded_from', { amount: money(balance) })}</Text> : null}
170
- <Text testID="tender-entry-hint" className={cn('min-h-6 text-center text-sm', noChange || pickRefused ? 'text-warning-text' : entryChange > 0 ? 'text-success' : 'text-muted-foreground')}>{hint}</Text>
231
+ <Text testID="tender-entry-hint" className={cn('min-h-6 text-center text-sm', noChange || capped || pickRefused || cashWaits || pickLimit || settleLimit ? 'text-warning-text' : 'text-muted-foreground')}>{hint}</Text>
171
232
  </>}
172
233
  </View> : null}
173
234
 
174
- {ledger ? <TenderLedger sale={sale} methods={methods} confirmVoid={confirmVoid} /> : null}
235
+ {ledger ? <TenderLedger sale={sale} methods={methods} confirmVoid={confirmVoid} beforeVoid={beforeVoid} afterVoid={afterVoid} /> : null}
175
236
 
176
237
  {/* cardReference holds only for an external leg; the edit keeps that leg's method and its own methodId. */}
177
238
  {cardReference ? <TextInput accessibilityLabel={t('tender.terminal_reference')} placeholder={t('tender.terminal_reference')} maxLength={REFERENCE_MAX}
178
- value={onlyLeg.reference ?? ''} onChangeText={(text) => sale.setTender({ method: 'external', ...(onlyLeg.methodId !== undefined ? { methodId: onlyLeg.methodId } : {}), amountMinor: onlyLeg.amountMinor, reference: text })}
239
+ value={prefill.reference ?? ''} onChangeText={(text) => sale.setTender({ method: 'external', ...(prefill.methodId !== undefined ? { methodId: prefill.methodId } : {}), amountMinor: prefill.amountMinor, reference: text })}
179
240
  className="rounded-md border border-border px-3 py-2 text-foreground" /> : null}
180
241
 
181
242
  {balance > 0 ? <View testID="tender-entry" className="gap-3">
@@ -202,7 +263,7 @@ export function TenderPane({ sale, state, dispatch, methods, ledger = true, back
202
263
  ))}
203
264
  </View>
204
265
  {planned ? <Text testID="tender-plan" className="text-sm text-muted-foreground">{t('pos_checkout.n_of_ways', { n: planned.label.n, ways: planned.label.ways })}</Text> : null}
205
- {method?.id === 'external' ? <TextInput accessibilityLabel={t('tender.terminal_reference')} placeholder={t('tender.terminal_reference')} maxLength={REFERENCE_MAX}
266
+ {method && wireMethodOf(method) === 'external' ? <TextInput accessibilityLabel={t('tender.terminal_reference')} placeholder={t('tender.terminal_reference')} maxLength={REFERENCE_MAX}
206
267
  value={reference} onChangeText={setReference} className="rounded-md border border-border px-3 py-2 text-foreground" /> : null}
207
268
  {state.splitView && !plan ? <>
208
269
  <Text testID="tender-split-heading" className="text-center text-sm text-muted-foreground">
@@ -221,7 +282,11 @@ export function TenderPane({ sale, state, dispatch, methods, ledger = true, back
221
282
  </View>)}
222
283
  </ScrollView>
223
284
  </> : null}
224
- {chips.length || balanceChip !== null ? <View testID="tender-quick" className="flex-row flex-wrap justify-center gap-2">
285
+ {chips.length || balanceChip !== null || cashNotPayable ? <View testID="tender-quick" className="flex-row flex-wrap justify-center gap-2">
286
+ {cashNotPayable ? [cashNotPayable.belowMinor, cashNotPayable.aboveMinor].filter((minor) => minor !== 0).map((minor) => <Pressable key={minor}
287
+ testID={minor === cashNotPayable.belowMinor ? 'tender-payable-below' : 'tender-payable-above'} accessibilityRole="button" onPress={() => dispatch({ type: 'set-entry', minor })} className={button}>
288
+ <Text className="font-semibold text-foreground">{money(minor)}</Text>
289
+ </Pressable>) : null}
225
290
  {chips.map((minor, index) => <Pressable key={minor} testID={index === 0 ? 'tender-quick-exact' : `tender-quick-${minor}`} accessibilityRole="button"
226
291
  onPress={() => dispatch({ type: 'set-entry', minor })} className={cn(button, state.entryDirty && figures.entryMinor === minor && 'border-primary')}>
227
292
  <Text className="font-semibold text-foreground">{index === 0 ? t('pos_checkout.exact_amount', { amount: money(minor) }) : money(minor)}</Text>
@@ -241,22 +306,25 @@ export function TenderPane({ sale, state, dispatch, methods, ledger = true, back
241
306
  </View> : null}
242
307
 
243
308
  {refused.length > 0 ? <>
244
- <Text testID="tender-store-holds" className="text-foreground">{t('pos_checkout.store_holds_payment', { amount: money(refusedMinor) })}</Text>
245
- {refused.filter((id) => !order.payments.some((leg) => leg.id === id && heldTillLeg(order, leg))).map((id) => <Pressable key={id} testID={`tender-leg-${id}-remove`} accessibilityRole="button" onPress={() => sale.removeTender(id)} className={button}>
246
- <Text className="text-center text-foreground">{t('pos_checkout.remove_payment')}</Text>
247
- </Pressable>)}
309
+ <Text testID="tender-store-holds" className="text-foreground">{kept.length ? t('pos_checkout.store_holds_park', { amount: money(kept.reduce((total, leg) => total + leg.amountMinor, 0)) })
310
+ : t('pos_checkout.store_holds_payment', { amount: money(refusedMinor) })}</Text>
311
+ {refusedLegs.filter((leg) => !heldTillLeg(order, leg)).map((leg) => voidableLeg(order, offered, leg)
312
+ ? <Pressable key={leg.id} testID={`tender-leg-${leg.id}-refused-void`} accessibilityRole="button" onPress={() => sale.voidTender(leg.id)} className={button}>
313
+ <Text className="text-center text-foreground">{t('pos_checkout.cancel_payment')}</Text>
314
+ </Pressable>
315
+ : <Text key={leg.id} testID={`tender-leg-${leg.id}-refused-refund`} className="text-foreground">{cancelLine(t, money, leg, legDescriptor(offered, leg), false, leg.amountMinor)}</Text>)}
248
316
  </> : null}
249
317
  <Pressable testID="tender-complete" accessibilityRole="button" disabled={!canComplete} onPress={sale.complete}
250
318
  className={cn('rounded-md bg-primary px-4 py-3', !canComplete && 'opacity-50')}>
251
319
  <Text className="text-center font-semibold text-primary-foreground">{t('tender.complete_sale')}</Text>
252
320
  </Pressable>
253
- {sale.error ? <Text accessibilityRole="alert" className="text-destructive">{sale.error}</Text> : null}
321
+ {sale.error ? <Text accessibilityRole="alert" className="text-destructive">{saleErrorText(t, sale.error)}</Text> : null}
254
322
  {sale.canContinue ? <>
255
323
  <Text className="text-foreground">{t('tender.stored_will_send')}</Text>
256
324
  <Pressable accessibilityRole="button" onPress={() => sale.continueSale()} className="rounded-md bg-primary px-4 py-3">
257
325
  <Text className="text-center font-semibold text-primary-foreground">{t('tender.continue')}</Text>
258
326
  </Pressable>
259
327
  </> : null}
260
- {back ? <Pressable accessibilityRole="button" onPress={sale.cancelTender} className={button}><Text className="text-center text-foreground">{t('common.back')}</Text></Pressable> : null}
328
+ {back ? <Pressable accessibilityRole="button" onPress={() => (cancelLegs(order).length ? setCancelling(true) : sale.cancelTender())} className={button}><Text className="text-center text-foreground">{t('common.back')}</Text></Pressable> : null}
261
329
  </View>;
262
330
  }
@@ -2,22 +2,24 @@ import { useReducer, type JSX } from 'react';
2
2
  import { type PaymentMethodDescriptor } from '@tallyui/core';
3
3
  import { initTenderState, tenderReducer, type useSale } from '@tallyui/pos';
4
4
  import { openingMethodId, type useTender } from './use-tender';
5
- import { TenderPane } from './tender-pane';
5
+ import { TenderPane, type TenderPaneProps } from './tender-pane';
6
6
 
7
7
  type Sale = ReturnType<typeof useSale>;
8
8
 
9
- function HostedPane({ sale, method, methods, ledger, back, confirmVoid, tender }: TenderProps & { method: string }) {
9
+ function HostedPane({ sale, method, methods, ledger, back, confirmVoid, beforeVoid, afterVoid, tender }: TenderProps & { method: string }) {
10
10
  const [state, dispatch] = useReducer(tenderReducer, { methodId: openingMethodId(method, methods), balanceMinor: sale.order.balanceDueMinor, payments: sale.order.payments }, initTenderState);
11
- return <TenderPane sale={sale} state={tender ? tender.state : state} dispatch={tender ? tender.dispatch : dispatch} methods={methods} ledger={ledger} back={back} confirmVoid={confirmVoid} />;
11
+ return <TenderPane sale={sale} state={tender ? tender.state : state} dispatch={tender ? tender.dispatch : dispatch} methods={methods} ledger={ledger} back={back} confirmVoid={confirmVoid} beforeVoid={beforeVoid} afterVoid={afterVoid} />;
12
12
  }
13
13
 
14
14
  type TenderProps = { sale: Sale; methods?: PaymentMethodDescriptor[]; /** Passed to TenderPane: `false` leaves the ledger to Cart's `tenderLedger`. Default `true`. */ ledger?: boolean; /** Passed to TenderPane: `false` hides Back (v2's phone checkout). Default `true`. */ back?: boolean;
15
15
  /** Passed to TenderPane's ledger: v2's "Cancel this payment?" before a leg is voided. Default `false`. */ confirmVoid?: boolean;
16
+ /** Passed to TenderPane's ledger and its cancel-payment view: runs before either voids a leg; the void waits for it. */ beforeVoid?: TenderPaneProps['beforeVoid'];
17
+ /** Passed to TenderPane's ledger and its cancel-payment view: runs after either voids a leg `beforeVoid` approved, with whether it was voided. */ afterVoid?: TenderPaneProps['afterVoid'];
16
18
  /** One reducer shared with Cart's `picker` (useTender). Without it, Tender keeps its own reducer, as before. */ tender?: ReturnType<typeof useTender> };
17
19
 
18
20
  /** The tender pane with its own reducer, opened on the method `startTender` chose. Renders nothing outside the tender stage. */
19
- export function Tender({ sale, methods, ledger, back, confirmVoid, tender }: TenderProps): JSX.Element | null {
20
- return sale.stage.kind === 'tender' ? <HostedPane sale={sale} method={sale.stage.method} methods={methods} ledger={ledger} back={back} confirmVoid={confirmVoid} tender={tender} /> : null;
21
+ export function Tender({ sale, methods, ledger, back, confirmVoid, beforeVoid, afterVoid, tender }: TenderProps): JSX.Element | null {
22
+ return sale.stage.kind === 'tender' ? <HostedPane sale={sale} method={sale.stage.method} methods={methods} ledger={ledger} back={back} confirmVoid={confirmVoid} beforeVoid={beforeVoid} afterVoid={afterVoid} tender={tender} /> : null;
21
23
  }
22
24
 
23
25
  /** @deprecated Use Tender: the pane now handles split payments. */
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The legs whose beforeVoid is in flight, shared by every TenderLedger and CancelPaymentView (#1271): a second mounted
3
+ * view, or a ledger remounted while the hook awaits, cannot run the hook again for the same leg. Keyed by order and leg.
4
+ */
5
+ const inFlight = new Set<string>();
6
+ const keyOf = (orderId: string, legId: string) => `${orderId}\u0000${legId}`;
7
+
8
+ /** Holds the leg for one beforeVoid; false when another view already holds it. */
9
+ export function claimVoid(orderId: string, legId: string): boolean {
10
+ const key = keyOf(orderId, legId);
11
+ if (inFlight.has(key)) return false;
12
+ inFlight.add(key);
13
+ return true;
14
+ }
15
+
16
+ /** Lets the leg go once its beforeVoid has settled. */
17
+ export function releaseVoid(orderId: string, legId: string): void {
18
+ inFlight.delete(keyOf(orderId, legId));
19
+ }
@@ -8,7 +8,7 @@ const Tabs = TabsPrimitive.Root;
8
8
  function TabsList({ className, ...props }: React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>) {
9
9
  return (
10
10
  <TabsPrimitive.List
11
- className={cn('inline-flex h-10 items-center justify-center rounded-md bg-muted p-1', className)}
11
+ className={cn('inline-flex flex-row h-10 items-center justify-center rounded-md bg-muted p-1', className)}
12
12
  {...props}
13
13
  />
14
14
  );
@@ -1,28 +0,0 @@
1
- import { describe, expectTypeOf, it } from 'vitest';
2
- import type { PaymentKind } from '@tallyui/core';
3
- import type {
4
- OrderFilterBarProps,
5
- PaymentMethod,
6
- PaymentMethodKind,
7
- PaymentSelectorMethod,
8
- PaymentSelectorProps,
9
- } from '../index';
10
-
11
- describe('component payment types', () => {
12
- it('keeps PaymentMethodKind as an alias of core PaymentKind', () => {
13
- expectTypeOf<PaymentMethodKind>().toEqualTypeOf<PaymentKind>();
14
- });
15
-
16
- it('keeps PaymentMethod as an alias of PaymentSelectorMethod', () => {
17
- expectTypeOf<PaymentMethod>().toEqualTypeOf<PaymentSelectorMethod>();
18
- });
19
-
20
- it('uses PaymentSelectorMethod for selector methods', () => {
21
- expectTypeOf<PaymentSelectorProps['methods']>().toEqualTypeOf<PaymentSelectorMethod[]>();
22
- });
23
-
24
- it('uses core PaymentKind for optional filter kinds', () => {
25
- type PaymentOption = NonNullable<NonNullable<OrderFilterBarProps['options']>['paymentMethod']>[number];
26
- expectTypeOf<PaymentOption['kind']>().toEqualTypeOf<PaymentKind | undefined>();
27
- });
28
- });