@tallyui/components 3.20.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/dist/index.d.ts +1114 -90
  2. package/dist/index.js +8077 -3352
  3. package/package.json +10 -11
  4. package/src/cart/cart-charge-line.tsx +58 -0
  5. package/src/cart/cart-columns-form.tsx +98 -0
  6. package/src/cart/cart-columns.tsx +49 -18
  7. package/src/cart/cart-foot.tsx +7 -2
  8. package/src/cart/cart-line-strip.tsx +59 -0
  9. package/src/cart/cart-line.tsx +20 -8
  10. package/src/cart/cart-note-row.tsx +30 -0
  11. package/src/cart/cart-panel.tsx +9 -1
  12. package/src/cart/cart-row-motion.tsx +125 -0
  13. package/src/cart/cart-total.tsx +44 -15
  14. package/src/cart/index.ts +2 -1
  15. package/src/checkout/cash-tendered.tsx +8 -7
  16. package/src/checkout/change-display.tsx +2 -1
  17. package/src/checkout/index.ts +1 -1
  18. package/src/checkout/payment-selector.tsx +6 -2
  19. package/src/checkout/payment-types.test-d.ts +28 -0
  20. package/src/customer/address-editor.tsx +87 -0
  21. package/src/customer/address-fields.tsx +120 -0
  22. package/src/customer/customer-dropdown.tsx +200 -0
  23. package/src/customer/customer-editor.tsx +99 -0
  24. package/src/customer/customer-form.tsx +39 -5
  25. package/src/customer/customer-picker.tsx +38 -14
  26. package/src/customer/customers-list.tsx +83 -0
  27. package/src/customer/index.ts +5 -0
  28. package/src/filter/filter-pills.tsx +63 -0
  29. package/src/i18n/locales/en/components.json +85 -0
  30. package/src/index.ts +40 -2
  31. package/src/input/decimal-entry.ts +21 -0
  32. package/src/layout/checkout-layout.tsx +1 -1
  33. package/src/layout/live-tab-screen.tsx +1 -1
  34. package/src/layout/pos-layout.tsx +80 -4
  35. package/src/layout/settings-layout.tsx +1 -1
  36. package/src/layout/store-settings-choice-screen.tsx +1 -1
  37. package/src/lib/current-row.ts +13 -0
  38. package/src/lib/money-input.ts +16 -0
  39. package/src/lib/motion.ts +22 -0
  40. package/src/lib/use-reduced-motion.ts +20 -0
  41. package/src/order/index.ts +1 -1
  42. package/src/order/order-detail.tsx +123 -5
  43. package/src/order/order-filter-bar.tsx +7 -57
  44. package/src/order/order-status-badge.tsx +42 -19
  45. package/src/order/refund-form.tsx +7 -5
  46. package/src/product/camera-scan-button.tsx +2 -0
  47. package/src/product/category-nav.tsx +8 -0
  48. package/src/product/category-tile.tsx +65 -15
  49. package/src/product/in-cart-badge.tsx +55 -6
  50. package/src/product/index.ts +1 -0
  51. package/src/product/press-veil.tsx +7 -0
  52. package/src/product/product-card.tsx +5 -1
  53. package/src/product/product-grid.tsx +5 -0
  54. package/src/product/product-price.tsx +6 -3
  55. package/src/product/product-stock-badge.tsx +3 -2
  56. package/src/product/product-table.tsx +96 -8
  57. package/src/product/products-screen-columns.tsx +74 -0
  58. package/src/product/variant-tile.tsx +68 -0
  59. package/src/product/variation-picker.tsx +3 -3
  60. package/src/product/view-toggle.tsx +33 -4
  61. package/src/register/cashier-sheet.tsx +195 -0
  62. package/src/register/closure-sheet.tsx +54 -3
  63. package/src/register/handover-slip.tsx +2 -1
  64. package/src/register/index.ts +2 -1
  65. package/src/register/movement-sheet.tsx +66 -7
  66. package/src/register/open-register-card.tsx +11 -11
  67. package/src/register/register-bar.helpers.ts +17 -4
  68. package/src/register/register-bar.tsx +26 -5
  69. package/src/register/register-count.tsx +158 -24
  70. package/src/register/register-panel.tsx +16 -5
  71. package/src/register/register-side-sheet.tsx +32 -8
  72. package/src/register/switch-confirm.tsx +2 -2
  73. package/src/reports/card-panel.tsx +131 -0
  74. package/src/reports/cards.tsx +53 -36
  75. package/src/reports/hero.tsx +2 -1
  76. package/src/reports/index.ts +1 -0
  77. package/src/reports/sales-room.tsx +4 -2
  78. package/src/sale/breadcrumb.tsx +48 -0
  79. package/src/sale/cart-bar.tsx +2 -1
  80. package/src/sale/cart.tsx +127 -38
  81. package/src/sale/catalogue-settings-form.tsx +92 -0
  82. package/src/sale/catalogue.tsx +304 -42
  83. package/src/sale/category-browse.tsx +27 -0
  84. package/src/sale/charge-form.tsx +85 -21
  85. package/src/sale/customer-display-screen.tsx +22 -6
  86. package/src/sale/discount-form.tsx +132 -28
  87. package/src/sale/index.ts +6 -3
  88. package/src/sale/line-popover.tsx +72 -36
  89. package/src/sale/offered-methods.ts +16 -0
  90. package/src/sale/open-sale-tabs.tsx +58 -10
  91. package/src/sale/order-note-sheet.tsx +37 -0
  92. package/src/sale/order-reference.ts +3 -0
  93. package/src/sale/orders-list.tsx +76 -37
  94. package/src/sale/parked-sales.tsx +2 -1
  95. package/src/sale/price-form.tsx +7 -5
  96. package/src/sale/product-filter-bar.tsx +38 -5
  97. package/src/sale/receipt-sheet.tsx +243 -0
  98. package/src/sale/receipt.tsx +19 -9
  99. package/src/sale/sync-status.tsx +10 -0
  100. package/src/sale/tender-ledger.tsx +92 -0
  101. package/src/sale/tender-pane.tsx +159 -73
  102. package/src/sale/tender.tsx +10 -7
  103. package/src/sale/use-tender.ts +63 -0
  104. package/src/scale/min-target.tsx +36 -0
  105. package/src/settings/barcode-scanning-settings.tsx +164 -0
  106. package/src/settings/connector-status.tsx +1 -1
  107. package/src/settings/customer-display-settings.tsx +12 -25
  108. package/src/settings/index.ts +5 -0
  109. package/src/settings/printer-form.tsx +161 -0
  110. package/src/settings/printing-settings.tsx +268 -0
  111. package/src/settings/settings-group.tsx +2 -1
  112. package/src/settings/tax-calculation-settings.tsx +1 -1
  113. package/src/shell/added-to-cart-toast.tsx +61 -0
  114. package/src/shell/app-shell.tsx +5 -1
  115. package/src/shell/connectivity-toast.tsx +70 -0
  116. package/src/shell/index.ts +2 -0
  117. package/src/shell/nav-drawer.tsx +5 -2
  118. package/src/shell/nav-item.tsx +7 -4
  119. package/src/shell/nav-rail.tsx +9 -2
  120. package/src/ui/accordion/index.tsx +86 -8
  121. package/src/ui/alert-dialog/index.tsx +19 -5
  122. package/src/ui/combobox/index.tsx +21 -2
  123. package/src/ui/confirm-dialog/index.tsx +53 -0
  124. package/src/ui/dialog/index.tsx +68 -14
  125. package/src/ui/dialog/motion.ts +54 -0
  126. package/src/ui/icon/activity-heartbeat-icon.tsx +7 -0
  127. package/src/ui/icon/alert-circle-icon.tsx +5 -0
  128. package/src/ui/icon/alert-triangle-icon.tsx +7 -0
  129. package/src/ui/icon/banknote-icon.tsx +11 -0
  130. package/src/ui/icon/cash-register-icon.tsx +10 -0
  131. package/src/ui/icon/category-icon.tsx +7 -0
  132. package/src/ui/icon/chart-line-icon.tsx +5 -0
  133. package/src/ui/icon/check-icon.tsx +5 -0
  134. package/src/ui/icon/chevron-left-icon.tsx +4 -0
  135. package/src/ui/icon/chevron-right-icon.tsx +4 -0
  136. package/src/ui/icon/credit-card-icon.tsx +10 -0
  137. package/src/ui/icon/discount-icon.tsx +11 -0
  138. package/src/ui/icon/gift-icon.tsx +10 -0
  139. package/src/ui/icon/info-circle-icon.tsx +10 -0
  140. package/src/ui/icon/map-pin-icon.tsx +10 -0
  141. package/src/ui/icon/message-question-icon.tsx +7 -0
  142. package/src/ui/icon/pencil-icon.tsx +10 -0
  143. package/src/ui/icon/plus-icon.tsx +9 -0
  144. package/src/ui/icon/printer-icon.tsx +10 -0
  145. package/src/ui/icon/receipt-icon.tsx +7 -0
  146. package/src/ui/icon/settings-icon.tsx +10 -0
  147. package/src/ui/icon/sticky-note-icon.tsx +10 -0
  148. package/src/ui/icon/user-icon.tsx +4 -0
  149. package/src/ui/icon/users-icon.tsx +7 -0
  150. package/src/ui/icon/view-grid-icon.tsx +7 -0
  151. package/src/ui/icon/view-list-icon.tsx +7 -0
  152. package/src/ui/index.ts +24 -1
  153. package/src/ui/list-row/index.tsx +93 -0
  154. package/src/ui/notice/index.tsx +65 -0
  155. package/src/ui/select/index.tsx +2 -0
  156. package/src/ui/skeleton/index.tsx +37 -0
  157. package/src/ui/status-badge/index.tsx +43 -0
  158. package/src/ui/switch/index.tsx +1 -1
  159. package/src/ui/tabs/index.tsx +11 -2
  160. package/src/ui/toggle-group/index.tsx +3 -1
  161. package/src/ui/tone-disc/index.tsx +41 -0
@@ -1,7 +1,10 @@
1
1
  import { Pressable, ScrollView, Text, View } from 'react-native';
2
2
  import { cn } from '@tallyui/theme';
3
+ import { ComboboxPill, type FilterOption } from '../filter/filter-pills';
3
4
  import { XIcon } from '../ui/icon/x-icon';
4
5
 
6
+ export type { FilterOption };
7
+
5
8
  // v2's built-in pills, in its order: packages/core/src/screens/main/pos/products/filter-bar/filter-bar-layout.ts
6
9
  // `BUILT_IN_PILL_IDS` (MIT, WCPOS).
7
10
  export type ProductFilterChip = 'inStock' | 'featured' | 'onSale' | 'category' | 'tag' | 'brand';
@@ -17,13 +20,30 @@ export const PRODUCT_FILTER_CHIPS: readonly ProductFilterChip[] = ['inStock', 'f
17
20
  const LABELS: Record<ProductFilterChip, string> = {
18
21
  inStock: 'In Stock', featured: 'Featured', onSale: 'On Sale', category: 'Category', tag: 'Tag', brand: 'Brand',
19
22
  };
23
+ const SEARCH: Record<TermChip, string> = { category: 'Search categories', tag: 'Search tags', brand: 'Search brands' };
24
+
25
+ export interface ProductTermFilter {
26
+ /** The app's terms for this taxonomy. */
27
+ options: readonly FilterOption[];
28
+ /** The picked term's value; undefined when none is picked. */
29
+ value?: string;
30
+ onChange: (next: string | undefined) => void;
31
+ /** Search the app's terms server-side; without it the pill filters `options` by label. */
32
+ onSearch?: (text: string) => void;
33
+ }
20
34
 
21
35
  export interface ProductFilterBarProps {
22
36
  value: ProductFilters;
23
37
  onChange: (next: ProductFilters) => void;
24
38
  /** Which chips to show, in this order. Default PRODUCT_FILTER_CHIPS. */
25
39
  chips?: readonly ProductFilterChip[];
26
- /** Opens the app's term picker; the category, tag and brand chips render only when it is given. */
40
+ /** Picker pills for Category, Tag and Brand (v2 filter-bar/*-pill.tsx). A chip with an entry here opens its own
41
+ * picker. A chip without one falls back to `onTermPress`, and is hidden when neither is given. */
42
+ terms?: Partial<Record<TermChip, ProductTermFilter>>;
43
+ /** Extra term pills after the built-in chips, one per group, in this order (e.g. one per Vendure facet). Each is a
44
+ * single-select searchable picker like a `terms` entry; `searchPlaceholder` defaults to `Search <label>`. */
45
+ termGroups?: readonly (ProductTermFilter & { id: string; label: string; searchPlaceholder?: string })[];
46
+ /** Opens the app's term picker for a term chip that has no entry in `terms`. */
27
47
  onTermPress?: (chip: TermChip) => void;
28
48
  className?: string;
29
49
  }
@@ -34,14 +54,22 @@ function isToggle(chip: ProductFilterChip): chip is ToggleChip {
34
54
 
35
55
  /**
36
56
  * v2's always-on filter chips above the product grid: In Stock, Featured and On Sale toggle; Category, Tag
37
- * and Brand open the app's term picker. Ported from WCPOS v2 `FilterBar`,
38
- * packages/core/src/screens/main/pos/products/filter-bar/filter-bar.tsx (MIT, WCPOS).
57
+ * and Brand open a term picker, the bar's own (`terms`) or the app's (`onTermPress`). Ported from WCPOS v2
58
+ * `FilterBar`, packages/core/src/screens/main/pos/products/filter-bar/filter-bar.tsx (MIT, WCPOS).
59
+ * `termGroups` adds a pill per extra term group (TallyUI's extension; v2's set is fixed).
39
60
  */
40
- export function ProductFilterBar({ value, onChange, chips = PRODUCT_FILTER_CHIPS, onTermPress, className }: ProductFilterBarProps) {
41
- const shown = chips.filter((chip) => isToggle(chip) || onTermPress);
61
+ export function ProductFilterBar({ value, onChange, chips = PRODUCT_FILTER_CHIPS, terms, termGroups, onTermPress, className }: ProductFilterBarProps) {
62
+ const shown = chips.filter((chip) => isToggle(chip) || terms?.[chip] || onTermPress);
42
63
  return (
43
64
  <ScrollView horizontal showsHorizontalScrollIndicator={false} className={className} contentContainerClassName="flex-row gap-2">
44
65
  {shown.map((chip) => {
66
+ const t = isToggle(chip) ? undefined : terms?.[chip];
67
+ if (t) {
68
+ return (
69
+ <ComboboxPill key={chip} id={`filter-chip-${chip}`} offLabel={LABELS[chip]} placeholder={SEARCH[chip as TermChip]}
70
+ value={t.value} options={[...t.options]} onSearch={t.onSearch} onPick={t.onChange} onClear={() => t.onChange(undefined)} />
71
+ );
72
+ }
45
73
  const on = isToggle(chip) && value[chip];
46
74
  return (
47
75
  <Pressable key={chip} testID={`filter-chip-${chip}`} role="button" aria-pressed={isToggle(chip) ? on : undefined}
@@ -53,6 +81,11 @@ export function ProductFilterBar({ value, onChange, chips = PRODUCT_FILTER_CHIPS
53
81
  </Pressable>
54
82
  );
55
83
  })}
84
+ {termGroups?.map((group) => (
85
+ <ComboboxPill key={`filter-chip-group-${group.id}`} id={`filter-chip-group-${group.id}`} offLabel={group.label}
86
+ placeholder={group.searchPlaceholder ?? `Search ${group.label}`} value={group.value} options={[...group.options]}
87
+ onSearch={group.onSearch} onPick={group.onChange} onClear={() => group.onChange(undefined)} />
88
+ ))}
56
89
  </ScrollView>
57
90
  );
58
91
  }
@@ -0,0 +1,243 @@
1
+ /**
2
+ * The receipt print sheet: template choice, printer, the preview, and Close / Email Receipt / Print.
3
+ * Layout of WCPOS v2, MIT, WCPOS: packages/core/src/screens/main/receipt/receipt.tsx, print-sheet.tsx,
4
+ * receipt-body.tsx, template-switcher.tsx, printer-switcher.tsx and receipt-actions.tsx; the strings are v2's English ones from core.json;
5
+ * after a send the sheet shows v2's 'Email sent' / 'Receipt email queued' as a line, not a toast.
6
+ * Props-only: the sheet renders no receipt and prints nothing itself.
7
+ */
8
+ import { useState, type JSX, type ReactNode } from 'react';
9
+ import { ScrollView, View } from 'react-native';
10
+ import { cn } from '@tallyui/theme';
11
+ import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '../ui/dialog';
12
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select';
13
+ import { Button } from '../ui/button';
14
+ import { Input } from '../ui/input';
15
+ import { Switch } from '../ui/switch';
16
+ import { PrinterIcon } from '../ui/icon/printer-icon';
17
+ import { Loader } from '../ui/loader';
18
+ import { Text } from '../ui/text';
19
+ import { useT } from '../i18n';
20
+
21
+ export interface ReceiptSheetTemplate {
22
+ id: string;
23
+ title: string;
24
+ /** Shown but not choosable (v2: offline and not offline-capable). */
25
+ disabled?: boolean;
26
+ }
27
+
28
+ export interface ReceiptSheetEmail {
29
+ /** Prefills "Email Address" (v2: the order's billing email). */
30
+ defaultAddress?: string;
31
+ /** Draws v2's offline notice; Send reads "Send when online". */
32
+ offline?: boolean;
33
+ /** Draws "Save email to the customer" (default off). */
34
+ saveToCustomer?: boolean;
35
+ /** Sends or queues the receipt. Returns a refusal to show, or null once sent or queued; the form then closes. */
36
+ onSend: (input: { address: string; saveToCustomer: boolean }) => Promise<string | null> | string | null;
37
+ }
38
+
39
+ export interface ReceiptSheetProps {
40
+ open: boolean;
41
+ onOpenChange: (open: boolean) => void;
42
+ /** Default "Receipt". */
43
+ title?: string;
44
+ templates: readonly ReceiptSheetTemplate[];
45
+ templateId?: string;
46
+ onTemplateChange?: (id: string) => void;
47
+ /** The Printer row's text. Default "Browser print dialog". */
48
+ printerLabel?: string;
49
+ /** v2's printer switcher. The app keeps the pick, for this print only, and resets it when the template changes, as v2 does. */
50
+ printers?: readonly { id: string; name?: string }[];
51
+ /** The cashier's pick for this print; null or undefined is Auto. */
52
+ printerId?: string | null;
53
+ /** The name Auto resolves to, worked out by the app (for example with `resolvePrinter` from `@tallyui/pos`). */
54
+ autoPrinterName?: string;
55
+ /** Called with the picked printer's id, or null for Auto. */
56
+ onPrinterChange?: (id: string | null) => void;
57
+ onPrint: () => void;
58
+ /** Print shows its loading state and cannot be pressed. */
59
+ printing?: boolean;
60
+ /** Print reads "Print again". */
61
+ printed?: boolean;
62
+ /** "Email Receipt" is drawn only when given. */
63
+ onEmail?: () => void;
64
+ /** v2's email form: "Email Receipt" opens it inside the sheet. When given, it takes the place of `onEmail`. */
65
+ email?: ReceiptSheetEmail;
66
+ /** v2's "Download PDF": drawn only when given, between Email Receipt and Print. The app makes and saves the PDF. */
67
+ onDownloadPdf?: () => void;
68
+ /** Download PDF shows its loading state and cannot be pressed. */
69
+ downloadingPdf?: boolean;
70
+ /** The preview. */
71
+ children: ReactNode;
72
+ }
73
+
74
+ /** v2's property list row: label left, value right (as SettingsRow lays one out, without the card). */
75
+ function SheetRow({ testID, label, children }: { testID: string; label: string; children: ReactNode }) {
76
+ return (
77
+ <View testID={testID} className="min-h-11 flex-row items-center gap-3">
78
+ <Text className="flex-1 text-sm font-medium text-foreground">{label}</Text>
79
+ {children}
80
+ </View>
81
+ );
82
+ }
83
+
84
+ function TemplateValue({ templates, templateId, onTemplateChange }:
85
+ Pick<ReceiptSheetProps, 'templates' | 'templateId' | 'onTemplateChange'>) {
86
+ if (templates.length === 1) return <Text className="text-sm text-foreground">{templates[0].title}</Text>;
87
+ const current = templates.find((template) => template.id === templateId);
88
+ return (
89
+ <Select value={current ? { value: current.id, label: current.title } : undefined}
90
+ onValueChange={(option) => { if (option && option.value !== templateId) onTemplateChange?.(option.value); }}>
91
+ <SelectTrigger testID="receipt-template-select" accessibilityLabel="Template" className="h-11 w-56 gap-2">
92
+ <SelectValue placeholder="Select template" className="shrink text-sm text-foreground" numberOfLines={1} />
93
+ </SelectTrigger>
94
+ <SelectContent className="w-56">
95
+ {templates.map((template) => (
96
+ <SelectItem key={template.id} value={template.id} label={template.title} disabled={template.disabled}
97
+ testID={`receipt-template-${template.id}`} className={cn('min-h-11', template.disabled && 'opacity-50')}>
98
+ <Text className="text-sm">{template.title}</Text>
99
+ </SelectItem>
100
+ ))}
101
+ </SelectContent>
102
+ </Select>
103
+ );
104
+ }
105
+
106
+ const AUTO = '__auto__';
107
+
108
+ /** v2's printer-switcher.tsx: Auto first, then every printer by name, falling back to its id. */
109
+ function PrinterValue({ printers, printerId, autoPrinterName, onPrinterChange }:
110
+ Required<Pick<ReceiptSheetProps, 'printers'>> & Pick<ReceiptSheetProps, 'printerId' | 'autoPrinterName' | 'onPrinterChange'>) {
111
+ const labelOf = (printer: { id: string; name?: string }) => printer.name?.trim() || printer.id;
112
+ const current = printers.find((printer) => printer.id === printerId);
113
+ const value = current
114
+ ? { value: current.id, label: labelOf(current) }
115
+ : { value: AUTO, label: autoPrinterName ? `Auto — ${autoPrinterName}` : 'Auto' };
116
+ return (
117
+ <Select value={value} onValueChange={(option) => {
118
+ if (option && option.value !== value.value) onPrinterChange?.(option.value === AUTO ? null : option.value);
119
+ }}>
120
+ <SelectTrigger testID="receipt-printer-select" accessibilityLabel="Printer" className="h-11 w-56 gap-2">
121
+ <SelectValue placeholder="Select printer" className="shrink text-sm text-foreground" numberOfLines={1} />
122
+ </SelectTrigger>
123
+ <SelectContent className="w-56">
124
+ <SelectItem value={AUTO} label="Auto" testID="receipt-printer-auto" className="min-h-11">
125
+ <Text className="text-sm">Auto</Text>
126
+ </SelectItem>
127
+ {printers.map((printer) => (
128
+ <SelectItem key={printer.id} value={printer.id} label={labelOf(printer)} testID={`receipt-printer-${printer.id}`} className="min-h-11">
129
+ <Text className="text-sm">{labelOf(printer)}</Text>
130
+ </SelectItem>
131
+ ))}
132
+ </SelectContent>
133
+ </Select>
134
+ );
135
+ }
136
+
137
+ const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+$/;
138
+
139
+ /** v2's email.tsx (MIT, WCPOS) inline: it mounts fresh on each open, so it starts from defaultAddress, switch off, no error. */
140
+ function EmailForm({ email, onDone }: { email: ReceiptSheetEmail; onDone: (queued: boolean) => void }) {
141
+ const [text, setText] = useState(email.defaultAddress ?? '');
142
+ const [save, setSave] = useState(false);
143
+ const [error, setError] = useState<string | null>(null);
144
+ const [sending, setSending] = useState(false);
145
+ const send = async () => {
146
+ if (sending) return;
147
+ const address = text.trim();
148
+ if (!EMAIL_PATTERN.test(address)) return setError('Enter an email address.');
149
+ setError(null);
150
+ let refusal: string | null;
151
+ try {
152
+ const result = email.onSend({ address, saveToCustomer: save });
153
+ if (typeof result === 'string' || result === null) refusal = result;
154
+ else { setSending(true); refusal = await result; }
155
+ } catch (cause) {
156
+ refusal = cause instanceof Error ? cause.message : 'Could not send the receipt.';
157
+ }
158
+ setSending(false);
159
+ if (refusal === null) onDone(Boolean(email.offline)); else setError(refusal);
160
+ };
161
+ return (
162
+ <View testID="receipt-email-form" className="gap-2 py-2">
163
+ <Text className="text-sm font-medium text-foreground">Email Address</Text>
164
+ <Input><Input.Field testID="receipt-email-address" accessibilityLabel="Email Address" value={text} onChangeText={setText}
165
+ keyboardType="email-address" autoCapitalize="none" autoCorrect={false} /></Input>
166
+ {email.saveToCustomer ? (
167
+ <SheetRow testID="receipt-email-save-row" label="Save email to the customer">
168
+ <Switch testID="receipt-email-save" accessibilityLabel="Save email to the customer" checked={save} onCheckedChange={setSave} />
169
+ </SheetRow>
170
+ ) : null}
171
+ {email.offline ? (
172
+ <Text testID="receipt-email-offline" className="text-sm text-muted-foreground">
173
+ This device can’t reach your store right now. The receipt will be emailed automatically when the connection returns.
174
+ </Text>
175
+ ) : null}
176
+ {error ? <Text testID="receipt-email-error" accessibilityRole="alert" className="text-sm text-destructive">{error}</Text> : null}
177
+ <Button testID="receipt-email-send" className="self-end" onPress={() => void send()} disabled={sending}
178
+ accessibilityState={{ disabled: sending, busy: sending }}>
179
+ {sending ? <Loader size="sm" /> : null}
180
+ <Text>{email.offline ? 'Send when online' : 'Send'}</Text>
181
+ </Button>
182
+ </View>
183
+ );
184
+ }
185
+
186
+ export function ReceiptSheet({ open, onOpenChange, title = 'Receipt', templates, templateId, onTemplateChange,
187
+ printerLabel = 'Browser print dialog', printers, printerId, autoPrinterName, onPrinterChange,
188
+ onPrint, printing = false, printed = false, onEmail, email, onDownloadPdf, downloadingPdf = false, children }: ReceiptSheetProps): JSX.Element {
189
+ const t = useT();
190
+ const [sent, setSent] = useState<'sent' | 'queued' | null>(null);
191
+ const [emailOpen, setEmailOpen] = useState(false);
192
+ // Closing the sheet closes the form too, so it opens fresh next time.
193
+ if (!open && (emailOpen || sent)) { setEmailOpen(false); setSent(null); }
194
+ const onEmailPress = email ? () => { setSent(null); setEmailOpen((was) => !was); } : onEmail;
195
+ return (
196
+ <Dialog open={open} onOpenChange={onOpenChange}>
197
+ <DialogContent side="right" testID="receipt-dialog" className="flex-col" showClose>
198
+ <DialogHeader>
199
+ {/* v2 titles a refund document "Refund receipt"; TallyUI's app passes `title` for that. */}
200
+ <DialogTitle>{title}</DialogTitle>
201
+ </DialogHeader>
202
+ <View>
203
+ {templates.length === 0 ? null : (
204
+ <SheetRow testID="print-sheet-template" label="Template">
205
+ <TemplateValue templates={templates} templateId={templateId} onTemplateChange={onTemplateChange} />
206
+ </SheetRow>
207
+ )}
208
+ {/* v2's printer-switcher.tsx when the app passes printers; otherwise the app's one label. */}
209
+ <SheetRow testID="print-sheet-printer" label="Printer">
210
+ {printers && printers.length > 0 ? (
211
+ <PrinterValue printers={printers} printerId={printerId} autoPrinterName={autoPrinterName} onPrinterChange={onPrinterChange} />
212
+ ) : <Text className="text-sm text-foreground">{printerLabel}</Text>}
213
+ </SheetRow>
214
+ </View>
215
+ {/* v2 draws its own WebView preview with zoom and loading states; here the app's preview is the child. */}
216
+ <ScrollView className="flex-1" contentContainerClassName="pb-2">{children}</ScrollView>
217
+ {email && emailOpen ? <EmailForm email={email} onDone={(queued) => { setEmailOpen(false); setSent(queued ? 'queued' : 'sent'); }} /> : null}
218
+ {email && sent ? <Text testID="receipt-email-sent" className="py-2 text-sm text-foreground">{t(sent === 'queued' ? 'receipt.email_queued' : 'receipt.email_sent')}</Text> : null}
219
+ {/* v2's footer also has Sync order, which TallyUI does not have. `email` draws v2's form above, and the app sends. Download PDF is drawn when `onDownloadPdf` is given. */}
220
+ <DialogFooter bordered className="gap-2" testID="receipt-footer">
221
+ <DialogClose asChild>
222
+ <Button variant="outline" testID="receipt-close-button"><Text>Close</Text></Button>
223
+ </DialogClose>
224
+ {onEmailPress ? (
225
+ <Button variant="outline" testID="receipt-email-button" onPress={onEmailPress}><Text>Email Receipt</Text></Button>
226
+ ) : null}
227
+ {onDownloadPdf ? (
228
+ <Button variant="outline" testID="receipt-download-pdf-button" onPress={onDownloadPdf} disabled={downloadingPdf}
229
+ accessibilityState={{ disabled: downloadingPdf, busy: downloadingPdf }}>
230
+ {downloadingPdf ? <Loader size="sm" /> : null}
231
+ <Text>Download PDF</Text>
232
+ </Button>
233
+ ) : null}
234
+ <Button testID="receipt-print-button" onPress={onPrint} disabled={printing}
235
+ accessibilityState={{ disabled: printing, busy: printing }}>
236
+ {printing ? <Loader size="sm" /> : <PrinterIcon size={16} className="text-primary-foreground" />}
237
+ <Text>{printed ? 'Print again' : 'Print receipt'}</Text>
238
+ </Button>
239
+ </DialogFooter>
240
+ </DialogContent>
241
+ </Dialog>
242
+ );
243
+ }
@@ -1,7 +1,7 @@
1
1
  import { useEffect, type ReactNode } from 'react';
2
2
  import { Pressable, Text, View } from 'react-native';
3
- import { formatMoney } from '@tallyui/core';
4
- import { buildReceiptData, noteDelivery, type ReceiptData, type SentOrder } from '@tallyui/pos';
3
+ import { useFormatMoney } from '@tallyui/core';
4
+ import { buildReceiptData, isCarriedCouponLabel, noteDelivery, type ReceiptData, type SentOrder } from '@tallyui/pos';
5
5
  import type { PosOrder } from '@tallyui/pos';
6
6
  import { injectPrintStyle } from './print-style';
7
7
  import { discountLabel } from './discount-form';
@@ -10,12 +10,13 @@ import { NOTE_NOT_SENT, orderReference } from './order-reference';
10
10
  const defaultFormatDate = (iso: string) => new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' }).format(new Date(iso));
11
11
 
12
12
  type ReceiptProps = {
13
- newSale: () => void;
14
13
  taxLabel?: (ratePpm: number) => string; topInset?: number; formatDate?: (iso: string) => string;
15
14
  /** Prints after the Change row and above the on-screen buttons (e.g. an app's register/software block). */
16
15
  footerSlot?: ReactNode;
17
16
  /** The second button's text; default `New sale`. */
18
17
  doneLabel?: string;
18
+ /** The app's own record that this receipt was printed; Print reads 'Print again' (as `ReceiptSheet`, v2's `printedTo`). Ignored when `actions` replaces the buttons. */
19
+ printed?: boolean;
19
20
  } & ({
20
21
  order: SentOrder; store: { name: string; address?: string }; cashier: string; registerId: string;
21
22
  /** The register's name, printed as `Register: <name>`; the id is never printed. */
@@ -30,13 +31,18 @@ type ReceiptProps = {
30
31
  /** With it the receipt prints its reference, the same as Orders; without it, the receipt's own order number. */
31
32
  posOrder?: PosOrder;
32
33
  order?: never; store?: never; cashier?: never; registerId?: never; registerName?: never;
34
+ }) & ({ newSale: () => void; actions?: undefined } | {
35
+ newSale?: () => void;
36
+ /** Replaces Print receipt and New sale (never printed), e.g. a host footer as in v2's receipt stage; `false` draws no buttons. */
37
+ actions: ReactNode | false;
33
38
  });
34
39
 
35
40
  /** `store`/`taxLabel`/`topInset`/`formatDate` replace the app's Medusa settings, hard-coded VAT (default matches
36
41
  * TV6a's `Cart`), outbox strip and date util, so `Receipt` stays platform-neutral (ADR-052). */
37
42
  export function Receipt(props: ReceiptProps) {
43
+ const formatMoney = useFormatMoney();
38
44
  const { posOrder, newSale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`,
39
- topInset = 0, formatDate = defaultFormatDate, footerSlot, doneLabel = 'New sale' } = props;
45
+ topInset = 0, formatDate = defaultFormatDate, footerSlot, doneLabel = 'New sale', actions, printed = false } = props;
40
46
  useEffect(injectPrintStyle, []);
41
47
  const order = props.receipt === undefined ? props.order : undefined;
42
48
  const receipt = props.receipt === undefined ? buildReceiptData(props.order, {
@@ -69,8 +75,9 @@ export function Receipt(props: ReceiptProps) {
69
75
  {Object.entries(line.attributes ?? {}).map(([name, value]) => <Text key={name} className="text-muted-foreground">{`${name}: ${value}`}</Text>)}
70
76
  {/* Before any discount, then the line's own discounts as sub-rows (TallyUI ADR-063); they add up to the subtotal. */}
71
77
  {row(`${line.quantity} × ${money(line.unitPriceMinor)}`, money(line.displayAmountMinor))}
72
- {line.displayDiscounts.map((discount, i) => <View key={i} className="pl-4">{row(`${order ? discountLabel(
73
- order.lineItems[index].discounts[i], receipt.currency) : discount.label} off`, `−${money(discount.amountMinor)}`)}</View>)}
78
+ {/* A row with no cart discount behind it (a carried coupon) prints under its own label. */}
79
+ {line.displayDiscounts.map((discount, i) => <View key={i} className="pl-4">{row((order && !order.lineItems[index].discounts[i]) || (!order && isCarriedCouponLabel(discount.label)) ? discount.label
80
+ : `${order ? discountLabel(order.lineItems[index].discounts[i], receipt.currency, formatMoney) : discount.label} off`, `−${money(discount.amountMinor)}`)}</View>)}
74
81
  </View>)}
75
82
  {/* Each discount appears once in the totals: line discounts are itemised under their lines and summed once here;
76
83
  the order discount appears once. order.display's figures (ADR-063; medusapos ADR 0008). */}
@@ -86,6 +93,7 @@ export function Receipt(props: ReceiptProps) {
86
93
  : order || payment.method === 'external' ? 'Card terminal' : payment.method,
87
94
  money(payment.amountMinor) + (payment.reference ? ` · ${payment.reference}` : ''), false, index))}
88
95
  {order || receipt.changeDueMinor > 0 ? row('Change', money(receipt.changeDueMinor)) : null}
96
+ {receipt.refundDueMinor ? row('Refund due', money(receipt.refundDueMinor)) : null}
89
97
  {receipt.footer.note ? <View testID="receipt-note" className="gap-1">
90
98
  <Text className="text-foreground">{receipt.footer.note}</Text>
91
99
  {/* ADR-083 condition 2: for the cashier, so it is not printed. */}
@@ -93,11 +101,13 @@ export function Receipt(props: ReceiptProps) {
93
101
  ? <View dataSet={{ print: 'hide' }}><Text testID="receipt-note-not-sent" className="text-destructive">{NOTE_NOT_SENT}</Text></View> : null}
94
102
  </View> : null}
95
103
  {footerSlot ? <View testID="receipt-footer" className="mt-3 items-center border-t border-dashed border-border pt-3">{footerSlot}</View> : null}
96
- <View dataSet={{ print: 'hide' }} className="flex-row gap-4">
104
+ {actions === false ? null : <View dataSet={{ print: 'hide' }} className="flex-row gap-4">
105
+ {actions !== undefined ? actions : <>
97
106
  <Pressable accessibilityRole="button" onPress={() => { if (typeof window !== 'undefined' && typeof window.print === 'function') window.print(); }} className="rounded-md border border-border bg-card px-4 py-3">
98
- <Text className="text-center text-foreground">Print receipt</Text>
107
+ <Text className="text-center text-foreground">{printed ? 'Print again' : 'Print receipt'}</Text>
99
108
  </Pressable>
100
109
  <Pressable accessibilityRole="button" onPress={newSale} className="rounded-md bg-primary px-4 py-3"><Text className="text-center font-semibold text-primary-foreground">{doneLabel}</Text></Pressable>
101
- </View>
110
+ </>}
111
+ </View>}
102
112
  </View></>;
103
113
  }
@@ -83,6 +83,16 @@ function useAnnounceOnIos(...texts: (string | undefined)[]) {
83
83
  if (changed.length > 0 && Platform.OS === 'ios') AccessibilityInfo.announceForAccessibility(changed.join(' '));
84
84
  }, texts);
85
85
  }
86
+ /**
87
+ * True when `SyncStatus` with these props would show only "Sales are up to date.": no pull notice, nothing waiting,
88
+ * no refused sales and no missing backend. An app can hide the status line then.
89
+ */
90
+ export function syncStatusQuiet({ state, registerState, pullNotice }:
91
+ { state: OutboxState; registerState?: OutboxState; pullNotice?: SyncNotice }): boolean {
92
+ return !pullNotice && state.pending === 0 && (registerState?.pending ?? 0) === 0 && !state.rejected
93
+ && !(state.backendMissing ?? registerState?.backendMissing);
94
+ }
95
+
86
96
  /**
87
97
  * `pluginName` names the store's plugin in the detail, as its owners know it; `registerState` counts till updates.
88
98
  * `pullNotice` (a stopped product pull) shows as its own line and detail, above the outbox line.
@@ -0,0 +1,92 @@
1
+ /**
2
+ * The payments ledger, as WCPOS v2's LedgerLegs (monorepo main, packages/core/src/screens/main/pos/checkout/tender/ledger-pane.tsx):
3
+ * each leg with its status, Next and Cancel payment. `closing` is v2's checkout cart (cart/stilled-cart.tsx): a Payments
4
+ * heading, the legs, then Total, Paid and a Remaining (or Paid in full) lead row. Internal: TenderPane and Cart render it.
5
+ */
6
+ import { useState, type JSX } from 'react';
7
+ import { Pressable, Text, View } from 'react-native';
8
+ import { useFormatMoney, wireMethodOf, type PaymentMethodDescriptor } from '@tallyui/core';
9
+ import { canVoidLeg, countsTowardPaid, legStatus, type PaymentLegStatus, type useSale } from '@tallyui/pos';
10
+ import { cn } from '@tallyui/theme';
11
+ import { useT } from '../i18n';
12
+ import { ConfirmDialog } from '../ui/confirm-dialog';
13
+ import { offeredMethods } from './offered-methods';
14
+
15
+ /** v2 labels.ts statusLabel, as catalogue keys. */
16
+ const STATUS_LABEL: Record<PaymentLegStatus, string> = {
17
+ pending: 'pos_checkout.status_pending', authorized: 'pos_checkout.status_authorized', captured: 'pos_checkout.status_captured',
18
+ failed: 'pos_checkout.status_failed', voided: 'pos_checkout.status_voided',
19
+ };
20
+ /** v2 labels.ts statusVariant: coloured by what the cashier has to do about the leg. */
21
+ const STATUS_TONE: Record<PaymentLegStatus, string> = {
22
+ pending: 'text-muted-foreground', authorized: 'text-success', captured: 'text-success', failed: 'text-destructive', voided: 'text-muted-foreground',
23
+ };
24
+
25
+ export function TenderLedger({ sale, methods, closing = false, confirmVoid = false }: { sale: ReturnType<typeof useSale>; methods?: PaymentMethodDescriptor[]; closing?: boolean;
26
+ /** v2's "Cancel this payment?" before a leg is voided (use-tender-flow.ts cancelOne). Default false: Cancel payment voids at once. */
27
+ confirmVoid?: boolean }): JSX.Element | null {
28
+ const formatMoney = useFormatMoney();
29
+ const t = useT();
30
+ /** The id of the leg the one question is about (confirmVoid). */
31
+ const [asking, setAsking] = useState<string | null>(null);
32
+ const { order, stage } = sale;
33
+ if (stage.kind !== 'tender') return null;
34
+
35
+ const offered = offeredMethods(methods);
36
+ /** The leg's offered descriptor: its own id and its wire method both match, so a card-kind `cash` id never reads as Cash. */
37
+ const descriptorOf = (leg: { method: string; methodId?: string }) => offered.find((method) => method.id === (leg.methodId ?? leg.method) && wireMethodOf(method) === leg.method);
38
+ const money = (minor: number) => formatMoney({ amount: minor, currency: order.currency }) ?? '';
39
+ const balance = order.balanceDueMinor;
40
+ const settled = order.payments.some(countsTowardPaid);
41
+ const firstPending = order.payments.find((leg) => legStatus(leg) === 'pending');
42
+ const askedLeg = order.payments.find((leg) => leg.id === asking);
43
+ const asked = askedLeg && descriptorOf(askedLeg);
44
+ /** v2 cancelOne's body: cash not captured by the server goes back as cash, anything else is voided on its method. */
45
+ const question = askedLeg && asked ? asked.kind === 'cash' && asked.capture.mode !== 'server'
46
+ ? t('pos_checkout.return_cash', { amount: money(askedLeg.amountMinor) })
47
+ : t('pos_checkout.void_on_method', { amount: money(askedLeg.amountMinor), title: asked.title }) : undefined;
48
+
49
+ const legs = <View testID="tender-ledger" className="gap-1">
50
+ {order.payments.length === 0 ? <Text className="text-muted-foreground">{t('pos_checkout.no_payments_yet')}</Text> : order.payments.map((leg) => {
51
+ const status = legStatus(leg);
52
+ const voided = status === 'voided';
53
+ const descriptor = descriptorOf(leg);
54
+ return <View key={leg.id} testID={`tender-leg-${leg.id}`} className="gap-1 border-b border-border py-2">
55
+ <View className="flex-row items-center gap-2">
56
+ <Text className={cn('flex-1 font-semibold text-foreground', voided && 'line-through')}>{descriptor?.title ?? leg.methodId ?? leg.method}</Text>
57
+ <Text className={cn('text-foreground', voided && 'line-through')}>{money(leg.amountMinor)}</Text>
58
+ <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>
59
+ </View>
60
+ {leg.reference ? <Text className="text-sm text-muted-foreground">{leg.reference}</Text> : null}
61
+ {leg === firstPending ? <Text className="text-sm text-muted-foreground">{t('pos_checkout.next_leg')}</Text> : null}
62
+ {descriptor && canVoidLeg(leg, descriptor) ? <Pressable testID={`tender-leg-${leg.id}-void`} accessibilityRole="button" accessibilityLabel={t('pos_checkout.cancel_payment')}
63
+ onPress={() => (confirmVoid ? setAsking(leg.id) : sale.voidTender(leg.id))} className="self-start min-h-11 justify-center px-2">
64
+ <Text className="text-destructive">{t('pos_checkout.cancel_payment')}</Text>
65
+ </Pressable> : null}
66
+ </View>;
67
+ })}
68
+ {!closing && balance === 0 && settled ? <Text className="text-sm text-success">{t('pos_checkout.paid_in_full')}</Text> : null}
69
+ {confirmVoid ? <ConfirmDialog testID="tender-leg-void-dialog" tone="destructive" title={t('pos_checkout.cancel_payment_question')} description={question}
70
+ confirmLabel={t('pos_checkout.cancel_payment')} open={asking !== null} onOpenChange={(open) => { if (!open) setAsking(null); }}
71
+ onConfirm={() => { if (asking) sale.voidTender(asking); }} /> : null}
72
+ </View>;
73
+ if (!closing) return legs;
74
+
75
+ const row = (label: string, minor: number) => <View className="flex-row justify-between">
76
+ <Text className="text-sm text-muted-foreground">{label}</Text><Text className="text-sm text-foreground">{money(minor)}</Text>
77
+ </View>;
78
+ return <View testID="cart-payments" className="gap-2 border-t border-border p-2">
79
+ <Text className="font-semibold text-foreground">{t('pos_checkout.payments_tab')}</Text>
80
+ {legs}
81
+ <View testID="tender-ledger-totals" className="gap-1.5">
82
+ {row(t('common.total'), order.totalMinor)}
83
+ {row(t('pos_checkout.paid'), order.paidMinor)}
84
+ <View testID="tender-ledger-lead" className="mt-1.5 flex-row justify-between border-t border-border pt-2">
85
+ {balance === 0 && settled ? <Text className="font-semibold text-success">{t('pos_checkout.paid_in_full')}</Text> : <>
86
+ <Text className="font-semibold text-foreground">{t('pos_checkout.remaining')}</Text>
87
+ <Text testID="tender-ledger-remaining" className="font-semibold text-foreground">{money(order.balanceDueMinor)}</Text>
88
+ </>}
89
+ </View>
90
+ </View>
91
+ </View>;
92
+ }