@tallyui/components 3.20.1 → 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.
- package/dist/index.d.ts +1114 -90
- package/dist/index.js +8077 -3352
- package/package.json +10 -11
- package/src/cart/cart-charge-line.tsx +58 -0
- package/src/cart/cart-columns-form.tsx +98 -0
- package/src/cart/cart-columns.tsx +49 -18
- package/src/cart/cart-foot.tsx +7 -2
- package/src/cart/cart-line-strip.tsx +59 -0
- package/src/cart/cart-line.tsx +20 -8
- package/src/cart/cart-note-row.tsx +30 -0
- package/src/cart/cart-panel.tsx +9 -1
- package/src/cart/cart-row-motion.tsx +125 -0
- package/src/cart/cart-total.tsx +44 -15
- package/src/cart/index.ts +2 -1
- package/src/checkout/cash-tendered.tsx +8 -7
- package/src/checkout/change-display.tsx +2 -1
- package/src/checkout/index.ts +1 -1
- package/src/checkout/payment-selector.tsx +6 -2
- package/src/checkout/payment-types.test-d.ts +28 -0
- package/src/customer/address-editor.tsx +87 -0
- package/src/customer/address-fields.tsx +120 -0
- package/src/customer/customer-dropdown.tsx +200 -0
- package/src/customer/customer-editor.tsx +99 -0
- package/src/customer/customer-form.tsx +39 -5
- package/src/customer/customer-picker.tsx +38 -14
- package/src/customer/customers-list.tsx +83 -0
- package/src/customer/index.ts +5 -0
- package/src/filter/filter-pills.tsx +63 -0
- package/src/i18n/locales/en/components.json +85 -0
- package/src/index.ts +40 -2
- package/src/input/decimal-entry.ts +21 -0
- package/src/layout/checkout-layout.tsx +1 -1
- package/src/layout/live-tab-screen.tsx +1 -1
- package/src/layout/pos-layout.tsx +80 -4
- package/src/layout/settings-layout.tsx +1 -1
- package/src/layout/store-settings-choice-screen.tsx +1 -1
- package/src/lib/current-row.ts +13 -0
- package/src/lib/money-input.ts +16 -0
- package/src/lib/motion.ts +22 -0
- package/src/lib/use-reduced-motion.ts +20 -0
- package/src/order/index.ts +1 -1
- package/src/order/order-detail.tsx +123 -5
- package/src/order/order-filter-bar.tsx +7 -57
- package/src/order/order-status-badge.tsx +42 -19
- package/src/order/refund-form.tsx +7 -5
- package/src/product/camera-scan-button.tsx +2 -0
- package/src/product/category-nav.tsx +8 -0
- package/src/product/category-tile.tsx +65 -15
- package/src/product/in-cart-badge.tsx +55 -6
- package/src/product/index.ts +1 -0
- package/src/product/press-veil.tsx +7 -0
- package/src/product/product-card.tsx +5 -1
- package/src/product/product-grid.tsx +5 -0
- package/src/product/product-price.tsx +6 -3
- package/src/product/product-stock-badge.tsx +3 -2
- package/src/product/product-table.tsx +96 -8
- package/src/product/products-screen-columns.tsx +74 -0
- package/src/product/variant-tile.tsx +68 -0
- package/src/product/variation-picker.tsx +3 -3
- package/src/product/view-toggle.tsx +33 -4
- package/src/register/cashier-sheet.tsx +195 -0
- package/src/register/closure-sheet.tsx +54 -3
- package/src/register/handover-slip.tsx +2 -1
- package/src/register/index.ts +2 -1
- package/src/register/movement-sheet.tsx +66 -7
- package/src/register/open-register-card.tsx +11 -11
- package/src/register/register-bar.helpers.ts +17 -4
- package/src/register/register-bar.tsx +26 -5
- package/src/register/register-count.tsx +158 -24
- package/src/register/register-panel.tsx +16 -5
- package/src/register/register-side-sheet.tsx +32 -8
- package/src/register/switch-confirm.tsx +2 -2
- package/src/reports/card-panel.tsx +131 -0
- package/src/reports/cards.tsx +53 -36
- package/src/reports/hero.tsx +2 -1
- package/src/reports/index.ts +1 -0
- package/src/reports/sales-room.tsx +4 -2
- package/src/sale/breadcrumb.tsx +48 -0
- package/src/sale/cart-bar.tsx +2 -1
- package/src/sale/cart.tsx +127 -38
- package/src/sale/catalogue-settings-form.tsx +92 -0
- package/src/sale/catalogue.tsx +304 -42
- package/src/sale/category-browse.tsx +27 -0
- package/src/sale/charge-form.tsx +85 -21
- package/src/sale/customer-display-screen.tsx +22 -6
- package/src/sale/discount-form.tsx +132 -28
- package/src/sale/index.ts +6 -3
- package/src/sale/line-popover.tsx +72 -36
- package/src/sale/offered-methods.ts +16 -0
- package/src/sale/open-sale-tabs.tsx +58 -10
- package/src/sale/order-note-sheet.tsx +37 -0
- package/src/sale/order-reference.ts +3 -0
- package/src/sale/orders-list.tsx +76 -37
- package/src/sale/parked-sales.tsx +2 -1
- package/src/sale/price-form.tsx +7 -5
- package/src/sale/product-filter-bar.tsx +38 -5
- package/src/sale/receipt-sheet.tsx +243 -0
- package/src/sale/receipt.tsx +19 -9
- package/src/sale/sync-status.tsx +10 -0
- package/src/sale/tender-ledger.tsx +92 -0
- package/src/sale/tender-pane.tsx +159 -73
- package/src/sale/tender.tsx +10 -7
- package/src/sale/use-tender.ts +63 -0
- package/src/scale/min-target.tsx +36 -0
- package/src/settings/barcode-scanning-settings.tsx +164 -0
- package/src/settings/connector-status.tsx +1 -1
- package/src/settings/customer-display-settings.tsx +12 -25
- package/src/settings/index.ts +5 -0
- package/src/settings/printer-form.tsx +161 -0
- package/src/settings/printing-settings.tsx +268 -0
- package/src/settings/settings-group.tsx +2 -1
- package/src/settings/tax-calculation-settings.tsx +1 -1
- package/src/shell/added-to-cart-toast.tsx +61 -0
- package/src/shell/app-shell.tsx +5 -1
- package/src/shell/connectivity-toast.tsx +70 -0
- package/src/shell/index.ts +2 -0
- package/src/shell/nav-drawer.tsx +5 -2
- package/src/shell/nav-item.tsx +7 -4
- package/src/shell/nav-rail.tsx +9 -2
- package/src/ui/accordion/index.tsx +86 -8
- package/src/ui/alert-dialog/index.tsx +19 -5
- package/src/ui/combobox/index.tsx +21 -2
- package/src/ui/confirm-dialog/index.tsx +53 -0
- package/src/ui/dialog/index.tsx +68 -14
- package/src/ui/dialog/motion.ts +54 -0
- package/src/ui/icon/activity-heartbeat-icon.tsx +7 -0
- package/src/ui/icon/alert-circle-icon.tsx +5 -0
- package/src/ui/icon/alert-triangle-icon.tsx +7 -0
- package/src/ui/icon/banknote-icon.tsx +11 -0
- package/src/ui/icon/cash-register-icon.tsx +10 -0
- package/src/ui/icon/category-icon.tsx +7 -0
- package/src/ui/icon/chart-line-icon.tsx +5 -0
- package/src/ui/icon/check-icon.tsx +5 -0
- package/src/ui/icon/chevron-left-icon.tsx +4 -0
- package/src/ui/icon/chevron-right-icon.tsx +4 -0
- package/src/ui/icon/credit-card-icon.tsx +10 -0
- package/src/ui/icon/discount-icon.tsx +11 -0
- package/src/ui/icon/gift-icon.tsx +10 -0
- package/src/ui/icon/info-circle-icon.tsx +10 -0
- package/src/ui/icon/map-pin-icon.tsx +10 -0
- package/src/ui/icon/message-question-icon.tsx +7 -0
- package/src/ui/icon/pencil-icon.tsx +10 -0
- package/src/ui/icon/plus-icon.tsx +9 -0
- package/src/ui/icon/printer-icon.tsx +10 -0
- package/src/ui/icon/receipt-icon.tsx +7 -0
- package/src/ui/icon/settings-icon.tsx +10 -0
- package/src/ui/icon/sticky-note-icon.tsx +10 -0
- package/src/ui/icon/user-icon.tsx +4 -0
- package/src/ui/icon/users-icon.tsx +7 -0
- package/src/ui/icon/view-grid-icon.tsx +7 -0
- package/src/ui/icon/view-list-icon.tsx +7 -0
- package/src/ui/index.ts +24 -1
- package/src/ui/list-row/index.tsx +93 -0
- package/src/ui/notice/index.tsx +65 -0
- package/src/ui/select/index.tsx +2 -0
- package/src/ui/skeleton/index.tsx +37 -0
- package/src/ui/status-badge/index.tsx +43 -0
- package/src/ui/switch/index.tsx +1 -1
- package/src/ui/tabs/index.tsx +11 -2
- package/src/ui/toggle-group/index.tsx +3 -1
- package/src/ui/tone-disc/index.tsx +41 -0
package/src/sale/cart.tsx
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
import { useState, type ReactNode } from 'react';
|
|
2
2
|
import { Pressable, Text, View, useWindowDimensions } from 'react-native';
|
|
3
|
-
import { formatMoney } from '@tallyui/core';
|
|
4
3
|
import { buildReceiptData } from '@tallyui/pos';
|
|
5
4
|
import type { useSale } from '@tallyui/pos';
|
|
5
|
+
import { useFormatMoney, type PaymentMethodDescriptor } from '@tallyui/core';
|
|
6
6
|
import { CartColumnHeads, CartFoot, CartLine, CartLineActions, CartPanel, CartTotal, type CartFootAction } from '../cart';
|
|
7
|
+
import { CartChargeLine } from '../cart/cart-charge-line';
|
|
8
|
+
import { CartLineStrip } from '../cart/cart-line-strip';
|
|
9
|
+
import { MotionRows } from '../cart/cart-row-motion';
|
|
7
10
|
import { cartShowsPrice } from '../cart/cart-columns';
|
|
8
11
|
import type { CartColumnSettings } from '../cart/cart-columns';
|
|
9
12
|
import { DiscountChips, DiscountForm } from './discount-form';
|
|
10
13
|
import { PriceForm } from './price-form';
|
|
11
14
|
import { ChargeForm } from './charge-form';
|
|
12
15
|
import { LinePopover } from './line-popover';
|
|
16
|
+
import { OrderNoteSheet } from './order-note-sheet';
|
|
17
|
+
import { TenderLedger } from './tender-ledger';
|
|
13
18
|
import { ShoppingCartIcon } from '../ui';
|
|
19
|
+
import { useT } from '../i18n';
|
|
14
20
|
|
|
15
21
|
/** `taxLabel` names each tax row; VAT isn't universal, so a platform passes its own (medusapos passes `VAT ${rate}%`). */
|
|
16
|
-
export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10000}%`, canEditPrice = false, onPriceChange, quickDiscounts, taxClasses, afterSubtotal, showTotal = true, couponDiscountMinor, orderActions = true, checkout, lineEditor = 'inline',
|
|
17
|
-
columns,
|
|
22
|
+
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',
|
|
23
|
+
lineCommit = 'apply', columns, chargeTaxSwitch = true,
|
|
18
24
|
emptyIcon = <ShoppingCartIcon size={48} />, emptyText = 'Tap a product to start a sale' }:
|
|
19
25
|
{ sale: ReturnType<typeof useSale>; taxLabel?: (ratePpm: number) => string;
|
|
20
26
|
taxClasses?: ReadonlyArray<{ id: string; label: string }>;
|
|
@@ -28,24 +34,51 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
28
34
|
afterSubtotal?: ReactNode;
|
|
29
35
|
/** Draws the totals' Total row. Pass `false` for v2's cart, where the total is on the Checkout button (`checkout`). Default `true`. */
|
|
30
36
|
showTotal?: boolean;
|
|
31
|
-
/** The coupon amount the app itemises in `afterSubtotal` (e.g. Σ `order.display.coupons`
|
|
37
|
+
/** The coupon amount the app itemises in `afterSubtotal` (e.g. Σ `order.display.coupons` and, with
|
|
38
|
+
* `orderDiscountChips={false}`, `order.display.orderDiscountMinor`), in integer minor units of
|
|
32
39
|
* the order's currency, in the display mode. When given, the Discount row shows the other discounts only (the
|
|
33
40
|
* totals' discount minus this) and is hidden when they come to 0. Absent: the Discount row is the whole discount. */
|
|
34
41
|
couponDiscountMinor?: number;
|
|
35
42
|
/** Cart's own Order discount and Add charge controls; pass `false` when the app hosts them in its own menu (v2's
|
|
36
43
|
* cart "+" menu). Applied discounts and charges still show and can be removed. */
|
|
37
44
|
orderActions?: boolean;
|
|
45
|
+
/** Draws the applied order discounts as removable chips under the lines. Pass `false` when the app draws them itself,
|
|
46
|
+
* e.g. as a removable Discount row in `afterSubtotal`; add their amount (`order.display.orderDiscountMinor`) to
|
|
47
|
+
* `couponDiscountMinor` so the Discount row does not count them twice. Default `true`. */
|
|
48
|
+
orderDiscountChips?: boolean;
|
|
38
49
|
/** Swaps the Cash and Card terminal row for v2's foot, `CartFoot`: "Checkout {total}" calls `onCheckout`, and the
|
|
39
|
-
* ⋮ menu lists `actions
|
|
40
|
-
checkout?: { onCheckout: () => void; actions?: readonly CartFootAction[] };
|
|
50
|
+
* ⋮ menu lists `actions`, with `note` above the buttons. Absent: the Cash and Card terminal row. */
|
|
51
|
+
checkout?: { onCheckout: () => void; actions?: readonly CartFootAction[]; note?: { text: string; onPress: () => void } };
|
|
52
|
+
/** v2's note editing, owned by the Cart: the ⋮ menu gains "Order details" (first), which opens `OrderNoteSheet`
|
|
53
|
+
* on `sale.order.note`, and the note row above the buttons shows that note and opens the sheet too. `label`
|
|
54
|
+
* names the note (default "Customer note"; a platform whose note the customer never sees passes its own, e.g.
|
|
55
|
+
* "Order note"). Needs `checkout`; when given, it replaces `checkout.note`. */
|
|
56
|
+
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 };
|
|
59
|
+
/** WCPOS v2's split-by-item bill (stilled-cart.tsx): the cart is read-only, and each line whose quantity is a positive
|
|
60
|
+
* whole number, whose total is not negative and that has units left unpaid shows this payment's `− n of unpaid +`
|
|
61
|
+
* stepper in its quantity cell, with what the picked units add under it. `picked`: this payment's units per line id;
|
|
62
|
+
* `paid`: the units earlier live payments took per line id; `unitMinor(lineId, units)`: the minor units `units` more
|
|
63
|
+
* of that line add after the paid ones; `onPick(lineId, units)` sets this payment's units. */
|
|
64
|
+
picker?: { picked: Readonly<Record<string, number>>; paid: Readonly<Record<string, number>>;
|
|
65
|
+
unitMinor: (lineId: string, units: number) => number; onPick: (lineId: string, units: number) => void };
|
|
41
66
|
/** `popover`: tapping a line's quantity or price opens v2's keypad (WCPOS cart cells/quantity-keypad.tsx and
|
|
42
67
|
* cells/price.tsx), the price one with the quick-discount keys and the struck regular price. Popover mode draws no
|
|
43
68
|
* button row under the line: Discount, Price (narrow cart) and Remove are in the quantity popover, Discount in the
|
|
44
69
|
* price popover. Default `inline`: the − / + buttons and Price form. */
|
|
45
70
|
lineEditor?: 'inline' | 'popover';
|
|
71
|
+
/** With `lineEditor="popover"`, `close` gives both popovers v2's grow keypad (LinePopover's `commit="close"`): Done;
|
|
72
|
+
* Escape closes without writing, any other close writes what was typed, and a refused price on that close shows under
|
|
73
|
+
* the line. The quantity one adds − / + steppers that write at once, − turning into Remove at 1 (in place of the
|
|
74
|
+
* Remove action). Default `apply`. */
|
|
75
|
+
lineCommit?: 'apply' | 'close';
|
|
46
76
|
/** v2's Cart Settings › Columns: which columns show, a Split link under a quantity above 1 (`quantity.split`) and the
|
|
47
77
|
* SKU under the name (`name.sku`). The defaults are today's cart: Qty, Item, Price (folding as before) and Total. */
|
|
48
78
|
columns?: CartColumnSettings;
|
|
79
|
+
/** Shows ChargeForm's "Amount Includes Tax" switch on fees and shipping. Pass `false` to hide it, so a new charge takes
|
|
80
|
+
* the store's tax mode; an existing charge keeps the flag it already has. Default `true`. */
|
|
81
|
+
chargeTaxSwitch?: boolean;
|
|
49
82
|
/** The empty cart's icon, centred above `emptyText` and hidden from screen readers. Default: v2's cart icon in the
|
|
50
83
|
* muted colour. Pass `null` for no icon. */
|
|
51
84
|
emptyIcon?: ReactNode;
|
|
@@ -53,11 +86,12 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
53
86
|
emptyText?: string;
|
|
54
87
|
}) {
|
|
55
88
|
const { order } = sale;
|
|
89
|
+
const [noteOpen, setNoteOpen] = useState(false);
|
|
56
90
|
// v2's empty cart: an icon and a line, no heads and no foot. A fee or shipping row alone keeps the cart.
|
|
57
91
|
const empty = !order.lineItems.length && !order.fees?.length && !order.shipping?.length;
|
|
58
92
|
const money = (amount: number) => ({ amount, currency: order.currency });
|
|
59
93
|
// order.display's figures (TallyUI ADR-063), with its tax split by rate; never app arithmetic (medusapos ADR 0008).
|
|
60
|
-
const { totals } = buildReceiptData(order, { storeName: '' });
|
|
94
|
+
const { totals, fees, shipping } = buildReceiptData(order, { storeName: '' });
|
|
61
95
|
const taxRows = totals.taxLines.map((line) => ({ label: taxLabel(line.ratePpm), amount: money(line.amountMinor) }));
|
|
62
96
|
// Each line before its discounts, with its own discounts' amounts. The order discounts are one figure: a single
|
|
63
97
|
// order discount's chip carries it; several keep their own labels, as no single one has a display amount.
|
|
@@ -70,11 +104,19 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
70
104
|
const refused = sale.splitLine(lineId);
|
|
71
105
|
setSplitError(refused === null ? null : { lineId, message: refused });
|
|
72
106
|
};
|
|
73
|
-
//
|
|
74
|
-
const [
|
|
107
|
+
// A line's price refused on a popover close (lineCommit="close"), shown under it until that line's next price write.
|
|
108
|
+
const [priceError, setPriceError] = useState<{ lineId: string; message: string } | null>(null);
|
|
109
|
+
// One open form: a line's discount or price, the order's discount (lineId null), a new charge, or a charge's edit.
|
|
110
|
+
const [openForm, setForm] = useState<{ type: 'discount'; lineId: string | null } | { type: 'price'; lineId: string } | { type: 'charge' }
|
|
111
|
+
| { type: 'edit-charge'; kind: 'fees' | 'shipping'; id: string } | null>(null);
|
|
112
|
+
// The picker's bill is read-only: no form shows, nor any control that opens one.
|
|
113
|
+
const form = picker ? null : openForm;
|
|
114
|
+
const ChargeStrip = picker ? ReadOnlyStrip : CartLineStrip;
|
|
75
115
|
const chargesOffered = (sale.capabilities?.orderCreate ?? 0) >= 5;
|
|
76
|
-
|
|
77
|
-
const
|
|
116
|
+
// #1115: front desk 2026-11-20, a Woo store at order.create 6+ takes a No tax shipping line (stock 2.0.4 proof F2).
|
|
117
|
+
const shippingNoTax = (sale.capabilities?.orderCreate ?? 0) >= 6;
|
|
118
|
+
const showOrderDiscount = !picker && order.lineItems.length > 0 && (orderActions || (orderDiscountChips && order.discounts.length > 0));
|
|
119
|
+
const showCharge = !picker && orderActions && chargesOffered;
|
|
78
120
|
const discountForm = (lineId: string | null, title: string) => form?.type === 'discount' && form.lineId === lineId
|
|
79
121
|
? <DiscountForm key={lineId ?? 'order'} title={title} currency={order.currency} onClose={() => setForm(null)}
|
|
80
122
|
onApply={(discount) => sale.applyDiscount(lineId, discount)} /> : null;
|
|
@@ -90,26 +132,35 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
90
132
|
const fromMinor = line.unitPriceMinor;
|
|
91
133
|
const refused = sale.setUnitPrice(line.id, amount);
|
|
92
134
|
if (refused === null) onPriceChange?.({ lineId: line.id, fromMinor, toMinor: amount, reason });
|
|
135
|
+
if (refused === null) setPriceError((now) => (now?.lineId === line.id ? null : now));
|
|
93
136
|
return refused;
|
|
94
137
|
};
|
|
138
|
+
const unpaid = (line: typeof order.lineItems[number]) => line.quantity - (picker?.paid[line.id] ?? 0);
|
|
139
|
+
const pickable = (line: typeof order.lineItems[number]) => Number.isInteger(line.quantity) && line.quantity > 0
|
|
140
|
+
&& display(line.id).amountMinor >= 0 && unpaid(line) > 0;
|
|
95
141
|
const renderItem = (line: typeof order.lineItems[number]) => <>
|
|
96
142
|
<CartLine name={line.name} attributes={line.attributes} quantity={line.quantity} unitPrice={money(line.unitPriceMinor)}
|
|
97
143
|
regularUnitPrice={line.regularUnitPriceMinor === undefined ? undefined : money(line.regularUnitPriceMinor)}
|
|
98
144
|
lineTotal={money(display(line.id).amountMinor)} showPrice={showPrice}
|
|
99
|
-
columns={columns} sku={line.sku} imageUrl={line.imageUrl} onSplit={() => split(line.id)}
|
|
100
|
-
quantitySlot={
|
|
101
|
-
|
|
145
|
+
columns={columns} sku={line.sku} imageUrl={line.imageUrl} onSplit={picker ? undefined : () => split(line.id)} picking={picker !== undefined}
|
|
146
|
+
quantitySlot={picker ? pickable(line) ? <PickStepper picker={picker} id={line.id} name={line.name} unpaid={unpaid(line)}
|
|
147
|
+
currency={order.currency} /> : undefined : lineEditor === 'popover' ? <LinePopover kind="quantity" lineName={line.name} currency={order.currency}
|
|
148
|
+
value={line.quantity} onApply={(quantity) => { sale.setQuantity(line.id, quantity); return null; }} commit={lineCommit}
|
|
149
|
+
onRemove={lineCommit === 'close' ? () => sale.remove(line.id) : undefined} actions={[
|
|
102
150
|
...(!pricePopover ? [{ id: 'discount', label: 'Discount', onPress: () => setForm({ type: 'discount', lineId: line.id }) }] : []),
|
|
103
151
|
...(canEditPrice && !pricePopover ? [{ id: 'price', label: 'Price', onPress: () => setForm({ type: 'price', lineId: line.id }) }] : []),
|
|
104
|
-
{ id: 'remove', label: 'Remove', destructive: true, onPress: () => sale.remove(line.id) },
|
|
152
|
+
...(lineCommit === 'close' ? [] : [{ id: 'remove', label: 'Remove', destructive: true, onPress: () => sale.remove(line.id) }]),
|
|
105
153
|
]} /> : undefined}
|
|
106
|
-
priceSlot={pricePopover ? <LinePopover kind="price" lineName={line.name} currency={order.currency} value={line.unitPriceMinor}
|
|
154
|
+
priceSlot={pricePopover && !picker ? <LinePopover kind="price" lineName={line.name} currency={order.currency} value={line.unitPriceMinor}
|
|
107
155
|
regularValue={line.regularUnitPriceMinor} actions={[{ id: 'discount', label: 'Discount', onPress: () => setForm({ type: 'discount', lineId: line.id }) }]}
|
|
108
|
-
quickDiscounts={quickDiscounts} textClassName="text-right text-muted-foreground" onApply={(amount) => applyPrice(line, amount)}
|
|
156
|
+
quickDiscounts={quickDiscounts} textClassName="text-right text-muted-foreground" onApply={(amount) => applyPrice(line, amount)}
|
|
157
|
+
commit={lineCommit} onCloseRefused={(message) => setPriceError({ lineId: line.id, message })} /> : undefined} />
|
|
109
158
|
{splitError?.lineId === line.id ? <Text accessibilityRole="alert" testID="cart-line-split-error"
|
|
110
159
|
className="px-3 text-sm text-destructive">{splitError.message}</Text> : null}
|
|
111
|
-
|
|
112
|
-
|
|
160
|
+
{priceError?.lineId === line.id ? <Text accessibilityRole="alert" testID="cart-line-price-error"
|
|
161
|
+
className="px-3 text-sm text-destructive">{priceError.message}</Text> : null}
|
|
162
|
+
{picker ? null : <DiscountChips discounts={line.discounts} amounts={display(line.id).discounts} currency={order.currency} onRemove={sale.removeDiscount} />}
|
|
163
|
+
{lineEditor === 'inline' && !picker ? <CartLineActions actions={[
|
|
113
164
|
{ id: 'discount', label: 'Discount', color: 'text-primary', onPress: () => setForm({ type: 'discount', lineId: line.id }) },
|
|
114
165
|
...(canEditPrice && !pricePopover ? [{ id: 'price', label: 'Price', color: 'text-primary', onPress: () => setForm({ type: 'price', lineId: line.id }) }] : []),
|
|
115
166
|
]}>
|
|
@@ -128,8 +179,8 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
128
179
|
onApply={(amount, reason) => applyPrice(line, amount, reason)} /> : null}
|
|
129
180
|
</>;
|
|
130
181
|
return <View dataSet={{ print: 'hide' }} className="flex-1 min-h-0" onLayout={(event) => setCartWidth(event.nativeEvent.layout.width)}>
|
|
131
|
-
{empty ? null : <CartColumnHeads showPrice={showPrice} columns={columns} />}
|
|
132
|
-
<CartPanel items={order.lineItems} renderItem={renderItem}
|
|
182
|
+
{empty ? null : <CartColumnHeads showPrice={showPrice} columns={columns} picking={picker !== undefined} />}
|
|
183
|
+
<CartPanel items={order.lineItems} renderItem={renderItem} pulseKey={(line) => line.quantity} identity={order.id}
|
|
133
184
|
footerClassName="px-2 py-2"
|
|
134
185
|
emptyState={empty ? <View testID="cart-empty" className="flex-1 items-center justify-center gap-3 px-3 py-6">
|
|
135
186
|
{emptyIcon === null ? null : <View aria-hidden accessibilityElementsHidden importantForAccessibility="no-hide-descendants"
|
|
@@ -139,42 +190,57 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
139
190
|
{sale.error ? <Text accessibilityRole="alert" className="text-destructive">{sale.error}</Text> : null}
|
|
140
191
|
</View> : undefined}
|
|
141
192
|
afterItems={<>
|
|
142
|
-
{(['fees', 'shipping'] as const).map((kind) => order[kind]
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
<
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
193
|
+
{(['fees', 'shipping'] as const).map((kind) => <MotionRows key={kind} items={order[kind] ?? []} keyOf={(charge) => charge.id}
|
|
194
|
+
pulseKey={() => 0} identity={order.id} renderItem={(charge, index) =>
|
|
195
|
+
<View testID={`cart-${kind === 'fees' ? 'fee' : 'shipping'}-${index}`}>
|
|
196
|
+
<ChargeStrip name={charge.name} onEdit={() => setForm({ type: 'edit-charge', kind, id: charge.id })}
|
|
197
|
+
onRemove={() => kind === 'fees' ? sale.removeFee(charge.id) : sale.removeShipping(charge.id)}>
|
|
198
|
+
{(wrapTotal) => <CartChargeLine name={charge.name} price={money(charge.amountMinor)} percent={charge.percent}
|
|
199
|
+
total={money(order.display[kind]!.find((row) => row.id === charge.id)!.amountMinor)}
|
|
200
|
+
showPrice={showPrice} columns={columns} picking={picker !== undefined} testID="cart-charge-line" wrapTotal={wrapTotal} />}
|
|
201
|
+
</ChargeStrip>
|
|
202
|
+
{form?.type === 'edit-charge' && form.kind === kind && form.id === charge.id ? <ChargeForm key={charge.id}
|
|
203
|
+
kind={kind === 'fees' ? 'fee' : 'shipping'} initial={charge} currency={order.currency} lineTax={sale.capabilities?.lineTax}
|
|
204
|
+
allowPercent pricesIncludeTax={chargeTaxSwitch ? order.pricesIncludeTax : undefined}
|
|
205
|
+
taxClasses={taxClasses} shippingTaxFromStore={sale.capabilities?.taxRounding?.granularity === 'woocommerce'}
|
|
206
|
+
shippingNoTax={shippingNoTax} onClose={() => setForm(null)} onApply={({ name, amountMinor, taxStatus, taxClass, amountIncludesTax, percent }) => kind === 'fees'
|
|
207
|
+
? sale.updateFee(charge.id, { name, amountMinor, taxStatus, taxClass, amountIncludesTax, percent })
|
|
208
|
+
: sale.updateShipping(charge.id, { name, amountMinor, taxStatus, taxClass, amountIncludesTax })} /> : null}
|
|
209
|
+
</View>} />)}
|
|
151
210
|
{showOrderDiscount || showCharge ? <View className="gap-3 px-3 py-2">
|
|
152
211
|
{showOrderDiscount ? <>
|
|
153
|
-
<DiscountChips discounts={order.discounts} amounts={orderAmounts} currency={order.currency}
|
|
154
|
-
prefix="Order discount" />
|
|
212
|
+
{orderDiscountChips ? <DiscountChips discounts={order.discounts} amounts={orderAmounts} currency={order.currency}
|
|
213
|
+
onRemove={sale.removeDiscount} prefix="Order discount" /> : null}
|
|
155
214
|
{!orderActions ? null : form?.type === 'discount' && form.lineId === null ? discountForm(null, 'Order discount') : <Pressable accessibilityRole="button"
|
|
156
215
|
onPress={() => setForm({ type: 'discount', lineId: null })} className="self-start rounded-md border border-border bg-card px-4 py-2 min-h-11 justify-center">
|
|
157
216
|
<Text className="text-foreground">Order discount</Text></Pressable>}
|
|
158
217
|
</> : null}
|
|
159
218
|
{showCharge ? form?.type === 'charge' ? <ChargeForm currency={order.currency} lineTax={sale.capabilities?.lineTax}
|
|
219
|
+
allowPercent pricesIncludeTax={chargeTaxSwitch ? order.pricesIncludeTax : undefined}
|
|
160
220
|
taxClasses={taxClasses} shippingTaxFromStore={sale.capabilities?.taxRounding?.granularity === 'woocommerce'}
|
|
161
|
-
onClose={() => setForm(null)} onApply={({ kind, name, amountMinor, taxStatus, taxClass }) => {
|
|
221
|
+
shippingNoTax={shippingNoTax} onClose={() => setForm(null)} onApply={({ kind, name, amountMinor, taxStatus, taxClass, amountIncludesTax, percent }) => {
|
|
162
222
|
const result = kind === 'custom' ? sale.addCustomLine({ name, priceMinor: amountMinor, taxStatus, taxClass })
|
|
163
|
-
: kind === 'fee' ? sale.addFee({ name, amountMinor, taxStatus, taxClass })
|
|
164
|
-
: sale.addShipping({ name, amountMinor, taxStatus, taxClass });
|
|
223
|
+
: kind === 'fee' ? sale.addFee({ name, amountMinor, taxStatus, taxClass, amountIncludesTax, percent })
|
|
224
|
+
: sale.addShipping({ name, amountMinor, taxStatus, taxClass, amountIncludesTax });
|
|
165
225
|
return typeof result === 'string' ? result : null;
|
|
166
226
|
}} /> : <Pressable accessibilityRole="button" onPress={() => setForm({ type: 'charge' })}
|
|
167
227
|
className="self-start rounded-md border border-border bg-card px-4 py-2 min-h-11 justify-center">
|
|
168
228
|
<Text className="text-foreground">Add charge</Text></Pressable> : null}
|
|
169
229
|
</View> : null}</>}
|
|
170
230
|
footer={empty ? undefined : <View testID="cart-footer" className="gap-2">
|
|
171
|
-
{/* Exclusive: subtotal − discount + tax = total. Inclusive: subtotal − discount
|
|
231
|
+
{/* Exclusive: subtotal − discount + fees + shipping + tax = total. Inclusive: subtotal − discount + fees + shipping =
|
|
232
|
+
total, the tax "incl.", not added. */}
|
|
172
233
|
<CartTotal className="px-0 py-0" subtotal={money(totals.subtotalMinor)} total={money(totals.totalMinor)}
|
|
173
234
|
discount={money(couponDiscountMinor === undefined ? totals.discountMinor : Math.max(0, totals.discountMinor - couponDiscountMinor))}
|
|
235
|
+
fees={money(fees.reduce((sum, row) => sum + row.amountMinor, 0))}
|
|
236
|
+
shipping={money(shipping.reduce((sum, row) => sum + row.amountMinor, 0))}
|
|
174
237
|
taxLines={taxRows} taxInclusive={totals.taxInclusive} afterSubtotal={afterSubtotal} showTotal={showTotal} />
|
|
175
238
|
{sale.error ? <Text accessibilityRole="alert" className="text-destructive">{sale.error}</Text> : null}
|
|
176
|
-
{checkout ?
|
|
177
|
-
|
|
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
|
+
actions={noteSheet ? [{ label: 'Order details', onPress: () => setNoteOpen(true) }, ...(checkout.actions ?? [])] : checkout.actions}
|
|
241
|
+
note={noteSheet ? { text: order.note, onPress: () => setNoteOpen(true) } : checkout.note} disabled={!order.lineItems.length} />
|
|
242
|
+
{noteSheet && noteOpen ? <OrderNoteSheet value={order.note} onChangeText={sale.setNote}
|
|
243
|
+
label={noteSheet.label} onOpenChange={setNoteOpen} /> : null}</> : <View className="flex-row gap-3">
|
|
178
244
|
<Pressable accessibilityRole="button" disabled={!order.lineItems.length} onPress={() => sale.startTender('cash')} className={pay}>
|
|
179
245
|
<Text className="text-center font-semibold text-primary-foreground">Cash</Text>
|
|
180
246
|
</Pressable>
|
|
@@ -185,3 +251,26 @@ export function Cart({ sale, taxLabel = (ratePpm: number) => `Tax ${ratePpm / 10
|
|
|
185
251
|
</View>} />
|
|
186
252
|
</View>;
|
|
187
253
|
}
|
|
254
|
+
|
|
255
|
+
/** A fee or shipping row on the picker's read-only bill: the row alone, no Edit or Remove strip. */
|
|
256
|
+
const ReadOnlyStrip = ({ children }: Parameters<typeof CartLineStrip>[0]) => <>{children((content) => content)}</>;
|
|
257
|
+
|
|
258
|
+
/** Cart's `picker` stepper, v2's `− n of unpaid +` (tender/unit-stepper.tsx), with what the picked units add under it. */
|
|
259
|
+
function PickStepper({ picker, id, name, unpaid, currency }: { picker: NonNullable<Parameters<typeof Cart>[0]['picker']>;
|
|
260
|
+
id: string; name: string; unpaid: number; currency: string }) {
|
|
261
|
+
const t = useT();
|
|
262
|
+
const formatMoney = useFormatMoney();
|
|
263
|
+
const units = picker.picked[id] ?? 0;
|
|
264
|
+
const button = 'rounded-md border border-border bg-card px-3 py-2 min-h-11 min-w-11 items-center justify-center';
|
|
265
|
+
return <View className="items-center gap-1">
|
|
266
|
+
<View className="flex-row items-center gap-2">
|
|
267
|
+
<Pressable accessibilityRole="button" accessibilityLabel={t('pos_checkout.pick_fewer', { name })} testID={`cart-line-${id}-pick-minus`}
|
|
268
|
+
disabled={units <= 0} onPress={() => picker.onPick(id, units - 1)} className={button}><Text className="text-center text-foreground">−</Text></Pressable>
|
|
269
|
+
<Text testID={`cart-line-${id}-pick-units`} className="tabular-nums text-foreground">{t('pos_checkout.n_of_units', { n: units, total: unpaid })}</Text>
|
|
270
|
+
<Pressable accessibilityRole="button" accessibilityLabel={t('pos_checkout.pick_more', { name })} testID={`cart-line-${id}-pick-plus`}
|
|
271
|
+
disabled={units >= unpaid} onPress={() => picker.onPick(id, Math.min(units + 1, unpaid))} className={button}><Text className="text-center text-foreground">+</Text></Pressable>
|
|
272
|
+
</View>
|
|
273
|
+
{units > 0 ? <Text testID={`cart-line-${id}-pick-amount`} className="font-semibold tabular-nums text-foreground">
|
|
274
|
+
{formatMoney({ amount: picker.unitMinor(id, units), currency }) ?? '—'}</Text> : null}
|
|
275
|
+
</View>;
|
|
276
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Ported from WCPOS v2 packages/core/src/screens/main/pos/products/ui-settings-form.tsx (Tile Size and Tile Fields)
|
|
2
|
+
// and contexts/ui-settings/use-ui-label.ts (the labels), MIT, WCPOS. TallyUI adds the Auto switch for
|
|
3
|
+
// `gridColumns: 'auto'`.
|
|
4
|
+
import type { JSX } from 'react';
|
|
5
|
+
import { View, type ViewProps } from 'react-native';
|
|
6
|
+
import { DEFAULT_CATALOGUE_VIEW_STATE, DEFAULT_TILE_FIELDS } from '@tallyui/pos';
|
|
7
|
+
import type { CatalogueGridColumns, TileField, TileFields } from '@tallyui/pos';
|
|
8
|
+
import { cn } from '@tallyui/theme';
|
|
9
|
+
import { useT } from '../i18n';
|
|
10
|
+
import { Button } from '../ui/button';
|
|
11
|
+
import { Slider } from '../ui/slider';
|
|
12
|
+
import { Switch } from '../ui/switch';
|
|
13
|
+
import { Text } from '../ui/text';
|
|
14
|
+
|
|
15
|
+
/** Each tile field's catalogue key, v2's `use-ui-label.ts`. */
|
|
16
|
+
const LABELS: Record<TileField, string> = {
|
|
17
|
+
name: 'common.product_name', price: 'common.price', onSale: 'common.on_sale', categories: 'common.categories',
|
|
18
|
+
sku: 'common.sku', barcode: 'common.barcode', stock: 'common.stock',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** v2's default products per row, emitted when Auto is turned off. */
|
|
22
|
+
const V2_TILE_SIZE = 4;
|
|
23
|
+
|
|
24
|
+
export interface CatalogueSettingsFormProps extends Omit<ViewProps, 'children'> {
|
|
25
|
+
/** The products-per-row setting (default `'auto'`), from the app's CatalogueViewState. */
|
|
26
|
+
gridColumns?: CatalogueGridColumns;
|
|
27
|
+
onGridColumnsChange: (next: CatalogueGridColumns) => void;
|
|
28
|
+
/** The saved tile fields, merged over DEFAULT_TILE_FIELDS (default: today's tile). */
|
|
29
|
+
tileFields?: Partial<TileFields>;
|
|
30
|
+
/** Called with a fresh, full TileFields on every switch; the form stores nothing. */
|
|
31
|
+
onTileFieldsChange: (next: TileFields) => void;
|
|
32
|
+
/** Draw Restore Default Settings, which emits 'auto' and DEFAULT_TILE_FIELDS (default false). */
|
|
33
|
+
showReset?: boolean;
|
|
34
|
+
className?: string;
|
|
35
|
+
/** Default `catalogue-settings`. */
|
|
36
|
+
testID?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* v2's product settings: Tile Size (an Auto switch, then a 2 to 8 slider) and a Tile Fields switch per tile word.
|
|
41
|
+
* It emits `gridColumns` for the catalogue view state and a `TileFields` for `Catalogue`'s `tileFields`.
|
|
42
|
+
*
|
|
43
|
+
* ```tsx
|
|
44
|
+
* <CatalogueSettingsForm gridColumns={view.gridColumns} onGridColumnsChange={setColumns}
|
|
45
|
+
* tileFields={settings['catalogue.tileFields']} onTileFieldsChange={(next) => setSetting('catalogue.tileFields', next)} />
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function CatalogueSettingsForm({
|
|
49
|
+
gridColumns = 'auto', onGridColumnsChange, tileFields, onTileFieldsChange, showReset = false, className,
|
|
50
|
+
testID = 'catalogue-settings', ...viewProps
|
|
51
|
+
}: CatalogueSettingsFormProps): JSX.Element {
|
|
52
|
+
const t = useT();
|
|
53
|
+
const merged: TileFields = { ...DEFAULT_TILE_FIELDS, ...tileFields };
|
|
54
|
+
const auto = gridColumns === 'auto';
|
|
55
|
+
return (
|
|
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>
|
|
58
|
+
<View className="flex-row items-center gap-3 py-1">
|
|
59
|
+
<Switch testID={`${testID}-auto`} accessibilityLabel={t('common.auto')} checked={auto}
|
|
60
|
+
onCheckedChange={(on) => onGridColumnsChange(on ? 'auto' : V2_TILE_SIZE)} />
|
|
61
|
+
<Text className="flex-1">{t('common.auto')}</Text>
|
|
62
|
+
</View>
|
|
63
|
+
{auto ? null : (
|
|
64
|
+
<View className="flex-row items-center gap-3 py-1">
|
|
65
|
+
<Slider testID={`${testID}-tile-size`} accessibilityLabel={t('common.tile_size')} className="flex-1"
|
|
66
|
+
value={gridColumns} min={2} max={8} step={1}
|
|
67
|
+
onValueChange={(n) => onGridColumnsChange(n as CatalogueGridColumns)} /* snapped to 2..8, step 1 */ />
|
|
68
|
+
<Text className="w-6 text-right tabular-nums">{String(gridColumns)}</Text>
|
|
69
|
+
</View>
|
|
70
|
+
)}
|
|
71
|
+
<Text role="heading" className="pb-1 pt-3 text-base font-semibold">{t('common.tile_fields')}</Text>
|
|
72
|
+
{(Object.keys(DEFAULT_TILE_FIELDS) as TileField[]).map((field) => {
|
|
73
|
+
const label = t(LABELS[field]);
|
|
74
|
+
return (
|
|
75
|
+
<View key={field} className="flex-row items-center gap-3 py-1">
|
|
76
|
+
<Switch testID={`${testID}-field-${field}`} accessibilityLabel={label} checked={merged[field]}
|
|
77
|
+
onCheckedChange={(on) => onTileFieldsChange({ ...merged, [field]: on })} />
|
|
78
|
+
<Text className="flex-1">{label}</Text>
|
|
79
|
+
</View>
|
|
80
|
+
);
|
|
81
|
+
})}
|
|
82
|
+
{showReset ? (
|
|
83
|
+
<Button variant="outline" testID={`${testID}-reset`} className="mt-2 self-start" onPress={() => {
|
|
84
|
+
onGridColumnsChange(DEFAULT_CATALOGUE_VIEW_STATE.gridColumns);
|
|
85
|
+
onTileFieldsChange({ ...DEFAULT_TILE_FIELDS });
|
|
86
|
+
}}>
|
|
87
|
+
<Text>{t('common.restore_default_settings')}</Text>
|
|
88
|
+
</Button>
|
|
89
|
+
) : null}
|
|
90
|
+
</View>
|
|
91
|
+
);
|
|
92
|
+
}
|