@tallyui/components 3.20.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/catalogue.tsx
CHANGED
|
@@ -1,24 +1,56 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
|
2
|
-
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
|
3
|
-
import {
|
|
2
|
+
import { Platform, Pressable, StyleSheet, Text, View, useWindowDimensions } from 'react-native';
|
|
3
|
+
import { cn } from '@tallyui/theme';
|
|
4
|
+
import { useProductStock, useStockOverlaid, useStockOverlayAsOf, type ProductTraits, type ProductCategory, type VariantSummary } from '@tallyui/core';
|
|
4
5
|
import { catalogueEntries, findEntryByCode, searchProducts, variantPriceLabel, sortProducts, productSortValue,
|
|
5
6
|
catalogueViewReducer, normalizeCatalogueViewState, resolveGridColumns, DEFAULT_CATALOGUE_VIEW_STATE,
|
|
6
|
-
listCategories, inCategory, cartQuantities,
|
|
7
|
-
type CatalogueEntry, type CatalogueViewState, type CatalogueViewAction, type CartQuantityLine } from '@tallyui/pos';
|
|
7
|
+
listCategories, inCategory, productCategories, cartQuantities, listTermGroups, hasTerm, DEFAULT_TILE_FIELDS,
|
|
8
|
+
type TileFields, type CatalogueEntry, type CatalogueViewState, type CatalogueViewAction, type CartQuantityLine } from '@tallyui/pos';
|
|
8
9
|
import { ProductGrid, ProductImage, ProductPrice, ProductStockBadge, ProductTitle, ProductTable, ViewToggle, CategoryNav } from '../product';
|
|
9
10
|
import { ProductVariantPicker } from '../product/product-variant-picker';
|
|
11
|
+
import { STOCK_STATUS_LABELS } from '../product/product-stock-badge';
|
|
10
12
|
import { VariationPicker } from '../product/variation-picker';
|
|
11
13
|
import { InCartBadge } from '../product/in-cart-badge';
|
|
14
|
+
import { PressVeil } from '../product/press-veil';
|
|
15
|
+
import { VariantParentTile, VariantTile } from '../product/variant-tile';
|
|
12
16
|
import { Popover } from '@tallyui/primitives';
|
|
13
17
|
import { CameraScanButton } from '../product/camera-scan-button';
|
|
14
18
|
import { CameraScannerPanel, type CameraScannerPanelProps } from '../product/camera-scanner-panel';
|
|
15
19
|
import { ProductFilterBar, DEFAULT_PRODUCT_FILTERS, type ProductFilterChip, type ProductFilters } from './product-filter-bar';
|
|
20
|
+
import { CategoryBrowseGrid } from './category-browse';
|
|
21
|
+
import { Breadcrumb } from './breadcrumb';
|
|
22
|
+
import { CategoryTile, TileStack } from '../product/category-tile';
|
|
23
|
+
import { useT } from '../i18n';
|
|
16
24
|
import { SearchInput } from '../input';
|
|
17
|
-
import { VStack } from '../ui';
|
|
25
|
+
import { VStack, IconButton, PlusIcon } from '../ui';
|
|
26
|
+
import { skeletonCount } from '../ui/skeleton';
|
|
27
|
+
import { useMinTarget } from '../scale/min-target';
|
|
28
|
+
import { usePointer } from '../scale/use-pointer';
|
|
18
29
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
// ProductTable's add column (product-table.tsx ACTION_WIDTH), so a variant row's + sits under its parent row's +.
|
|
31
|
+
const VARIANT_ADD_WIDTH = 56;
|
|
32
|
+
|
|
33
|
+
// Below either number the window is a phone (v2 packages/components/src/lib/device.ts:15-24), and the search
|
|
34
|
+
// field is not capped: v2 caps it only at wide widths (packages/components/src/page-bar/index.tsx:138-139).
|
|
35
|
+
const WIDE_MIN_WIDTH = 768;
|
|
36
|
+
const WIDE_MIN_HEIGHT = 480;
|
|
37
|
+
// A loading tile in the grid tile's frame (the tile below, as ProductCard): its 80 px image, then the band under it,
|
|
38
|
+
// one gap-2 (8) above each row the tile draws for its fields. Title, price and stock badge with their gaps were 75 px
|
|
39
|
+
// at the regular scale, measured in the demo (a tile with no image is 101 px: 75 + p-3 + border). The title and price
|
|
40
|
+
// rows are text-sm's 20 px line, and the badge's 19 is what is left of the measured 75. A fact row (SKU, barcode,
|
|
41
|
+
// categories) is text-xs's 16 px line, from the type scale, not measured.
|
|
42
|
+
const TILE_IMAGE = 80;
|
|
43
|
+
const TILE_GAP = 8;
|
|
44
|
+
const TILE_ROW_HEIGHTS: [keyof TileFields, number][] = [['name', 20], ['price', 20], ['sku', 16], ['barcode', 16], ['categories', 16], ['stock', 19]];
|
|
45
|
+
function tileBand(fields: TileFields): number {
|
|
46
|
+
return TILE_ROW_HEIGHTS.reduce((band, [field, height]) => band + (fields[field] ? TILE_GAP + height : 0), 0);
|
|
47
|
+
}
|
|
48
|
+
// One grid row: the tile's p-3 and border (12 + 1 each side) and the grid cell's p-1 (4 each side) around image and band.
|
|
49
|
+
// TallyUI difference: v2 counts rows at the tile's width plus its band, as its poster image is the tile's width; here the
|
|
50
|
+
// image is a fixed 80 px, so the row is a fixed height.
|
|
51
|
+
const tileRow = (fields: TileFields) => TILE_IMAGE + tileBand(fields) + 2 * (12 + 1 + 4);
|
|
52
|
+
// A level's first grid slot, its own category as a back poster (v2 browse/term-grid.tsx:271-272), as the drill's parent.
|
|
53
|
+
const LEVEL_PARENT = { id: 'level-parent' };
|
|
22
54
|
|
|
23
55
|
// locale/hour12/now are injected (rather than read from the device or the clock inside this
|
|
24
56
|
// function) so the formatting is testable without the device; callers default them to the
|
|
@@ -40,9 +72,14 @@ function laterOf(a: Date | null | undefined, b: Date | null | undefined): Date |
|
|
|
40
72
|
return a.getTime() >= b.getTime() ? a : b;
|
|
41
73
|
}
|
|
42
74
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
75
|
+
// Only when React would draw it: `!open && <Notice />` passes false, which must not leave a blank band.
|
|
76
|
+
function draws(node: ReactNode): boolean {
|
|
77
|
+
return node != null && typeof node !== 'boolean' && node !== '';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function Catalogue<Doc>({ products, traits, currency, onSelect, statusText, statusAccessory, searchAccessory, lastSyncedAt, loading, pullError, lastStockCheckAt, hour12, minCodeLength,
|
|
81
|
+
viewState, defaultViewState, loadViewState, saveViewState, onViewStateError, onStateChange, showViewToggle = false, items, onQueryChange, showCategoryNav = false, categoryBrowse = 'chips', categories, pickAnyOptions = false,
|
|
82
|
+
cartLines, showFilterBar = false, filterChips = ['inStock'], inStockKeepsBackorder = false, termPills = false, filters: filtersProp, onFiltersChange, variationsStyle = 'list', cameraScan = false, cameraScanner, tableRow, rowsSlot, tileFields }: {
|
|
46
83
|
products: Doc[];
|
|
47
84
|
traits: ProductTraits<Doc>;
|
|
48
85
|
currency: string;
|
|
@@ -51,6 +88,9 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
51
88
|
statusText?: string;
|
|
52
89
|
/** Rendered at the end of the status line, e.g. a register control at phone width; the row renders even without `statusText`. */
|
|
53
90
|
statusAccessory?: ReactNode;
|
|
91
|
+
/** v2's own controls beside the search field (its PageBar children, e.g. the Product settings button): rendered
|
|
92
|
+
* at the end of the search row, after the camera scan button and the view toggle. Default none. */
|
|
93
|
+
searchAccessory?: ReactNode;
|
|
54
94
|
lastSyncedAt: Date | null;
|
|
55
95
|
/** The catalogue's first pull is still running, so an empty grid says "Loading products…" rather than "No products yet.". Defaults to lastSyncedAt === null with no pullError; pass false
|
|
56
96
|
* when a null lastSyncedAt doesn't mean a pull is running (e.g. offline on first start). */
|
|
@@ -80,10 +120,14 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
80
120
|
onViewStateError?: (error: unknown) => void;
|
|
81
121
|
/** Loaded state or a cashier's next state (requested state when controlled). */
|
|
82
122
|
onStateChange?: (state: CatalogueViewState) => void;
|
|
83
|
-
/** Show
|
|
123
|
+
/** Show v2's single view-mode icon button (grid/table) in the search row, beside the search field as in v2. Default false. */
|
|
84
124
|
showViewToggle?: boolean;
|
|
85
125
|
/** Show the category nav in the header. Default false. */
|
|
86
126
|
showCategoryNav?: boolean;
|
|
127
|
+
/** How the categories show when showCategoryNav is set: 'chips' (default) is the CategoryNav row; 'tiles' is v2's
|
|
128
|
+
* browse root, the categories as poster tiles with their product counts, opening one under a "Categories › name"
|
|
129
|
+
* breadcrumb. A search typed at the root searches every product. */
|
|
130
|
+
categoryBrowse?: 'chips' | 'tiles';
|
|
87
131
|
/** Replaces the categories derived from the listed products. */
|
|
88
132
|
categories?: ProductCategory[];
|
|
89
133
|
/** App-filtered, sorted list shown as given; products still drives scanning and variant choices. */
|
|
@@ -92,19 +136,27 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
92
136
|
onQueryChange?: (query: string) => void;
|
|
93
137
|
/** Ask for a value for each of a variant's local "Any" option groups before onSelect (#495); set it only when the store accepts order.create version 6. */
|
|
94
138
|
pickAnyOptions?: boolean;
|
|
95
|
-
/** The open sale's lines (e.g. useSale's order.lineItems); each grid tile shows its product's summed quantity.
|
|
96
|
-
|
|
139
|
+
/** The open sale's lines (e.g. useSale's order.lineItems); each grid tile shows its product's summed quantity.
|
|
140
|
+
* A line's optional `variantId`, which a sale line has, lets the drill count each variant. */
|
|
141
|
+
cartLines?: readonly (CartQuantityLine & { variantId?: string })[];
|
|
97
142
|
/** Show v2's filter chips under the search box. Default false. */
|
|
98
143
|
showFilterBar?: boolean;
|
|
99
144
|
/** Which chips the bar shows. Default ['inStock'], the one Catalogue applies itself. */
|
|
100
145
|
filterChips?: readonly ProductFilterChip[];
|
|
146
|
+
/** With the In Stock pill on, keep 'backorder' products in the grid (only 'out_of_stock' is dropped). Default false: WCPOS v2's pill is stock_status 'instock' and drops backorders too. */
|
|
147
|
+
inStockKeepsBackorder?: boolean;
|
|
148
|
+
/** With showFilterBar, a term pill per term group (traits.getTerms) after the chips: `true` for every group the listed
|
|
149
|
+
* products carry, in listTermGroups order, or the group ids to show, in this order (a group with no terms is not drawn).
|
|
150
|
+
* Single select per group; groups AND together; local only, never persisted. Not drawn with `items`. Default off. */
|
|
151
|
+
termPills?: boolean | readonly string[];
|
|
101
152
|
/** Controlled filters; changes are reported through onFiltersChange. */
|
|
102
153
|
filters?: ProductFilters;
|
|
103
154
|
/** The cashier's next filters (requested filters when controlled). */
|
|
104
155
|
onFiltersChange?: (filters: ProductFilters) => void;
|
|
105
156
|
/** v2's Product settings › Variations. 'list' (default) opens the variant list chooser; 'popover' opens a grid tile's
|
|
106
|
-
* VariationPicker in a popover for a product with option groups
|
|
107
|
-
|
|
157
|
+
* VariationPicker in a popover for a product with option groups; 'drill' swaps the grid for the product's variant
|
|
158
|
+
* tiles, with the product's tile first as Back, as v2's "Open in place". The table view keeps the list chooser. */
|
|
159
|
+
variationsStyle?: 'list' | 'popover' | 'drill';
|
|
108
160
|
/** Show v2's camera scan button beside the search box; it opens an inline CameraScannerPanel. Default false.
|
|
109
161
|
* The button shows only when cameraScanner is passed too. */
|
|
110
162
|
cameraScan?: boolean;
|
|
@@ -112,6 +164,18 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
112
164
|
* here, { onDetected: camera.offer, onOpen: camera.reset, scanCount: camera.scanCount }, plus height, permission,
|
|
113
165
|
* viewfinder, decoder and readiness; its useBarcodeScanner then handles camera scans like device scans. */
|
|
114
166
|
cameraScanner?: Omit<CameraScannerPanelProps, 'onClose'>;
|
|
167
|
+
/** v2's table row extras in table view: thumbnail leads the row, addButton ends it with the + (> for a product
|
|
168
|
+
* with variants) that does what a row press does. With expand and thumbnail, a product with more than one variant
|
|
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. Default: none. */
|
|
171
|
+
tableRow?: { thumbnail?: boolean; addButton?: boolean; expand?: boolean };
|
|
172
|
+
/** v2's rows between the chips and the products (its ListColumn `rows`): notices such as "Price check only until
|
|
173
|
+
* the register is open.", rendered under the header and above the grid, table or category tiles. Default none. */
|
|
174
|
+
rowsSlot?: ReactNode;
|
|
175
|
+
/** v2's Product settings › Tile Fields: which words a grid tile shows. Merged over DEFAULT_TILE_FIELDS (today's tile:
|
|
176
|
+
* name, price with its on-sale strike, stock status). Apps feed it from the `catalogue.tileFields` app setting. The grid
|
|
177
|
+
* tiles, the drill's variant tiles and the loading skeleton follow it; the table does not. */
|
|
178
|
+
tileFields?: Partial<TileFields>;
|
|
115
179
|
}) {
|
|
116
180
|
const [initial] = useState<{
|
|
117
181
|
state: CatalogueViewState; loaded?: CatalogueViewState; pending?: Promise<unknown>; failed?: boolean; error?: unknown;
|
|
@@ -129,6 +193,7 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
129
193
|
});
|
|
130
194
|
const [internalState, setInternalState] = useState(initial.state);
|
|
131
195
|
const state = viewState ?? internalState;
|
|
196
|
+
const fields: TileFields = { ...DEFAULT_TILE_FIELDS, ...tileFields };
|
|
132
197
|
const cashierChanged = useRef(false);
|
|
133
198
|
useEffect(() => {
|
|
134
199
|
let mounted = true;
|
|
@@ -164,40 +229,112 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
164
229
|
onFiltersChange?.(next);
|
|
165
230
|
}
|
|
166
231
|
const quantities = useMemo(() => cartQuantities(cartLines ?? []), [cartLines]);
|
|
232
|
+
// The drill's per-variant count, by cartQuantities' rule: a custom line counts for no variant.
|
|
233
|
+
const variantQuantities = useMemo(() => {
|
|
234
|
+
const byVariant = new Map<string, number>();
|
|
235
|
+
for (const line of cartLines ?? []) if (!line.custom && line.variantId) byVariant.set(line.variantId, (byVariant.get(line.variantId) ?? 0) + line.quantity);
|
|
236
|
+
return byVariant;
|
|
237
|
+
}, [cartLines]);
|
|
167
238
|
|
|
168
239
|
const isLoading = loading ?? (lastSyncedAt === null && pullError == null);
|
|
169
240
|
// Idempotent (the adapter's overlay returns just the fields the stock map sets), so an app that already
|
|
170
241
|
// merges the overlay itself keeps working, and can drop its own merge.
|
|
171
242
|
const shown = useStockOverlaid(products) as Doc[];
|
|
172
243
|
const categoryList = useMemo(() => categories ?? listCategories(shown, traits), [categories, shown, traits]);
|
|
244
|
+
const counts = useMemo(() => {
|
|
245
|
+
const counts = new Map<string, number>();
|
|
246
|
+
for (const doc of shown) {
|
|
247
|
+
for (const id of new Set(productCategories(doc, traits).map((category) => category.id))) {
|
|
248
|
+
counts.set(id, (counts.get(id) ?? 0) + 1);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return counts;
|
|
252
|
+
}, [shown, traits]);
|
|
173
253
|
const activeCategory = showCategoryNav ? categoryList.find((category) => category.id === state.categoryId) : undefined;
|
|
174
254
|
const suppliedItems = useStockOverlaid(items ?? products) as Doc[];
|
|
175
255
|
const overlayAsOf = useStockOverlayAsOf();
|
|
176
256
|
const parsedOverlayAsOf = overlayAsOf ? new Date(overlayAsOf) : undefined;
|
|
177
257
|
const validOverlayAsOf = parsedOverlayAsOf && !isNaN(parsedOverlayAsOf.getTime()) ? parsedOverlayAsOf : undefined;
|
|
178
258
|
const stockAsOf = laterOf(laterOf(lastStockCheckAt, validOverlayAsOf), lastSyncedAt);
|
|
259
|
+
const t = useT();
|
|
179
260
|
const [query, setQuery] = useState('');
|
|
261
|
+
const [allOpen, setAllOpen] = useState(false);
|
|
262
|
+
// Opening a category by its tile focuses the crumb (v2 focuses on mount); a stored category does not.
|
|
263
|
+
const [crumbFocus, setCrumbFocus] = useState(false);
|
|
264
|
+
const browsing = showCategoryNav && categoryBrowse === 'tiles';
|
|
265
|
+
const level = browsing && (activeCategory || allOpen);
|
|
266
|
+
const back = () => { setCrumbFocus(false); setAllOpen(false); changeState({ type: 'setCategory', categoryId: null }); };
|
|
267
|
+
const atRoot = browsing && !activeCategory && !allOpen && !query.trim()
|
|
268
|
+
&& categoryList.some((category) => (counts.get(category.id) ?? 0) > 0);
|
|
180
269
|
const [scannerOpen, setScannerOpen] = useState(false);
|
|
270
|
+
// The search row is shorter than a control's band at Compact: under a coarse pointer it is the band's height.
|
|
271
|
+
const band = useMinTarget();
|
|
272
|
+
const coarse = usePointer() === 'coarse';
|
|
273
|
+
const window = useWindowDimensions();
|
|
274
|
+
const phone = window.width < WIDE_MIN_WIDTH || window.height < WIDE_MIN_HEIGHT;
|
|
181
275
|
// The chooser is live (medusapos ADR 0007): it holds only the chosen product's id and derives its choices
|
|
182
276
|
// from the current entries below, so an open chooser shows each reconcile pass as it lands.
|
|
183
277
|
const [chooserId, setChooserId] = useState<string | null>(null);
|
|
278
|
+
// The product ids whose table rows are expanded (local, never saved).
|
|
279
|
+
const [expandedIds, setExpandedIds] = useState<ReadonlySet<string>>(() => new Set());
|
|
184
280
|
const [width, setWidth] = useState(0);
|
|
281
|
+
const [loadingHeight, setLoadingHeight] = useState(0);
|
|
185
282
|
const columns = resolveGridColumns(state.gridColumns, width);
|
|
186
283
|
const entries = useMemo(() => catalogueEntries(shown, traits, { currency }), [shown, traits, currency]);
|
|
187
|
-
//
|
|
284
|
+
// Entries per product id: the drill stacks a tile that selectProduct would drill into (v2 product-tile.tsx:54,76).
|
|
285
|
+
const entryCounts = useMemo(() => {
|
|
286
|
+
const counts = new Map<string, number>();
|
|
287
|
+
for (const entry of entries) counts.set(traits.getId(entry.product), (counts.get(traits.getId(entry.product)) ?? 0) + 1);
|
|
288
|
+
return counts;
|
|
289
|
+
}, [entries, traits]);
|
|
290
|
+
// v2's In Stock pill drops backorders unless inStockKeepsBackorder is set; a stock the backend did not report stays.
|
|
188
291
|
const stockFiltered = showFilterBar && filters.inStock;
|
|
292
|
+
// The term pills: local picks (group id to term id), never saved or reported. A pick whose term no drawn group still
|
|
293
|
+
// holds is not applied but kept, and applies again when the term returns, as a stored category does.
|
|
294
|
+
const [termPicks, setTermPicks] = useState<Readonly<Record<string, string>>>({});
|
|
295
|
+
const allTermGroups = useMemo(() => (showFilterBar && termPills && items === undefined ? listTermGroups(shown, traits) : []),
|
|
296
|
+
[showFilterBar, termPills, items, shown, traits]);
|
|
297
|
+
const termGroups = useMemo(() => (termPills === true ? allTermGroups
|
|
298
|
+
: termPills ? termPills.flatMap((id) => allTermGroups.filter((group) => group.id === id)) : []), [allTermGroups, termPills]);
|
|
299
|
+
const activeTerms = useMemo(() => termGroups
|
|
300
|
+
.filter((group) => group.terms.some((term) => term.id === termPicks[group.id]))
|
|
301
|
+
.map((group) => [group.id, termPicks[group.id]] as const), [termGroups, termPicks]);
|
|
302
|
+
function pickTerm(group: string, term: string | undefined) {
|
|
303
|
+
setTermPicks((current) => {
|
|
304
|
+
const next = { ...current };
|
|
305
|
+
if (term === undefined) delete next[group]; else next[group] = term;
|
|
306
|
+
return next;
|
|
307
|
+
});
|
|
308
|
+
}
|
|
189
309
|
const results = useMemo(() => {
|
|
190
310
|
if (items !== undefined) return suppliedItems;
|
|
191
311
|
const matched = searchProducts(activeCategory
|
|
192
312
|
? shown.filter((doc) => inCategory(doc, activeCategory.id, traits)) : shown, query, traits);
|
|
193
|
-
const
|
|
194
|
-
? matched.filter((doc) => !['out_of_stock', 'backorder'].includes(traits.getStock(doc).status)) : matched;
|
|
313
|
+
const stocked = stockFiltered
|
|
314
|
+
? matched.filter((doc) => !(inStockKeepsBackorder ? ['out_of_stock'] : ['out_of_stock', 'backorder']).includes(traits.getStock(doc).status)) : matched;
|
|
315
|
+
const filtered = activeTerms.length > 0
|
|
316
|
+
? stocked.filter((doc) => activeTerms.every(([group, term]) => hasTerm(doc, group, term, traits))) : stocked;
|
|
195
317
|
return state.sort ? sortProducts(filtered, state.sort, (doc, field) => productSortValue(doc, field, traits, { currency })) : filtered;
|
|
196
|
-
}, [items, suppliedItems, shown, query, traits, state.sort, currency, showCategoryNav, activeCategory, stockFiltered]);
|
|
318
|
+
}, [items, suppliedItems, shown, query, traits, state.sort, currency, showCategoryNav, activeCategory, stockFiltered, inStockKeepsBackorder, activeTerms]);
|
|
197
319
|
const choices = useMemo(() => (chooserId === null ? []
|
|
198
320
|
: entries.filter((entry) => traits.getId(entry.product) === chooserId)), [entries, chooserId, traits]);
|
|
199
321
|
// A product that leaves the catalogue (a resync, or no longer sellable) closes its chooser.
|
|
200
322
|
useEffect(() => { if (chooserId !== null && choices.length === 0) setChooserId(null); }, [chooserId, choices]);
|
|
323
|
+
// The drill ('drill' style, grid view) is live like the chooser: the product's id, its tiles from the current entries.
|
|
324
|
+
const [drillId, setDrillId] = useState<string | null>(null);
|
|
325
|
+
const drillEntries = useMemo(() => (drillId === null ? []
|
|
326
|
+
: entries.filter((entry) => traits.getId(entry.product) === drillId)), [entries, drillId, traits]);
|
|
327
|
+
// A product that leaves the catalogue leaves its drill; so do a new search, a category change and the table view.
|
|
328
|
+
useEffect(() => { if (drillId !== null && drillEntries.length === 0) setDrillId(null); }, [drillId, drillEntries]);
|
|
329
|
+
useEffect(() => { setDrillId(null); }, [query, activeCategory?.id, state.view]);
|
|
330
|
+
// The variant's option values in the product's group order, then any other options; the title when it has none.
|
|
331
|
+
function chipsOf(entry: CatalogueEntry<Doc>) {
|
|
332
|
+
const options = entry.variant.options ?? {};
|
|
333
|
+
const names = (traits.getVariantOptions?.(entry.product) ?? []).map(({ name }) => name)
|
|
334
|
+
.filter((name) => Object.prototype.hasOwnProperty.call(options, name));
|
|
335
|
+
const chips = [...names, ...Object.keys(options).filter((name) => !names.includes(name))].map((name) => options[name]);
|
|
336
|
+
return chips.length > 0 ? chips : [entry.variant.title ?? traits.getName(entry.product)];
|
|
337
|
+
}
|
|
201
338
|
|
|
202
339
|
// The picker step (#495): the entry waiting for its "Any" picks, and the cashier's picks so far.
|
|
203
340
|
const [pickEntry, setPickEntry] = useState<CatalogueEntry<Doc> | null>(null);
|
|
@@ -232,7 +369,28 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
232
369
|
function selectProduct(product: Doc) {
|
|
233
370
|
const variants = entries.filter((entry) => traits.getId(entry.product) === traits.getId(product));
|
|
234
371
|
if (variants.length === 1) select(variants[0]);
|
|
235
|
-
else
|
|
372
|
+
else if (variationsStyle === 'drill' && state.view !== 'table' && variants.length > 1) {
|
|
373
|
+
closePicker(); setChooserId(null); setDrillId(traits.getId(product));
|
|
374
|
+
} else { closePicker(); setChooserId(traits.getId(product)); }
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function variantRows(product: Doc) {
|
|
378
|
+
const variants = entries.filter((entry) => traits.getId(entry.product) === traits.getId(product));
|
|
379
|
+
if (variants.length === 0) return <Text className="px-3 py-1.5 text-sm text-muted-foreground">No variants to show.</Text>;
|
|
380
|
+
return variants.map((entry) => (
|
|
381
|
+
<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
|
+
<View testID={`variation-row-${entry.variant.id}-chips`} className="min-w-0 flex-1 flex-row flex-wrap gap-1">
|
|
383
|
+
{chipsOf(entry).map((chip, index) => <Text key={index} className="rounded bg-foreground/12 px-1.5 text-xs font-bold text-foreground">{chip}</Text>)}
|
|
384
|
+
</View>
|
|
385
|
+
<Text className="text-sm text-foreground">{variantPriceLabel(entry.variant, currency) ?? '—'}</Text>
|
|
386
|
+
<Text className="text-xs text-muted-foreground">{STOCK_STATUS_LABELS[entry.variant.stock.status] ?? STOCK_STATUS_LABELS.unknown}</Text>
|
|
387
|
+
<View style={{ width: VARIANT_ADD_WIDTH }} className="flex-none items-center">
|
|
388
|
+
<IconButton testID={`variation-row-add-${entry.variant.id}`} accessibilityLabel="Add to cart" onPress={() => select(entry)}>
|
|
389
|
+
<View className="text-muted-foreground"><PlusIcon size={18} /></View>
|
|
390
|
+
</IconButton>
|
|
391
|
+
</View>
|
|
392
|
+
</View>
|
|
393
|
+
));
|
|
236
394
|
}
|
|
237
395
|
|
|
238
396
|
// The variations popover (#719): the one open popover's product id, and each product's current entries in order.
|
|
@@ -268,13 +426,36 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
268
426
|
setPopoverId(null);
|
|
269
427
|
}
|
|
270
428
|
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
429
|
+
const emptyText = query.trim() ? `No products match "${query.trim()}".` : activeCategory ? `No products in ${activeCategory.name}.`
|
|
430
|
+
: activeTerms.length > 0 && items === undefined ? 'No products match the picked filters.'
|
|
431
|
+
: stockFiltered && items === undefined && shown.length > 0 ? 'No products in stock.'
|
|
432
|
+
: isLoading ? 'Loading products…' : 'No products yet.';
|
|
433
|
+
// Where the text would say "Loading products…", v2 holds the screen in the shape of what is coming; the words stay
|
|
434
|
+
// as the accessible label.
|
|
435
|
+
const showLoading = emptyText === 'Loading products…';
|
|
436
|
+
const emptyState = showLoading && state.view !== 'table' ? (
|
|
437
|
+
<View accessibilityLabel="Loading products…" aria-busy testID="catalogue-loading" className="flex-1 overflow-hidden p-1"
|
|
438
|
+
onLayout={(event) => setLoadingHeight(event.nativeEvent.layout.height)}>
|
|
439
|
+
{Array.from({ length: skeletonCount(loadingHeight, tileRow(fields)) }, (_, row) => (
|
|
440
|
+
<View key={row} className="flex-row">
|
|
441
|
+
{Array.from({ length: columns }, (_, column) => (
|
|
442
|
+
<View key={column} style={{ width: `${100 / columns}%` }} className="p-1">
|
|
443
|
+
<View testID="catalogue-loading-tile" aria-busy className="items-center rounded-lg border border-transparent bg-muted p-3">
|
|
444
|
+
<View style={{ width: TILE_IMAGE, height: TILE_IMAGE }} />
|
|
445
|
+
<View testID="catalogue-loading-band" style={{ height: tileBand(fields) }} />
|
|
446
|
+
</View>
|
|
447
|
+
</View>
|
|
448
|
+
))}
|
|
449
|
+
</View>
|
|
450
|
+
))}
|
|
451
|
+
</View>
|
|
452
|
+
) : <Text className="mt-10 text-center text-sm text-muted-foreground">{emptyText}</Text>;
|
|
276
453
|
|
|
277
|
-
const searchInput = <SearchInput value={query} onChangeText={(text) => {
|
|
454
|
+
const searchInput = <SearchInput value={query} onChangeText={(text) => {
|
|
455
|
+
// A search typed inside a level leaves it and spans every product (v2 browse/use-browse-path.ts:521-534).
|
|
456
|
+
if (browsing && level && text.trim() !== '') back();
|
|
457
|
+
setQuery(text); onQueryChange?.(text);
|
|
458
|
+
}} placeholder="Search or scan barcode / SKU" autoFocus
|
|
278
459
|
onSubmitEditing={() => {
|
|
279
460
|
if (minCodeLength && query.trim().length < minCodeLength) return;
|
|
280
461
|
const entry = findEntryByCode(entries, query);
|
|
@@ -284,24 +465,29 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
284
465
|
return (
|
|
285
466
|
<View className="flex-1" onLayout={(event) => setWidth(event.nativeEvent.layout.width)}>
|
|
286
467
|
<View className="gap-2 border-b border-border bg-card px-4 pb-3 pt-3">
|
|
287
|
-
{cameraScan && cameraScanner ? (
|
|
288
|
-
<View className="flex-row items-center gap-2">
|
|
289
|
-
<View className="flex-1">{searchInput}</View>
|
|
290
|
-
<CameraScanButton open={scannerOpen} onPress={() => setScannerOpen((open) => !open)} />
|
|
468
|
+
{(cameraScan && cameraScanner) || showViewToggle || draws(searchAccessory) ? (
|
|
469
|
+
<View testID="catalogue-search-row" className="flex-row items-center gap-2" style={coarse ? { minHeight: band } : undefined}>
|
|
470
|
+
<View className="min-w-0 flex-1 flex-row"><View testID="catalogue-search" className={cn('min-w-0 flex-1', !phone && 'max-w-160')}>{searchInput}</View></View>
|
|
471
|
+
{cameraScan && cameraScanner ? <CameraScanButton open={scannerOpen} onPress={() => setScannerOpen((open) => !open)} /> : null}
|
|
472
|
+
{showViewToggle ? <ViewToggle variant="icon" className="self-center" value={state.view} onChange={(view) => changeState({ type: 'setView', view })} /> : null}
|
|
473
|
+
{draws(searchAccessory) ? searchAccessory : null}
|
|
291
474
|
</View>
|
|
292
475
|
) : searchInput}
|
|
293
|
-
{showFilterBar ? <ProductFilterBar value={filters} onChange={changeFilters} chips={filterChips}
|
|
476
|
+
{showFilterBar ? <ProductFilterBar value={filters} onChange={changeFilters} chips={filterChips}
|
|
477
|
+
termGroups={termGroups.length > 0 ? termGroups.map((group) => ({
|
|
478
|
+
id: group.id, label: group.name, options: group.terms.map((term) => ({ value: term.id, label: term.name })),
|
|
479
|
+
value: activeTerms.find(([id]) => id === group.id)?.[1], onChange: (term: string | undefined) => pickTerm(group.id, term),
|
|
480
|
+
})) : undefined} /> : null}
|
|
294
481
|
{cameraScan && cameraScanner && scannerOpen ?<CameraScannerPanel {...cameraScanner} onClose={() => setScannerOpen(false)} /> : null}
|
|
295
|
-
{(statusText || statusAccessory
|
|
482
|
+
{(statusText || statusAccessory) ? (
|
|
296
483
|
<View testID="catalogue-status-row" className="flex-row items-center gap-2">
|
|
297
484
|
{statusText ? <Text className="flex-1 text-xs text-muted-foreground" numberOfLines={statusAccessory ? 1 : undefined}>
|
|
298
485
|
{statusText}{query.trim() ? ` · ${results.length.toLocaleString()} matching` : ''}
|
|
299
486
|
</Text> : null}
|
|
300
487
|
{statusAccessory}
|
|
301
|
-
{showViewToggle ? <ViewToggle value={state.view} onChange={(view) => changeState({ type: 'setView', view })} /> : null}
|
|
302
488
|
</View>
|
|
303
489
|
) : null}
|
|
304
|
-
{showCategoryNav ? <CategoryNav categories={[{ id: '', name: 'All products' }, ...categoryList]}
|
|
490
|
+
{showCategoryNav && !browsing ? <CategoryNav categories={[{ id: '', name: 'All products' }, ...categoryList]}
|
|
305
491
|
selectedId={activeCategory?.id ?? ''}
|
|
306
492
|
onSelect={(id) => changeState({ type: 'setCategory', categoryId: id === '' ? null : id })} /> : null}
|
|
307
493
|
{pickEntry ? (
|
|
@@ -324,7 +510,7 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
324
510
|
<Text className="font-semibold text-foreground">{entry.variant.title}</Text>
|
|
325
511
|
<Text className="text-muted-foreground">{entry.variant.sku}</Text>
|
|
326
512
|
<Text className="text-foreground">{variantPriceLabel(entry.variant, currency)}</Text>
|
|
327
|
-
<Text className="text-muted-foreground">{
|
|
513
|
+
<Text className="text-muted-foreground">{STOCK_STATUS_LABELS[entry.variant.stock.status]} · {stockAsOf ? `as of ${formatStockSyncTime(stockAsOf, undefined, hour12)}` : 'not yet synced'}</Text>
|
|
328
514
|
</Pressable>
|
|
329
515
|
))}
|
|
330
516
|
<Pressable accessibilityRole="button" onPress={() => setChooserId(null)} className="rounded-md border border-border bg-card px-4 py-3">
|
|
@@ -333,26 +519,63 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
333
519
|
</View>
|
|
334
520
|
) : null}
|
|
335
521
|
</View>
|
|
522
|
+
{draws(rowsSlot) ? <View testID="catalogue-rows" className="gap-4 p-4">{rowsSlot}</View> : null}
|
|
523
|
+
{atRoot ? <CategoryBrowseGrid categories={categoryList} counts={counts} total={shown.length} columns={columns}
|
|
524
|
+
onOpen={(id) => { setCrumbFocus(true); if (id === null) setAllOpen(true); else changeState({ type: 'setCategory', categoryId: id }); }} /> : <LevelWrap level={!!level} onBack={back}>
|
|
525
|
+
{level && drillEntries.length === 0 ? <Breadcrumb testID="category-crumb" phone={phone} autoFocus={crumbFocus}
|
|
526
|
+
parents={[{ label: 'Categories', testID: 'category-crumb-root', onPress: back }]} here={activeCategory?.name ?? 'All products'} /> : null}
|
|
336
527
|
{state.view === 'table' ? (
|
|
337
528
|
<ProductTable items={results} sort={state.sort} onSortChange={(sort) => changeState({ type: 'setSort', sort })}
|
|
338
|
-
sortItems={false} onSelect={selectProduct} emptyState={emptyState}
|
|
339
|
-
|
|
529
|
+
sortItems={false} onSelect={selectProduct} emptyState={emptyState} loading={showLoading}
|
|
530
|
+
showThumbnail={tableRow?.thumbnail} showAddButton={tableRow?.addButton}
|
|
531
|
+
isExpanded={tableRow?.expand ? (doc) => expandedIds.has(traits.getId(doc)) : undefined}
|
|
532
|
+
onToggleExpand={tableRow?.expand ? (doc) => setExpandedIds((current) => {
|
|
533
|
+
const key = traits.getId(doc), next = new Set(current);
|
|
534
|
+
if (next.has(key)) next.delete(key); else next.add(key);
|
|
535
|
+
return next;
|
|
536
|
+
}) : undefined}
|
|
537
|
+
renderExpanded={tableRow?.expand ? variantRows : undefined}
|
|
538
|
+
cartQuantity={(doc) => quantities.get(traits.getId(doc)) ?? 0} />
|
|
539
|
+
) : drillEntries.length > 0 ? <LevelWrap level onBack={() => setDrillId(null)}>
|
|
540
|
+
{/* v2 drill-in.tsx:44-68: "Products › name" above the variant tiles; at phone width the Breadcrumb drops the separator. */}
|
|
541
|
+
<Breadcrumb testID="products-breadcrumb" phone={phone} autoFocus
|
|
542
|
+
parents={[{ label: 'Products', testID: 'products-breadcrumb-back', onPress: () => setDrillId(null) }]}
|
|
543
|
+
here={traits.getName(drillEntries[0].product)} />
|
|
544
|
+
<ProductGrid numColumns={columns} showUnsellable
|
|
545
|
+
items={[{ id: 'parent' }, ...drillEntries.map((entry) => ({ id: `variant-${entry.variant.id}`, entry }))]}
|
|
546
|
+
renderItem={({ entry }: { entry?: CatalogueEntry<Doc> }) => entry
|
|
547
|
+
? <VariantTile testID={`variation-tile-${entry.variant.id}`} name={traits.getName(entry.product)} chips={chipsOf(entry)}
|
|
548
|
+
price={variantPriceLabel(entry.variant, currency)} stockStatus={entry.variant.stock.status} onPress={() => select(entry)}
|
|
549
|
+
fields={fields} sku={entry.variant.sku} barcode={entry.variant.barcode}
|
|
550
|
+
inCart={variantQuantities.get(entry.variant.id) ?? 0} />
|
|
551
|
+
: <VariantParentTile doc={drillEntries[0].product} onPress={() => setDrillId(null)} />} />
|
|
552
|
+
</LevelWrap>
|
|
553
|
+
: <ProductGrid items={level && results.length > 0 ? [LEVEL_PARENT, ...results] : results} numColumns={columns}
|
|
340
554
|
renderItem={(product: Doc) => {
|
|
555
|
+
if (product === LEVEL_PARENT) return <CategoryTile testID="category-level-parent" back stacked accessibilityLabel={t('common.back')}
|
|
556
|
+
name={activeCategory?.name ?? 'All products'} imageUrl={activeCategory?.imageUrl}
|
|
557
|
+
mark={activeCategory ? 'folder' : 'all'} count={results.length} onPress={back} />;
|
|
341
558
|
const id = traits.getId(product);
|
|
342
559
|
const groups = variationsStyle === 'popover' ? popoverGroupsOf(product) : [];
|
|
560
|
+
const tileTestID = `product-tile-${traits.getName(product)}`;
|
|
561
|
+
const stacked = variationsStyle === 'drill' && (entryCounts.get(id) ?? 0) > 1;
|
|
343
562
|
// TallyUI's ProductCard has no children slot, so the tile is composed directly here
|
|
344
563
|
// (same structure/classes as ProductCard) to add the stock badge as a fourth child,
|
|
345
564
|
// inside the card and centred with the rest, rather than adding a slot to ProductCard (out of scope for TV6b).
|
|
346
565
|
const tile = (
|
|
347
|
-
<Pressable accessibilityRole="button" testID={
|
|
566
|
+
<Pressable accessibilityRole="button" testID={tileTestID}
|
|
567
|
+
// v2 product-tile.tsx:81: with the name off, the name stays the tile's label.
|
|
568
|
+
{...(fields.name ? {} : { accessibilityLabel: traits.getName(product) })}
|
|
348
569
|
onPress={groups.length > 0 ? () => { closePicker(); setChooserId(null); } : () => selectProduct(product)}>
|
|
570
|
+
{({ pressed }) => <>
|
|
571
|
+
{stacked ? <TileStack id={tileTestID} /> : null}
|
|
349
572
|
<VStack space="sm" className="items-center rounded-lg border border-border bg-card p-3">
|
|
350
573
|
<ProductImage doc={product} size={80} className="rounded-md" />
|
|
351
|
-
<
|
|
352
|
-
<ProductPrice doc={product} />
|
|
353
|
-
<ProductStockBadge doc={product} showAsOf={false} className="self-center" />
|
|
574
|
+
<TileWords doc={product} traits={traits} fields={fields} />
|
|
354
575
|
</VStack>
|
|
576
|
+
<PressVeil pressed={pressed} className="rounded-lg" />
|
|
355
577
|
<InCartBadge count={quantities.get(id) ?? 0} className="absolute right-2 top-2" testID={`in-cart-${id}`} />
|
|
578
|
+
</>}
|
|
356
579
|
</Pressable>
|
|
357
580
|
);
|
|
358
581
|
if (groups.length === 0) return tile;
|
|
@@ -374,6 +597,45 @@ export function Catalogue<Doc>({ products, traits, currency, onSelect, statusTex
|
|
|
374
597
|
);
|
|
375
598
|
}}
|
|
376
599
|
emptyState={emptyState} />}
|
|
600
|
+
</LevelWrap>}
|
|
377
601
|
</View>
|
|
378
602
|
);
|
|
379
603
|
}
|
|
604
|
+
|
|
605
|
+
// The words under a grid tile's image, as v2's tile-words.tsx: a field that is off is not drawn; the facts (SKU,
|
|
606
|
+
// barcode, categories) come after the price, each one line, only when on and set (tile-words.tsx:110-162).
|
|
607
|
+
function TileWords<Doc>({ doc, traits, fields }: { doc: Doc; traits: ProductTraits<Doc>; fields: TileFields }) {
|
|
608
|
+
const sku = traits.getSku(doc);
|
|
609
|
+
const facts = [
|
|
610
|
+
['sku', fields.sku && sku ? `SKU ${sku}` : ''],
|
|
611
|
+
['barcode', fields.barcode ? traits.getBarcode(doc) ?? '' : ''],
|
|
612
|
+
['categories', fields.categories ? traits.getCategoryNames(doc).join(', ') : ''],
|
|
613
|
+
].filter(([, text]) => text);
|
|
614
|
+
return <>
|
|
615
|
+
{fields.name ? <ProductTitle doc={doc} className="text-sm" numberOfLines={2} /> : null}
|
|
616
|
+
{fields.price ? <ProductPrice doc={doc} {...(fields.onSale ? {} : { showWas: false })} /> : null}
|
|
617
|
+
{facts.map(([key, text]) => <Text key={key} numberOfLines={1} className="text-center text-xs text-muted-foreground">{text}</Text>)}
|
|
618
|
+
{fields.stock ? <ProductStockBadge doc={doc} showAsOf={false} className="self-center" />
|
|
619
|
+
: fields.price ? <OutOfStockMark doc={doc} /> : null}
|
|
620
|
+
</>;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// With stock off, an out-of-stock product still says so while its price shows (v2 tile-words.tsx:66-71). Its own
|
|
624
|
+
// component so useProductStock runs only on this path, never on the default tile.
|
|
625
|
+
function OutOfStockMark({ doc }: { doc: unknown }) {
|
|
626
|
+
return useProductStock(doc).status === 'out_of_stock' ? <ProductStockBadge doc={doc} showAsOf={false} className="self-center" /> : null;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// An open category is a level: on web, Escape inside it goes back (v2 packages/core/src/screens/main/pos/products/
|
|
630
|
+
// level-back.tsx:37-49, the web part only). Outside a level the children render as before, with no wrapper.
|
|
631
|
+
function LevelWrap({ level, onBack, children }: { level: boolean; onBack: () => void; children: ReactNode }) {
|
|
632
|
+
if (!level) return <>{children}</>;
|
|
633
|
+
return (
|
|
634
|
+
// RN's View types lack onKeyDown; react-native-web passes it to the div (as open-sale-tabs.tsx does).
|
|
635
|
+
<View className="flex-1" {...(Platform.OS === 'web' ? {
|
|
636
|
+
onKeyDown: (event: { nativeEvent: { key: string }; stopPropagation: () => void }) => {
|
|
637
|
+
if (event.nativeEvent.key === 'Escape') { event.stopPropagation(); onBack(); }
|
|
638
|
+
},
|
|
639
|
+
} : {})}>{children}</View>
|
|
640
|
+
);
|
|
641
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ScrollView, Text, View } from 'react-native';
|
|
2
|
+
import type { ProductCategory } from '@tallyui/core';
|
|
3
|
+
import { CategoryTile } from '../product/category-tile';
|
|
4
|
+
|
|
5
|
+
export function CategoryBrowseGrid({ categories, counts, total, columns, onOpen }: {
|
|
6
|
+
categories: ProductCategory[]; counts: ReadonlyMap<string, number>; total: number; columns: number;
|
|
7
|
+
onOpen: (id: string | null) => void;
|
|
8
|
+
}) {
|
|
9
|
+
// v2 term-tree.ts hides a term with no products; the All tile always shows.
|
|
10
|
+
const shown = categories.filter((category) => (counts.get(category.id) ?? 0) > 0);
|
|
11
|
+
return (
|
|
12
|
+
<ScrollView testID="category-browse" className="flex-1" contentContainerClassName="flex-row flex-wrap p-2">
|
|
13
|
+
<View className="p-1" style={{ width: `${100 / columns}%` }}>
|
|
14
|
+
<CategoryTile testID="category-tile-all" name="All products" count={total} stacked mark="all" onPress={() => onOpen(null)} />
|
|
15
|
+
</View>
|
|
16
|
+
{shown.map((category) => (
|
|
17
|
+
<View key={category.id} className="p-1" style={{ width: `${100 / columns}%` }}>
|
|
18
|
+
<CategoryTile testID={`category-tile-${category.id}`} name={category.name} imageUrl={category.imageUrl}
|
|
19
|
+
count={counts.get(category.id) ?? 0} stacked mark="folder" onPress={() => onOpen(category.id)} />
|
|
20
|
+
</View>
|
|
21
|
+
))}
|
|
22
|
+
<Text testID="category-browse-footer" className="w-full px-2 py-3 text-center text-sm text-muted-foreground">
|
|
23
|
+
{`${shown.length === 1 ? '1 category' : `${shown.length} categories`} · ${total === 1 ? '1 product' : `${total} products`}`}
|
|
24
|
+
</Text>
|
|
25
|
+
</ScrollView>
|
|
26
|
+
);
|
|
27
|
+
}
|