@tallyui/components 4.2.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 +95 -45
- package/dist/index.js +2057 -1713
- 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 +22 -2
- package/src/index.ts +2 -0
- 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/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 +8 -6
- package/src/sale/catalogue-settings-form.tsx +2 -2
- package/src/sale/catalogue.tsx +53 -9
- package/src/sale/customer-display-screen.tsx +2 -1
- package/src/sale/open-sale-tabs.tsx +23 -3
- package/src/sale/orders-list.tsx +10 -3
- package/src/sale/receipt.tsx +1 -0
- package/src/sale/sale-error-text.ts +10 -0
- package/src/sale/sync-status.tsx +6 -1
- package/src/sale/tender-ledger.tsx +47 -9
- 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
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}
|
|
@@ -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';
|
|
@@ -278,6 +278,17 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
278
278
|
const [chooserId, setChooserId] = useState<string | null>(null);
|
|
279
279
|
// The product ids whose table rows are expanded (local, never saved).
|
|
280
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
|
+
}
|
|
281
292
|
const [width, setWidth] = useState(0);
|
|
282
293
|
const [loadingHeight, setLoadingHeight] = useState(0);
|
|
283
294
|
const columns = resolveGridColumns(state.gridColumns, width);
|
|
@@ -376,9 +387,46 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
376
387
|
}
|
|
377
388
|
|
|
378
389
|
function variantRows(product: Doc) {
|
|
379
|
-
const
|
|
390
|
+
const id = traits.getId(product);
|
|
391
|
+
const variants = entries.filter((entry) => traits.getId(entry.product) === id);
|
|
380
392
|
if (variants.length === 0) return <Text className="px-3 py-1.5 text-sm text-muted-foreground">No variants to show.</Text>;
|
|
381
|
-
|
|
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) => (
|
|
382
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">
|
|
383
431
|
<View testID={`variation-row-${entry.variant.id}-chips`} className="min-w-0 flex-1 flex-row flex-wrap gap-1">
|
|
384
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>)}
|
|
@@ -391,7 +439,7 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
391
439
|
</IconButton>
|
|
392
440
|
</View>
|
|
393
441
|
</View>
|
|
394
|
-
));
|
|
442
|
+
))];
|
|
395
443
|
}
|
|
396
444
|
|
|
397
445
|
// The variations popover (#719): the one open popover's product id, and each product's current entries in order.
|
|
@@ -530,11 +578,7 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
530
578
|
sortItems={false} onSelect={selectProduct} emptyState={emptyState} loading={showLoading}
|
|
531
579
|
showThumbnail={tableRow?.thumbnail} showAddButton={tableRow?.addButton}
|
|
532
580
|
isExpanded={tableRow?.expand ? (doc) => expandedIds.has(traits.getId(doc)) : undefined}
|
|
533
|
-
onToggleExpand={tableRow?.expand ? (doc) =>
|
|
534
|
-
const key = traits.getId(doc), next = new Set(current);
|
|
535
|
-
if (next.has(key)) next.delete(key); else next.add(key);
|
|
536
|
-
return next;
|
|
537
|
-
}) : undefined}
|
|
581
|
+
onToggleExpand={tableRow?.expand ? (doc) => toggleExpanded(traits.getId(doc)) : undefined}
|
|
538
582
|
renderExpanded={tableRow?.expand ? variantRows : undefined} variationsButton={tableRow?.variationsButton}
|
|
539
583
|
cartQuantity={(doc) => quantities.get(traits.getId(doc)) ?? 0} />
|
|
540
584
|
) : drillEntries.length > 0 ? <LevelWrap level onBack={() => setDrillId(null)}>
|
|
@@ -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}
|
|
@@ -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}
|
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/sync-status.tsx
CHANGED
|
@@ -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.";
|
|
@@ -115,16 +118,18 @@ export function SyncStatus({ state, registerState, pluginName = 'the POS plugin'
|
|
|
115
118
|
const label = [state.pending && count(state.pending, 'sale'),
|
|
116
119
|
updates && count(updates, 'till update')].filter(Boolean).join(' and ') + ' waiting to sync';
|
|
117
120
|
const { stuck } = state;
|
|
121
|
+
const needsAdmin = stuck?.orders.filter((entry) => needsAdminReasonOf(entry.reason) !== undefined).length ?? 0;
|
|
118
122
|
const backendMissing = state.backendMissing ?? registerState?.backendMissing;
|
|
119
123
|
const backendMissingText = state.pending === 0 && updates > 0 ? (registerState?.stuck
|
|
120
124
|
? TILL_UPDATES_MISSING_SINCE.replace('{time}', () => sinceText(registerState.stuck!)) : TILL_UPDATES_MISSING)
|
|
121
125
|
: stuck ? BACKEND_MISSING_SINCE.replace('{time}', () => sinceText(stuck)) : BACKEND_MISSING;
|
|
122
126
|
const upToDate = state.pending === 0 && updates === 0;
|
|
123
127
|
// The sentence shows with the store missing, or once the waiting sales (with none waiting, the till updates) are stuck, then as
|
|
124
|
-
// its "since" variant
|
|
128
|
+
// its "since" variant, unless a parked sale needs a manager; no reason code is shown.
|
|
125
129
|
// A refused batch from the outbox shown (the sales', whenever a sale waits) replaces that sentence: it is the store's latest
|
|
126
130
|
// answer, and sending waits for that outbox's next command or start.
|
|
127
131
|
const sentence = outbox.refused ? ` · ${outbox === state ? SALES_REFUSED : TILL_UPDATES_REFUSED}`
|
|
132
|
+
: outbox === state && needsAdmin > 0 ? ` · ${NEEDS_ADMIN_SALES(needsAdmin)}`
|
|
128
133
|
: backendMissing || (state.pending === 0 && updates > 0 ? registerState?.stuck : stuck) ? ` · ${backendMissingText}` : '';
|
|
129
134
|
// The live region holds only the substance (counts and the sentence), so it is announced when that changes and never as sending
|
|
130
135
|
// or retrying flips or the countdown ticks: those are a short line of their own below it, outside any live region.
|
|
@@ -6,13 +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';
|
|
15
16
|
import { shortTime } from './since-text';
|
|
17
|
+
import { claimVoid, releaseVoid } from './void-in-flight';
|
|
16
18
|
|
|
17
19
|
/** v2 labels.ts statusLabel, as catalogue keys. */
|
|
18
20
|
const STATUS_LABEL: Record<PaymentLegStatus, string> = {
|
|
@@ -24,13 +26,32 @@ const STATUS_TONE: Record<PaymentLegStatus, string> = {
|
|
|
24
26
|
pending: 'text-muted-foreground', authorized: 'text-success', captured: 'text-success', failed: 'text-destructive', voided: 'text-muted-foreground',
|
|
25
27
|
};
|
|
26
28
|
|
|
27
|
-
|
|
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;
|
|
28
40
|
/** v2's "Cancel this payment?" before a leg is voided (use-tender-flow.ts cancelOne). Default false: Cancel payment voids at once. */
|
|
29
|
-
confirmVoid?: boolean
|
|
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 {
|
|
30
49
|
const formatMoney = useFormatMoney();
|
|
31
50
|
const t = useT();
|
|
32
51
|
/** The id of the leg the one question is about (confirmVoid). */
|
|
33
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());
|
|
34
55
|
const { order, stage } = sale;
|
|
35
56
|
if (stage.kind !== 'tender') return null;
|
|
36
57
|
|
|
@@ -46,16 +67,27 @@ export function TenderLedger({ sale, methods, closing = false, confirmVoid = fal
|
|
|
46
67
|
const firstPending = order.payments.find((leg) => legStatus(leg) === 'pending');
|
|
47
68
|
const askedLeg = order.payments.find((leg) => leg.id === asking);
|
|
48
69
|
const asked = askedLeg && descriptorOf(askedLeg);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
};
|
|
53
84
|
|
|
54
85
|
const legs = <View testID="tender-ledger" className="gap-1">
|
|
55
86
|
{order.payments.length === 0 ? <Text className="text-muted-foreground">{t('pos_checkout.no_payments_yet')}</Text> : order.payments.map((leg) => {
|
|
56
87
|
const status = legStatus(leg);
|
|
57
88
|
const voided = status === 'voided';
|
|
58
89
|
const descriptor = descriptorOf(leg);
|
|
90
|
+
const inFlight = voiding.has(leg.id);
|
|
59
91
|
return <View key={leg.id} testID={`tender-leg-${leg.id}`} className="gap-1 border-b border-border py-2">
|
|
60
92
|
<View className="flex-row items-center gap-2">
|
|
61
93
|
<Text className={cn('flex-1 font-semibold text-foreground', voided && 'line-through')}>{descriptor?.title ?? leg.methodId ?? leg.method}</Text>
|
|
@@ -66,15 +98,21 @@ export function TenderLedger({ sale, methods, closing = false, confirmVoid = fal
|
|
|
66
98
|
{leg.takenAt ? <Text testID={`tender-leg-${leg.id}-time`} className="text-sm text-muted-foreground">{shortTime(leg.takenAt)}</Text> : null}
|
|
67
99
|
{leg === firstPending ? <Text className="text-sm text-muted-foreground">{t('pos_checkout.next_leg')}</Text> : null}
|
|
68
100
|
{descriptor && canVoidLeg(leg, descriptor) && !heldTillLeg(order, leg) ? <Pressable testID={`tender-leg-${leg.id}-void`} accessibilityRole="button" accessibilityLabel={t('pos_checkout.cancel_payment')}
|
|
69
|
-
|
|
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">
|
|
70
103
|
<Text className="text-destructive">{t('pos_checkout.cancel_payment')}</Text>
|
|
71
104
|
</Pressable> : null}
|
|
72
105
|
</View>;
|
|
73
106
|
})}
|
|
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>)}
|
|
74
112
|
{!closing && balance === 0 && settled ? <Text className="text-sm text-success">{paidInFull}</Text> : null}
|
|
75
113
|
{confirmVoid ? <ConfirmDialog testID="tender-leg-void-dialog" tone="destructive" title={t('pos_checkout.cancel_payment_question')} description={question}
|
|
76
114
|
confirmLabel={t('pos_checkout.cancel_payment')} open={asking !== null} onOpenChange={(open) => { if (!open) setAsking(null); }}
|
|
77
|
-
onConfirm={() => { if (
|
|
115
|
+
onConfirm={() => { if (askedLeg) void cancel(askedLeg); }} /> : null}
|
|
78
116
|
</View>;
|
|
79
117
|
if (!closing) return legs;
|
|
80
118
|
|