@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.
- package/dist/index.d.ts +133 -50
- package/dist/index.js +2134 -1722
- package/package.json +10 -9
- package/src/cart/cart-columns-form.tsx +1 -1
- package/src/cart/cart-line-strip.tsx +17 -4
- package/src/customer/customer-dropdown.tsx +6 -2
- package/src/customer/customer-editor.tsx +2 -2
- package/src/customer/customer-picker.tsx +15 -12
- package/src/i18n/locales/en/components.json +23 -2
- package/src/index.ts +4 -2
- package/src/layout/settings-layout.tsx +16 -4
- package/src/lib/motion.ts +6 -0
- package/src/order/index.ts +1 -0
- package/src/order/refund-form.tsx +16 -3
- package/src/order/refund-needs-admin-notice.tsx +29 -0
- package/src/product/product-table.tsx +18 -7
- package/src/product/product-variant-picker.tsx +4 -0
- package/src/register/register-count.tsx +1 -1
- package/src/reports/card-panel.tsx +3 -1
- package/src/reports/cards.tsx +1 -0
- package/src/sale/cancel-payment-view.tsx +102 -0
- package/src/sale/cart.tsx +12 -8
- package/src/sale/catalogue-settings-form.tsx +2 -2
- package/src/sale/catalogue.tsx +57 -12
- package/src/sale/charge-form.tsx +21 -3
- package/src/sale/customer-display-screen.tsx +2 -1
- package/src/sale/index.ts +2 -2
- package/src/sale/open-sale-tabs.tsx +23 -3
- package/src/sale/orders-list.tsx +10 -3
- package/src/sale/receipt-sheet.tsx +28 -8
- package/src/sale/receipt.tsx +1 -0
- package/src/sale/sale-error-text.ts +10 -0
- package/src/sale/since-text.ts +6 -3
- package/src/sale/sync-status.tsx +10 -1
- package/src/sale/tender-ledger.tsx +54 -11
- package/src/sale/tender-pane.tsx +106 -38
- package/src/sale/tender.tsx +7 -5
- package/src/sale/void-in-flight.ts +19 -0
- package/src/ui/tabs/index.tsx +1 -1
- package/src/checkout/payment-types.test-d.ts +0 -28
|
@@ -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
|
+
}
|
package/src/sale/cart.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, type ReactNode } from 'react';
|
|
1
|
+
import { useState, type ComponentProps, type ReactNode } from 'react';
|
|
2
2
|
import { Pressable, Text, View, useWindowDimensions } from 'react-native';
|
|
3
3
|
import { buildReceiptData } from '@tallyui/pos';
|
|
4
4
|
import type { useSale } from '@tallyui/pos';
|
|
@@ -17,6 +17,7 @@ import { OrderNoteSheet } from './order-note-sheet';
|
|
|
17
17
|
import { TenderLedger } from './tender-ledger';
|
|
18
18
|
import { ShoppingCartIcon } from '../ui';
|
|
19
19
|
import { useT } from '../i18n';
|
|
20
|
+
import { saleErrorText } from './sale-error-text';
|
|
20
21
|
|
|
21
22
|
/** `taxLabel` names each tax row; VAT isn't universal, so a platform passes its own (medusapos passes `VAT ${rate}%`). */
|
|
22
23
|
export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`, canEditPrice = false, onPriceChange, quickDiscounts, taxClasses, afterSubtotal, showTotal = true, couponDiscountMinor, orderActions = true, orderDiscountChips = true, checkout, noteSheet, tenderLedger, picker, lineEditor = 'inline',
|
|
@@ -54,8 +55,8 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
54
55
|
* names the note (default "Customer note"; a platform whose note the customer never sees passes its own, e.g.
|
|
55
56
|
* "Order note"). Needs `checkout`; when given, it replaces `checkout.note`. */
|
|
56
57
|
noteSheet?: { label?: string };
|
|
57
|
-
/** v2's checkout cart (stilled-cart.tsx): while `sale.stage` is tender, the payments ledger (each leg with its status and Cancel payment, then Total, Paid and Remaining) sits under the totals in place of the foot. `methods` names the legs, as on Tender. Pair it with `<Tender ledger={false} />`. `confirmVoid` asks v2's "Cancel this payment?" before a leg is voided (default `false`). */
|
|
58
|
-
tenderLedger?: { methods?: PaymentMethodDescriptor[]; confirmVoid?: boolean };
|
|
58
|
+
/** v2's checkout cart (stilled-cart.tsx): while `sale.stage` is tender, the payments ledger (each leg with its status and Cancel payment, then Total, Paid and Remaining) sits under the totals in place of the foot. `methods` names the legs, as on Tender. Pair it with `<Tender ledger={false} />`. `confirmVoid` asks v2's "Cancel this payment?" before a leg is voided (default `false`). `beforeVoid` runs before Cancel payment voids a leg, as on TenderLedger. */
|
|
59
|
+
tenderLedger?: { methods?: PaymentMethodDescriptor[]; confirmVoid?: boolean; beforeVoid?: ComponentProps<typeof TenderLedger>['beforeVoid']; afterVoid?: ComponentProps<typeof TenderLedger>['afterVoid'] };
|
|
59
60
|
/** WCPOS v2's split-by-item bill (stilled-cart.tsx): the cart is read-only, and each line whose quantity is a positive
|
|
60
61
|
* whole number, whose total is not negative and that has units left unpaid shows this payment's `− n of unpaid +`
|
|
61
62
|
* stepper in its quantity cell, with what the picked units add under it. `picked`: this payment's units per line id;
|
|
@@ -85,6 +86,7 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
85
86
|
/** The empty cart's line. Default: v2's "Tap a product to start a sale". */
|
|
86
87
|
emptyText?: string;
|
|
87
88
|
}) {
|
|
89
|
+
const t = useT();
|
|
88
90
|
const { order } = sale;
|
|
89
91
|
const [noteOpen, setNoteOpen] = useState(false);
|
|
90
92
|
// v2's empty cart: an icon and a line, no heads and no foot. A fee or shipping row alone keeps the cart.
|
|
@@ -187,7 +189,7 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
187
189
|
className="text-muted-foreground">{emptyIcon}</View>}
|
|
188
190
|
<Text testID="cart-empty-text" className="text-center text-muted-foreground">{emptyText}</Text>
|
|
189
191
|
{/* The footer is gone, so a resume or coupon message on an empty cart shows here. */}
|
|
190
|
-
{sale.error ? <Text accessibilityRole="alert" className="text-destructive">{sale.error}</Text> : null}
|
|
192
|
+
{sale.error ? <Text accessibilityRole="alert" className="text-destructive">{saleErrorText(t, sale.error)}</Text> : null}
|
|
191
193
|
</View> : undefined}
|
|
192
194
|
afterItems={<>
|
|
193
195
|
{(['fees', 'shipping'] as const).map((kind) => <MotionRows key={kind} items={order[kind] ?? []} keyOf={(charge) => charge.id}
|
|
@@ -235,8 +237,8 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
235
237
|
fees={money(fees.reduce((sum, row) => sum + row.amountMinor, 0))}
|
|
236
238
|
shipping={money(shipping.reduce((sum, row) => sum + row.amountMinor, 0))}
|
|
237
239
|
taxLines={taxRows} taxInclusive={totals.taxInclusive} afterSubtotal={afterSubtotal} showTotal={showTotal} />
|
|
238
|
-
{sale.error ? <Text accessibilityRole="alert" className="text-destructive">{sale.error}</Text> : null}
|
|
239
|
-
{tenderLedger && sale.stage.kind === 'tender' ? <TenderLedger sale={sale} methods={tenderLedger.methods} confirmVoid={tenderLedger.confirmVoid} closing /> : checkout ? <><CartFoot total={money(totals.totalMinor)} onCheckout={checkout.onCheckout}
|
|
240
|
+
{sale.error ? <Text accessibilityRole="alert" className="text-destructive">{saleErrorText(t, sale.error)}</Text> : null}
|
|
241
|
+
{tenderLedger && sale.stage.kind === 'tender' ? <TenderLedger sale={sale} methods={tenderLedger.methods} confirmVoid={tenderLedger.confirmVoid} beforeVoid={tenderLedger.beforeVoid} afterVoid={tenderLedger.afterVoid} closing /> : checkout ? <><CartFoot total={money(totals.totalMinor)} onCheckout={checkout.onCheckout}
|
|
240
242
|
actions={noteSheet ? [{ label: 'Order details', onPress: () => setNoteOpen(true) }, ...(checkout.actions ?? [])] : checkout.actions}
|
|
241
243
|
note={noteSheet ? { text: order.note, onPress: () => setNoteOpen(true) } : checkout.note} disabled={!order.lineItems.length} />
|
|
242
244
|
{noteSheet && noteOpen ? <OrderNoteSheet value={order.note} onChangeText={sale.setNote}
|
|
@@ -255,8 +257,10 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
255
257
|
/** A fee or shipping row on the picker's read-only bill: the row alone, no Edit or Remove strip. */
|
|
256
258
|
const ReadOnlyStrip = ({ children }: Parameters<typeof CartLineStrip>[0]) => <>{children((content) => content)}</>;
|
|
257
259
|
|
|
258
|
-
/**
|
|
259
|
-
|
|
260
|
+
/** WCPOS v2's `− n of unpaid +` stepper (tender/unit-stepper.tsx), the one Cart's `picker` draws in each pickable line's
|
|
261
|
+
* quantity cell, with what the picked units add under it. An app cart built on CartPanel and CartLine passes it as
|
|
262
|
+
* CartLine's `quantitySlot` (with `picking`), with the same `picker` object Cart takes. */
|
|
263
|
+
export function PickStepper({ picker, id, name, unpaid, currency }: { picker: NonNullable<Parameters<typeof Cart>[0]['picker']>;
|
|
260
264
|
id: string; name: string; unpaid: number; currency: string }) {
|
|
261
265
|
const t = useT();
|
|
262
266
|
const formatMoney = useFormatMoney();
|
|
@@ -54,7 +54,7 @@ export function CatalogueSettingsForm({
|
|
|
54
54
|
const auto = gridColumns === 'auto';
|
|
55
55
|
return (
|
|
56
56
|
<View testID={testID} className={cn('gap-1', className)} {...viewProps}>
|
|
57
|
-
<Text role="heading" className="pb-1 text-base font-semibold">{t('common.tile_size')}</Text>
|
|
57
|
+
<Text role="heading" aria-level={4} className="pb-1 text-base font-semibold">{t('common.tile_size')}</Text>
|
|
58
58
|
<View className="flex-row items-center gap-3 py-1">
|
|
59
59
|
<Switch testID={`${testID}-auto`} accessibilityLabel={t('common.auto')} checked={auto}
|
|
60
60
|
onCheckedChange={(on) => onGridColumnsChange(on ? 'auto' : V2_TILE_SIZE)} />
|
|
@@ -68,7 +68,7 @@ export function CatalogueSettingsForm({
|
|
|
68
68
|
<Text className="w-6 text-right tabular-nums">{String(gridColumns)}</Text>
|
|
69
69
|
</View>
|
|
70
70
|
)}
|
|
71
|
-
<Text role="heading" className="pb-1 pt-3 text-base font-semibold">{t('common.tile_fields')}</Text>
|
|
71
|
+
<Text role="heading" aria-level={4} className="pb-1 pt-3 text-base font-semibold">{t('common.tile_fields')}</Text>
|
|
72
72
|
{(Object.keys(DEFAULT_TILE_FIELDS) as TileField[]).map((field) => {
|
|
73
73
|
const label = t(LABELS[field]);
|
|
74
74
|
return (
|
package/src/sale/catalogue.tsx
CHANGED
|
@@ -22,7 +22,7 @@ import { Breadcrumb } from './breadcrumb';
|
|
|
22
22
|
import { CategoryTile, TileStack } from '../product/category-tile';
|
|
23
23
|
import { useT } from '../i18n';
|
|
24
24
|
import { SearchInput } from '../input';
|
|
25
|
-
import { VStack, IconButton, PlusIcon } from '../ui';
|
|
25
|
+
import { VStack, IconButton, PlusIcon, ChevronDownIcon, Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui';
|
|
26
26
|
import { skeletonCount } from '../ui/skeleton';
|
|
27
27
|
import { useMinTarget } from '../scale/min-target';
|
|
28
28
|
import { usePointer } from '../scale/use-pointer';
|
|
@@ -167,8 +167,9 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
167
167
|
/** v2's table row extras in table view: thumbnail leads the row, addButton ends it with the + (> for a product
|
|
168
168
|
* with variants) that does what a row press does. With expand and thumbnail, a product with more than one variant
|
|
169
169
|
* has its thumbnail show or hide its variants as rows under it: option chips, price, stock and a + that adds that
|
|
170
|
-
* variant as the list chooser does
|
|
171
|
-
|
|
170
|
+
* variant as the list chooser does; variationsButton adds v2's '{count} variations' button under the name, which shows
|
|
171
|
+
* or hides the variants as expand does; it needs expand. Default: none. */
|
|
172
|
+
tableRow?: { thumbnail?: boolean; addButton?: boolean; expand?: boolean; variationsButton?: boolean };
|
|
172
173
|
/** v2's rows between the chips and the products (its ListColumn `rows`): notices such as "Price check only until
|
|
173
174
|
* the register is open.", rendered under the header and above the grid, table or category tiles. Default none. */
|
|
174
175
|
rowsSlot?: ReactNode;
|
|
@@ -277,6 +278,17 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
277
278
|
const [chooserId, setChooserId] = useState<string | null>(null);
|
|
278
279
|
// The product ids whose table rows are expanded (local, never saved).
|
|
279
280
|
const [expandedIds, setExpandedIds] = useState<ReadonlySet<string>>(() => new Set());
|
|
281
|
+
// An expanded row's option filters (product id to group name to value), dropped when the row collapses.
|
|
282
|
+
const [variantFilters, setVariantFilters] = useState<Readonly<Record<string, Readonly<Record<string, string>>>>>({});
|
|
283
|
+
function toggleExpanded(key: string) {
|
|
284
|
+
const open = !expandedIds.has(key);
|
|
285
|
+
setExpandedIds((current) => {
|
|
286
|
+
const next = new Set(current);
|
|
287
|
+
if (open) next.add(key); else next.delete(key);
|
|
288
|
+
return next;
|
|
289
|
+
});
|
|
290
|
+
if (!open) setVariantFilters((current) => { const next = { ...current }; delete next[key]; return next; });
|
|
291
|
+
}
|
|
280
292
|
const [width, setWidth] = useState(0);
|
|
281
293
|
const [loadingHeight, setLoadingHeight] = useState(0);
|
|
282
294
|
const columns = resolveGridColumns(state.gridColumns, width);
|
|
@@ -375,9 +387,46 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
375
387
|
}
|
|
376
388
|
|
|
377
389
|
function variantRows(product: Doc) {
|
|
378
|
-
const
|
|
390
|
+
const id = traits.getId(product);
|
|
391
|
+
const variants = entries.filter((entry) => traits.getId(entry.product) === id);
|
|
379
392
|
if (variants.length === 0) return <Text className="px-3 py-1.5 text-sm text-muted-foreground">No variants to show.</Text>;
|
|
380
|
-
|
|
393
|
+
const picked = variantFilters[id] ?? {};
|
|
394
|
+
const groups = (traits.getVariantOptions?.(product) ?? []).filter(({ values }) => values.length > 1);
|
|
395
|
+
// A variant leaving a group unset fits any value of it; a picked group that draws no select no longer filters.
|
|
396
|
+
const matching = variants.filter(({ variant: { options } }) => groups.every(({ name }) => !picked[name]
|
|
397
|
+
|| options === undefined || !Object.prototype.hasOwnProperty.call(options, name) || options[name] === picked[name]));
|
|
398
|
+
const pick = (group: string, value: string) => setVariantFilters((current) => {
|
|
399
|
+
const next = { ...current[id] };
|
|
400
|
+
if (value === '') delete next[group]; else next[group] = value;
|
|
401
|
+
return { ...current, [id]: next };
|
|
402
|
+
});
|
|
403
|
+
// v2 variations/filters.tsx: a select per option group, then a chevron that folds the row.
|
|
404
|
+
const bar = (
|
|
405
|
+
<View key="filters" testID={`variation-filters-${id}`} className="flex-row items-center gap-2 border-t border-border px-3 py-1">
|
|
406
|
+
<View className="min-w-0 flex-1 flex-row flex-wrap gap-2">
|
|
407
|
+
{groups.map(({ name, values }) => (
|
|
408
|
+
<Select key={name} value={{ value: picked[name] ?? '', label: picked[name] ? `${name}: ${picked[name]}` : name }}
|
|
409
|
+
onValueChange={(option) => { if (option) pick(name, option.value); }}>
|
|
410
|
+
<SelectTrigger testID={`variation-filter-${id}-${name}`} accessibilityLabel={picked[name] ? `${name}: ${picked[name]}` : name} className="h-9 w-auto">
|
|
411
|
+
<SelectValue className="text-sm text-foreground" />
|
|
412
|
+
</SelectTrigger>
|
|
413
|
+
<SelectContent>
|
|
414
|
+
{['', ...values].map((value) => (
|
|
415
|
+
<SelectItem key={value} value={value} label={value || name}>
|
|
416
|
+
<Text className="text-sm text-popover-foreground">{value || 'All'}</Text>
|
|
417
|
+
</SelectItem>
|
|
418
|
+
))}
|
|
419
|
+
</SelectContent>
|
|
420
|
+
</Select>
|
|
421
|
+
))}
|
|
422
|
+
</View>
|
|
423
|
+
<IconButton size="sm" testID={`variation-filters-${id}-collapse`} accessibilityLabel="Collapse" onPress={() => toggleExpanded(id)}>
|
|
424
|
+
<View className="text-muted-foreground" style={{ transform: [{ rotate: '180deg' }] }}><ChevronDownIcon size={18} /></View>
|
|
425
|
+
</IconButton>
|
|
426
|
+
</View>
|
|
427
|
+
);
|
|
428
|
+
if (matching.length === 0) return [bar, <Text key="none" className="px-3 py-1.5 text-sm text-muted-foreground">No variants match.</Text>];
|
|
429
|
+
return [bar, ...matching.map((entry) => (
|
|
381
430
|
<View key={entry.variant.id} testID={`variation-row-${entry.variant.id}`} className="flex-row items-center gap-3 border-t border-border px-3 py-1.5">
|
|
382
431
|
<View testID={`variation-row-${entry.variant.id}-chips`} className="min-w-0 flex-1 flex-row flex-wrap gap-1">
|
|
383
432
|
{chipsOf(entry).map((chip, index) => <Text key={index} className="rounded bg-foreground/12 px-1.5 text-xs font-bold text-foreground">{chip}</Text>)}
|
|
@@ -390,7 +439,7 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
390
439
|
</IconButton>
|
|
391
440
|
</View>
|
|
392
441
|
</View>
|
|
393
|
-
));
|
|
442
|
+
))];
|
|
394
443
|
}
|
|
395
444
|
|
|
396
445
|
// The variations popover (#719): the one open popover's product id, and each product's current entries in order.
|
|
@@ -529,12 +578,8 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
529
578
|
sortItems={false} onSelect={selectProduct} emptyState={emptyState} loading={showLoading}
|
|
530
579
|
showThumbnail={tableRow?.thumbnail} showAddButton={tableRow?.addButton}
|
|
531
580
|
isExpanded={tableRow?.expand ? (doc) => expandedIds.has(traits.getId(doc)) : undefined}
|
|
532
|
-
onToggleExpand={tableRow?.expand ? (doc) =>
|
|
533
|
-
|
|
534
|
-
if (next.has(key)) next.delete(key); else next.add(key);
|
|
535
|
-
return next;
|
|
536
|
-
}) : undefined}
|
|
537
|
-
renderExpanded={tableRow?.expand ? variantRows : undefined}
|
|
581
|
+
onToggleExpand={tableRow?.expand ? (doc) => toggleExpanded(traits.getId(doc)) : undefined}
|
|
582
|
+
renderExpanded={tableRow?.expand ? variantRows : undefined} variationsButton={tableRow?.variationsButton}
|
|
538
583
|
cartQuantity={(doc) => quantities.get(traits.getId(doc)) ?? 0} />
|
|
539
584
|
) : drillEntries.length > 0 ? <LevelWrap level onBack={() => setDrillId(null)}>
|
|
540
585
|
{/* v2 drill-in.tsx:44-68: "Products › name" above the variant tiles; at phone width the Breadcrumb drops the separator. */}
|
package/src/sale/charge-form.tsx
CHANGED
|
@@ -18,19 +18,24 @@ export interface ChargeFormProps {
|
|
|
18
18
|
* Add Miscellaneous Product entries); absent, the form opens on Fee with the row. */
|
|
19
19
|
kind?: 'fee' | 'shipping' | 'custom';
|
|
20
20
|
/** Given, the form edits that charge: prefilled, titled `Edit <name>` as v2's record dialog. */
|
|
21
|
-
initial?: { name: string; amountMinor: number; taxStatus?: 'taxable' | 'none'; taxClass?: string; percent?: number; amountIncludesTax?: boolean
|
|
21
|
+
initial?: { name: string; amountMinor: number; taxStatus?: 'taxable' | 'none'; taxClass?: string; percent?: number; amountIncludesTax?: boolean;
|
|
22
|
+
sku?: string };
|
|
23
|
+
/** On the custom kind, shows v2's "+ SKU" add-row after the tax rows; pressing it shows the SKU field. */
|
|
24
|
+
sku?: boolean;
|
|
22
25
|
/** Shows the amount-unit toggle (currency symbol or %) on the fee kind, as v2's AmountUnitToggle. */
|
|
23
26
|
allowPercent?: boolean;
|
|
24
27
|
/** The store's tax mode. Given, the fee and shipping kinds show the "Amount Includes Tax" switch (not on a percent fee), which starts at this
|
|
25
28
|
* value (Desk Q4: default = store tax mode, ADR-075). */
|
|
26
29
|
pricesIncludeTax?: boolean;
|
|
27
30
|
onApply: (charge: { kind: 'fee' | 'shipping' | 'custom'; name: string; amountMinor: number;
|
|
28
|
-
taxStatus?: 'none'; taxClass?: string; percent?: number; amountIncludesTax?: boolean
|
|
31
|
+
taxStatus?: 'none'; taxClass?: string; percent?: number; amountIncludesTax?: boolean;
|
|
32
|
+
sku?: string }) => string | null;
|
|
29
33
|
onClose: () => void;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
const NAME_LABEL_ID = 'charge-form-name-label';
|
|
33
37
|
const AMOUNT_LABEL_ID = 'charge-form-amount-label';
|
|
38
|
+
const SKU_LABEL_ID = 'charge-form-sku-label';
|
|
34
39
|
|
|
35
40
|
const button = 'rounded-md border border-border px-3 py-2 min-h-11 items-center justify-center';
|
|
36
41
|
/** A blank name takes v2's default for the kind: add-fee.tsx:71 (`pos_cart.fee`), add-shipping.tsx:73
|
|
@@ -38,7 +43,7 @@ const button = 'rounded-md border border-border px-3 py-2 min-h-11 items-center
|
|
|
38
43
|
const DEFAULT_NAME: Record<'fee' | 'shipping' | 'custom', string> = { fee: 'Fee', shipping: 'Shipping', custom: 'Product' };
|
|
39
44
|
|
|
40
45
|
/** `onApply` returns a refusal to show inline, or null once applied. */
|
|
41
|
-
export function ChargeForm({ currency, lineTax, taxClasses, shippingTaxFromStore, shippingNoTax, kind: fixedKind, initial, allowPercent,
|
|
46
|
+
export function ChargeForm({ currency, lineTax, taxClasses, shippingTaxFromStore, shippingNoTax, kind: fixedKind, initial, sku, allowPercent,
|
|
42
47
|
pricesIncludeTax, onApply, onClose }: ChargeFormProps) {
|
|
43
48
|
const currencySymbol = useCurrencySymbol();
|
|
44
49
|
const format = useMoneyFormat();
|
|
@@ -54,7 +59,10 @@ export function ChargeForm({ currency, lineTax, taxClasses, shippingTaxFromStore
|
|
|
54
59
|
const [noTax, setNoTax] = useState(initial?.taxStatus === 'none');
|
|
55
60
|
const [includesTax, setIncludesTax] = useState(initial?.amountIncludesTax ?? pricesIncludeTax ?? false);
|
|
56
61
|
const [taxClass, setTaxClass] = useState(initial?.taxClass ?? '');
|
|
62
|
+
const [skuText, setSkuText] = useState(initial?.sku ?? '');
|
|
63
|
+
const [skuOpen, setSkuOpen] = useState(Boolean(initial?.sku));
|
|
57
64
|
const [error, setError] = useState<string | null>(null);
|
|
65
|
+
const showSku = Boolean(sku) && kind === 'custom';
|
|
58
66
|
const storeShipping = kind === 'shipping' && shippingTaxFromStore;
|
|
59
67
|
const showNoTax = storeShipping ? shippingNoTax : lineTax?.none;
|
|
60
68
|
const showUnit = Boolean(allowPercent) && kind === 'fee';
|
|
@@ -81,6 +89,7 @@ export function ChargeForm({ currency, lineTax, taxClasses, shippingTaxFromStore
|
|
|
81
89
|
...(percentMode ? { percent: parsed } : !showUnit && initial?.percent !== undefined ? { percent: initial.percent } : {}),
|
|
82
90
|
...(percentMode ? {} : showIncludesTax ? includesTax !== pricesIncludeTax ? { amountIncludesTax: includesTax } : {}
|
|
83
91
|
: initial?.amountIncludesTax !== undefined ? { amountIncludesTax: initial.amountIncludesTax } : {}),
|
|
92
|
+
...(showSku ? skuText.trim() ? { sku: skuText.trim() } : {} : initial?.sku ? { sku: initial.sku } : {}),
|
|
84
93
|
});
|
|
85
94
|
setError(refused);
|
|
86
95
|
if (refused === null) onClose();
|
|
@@ -130,6 +139,15 @@ export function ChargeForm({ currency, lineTax, taxClasses, shippingTaxFromStore
|
|
|
130
139
|
</Pressable>)}
|
|
131
140
|
</View> : null}
|
|
132
141
|
</>}
|
|
142
|
+
{/* v2's "+ SKU" add-row (add-misc-product.tsx) on the custom item. */}
|
|
143
|
+
{showSku ? skuOpen ? <>
|
|
144
|
+
<Label nativeID={SKU_LABEL_ID}>{t('common.sku')}</Label>
|
|
145
|
+
<TextInput testID="charge-form-sku-input" accessibilityLabelledBy={SKU_LABEL_ID} accessibilityLabel={t('common.sku')}
|
|
146
|
+
value={skuText} onChangeText={setSkuText}
|
|
147
|
+
className="min-w-0 rounded-md border border-border bg-background px-3 py-2 text-foreground" />
|
|
148
|
+
</> : <Pressable testID="charge-form-add-sku" accessibilityRole="button" onPress={() => setSkuOpen(true)}
|
|
149
|
+
className={`${button} bg-card self-start`}>
|
|
150
|
+
<Text className="text-foreground">{`+ ${t('common.sku')}`}</Text></Pressable> : null}
|
|
133
151
|
{error ? <Text accessibilityRole="alert" className="text-destructive">{error}</Text> : null}
|
|
134
152
|
<View className="flex-row gap-2">
|
|
135
153
|
<Pressable accessibilityRole="button" onPress={apply} className={`${button} bg-primary`}>
|
|
@@ -10,7 +10,7 @@ const COPY = {
|
|
|
10
10
|
discount: 'Discount', total_tax: 'Tax', included_tax: 'Tax included', total: 'Total', paid_so_far: 'Paid so far',
|
|
11
11
|
present_card: 'Please present your card', approved: 'Approved', declined: 'Declined',
|
|
12
12
|
try_another_card: 'Please try another card or ask staff', paid_in_full: 'Paid in full', change: 'Change',
|
|
13
|
-
thank_you: 'Thank you', tendered: 'Tendered',
|
|
13
|
+
thank_you: 'Thank you', tendered: 'Tendered', rounding: 'Rounding',
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
const CARD = { started: 'bg-primary', approved: 'bg-success', complete: 'bg-success', declined: 'bg-destructive' };
|
|
@@ -67,6 +67,7 @@ export function CustomerDisplayScreen({ state }: { state: DisplayState }) {
|
|
|
67
67
|
{row(t('subtotal'), money(receipt.totals.subtotalMinor))}
|
|
68
68
|
{receipt.fees.map((charge, index) => row(charge.name, money(charge.amountMinor), `fee-${index}`))}
|
|
69
69
|
{receipt.shipping.map((charge, index) => row(charge.name, money(charge.amountMinor), `shipping-${index}`))}
|
|
70
|
+
{receipt.rounding ? row(t('rounding'), money(receipt.rounding.amountMinor), 'rounding') : null}
|
|
70
71
|
{receipt.totals.discountMinor > 0 ? row(t('discount'), `-${money(receipt.totals.discountMinor)}`) : null}
|
|
71
72
|
{receipt.totals.taxMinor > 0 ? row(t(receipt.totals.taxInclusive ? 'included_tax' : 'total_tax'), money(receipt.totals.taxMinor)) : null}
|
|
72
73
|
{total}
|
package/src/sale/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Cart } from './cart';
|
|
1
|
+
export { Cart, PickStepper } from './cart';
|
|
2
2
|
export { OrderNoteSheet, type OrderNoteSheetProps } from './order-note-sheet';
|
|
3
3
|
export { CartBar } from './cart-bar';
|
|
4
4
|
export { Tender, SplitTender } from './tender';
|
|
@@ -10,7 +10,7 @@ export { ChargeForm, type ChargeFormProps } from './charge-form';
|
|
|
10
10
|
export { Catalogue, formatStockSyncTime } from './catalogue';
|
|
11
11
|
export { CatalogueSettingsForm, type CatalogueSettingsFormProps } from './catalogue-settings-form';
|
|
12
12
|
export { Receipt } from './receipt';
|
|
13
|
-
export { ReceiptSheet, type ReceiptSheetEmail, type ReceiptSheetProps, type ReceiptSheetTemplate } from './receipt-sheet';
|
|
13
|
+
export { ReceiptEmailForm, type ReceiptEmailFormProps, ReceiptSheet, type ReceiptSheetEmail, type ReceiptSheetProps, type ReceiptSheetTemplate } from './receipt-sheet';
|
|
14
14
|
export { orderReference } from './order-reference';
|
|
15
15
|
export { injectPrintStyle } from './print-style';
|
|
16
16
|
export { SyncStatus, syncStatusQuiet } from './sync-status';
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { useEffect, useRef, useState, type JSX } from 'react';
|
|
2
|
-
import { Platform, Pressable, ScrollView, View } from 'react-native';
|
|
2
|
+
import { Animated, Platform, Pressable, ScrollView, View } from 'react-native';
|
|
3
3
|
import { useFormatMoney } from '@tallyui/core';
|
|
4
4
|
import { isPartlyPaid, type OpenSale } from '@tallyui/pos';
|
|
5
5
|
import { cn } from '@tallyui/theme';
|
|
6
|
+
import { CROSSFADE, EASE, NEW_TAB_WIDTH, PLUS_WIDTH } from '../lib/motion';
|
|
7
|
+
import { useReducedMotion } from '../lib/use-reduced-motion';
|
|
6
8
|
import { Text } from '../ui/text';
|
|
7
9
|
|
|
8
10
|
const AGE_TICK_MS = 60_000; // Ages tick once a minute (v2).
|
|
@@ -52,6 +54,22 @@ export function OpenSaleTabs({ sales, currency, onSelect, onNew, className }: Op
|
|
|
52
54
|
// v2 cart/tabs.tsx: on a blank cart the active position is the + cell, just past the last sale; no wrap.
|
|
53
55
|
const activeIndex = blank ? sales.length : sales.findIndex((sale) => sale.current);
|
|
54
56
|
const focusPending = useRef(false);
|
|
57
|
+
const reduced = useReducedMotion() !== false; // Reduced or unknown motion jumps, as cart-line-strip.tsx.
|
|
58
|
+
const width = useRef(new Animated.Value(blank ? NEW_TAB_WIDTH : PLUS_WIDTH)).current;
|
|
59
|
+
const fade = useRef(new Animated.Value(blank ? 1 : 0)).current;
|
|
60
|
+
const [label, setLabel] = useState(blank); // "New" stays mounted through its fade out (v2 FadeOut).
|
|
61
|
+
const was = useRef(blank);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (was.current === blank) return; // The values start at their target: nothing animates on mount.
|
|
64
|
+
was.current = blank;
|
|
65
|
+
if (blank) setLabel(true);
|
|
66
|
+
const go = (value: Animated.Value, toValue: number, done = () => {}) => {
|
|
67
|
+
if (reduced) { value.setValue(toValue); done(); return; }
|
|
68
|
+
Animated.timing(value, { toValue, duration: CROSSFADE, easing: EASE, useNativeDriver: false }).start(({ finished }) => { if (finished) done(); });
|
|
69
|
+
};
|
|
70
|
+
go(width, blank ? NEW_TAB_WIDTH : PLUS_WIDTH); // v2 cart/tabs.tsx: the + cell widens to "+ New" on the blank cart.
|
|
71
|
+
go(fade, blank ? 1 : 0, () => { if (!was.current) setLabel(false); });
|
|
72
|
+
}, [blank, reduced, width, fade]);
|
|
55
73
|
const step = (delta: number) => {
|
|
56
74
|
const at = activeIndex + delta;
|
|
57
75
|
if (at < 0 || at > sales.length) return;
|
|
@@ -103,13 +121,15 @@ export function OpenSaleTabs({ sales, currency, onSelect, onNew, className }: Op
|
|
|
103
121
|
);
|
|
104
122
|
})}
|
|
105
123
|
</ScrollView>
|
|
124
|
+
<Animated.View className="h-full overflow-hidden" style={{ width }}>
|
|
106
125
|
<Pressable testID="new-sale-tab" ref={follow(blank)} accessibilityRole="tab" accessibilityLabel="New order" accessibilityState={{ selected: blank }} aria-selected={blank}
|
|
107
126
|
// Already on the blank cart: + is a place, not an action (v2).
|
|
108
127
|
onPress={() => { if (!blank) onNew(); }}
|
|
109
|
-
className={`h-full flex-row items-center justify-center gap-1.5 px-3 ${blank ? 'border-b-2 border-primary' : ''}`}>
|
|
128
|
+
className={`h-full w-full flex-row items-center justify-center gap-1.5 px-3 ${blank ? 'border-b-2 border-primary' : ''}`}>
|
|
110
129
|
<Text className={blank ? 'text-primary' : 'text-foreground'}>+</Text>
|
|
111
|
-
{blank && <Text testID="new-sale-tab-label" className="font-semibold">New</Text>}
|
|
130
|
+
{(blank || (!reduced && label)) && <Animated.View style={{ opacity: fade, flexShrink: 0 }}><Text testID="new-sale-tab-label" className="font-semibold">New</Text></Animated.View>}
|
|
112
131
|
</Pressable>
|
|
132
|
+
</Animated.View>
|
|
113
133
|
</View>
|
|
114
134
|
);
|
|
115
135
|
}
|
package/src/sale/orders-list.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useId, useRef, useState, type ReactNode } from 'react';
|
|
2
2
|
import { Pressable, ScrollView, Text, View } from 'react-native';
|
|
3
3
|
import { useFormatMoney, knownWarnings } from '@tallyui/core';
|
|
4
|
-
import { extrasNotSent, isRequeueableOrder, needsAttention, noteDelivery, refundDueOf, REOPENABLE_CODES, UPDATE_UNSENDABLE, UPDATE_UNSENDABLE_MESSAGE, type OutboxState, type PosOrder } from '@tallyui/pos';
|
|
4
|
+
import { extrasNotSent, isRequeueableOrder, needsAdminReasonOf, needsAttention, noteDelivery, refundDueOf, REOPENABLE_CODES, UPDATE_UNSENDABLE, UPDATE_UNSENDABLE_MESSAGE, type OutboxState, type PosOrder } from '@tallyui/pos';
|
|
5
5
|
import { META_NOT_SENT, NOTE_NOT_SENT, orderReference, TAX_IDS_NOT_SENT } from './order-reference';
|
|
6
6
|
import { sinceText } from './since-text';
|
|
7
7
|
|
|
@@ -50,11 +50,16 @@ export type OrderSyncNoticesProps = {
|
|
|
50
50
|
children?: ReactNode;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
// #1280: only session_closed guarantees the store holds no order.
|
|
54
|
+
const NEEDS_ADMIN_SESSION_CLOSED = 'Not in the online store yet. A manager must finish this sale in the store admin.';
|
|
55
|
+
const NEEDS_ADMIN_SALE = 'Not finished in the online store. A manager must check this sale in the store admin.';
|
|
56
|
+
|
|
53
57
|
/** The per-sale sync notices OrdersList shows under each order, for an app's own order screen. */
|
|
54
58
|
export function OrderSyncNotices({ order, stuck, children }: OrderSyncNoticesProps) {
|
|
55
59
|
const formatMoney = useFormatMoney();
|
|
56
60
|
// The order's own stuck entry: its clock and latest reason, not the earliest across all stuck orders.
|
|
57
61
|
const stuckEntry = order.syncStatus === 'pending' ? stuck?.orders.find((entry) => entry.commandId === order.commandId) : undefined;
|
|
62
|
+
const needsAdminReason = stuckEntry ? needsAdminReasonOf(stuckEntry.reason) : undefined;
|
|
58
63
|
const sentence = order.syncStatus === 'rejected'
|
|
59
64
|
? order.storeOrderId !== undefined && ['reopen_required', 'revision_conflict'].includes(order.error?.code ?? '')
|
|
60
65
|
? REOPEN_AGAIN_SENTENCE : refusalSentence(order.error?.code)
|
|
@@ -62,8 +67,10 @@ export function OrderSyncNotices({ order, stuck, children }: OrderSyncNoticesPro
|
|
|
62
67
|
const extras = extrasNotSent(order);
|
|
63
68
|
return <>
|
|
64
69
|
{stuckEntry ? <Text className="text-destructive">
|
|
65
|
-
{/*
|
|
66
|
-
{
|
|
70
|
+
{/* A parked sale needs a manager; other retries keep the hour as the status line has it (numeric, #245), with no reason code. */}
|
|
71
|
+
{needsAdminReason !== undefined
|
|
72
|
+
? needsAdminReason === 'session_closed' ? NEEDS_ADMIN_SESSION_CLOSED : NEEDS_ADMIN_SALE
|
|
73
|
+
: `Hasn't reached the online store since ${sinceText(stuckEntry)}.`}
|
|
67
74
|
</Text> : null}
|
|
68
75
|
{/* The code's sentence alone: the cashier sees no error code and never the store's message. */}
|
|
69
76
|
{sentence ? <Text className="text-destructive">{sentence}</Text> : null}
|
|
@@ -32,7 +32,7 @@ export interface ReceiptSheetEmail {
|
|
|
32
32
|
offline?: boolean;
|
|
33
33
|
/** Draws "Save email to the customer" (default off). */
|
|
34
34
|
saveToCustomer?: boolean;
|
|
35
|
-
/** Sends or queues the receipt. Returns a refusal to show, or null once sent or queued; the form then
|
|
35
|
+
/** Sends or queues the receipt. Returns a refusal to show, or null once sent or queued; the form then shows "Email sent", or "Receipt email queued" when offline. */
|
|
36
36
|
onSend: (input: { address: string; saveToCustomer: boolean }) => Promise<string | null> | string | null;
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -135,13 +135,31 @@ function PrinterValue({ printers, printerId, autoPrinterName, onPrinterChange }:
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+$/;
|
|
138
|
+
const SEND_FAILED = 'Could not send the receipt.';
|
|
138
139
|
|
|
139
|
-
/**
|
|
140
|
-
function
|
|
140
|
+
/** The sent/queued line, drawn by ReceiptEmailForm after a send and by ReceiptSheet in the form's place. */
|
|
141
|
+
function EmailSentLine({ queued }: { queued: boolean }) {
|
|
142
|
+
const t = useT();
|
|
143
|
+
return <Text testID="receipt-email-sent" className="py-2 text-sm text-foreground">{t(queued ? 'receipt.email_queued' : 'receipt.email_sent')}</Text>;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface ReceiptEmailFormProps {
|
|
147
|
+
email: ReceiptSheetEmail;
|
|
148
|
+
/** Called once after `onSend` returns null, with true when `email.offline` was set (queued). */
|
|
149
|
+
onDone?: (queued: boolean) => void;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* v2's email.tsx (MIT, WCPOS) inline, the form ReceiptSheet draws: "Email Address" prefilled from `defaultAddress`,
|
|
154
|
+
* the save switch (off), the offline notice and Send. After `onSend` returns null it shows "Email sent" or
|
|
155
|
+
* "Receipt email queued" in its own place and calls `onDone`. Remount it (for example with a new `key`) to send again.
|
|
156
|
+
*/
|
|
157
|
+
export function ReceiptEmailForm({ email, onDone }: ReceiptEmailFormProps): JSX.Element {
|
|
141
158
|
const [text, setText] = useState(email.defaultAddress ?? '');
|
|
142
159
|
const [save, setSave] = useState(false);
|
|
143
160
|
const [error, setError] = useState<string | null>(null);
|
|
144
161
|
const [sending, setSending] = useState(false);
|
|
162
|
+
const [sent, setSent] = useState<'sent' | 'queued' | null>(null);
|
|
145
163
|
const send = async () => {
|
|
146
164
|
if (sending) return;
|
|
147
165
|
const address = text.trim();
|
|
@@ -153,11 +171,14 @@ function EmailForm({ email, onDone }: { email: ReceiptSheetEmail; onDone: (queue
|
|
|
153
171
|
if (typeof result === 'string' || result === null) refusal = result;
|
|
154
172
|
else { setSending(true); refusal = await result; }
|
|
155
173
|
} catch (cause) {
|
|
156
|
-
refusal = cause instanceof Error ? cause.message :
|
|
174
|
+
refusal = cause instanceof Error ? cause.message : SEND_FAILED;
|
|
157
175
|
}
|
|
158
176
|
setSending(false);
|
|
159
|
-
if (refusal
|
|
177
|
+
if (refusal !== null) return setError(refusal || SEND_FAILED);
|
|
178
|
+
setSent(email.offline ? 'queued' : 'sent');
|
|
179
|
+
onDone?.(Boolean(email.offline));
|
|
160
180
|
};
|
|
181
|
+
if (sent) return <EmailSentLine queued={sent === 'queued'} />;
|
|
161
182
|
return (
|
|
162
183
|
<View testID="receipt-email-form" className="gap-2 py-2">
|
|
163
184
|
<Text className="text-sm font-medium text-foreground">Email Address</Text>
|
|
@@ -186,7 +207,6 @@ function EmailForm({ email, onDone }: { email: ReceiptSheetEmail; onDone: (queue
|
|
|
186
207
|
export function ReceiptSheet({ open, onOpenChange, title = 'Receipt', templates, templateId, onTemplateChange,
|
|
187
208
|
printerLabel = 'Browser print dialog', printers, printerId, autoPrinterName, onPrinterChange,
|
|
188
209
|
onPrint, printing = false, printed = false, onEmail, email, onDownloadPdf, downloadingPdf = false, children }: ReceiptSheetProps): JSX.Element {
|
|
189
|
-
const t = useT();
|
|
190
210
|
const [sent, setSent] = useState<'sent' | 'queued' | null>(null);
|
|
191
211
|
const [emailOpen, setEmailOpen] = useState(false);
|
|
192
212
|
// Closing the sheet closes the form too, so it opens fresh next time.
|
|
@@ -214,8 +234,8 @@ export function ReceiptSheet({ open, onOpenChange, title = 'Receipt', templates,
|
|
|
214
234
|
</View>
|
|
215
235
|
{/* v2 draws its own WebView preview with zoom and loading states; here the app's preview is the child. */}
|
|
216
236
|
<ScrollView className="flex-1" contentContainerClassName="pb-2">{children}</ScrollView>
|
|
217
|
-
{email && emailOpen ? <
|
|
218
|
-
{email && sent ? <
|
|
237
|
+
{email && emailOpen ? <ReceiptEmailForm email={email} onDone={(queued) => { setEmailOpen(false); setSent(queued ? 'queued' : 'sent'); }} /> : null}
|
|
238
|
+
{email && sent ? <EmailSentLine queued={sent === 'queued'} /> : null}
|
|
219
239
|
{/* 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
240
|
<DialogFooter bordered className="gap-2" testID="receipt-footer">
|
|
221
241
|
<DialogClose asChild>
|
package/src/sale/receipt.tsx
CHANGED
|
@@ -87,6 +87,7 @@ export function Receipt(props: ReceiptProps) {
|
|
|
87
87
|
{/* Charges are not in the subtotal (order.display): they follow it and its discounts, before tax. */}
|
|
88
88
|
{receipt.fees.map((charge, index) => row(charge.name, money(charge.amountMinor), false, index))}
|
|
89
89
|
{receipt.shipping.map((charge, index) => row(charge.name, money(charge.amountMinor), false, index))}
|
|
90
|
+
{receipt.rounding ? row(receipt.rounding.name, money(receipt.rounding.amountMinor)) : null}
|
|
90
91
|
{taxRows}
|
|
91
92
|
{row('Total', money(totals.totalMinor), true)}
|
|
92
93
|
{receipt.payments.map((payment, index) => row(payment.method === 'cash' ? 'Cash tendered'
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CASH_NOT_PAYABLE, CASH_PICK_LIMIT, CASH_SETTLE_LIMIT, CASH_WAITS_FOR_PAYMENT, VOID_LATER_CASH_FIRST } from '@tallyui/pos';
|
|
2
|
+
import type { useT } from '../i18n';
|
|
3
|
+
/** The sale's error as the cashier reads it: a core refusal with a catalogue key is translated; any other shows as given. */
|
|
4
|
+
export function saleErrorText(t: ReturnType<typeof useT>, error: string): string {
|
|
5
|
+
return error === VOID_LATER_CASH_FIRST ? t('pos_checkout.void_later_cash_first')
|
|
6
|
+
: error === CASH_NOT_PAYABLE ? t('pos_checkout.cash_not_payable_typed')
|
|
7
|
+
: error === CASH_WAITS_FOR_PAYMENT ? t('pos_checkout.cash_waits_for_payment')
|
|
8
|
+
: error === CASH_PICK_LIMIT ? t('pos_checkout.cash_pick_limit')
|
|
9
|
+
: error === CASH_SETTLE_LIMIT ? t('pos_checkout.cash_settle_limit') : error;
|
|
10
|
+
}
|
package/src/sale/since-text.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
// The device's own 12/24-hour format, with no forced leading zero on the hour.
|
|
2
|
+
export function shortTime(t: number | string): string {
|
|
3
|
+
return new Date(t).toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' });
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
// The time a stuck line names: the real first failure when this run has one, else "about" the virtual since (after a restart
|
|
2
7
|
// firstFailedAt is gone; see OutboxState.stuck).
|
|
3
8
|
export function sinceText(clock: { since: number; firstFailedAt?: number }): string {
|
|
4
|
-
|
|
5
|
-
const time = (t: number) => new Date(t).toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' });
|
|
6
|
-
return clock.firstFailedAt === undefined ? 'about ' + time(clock.since) : time(clock.firstFailedAt);
|
|
9
|
+
return clock.firstFailedAt === undefined ? 'about ' + shortTime(clock.since) : shortTime(clock.firstFailedAt);
|
|
7
10
|
}
|