@tallyui/components 3.13.0 → 3.14.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 +275 -27
- package/dist/index.js +1985 -1226
- package/package.json +9 -9
- package/src/cart/cart-columns.tsx +57 -0
- package/src/cart/cart-line.tsx +32 -17
- package/src/cart/index.ts +1 -0
- package/src/checkout/cash-tendered.tsx +5 -7
- package/src/index.ts +18 -2
- package/src/lib/error-text.ts +5 -0
- package/src/order/refund-form.tsx +2 -1
- package/src/product/category-tile.tsx +43 -0
- package/src/product/in-cart-badge.tsx +26 -0
- package/src/product/index.ts +2 -0
- package/src/register/closure-sheet.tsx +2 -1
- package/src/register/handover-slip.tsx +46 -0
- package/src/register/index.ts +2 -0
- package/src/register/movement-sheet.tsx +2 -1
- package/src/register/open-register-card.tsx +2 -1
- package/src/register/register-bar.tsx +57 -11
- package/src/register/register-column.tsx +2 -1
- package/src/register/register-count.tsx +30 -11
- package/src/register/register-panel.tsx +45 -4
- package/src/register/switch-confirm.tsx +102 -0
- package/src/sale/cart.tsx +37 -21
- package/src/sale/catalogue.tsx +34 -5
- package/src/sale/customer-display-screen.tsx +92 -0
- package/src/sale/index.ts +4 -2
- package/src/sale/parked-sales.tsx +2 -1
- package/src/sale/price-form.tsx +28 -4
- package/src/sale/product-filter-bar.tsx +58 -0
- package/src/sale/tender-pane.tsx +179 -0
- package/src/sale/tender.tsx +20 -35
- package/src/shell/app-shell.tsx +71 -0
- package/src/shell/index.ts +4 -0
- package/src/shell/nav-drawer.tsx +130 -0
- package/src/shell/nav-item.tsx +70 -0
- package/src/shell/nav-rail.tsx +58 -0
- package/src/shell/shell-context.ts +18 -0
- package/src/ui/icon/menu-icon.tsx +10 -0
- package/src/sale/split-tender.tsx +0 -81
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tallyui/components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Universal POS UI components for Tally UI",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,22 +28,22 @@
|
|
|
28
28
|
"directory": "packages/components"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@tallyui/core": "^3.
|
|
32
|
-
"@tallyui/primitives": "^3.
|
|
33
|
-
"@tallyui/theme": "^3.
|
|
31
|
+
"@tallyui/core": "^3.14.0",
|
|
32
|
+
"@tallyui/primitives": "^3.14.0",
|
|
33
|
+
"@tallyui/theme": "^3.14.0",
|
|
34
34
|
"react": ">=18",
|
|
35
35
|
"react-native": ">=0.74",
|
|
36
36
|
"react-native-svg": ">=15"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"class-variance-authority": "^0.7.1",
|
|
40
|
-
"@tallyui/pos": "3.
|
|
40
|
+
"@tallyui/pos": "3.14.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@tallyui/connector-medusa": "3.
|
|
44
|
-
"@tallyui/connector-vendure": "3.
|
|
45
|
-
"@tallyui/connector-woocommerce": "3.
|
|
46
|
-
"@tallyui/mock-api": "3.
|
|
43
|
+
"@tallyui/connector-medusa": "3.14.0",
|
|
44
|
+
"@tallyui/connector-vendure": "3.14.0",
|
|
45
|
+
"@tallyui/connector-woocommerce": "3.14.0",
|
|
46
|
+
"@tallyui/mock-api": "3.14.0",
|
|
47
47
|
"@types/react": ">=18",
|
|
48
48
|
"react": "^19.2.4",
|
|
49
49
|
"react-native-svg": "15.12.1",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Ported from WCPOS v2 packages/core/src/screens/main/pos/cart/table.tsx (AMOUNT_COLUMNS,
|
|
2
|
+
// PRICE_COLUMN_MIN_WIDTH, the header labels) and packages/components/src/lib/device.ts (the phone
|
|
3
|
+
// boundary), MIT, WCPOS.
|
|
4
|
+
import type { JSX } from 'react';
|
|
5
|
+
import { View, type ViewProps } from 'react-native';
|
|
6
|
+
import { cn } from '@tallyui/theme';
|
|
7
|
+
import { Text } from '../ui';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The cart's columns, head and cell. Item gives way: the amount columns hold a width and the name takes what is
|
|
11
|
+
* left, so a total never wraps. The total cell has a floor, so a long total widens its own cell rather than wrapping.
|
|
12
|
+
*/
|
|
13
|
+
export const CART_COLUMNS = {
|
|
14
|
+
quantity: { head: 'w-12 flex-none items-center pr-2 pl-3', cell: 'w-12 flex-none items-center pr-2 pl-3' },
|
|
15
|
+
name: { head: 'min-w-0 flex-1 px-3', cell: 'min-w-0 flex-1 px-3' },
|
|
16
|
+
price: { head: 'w-18 flex-none items-end px-2', cell: 'w-18 flex-none items-end px-2' },
|
|
17
|
+
total: { head: 'w-20 flex-none items-end pr-3 pl-2', cell: 'min-w-20 flex-none items-end pr-3 pl-2' },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Under this cart width the Price column folds away, so the item name keeps room to read. */
|
|
21
|
+
const PRICE_COLUMN_MIN_WIDTH = 300;
|
|
22
|
+
/** A window narrower or shorter than this is a phone, which has no Price column either. */
|
|
23
|
+
const WIDE_MIN_WIDTH = 768;
|
|
24
|
+
const WIDE_MIN_HEIGHT = 480;
|
|
25
|
+
|
|
26
|
+
/** Whether the Price column shows. An unmeasured cart (`cartWidth` undefined) counts as wide. */
|
|
27
|
+
export function cartShowsPrice({ cartWidth, windowWidth, windowHeight }:
|
|
28
|
+
{ cartWidth?: number; windowWidth: number; windowHeight: number }): boolean {
|
|
29
|
+
return (cartWidth ?? Infinity) >= PRICE_COLUMN_MIN_WIDTH && windowWidth >= WIDE_MIN_WIDTH && windowHeight >= WIDE_MIN_HEIGHT;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const HEADS = [['quantity', 'Qty'], ['name', 'Item'], ['price', 'Price'], ['total', 'Total']] as const;
|
|
33
|
+
|
|
34
|
+
export interface CartColumnHeadsProps extends Omit<ViewProps, 'children'> {
|
|
35
|
+
/** Show the Price head (default true); pass the same value as each CartLine's `showPrice`. */
|
|
36
|
+
showPrice?: boolean;
|
|
37
|
+
className?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The cart's header row, Qty, Item, Price and Total, over lines laid out by CartLine in the same columns.
|
|
42
|
+
*
|
|
43
|
+
* ```tsx
|
|
44
|
+
* <CartColumnHeads showPrice={showPrice} />
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function CartColumnHeads({ showPrice = true, className, ...props }: CartColumnHeadsProps): JSX.Element {
|
|
48
|
+
return (
|
|
49
|
+
<View role="row" className={cn('flex-row border-b border-border', className)} {...props}>
|
|
50
|
+
{HEADS.filter(([id]) => showPrice || id !== 'price').map(([id, label]) => (
|
|
51
|
+
<View key={id} role="columnheader" className={cn('h-9 justify-center', CART_COLUMNS[id].head)}>
|
|
52
|
+
<Text className="text-xs font-medium uppercase tracking-wide text-muted-foreground" numberOfLines={1}>{label}</Text>
|
|
53
|
+
</View>
|
|
54
|
+
))}
|
|
55
|
+
</View>
|
|
56
|
+
);
|
|
57
|
+
}
|
package/src/cart/cart-line.tsx
CHANGED
|
@@ -1,40 +1,55 @@
|
|
|
1
|
+
import { View } from 'react-native';
|
|
1
2
|
import { formatMoney, type Money } from '@tallyui/core';
|
|
2
3
|
import { cn } from '@tallyui/theme';
|
|
3
|
-
import { Text, HStack,
|
|
4
|
+
import { Text, HStack, type HStackProps } from '../ui';
|
|
5
|
+
import { CART_COLUMNS } from './cart-columns';
|
|
4
6
|
|
|
5
7
|
export interface CartLineProps extends Omit<HStackProps, 'children'> {
|
|
6
8
|
name: string;
|
|
7
|
-
/** The variant's chosen options, one "Name: Value"
|
|
9
|
+
/** The variant's chosen options, shown as one "Name: Value · Name: Value" line under the name. */
|
|
8
10
|
attributes?: Record<string, string>;
|
|
9
11
|
quantity: number;
|
|
10
12
|
unitPrice: Money;
|
|
13
|
+
/** The regular unit price; shown struck through above unitPrice only when it is above unitPrice. */
|
|
14
|
+
regularUnitPrice?: Money;
|
|
11
15
|
lineTotal: Money;
|
|
16
|
+
/** Show the Price column (default true); the Cart passes false on a narrow cart or a phone, as CartColumnHeads does. */
|
|
17
|
+
showPrice?: boolean;
|
|
12
18
|
locale?: string;
|
|
13
19
|
className?: string;
|
|
14
20
|
}
|
|
15
21
|
|
|
22
|
+
// Name and attributes: WCPOS v2 packages/core/src/screens/main/pos/cart/cells/product-name.tsx; price:
|
|
23
|
+
// cells/price.tsx; total: cells/product-total.tsx; MIT, WCPOS.
|
|
16
24
|
/**
|
|
17
|
-
*
|
|
25
|
+
* A single cart line in the columns of CartColumnHeads: quantity, the name with its attributes, the unit price
|
|
26
|
+
* (with the regular price struck through when it is higher) and the line total.
|
|
18
27
|
*
|
|
19
28
|
* ```tsx
|
|
20
29
|
* <CartLine name="Coffee" quantity={2} unitPrice={unitPrice} lineTotal={lineTotal} />
|
|
21
30
|
* ```
|
|
22
31
|
*/
|
|
23
|
-
export function CartLine({ name, attributes, quantity, unitPrice, lineTotal, locale, className, ...props }: CartLineProps) {
|
|
32
|
+
export function CartLine({ name, attributes, quantity, unitPrice, regularUnitPrice, lineTotal, showPrice = true, locale, className, ...props }: CartLineProps) {
|
|
33
|
+
const options = Object.entries(attributes ?? {}).map(([key, value]) => `${key}: ${value}`).join(' · ');
|
|
34
|
+
const regular = regularUnitPrice && regularUnitPrice.currency === unitPrice.currency && regularUnitPrice.amount > unitPrice.amount
|
|
35
|
+
? formatMoney(regularUnitPrice, locale) ?? '—' : null;
|
|
24
36
|
return (
|
|
25
|
-
<HStack className={cn('
|
|
26
|
-
<
|
|
27
|
-
<Text className="text-sm
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
<Text className="text-xs text-muted-foreground">
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{formatMoney(
|
|
37
|
-
</
|
|
37
|
+
<HStack space="none" className={cn('py-2.5', className)} {...props}>
|
|
38
|
+
<View className={CART_COLUMNS.quantity.cell}>
|
|
39
|
+
<Text className="text-sm tabular-nums">{quantity}</Text>
|
|
40
|
+
</View>
|
|
41
|
+
<View className={CART_COLUMNS.name.cell}>
|
|
42
|
+
<Text className="text-sm font-medium" numberOfLines={2}>{name}</Text>
|
|
43
|
+
{options ? <Text className="text-xs text-muted-foreground" numberOfLines={2}>{options}</Text> : null}
|
|
44
|
+
</View>
|
|
45
|
+
{showPrice ? <View className={CART_COLUMNS.price.cell}>
|
|
46
|
+
{regular ? <Text accessibilityLabel={`Regular price ${regular}`} style={{ textDecorationLine: 'line-through' }}
|
|
47
|
+
className="text-right text-sm tabular-nums text-muted-foreground line-through">{regular}</Text> : null}
|
|
48
|
+
<Text className="text-right text-sm tabular-nums text-muted-foreground">{formatMoney(unitPrice, locale) ?? '—'}</Text>
|
|
49
|
+
</View> : null}
|
|
50
|
+
<View className={CART_COLUMNS.total.cell}>
|
|
51
|
+
<Text className="text-right text-sm font-semibold tabular-nums">{formatMoney(lineTotal, locale) ?? '—'}</Text>
|
|
52
|
+
</View>
|
|
38
53
|
</HStack>
|
|
39
54
|
);
|
|
40
55
|
}
|
package/src/cart/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { CartLine, type CartLineProps } from './cart-line';
|
|
2
|
+
export { CartColumnHeads, type CartColumnHeadsProps } from './cart-columns';
|
|
2
3
|
export { CartTotal, type CartTotalProps } from './cart-total';
|
|
3
4
|
export { CartPanel, type CartPanelProps } from './cart-panel';
|
|
4
5
|
export { DiscountBadge, type DiscountBadgeProps } from './discount-badge';
|
|
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
2
2
|
import { Pressable, Text, TextInput, View, type ViewProps } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import { formatMoney, minorUnitDigits, moneyFromDecimalString, type Money } from '@tallyui/core';
|
|
5
|
+
import { quickTenderedAmounts } from '@tallyui/pos';
|
|
5
6
|
import { cn } from '@tallyui/theme';
|
|
6
7
|
|
|
7
8
|
export interface CashTenderedProps extends Omit<ViewProps, 'children'> {
|
|
@@ -14,15 +15,12 @@ export interface CashTenderedProps extends Omit<ViewProps, 'children'> {
|
|
|
14
15
|
className?: string;
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
/** Quick-cash round-ups in major units: WCPOS v2 tender-figures.ts:25 QUICK_TENDER_STEPS. */
|
|
19
|
+
export const QUICK_CASH_STEPS = [5, 10, 50] as const;
|
|
20
|
+
|
|
17
21
|
function defaultQuickAmounts(total: Money): Money[] {
|
|
18
22
|
const unit = 10 ** minorUnitDigits(total.currency);
|
|
19
|
-
|
|
20
|
-
total.amount,
|
|
21
|
-
Math.ceil(total.amount / (5 * unit)) * 5 * unit,
|
|
22
|
-
Math.ceil(total.amount / (10 * unit)) * 10 * unit,
|
|
23
|
-
Math.ceil(total.amount / (20 * unit)) * 20 * unit,
|
|
24
|
-
];
|
|
25
|
-
return [...new Set(amounts)].sort((a, b) => a - b).map((amount) => ({ amount, currency: total.currency }));
|
|
23
|
+
return quickTenderedAmounts(total.amount, QUICK_CASH_STEPS.map((step) => step * unit)).map((amount) => ({ amount, currency: total.currency }));
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
export function CashTendered({
|
package/src/index.ts
CHANGED
|
@@ -40,6 +40,10 @@ export {
|
|
|
40
40
|
ProductVariantPicker,
|
|
41
41
|
type ProductVariantPickerProps,
|
|
42
42
|
type VariantOption,
|
|
43
|
+
InCartBadge,
|
|
44
|
+
type InCartBadgeProps,
|
|
45
|
+
CategoryTile,
|
|
46
|
+
type CategoryTileProps,
|
|
43
47
|
} from './product';
|
|
44
48
|
|
|
45
49
|
// Cart components
|
|
@@ -57,6 +61,8 @@ export {
|
|
|
57
61
|
CartLineActions,
|
|
58
62
|
type CartLineActionsProps,
|
|
59
63
|
type CartAction,
|
|
64
|
+
CartColumnHeads,
|
|
65
|
+
type CartColumnHeadsProps,
|
|
60
66
|
} from './cart';
|
|
61
67
|
|
|
62
68
|
// Input components
|
|
@@ -157,6 +163,10 @@ export {
|
|
|
157
163
|
type RegisterCountProps,
|
|
158
164
|
ClosureSheet,
|
|
159
165
|
type ClosureSheetProps,
|
|
166
|
+
SwitchConfirm,
|
|
167
|
+
type SwitchConfirmProps,
|
|
168
|
+
HandoverSlip,
|
|
169
|
+
type HandoverSlipProps,
|
|
160
170
|
} from './register';
|
|
161
171
|
|
|
162
172
|
// Settings components
|
|
@@ -174,11 +184,12 @@ export {
|
|
|
174
184
|
|
|
175
185
|
// Sale components
|
|
176
186
|
export {
|
|
177
|
-
Cart, CartBar, Tender, SplitTender, DiscountForm, DiscountChips, parseDiscount, discountLabel,
|
|
187
|
+
Cart, CartBar, Tender, SplitTender, TenderPane, type TenderPaneProps, DiscountForm, DiscountChips, parseDiscount, discountLabel,
|
|
178
188
|
PriceForm, parsePrice,
|
|
179
189
|
ChargeForm, type ChargeFormProps,
|
|
180
190
|
Catalogue, formatStockSyncTime, Receipt, injectPrintStyle, SyncStatus, OrdersList, type OrderHistoryRow, orderReference,
|
|
181
|
-
ParkedSales, type ParkedSalesProps, OpenSaleTabs, type OpenSaleTabsProps,
|
|
191
|
+
ParkedSales, type ParkedSalesProps, OpenSaleTabs, type OpenSaleTabsProps, CustomerDisplayScreen,
|
|
192
|
+
ProductFilterBar, DEFAULT_PRODUCT_FILTERS, PRODUCT_FILTER_CHIPS, type ProductFilterBarProps, type ProductFilterChip, type ProductFilters,
|
|
182
193
|
} from './sale';
|
|
183
194
|
|
|
184
195
|
// Layout components
|
|
@@ -196,6 +207,11 @@ export {
|
|
|
196
207
|
type StoreSettingsChoiceScreenProps,
|
|
197
208
|
} from './layout';
|
|
198
209
|
|
|
210
|
+
// App shell
|
|
211
|
+
export {
|
|
212
|
+
AppShell, type AppShellProps, NavRail, type NavRailProps, NavDrawer, type NavDrawerProps, type ShellNavItem,
|
|
213
|
+
} from './shell';
|
|
214
|
+
|
|
199
215
|
// Reports components
|
|
200
216
|
export {
|
|
201
217
|
SalesRoom, type SalesRoomProps, SalesHero, type SalesHeroProps, SalesCards, type SalesCardsProps, type SalesCardId,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** What a cashier sees for a thrown value: an `Error`'s message alone (never its class name, which `String(e)` prefixes), "Something went wrong" when that is empty. A non-`Error` is shown as `String(value)`. */
|
|
2
|
+
export function errorText(error: unknown): string {
|
|
3
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
4
|
+
return text || 'Something went wrong';
|
|
5
|
+
}
|
|
@@ -3,6 +3,7 @@ import { Pressable, ScrollView, View } from 'react-native';
|
|
|
3
3
|
import { formatMoney, type OrderRefundPayload } from '@tallyui/core';
|
|
4
4
|
import { priceRefund, refundableLines, type EarlierRefund, type RefundableOrderLine } from '@tallyui/pos';
|
|
5
5
|
import { QuantityStepper } from '../input/quantity-stepper';
|
|
6
|
+
import { errorText } from '../lib/error-text';
|
|
6
7
|
import { parsePrice } from '../sale/price-form';
|
|
7
8
|
import { Button } from '../ui/button';
|
|
8
9
|
import { Checkbox } from '../ui/checkbox';
|
|
@@ -103,7 +104,7 @@ export function RefundForm({
|
|
|
103
104
|
try {
|
|
104
105
|
await onConfirm(value);
|
|
105
106
|
} catch (e) {
|
|
106
|
-
setThrown(
|
|
107
|
+
setThrown(errorText(e));
|
|
107
108
|
} finally {
|
|
108
109
|
busyRef.current = false;
|
|
109
110
|
setBusy(false);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Pressable, Text, View } from 'react-native';
|
|
2
|
+
import { Image } from '@tallyui/primitives';
|
|
3
|
+
import { cn } from '@tallyui/theme';
|
|
4
|
+
|
|
5
|
+
export interface CategoryTileProps {
|
|
6
|
+
name: string;
|
|
7
|
+
/** The category's photo; without one the tile shows the name's initial on a tint. */
|
|
8
|
+
imageUrl?: string;
|
|
9
|
+
/** Products in the category, shown under the name when above 0. */
|
|
10
|
+
count?: number;
|
|
11
|
+
onPress?: () => void;
|
|
12
|
+
testID?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A category as a square tile: its photo full-bleed with the name over the foot, or the name's initial on a
|
|
18
|
+
* tint when there is no photo.
|
|
19
|
+
*
|
|
20
|
+
* Ported from WCPOS v2 `TermTile`, packages/core/src/screens/main/pos/products/browse/term-tile.tsx
|
|
21
|
+
* (MIT, WCPOS): the picture fills the square (`contentFit="cover"`), else a tint; the name bold over two
|
|
22
|
+
* lines with the count under it.
|
|
23
|
+
*/
|
|
24
|
+
export function CategoryTile({ name, imageUrl, count, onPress, testID, className }: CategoryTileProps) {
|
|
25
|
+
const id = testID ?? 'category-tile';
|
|
26
|
+
return (
|
|
27
|
+
<Pressable testID={testID} role="button" accessibilityLabel={name} onPress={onPress}
|
|
28
|
+
className={cn('aspect-square overflow-hidden rounded-lg border border-border', imageUrl ? 'bg-card' : 'bg-primary/10', className)}>
|
|
29
|
+
{imageUrl ? (
|
|
30
|
+
<Image.Root testID={`${id}-image`} source={{ uri: imageUrl }} alt="" contentFit="cover"
|
|
31
|
+
className="absolute inset-0" style={{ width: '100%', height: '100%' }} />
|
|
32
|
+
) : (
|
|
33
|
+
<View testID={`${id}-fallback`} className="absolute inset-0 items-center justify-center">
|
|
34
|
+
<Text className="text-3xl font-semibold text-primary">{name.trim().charAt(0).toUpperCase() || '?'}</Text>
|
|
35
|
+
</View>
|
|
36
|
+
)}
|
|
37
|
+
<View className={cn('absolute inset-x-0 bottom-0 px-2.5 py-2', imageUrl && 'bg-card/80')}>
|
|
38
|
+
<Text className="font-bold text-foreground" numberOfLines={2}>{name}</Text>
|
|
39
|
+
{count !== undefined && count > 0 ? <Text className="text-xs text-muted-foreground">{count === 1 ? '1 product' : `${count} products`}</Text> : null}
|
|
40
|
+
</View>
|
|
41
|
+
</Pressable>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Text, View } from 'react-native';
|
|
2
|
+
import { cn } from '@tallyui/theme';
|
|
3
|
+
|
|
4
|
+
export interface InCartBadgeProps {
|
|
5
|
+
/** How many of the product the cart holds (e.g. from `cartQuantities`); nothing renders at 0. */
|
|
6
|
+
count: number;
|
|
7
|
+
/** Placement, e.g. `absolute right-2 top-2` for a tile's top-right corner. */
|
|
8
|
+
className?: string;
|
|
9
|
+
testID?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* How many of a product are in the cart: a primary circle with the count, hidden while there are none.
|
|
14
|
+
*
|
|
15
|
+
* Ported from WCPOS v2 `InCartCount`, packages/core/src/screens/main/pos/products/rows/in-cart-count.tsx
|
|
16
|
+
* (MIT, WCPOS), without its count beat.
|
|
17
|
+
*/
|
|
18
|
+
export function InCartBadge({ count, className, testID }: InCartBadgeProps) {
|
|
19
|
+
if (count <= 0) return null;
|
|
20
|
+
return (
|
|
21
|
+
<View testID={testID} accessibilityLabel={`${count} in cart`}
|
|
22
|
+
className={cn('h-6 min-w-6 items-center justify-center rounded-full bg-primary px-1.5', className)}>
|
|
23
|
+
<Text className="text-xs font-semibold tabular-nums text-primary-foreground">{String(count)}</Text>
|
|
24
|
+
</View>
|
|
25
|
+
);
|
|
26
|
+
}
|
package/src/product/index.ts
CHANGED
|
@@ -10,3 +10,5 @@ export { ProductTable, defaultProductColumns, useDefaultProductColumns, type Pro
|
|
|
10
10
|
export { ProductList, type ProductListProps } from './product-list';
|
|
11
11
|
export { CategoryNav, type CategoryNavProps, type CategoryItem } from './category-nav';
|
|
12
12
|
export { ProductVariantPicker, type ProductVariantPickerProps, type VariantOption } from './product-variant-picker';
|
|
13
|
+
export { InCartBadge, type InCartBadgeProps } from './in-cart-badge';
|
|
14
|
+
export { CategoryTile, type CategoryTileProps } from './category-tile';
|
|
@@ -4,6 +4,7 @@ import type { useRegisterSession } from '@tallyui/pos';
|
|
|
4
4
|
import { countVariance, TAX_ROUNDING_MIXED_NOTE, varianceText } from '@tallyui/pos';
|
|
5
5
|
|
|
6
6
|
import { formatMoney, minorUnitDigits } from '@tallyui/core';
|
|
7
|
+
import { errorText } from '../lib/error-text';
|
|
7
8
|
import { Button } from '../ui/button';
|
|
8
9
|
import { Dialog, DialogContent, DialogTitle } from '../ui/dialog';
|
|
9
10
|
import { Text } from '../ui/text';
|
|
@@ -81,7 +82,7 @@ export function ClosureSheet({ register, currency, onPrint, onDone }: ClosureShe
|
|
|
81
82
|
try {
|
|
82
83
|
await onPrint();
|
|
83
84
|
} catch (e) {
|
|
84
|
-
setError(
|
|
85
|
+
setError(errorText(e));
|
|
85
86
|
} finally {
|
|
86
87
|
setBusy(false);
|
|
87
88
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { View } from 'react-native';
|
|
2
|
+
import type { HandoverSlipData } from '@tallyui/pos';
|
|
3
|
+
|
|
4
|
+
import { formatMoney } from '@tallyui/core';
|
|
5
|
+
import { Text } from '../ui/text';
|
|
6
|
+
import { tenderLabel } from './register-count';
|
|
7
|
+
import { countLine } from './switch-confirm';
|
|
8
|
+
|
|
9
|
+
export interface HandoverSlipProps {
|
|
10
|
+
/** `handoverSlip(...)`'s result; `document` is not read here (it is what prints). */
|
|
11
|
+
slip: Omit<HandoverSlipData, 'document'>;
|
|
12
|
+
/** ISO 4217 code, for the expected figures. */
|
|
13
|
+
currency: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The hand-over slip on screen: what a closing cashier hands the next one (v2's "Hand-over slip", the open session's
|
|
18
|
+
* X report naming the cashier; WCPOS v2 monorepo `main` 51e7c4351 `switch-confirm.tsx` and `use-session-report.ts`).
|
|
19
|
+
* No dialog: the host places it, for example in a print preview. No expected figures while blind.
|
|
20
|
+
*/
|
|
21
|
+
export function HandoverSlip({ slip, currency }: HandoverSlipProps) {
|
|
22
|
+
const register = [slip.registerName, slip.openedAtTime && `open since ${slip.openedAtTime}`, slip.openedByName]
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.join(' · ');
|
|
25
|
+
return (
|
|
26
|
+
<View testID="handover-slip" className="gap-2">
|
|
27
|
+
<Text testID="handover-slip-title" className="text-lg font-semibold">Hand-over slip</Text>
|
|
28
|
+
<Text testID="handover-slip-register" className="text-muted-foreground">{register}</Text>
|
|
29
|
+
<Text testID="handover-slip-cashier">{`Handed over by ${slip.cashierName}`}</Text>
|
|
30
|
+
<Text testID="handover-slip-sales">{countLine(slip.salesCount, 'sale', 'sales')}</Text>
|
|
31
|
+
{Object.entries(slip.expected ?? {}).map(([method, amount]) => (
|
|
32
|
+
<Text key={method} testID={`handover-slip-expected-${method}`} className="tabular-nums">
|
|
33
|
+
{`Expected ${tenderLabel(method)} ${formatMoney({ amount, currency })}`}
|
|
34
|
+
</Text>
|
|
35
|
+
))}
|
|
36
|
+
{slip.unsentSales > 0 && (
|
|
37
|
+
<Text testID="handover-slip-unsent-sales">{countLine(slip.unsentSales, 'unsent sale', 'unsent sales')}</Text>
|
|
38
|
+
)}
|
|
39
|
+
{slip.unsentTillUpdates > 0 && (
|
|
40
|
+
<Text testID="handover-slip-unsent-till-updates">
|
|
41
|
+
{countLine(slip.unsentTillUpdates, 'unsent till update', 'unsent till updates')}
|
|
42
|
+
</Text>
|
|
43
|
+
)}
|
|
44
|
+
</View>
|
|
45
|
+
);
|
|
46
|
+
}
|
package/src/register/index.ts
CHANGED
|
@@ -10,3 +10,5 @@ export { RegisterPanel, type RegisterPanelProps } from './register-panel';
|
|
|
10
10
|
export { RegisterColumn, type RegisterColumnProps } from './register-column';
|
|
11
11
|
export { RegisterCount, APPROVAL_REQUIRED_TEXT, type RegisterCountProps } from './register-count';
|
|
12
12
|
export { ClosureSheet, type ClosureSheetProps } from './closure-sheet';
|
|
13
|
+
export { SwitchConfirm, type SwitchConfirmProps } from './switch-confirm';
|
|
14
|
+
export { HandoverSlip, type HandoverSlipProps } from './handover-slip';
|
|
@@ -3,6 +3,7 @@ import type { MovementType, useRegisterSession } from '@tallyui/pos';
|
|
|
3
3
|
import { movementFieldError, normalizeAmount, parseMinor } from '@tallyui/pos';
|
|
4
4
|
|
|
5
5
|
import { currencySymbol, minorUnitDigits } from '@tallyui/core';
|
|
6
|
+
import { errorText } from '../lib/error-text';
|
|
6
7
|
import { Button } from '../ui/button';
|
|
7
8
|
import { Dialog, DialogContent, DialogTitle } from '../ui/dialog';
|
|
8
9
|
import { Input } from '../ui/input';
|
|
@@ -63,7 +64,7 @@ export function MovementSheet({ register, type, currency, onDone, onOpenChange,
|
|
|
63
64
|
if (type === 'no_sale') onOpenDrawer?.();
|
|
64
65
|
onOpenChange(false);
|
|
65
66
|
} catch (e) {
|
|
66
|
-
setError(
|
|
67
|
+
setError(errorText(e));
|
|
67
68
|
} finally {
|
|
68
69
|
busyRef.current = false;
|
|
69
70
|
setBusy(false);
|
|
@@ -5,6 +5,7 @@ import { parseMinor, validAmount } from '@tallyui/pos';
|
|
|
5
5
|
|
|
6
6
|
import { currencySymbol, formatMoney, minorUnitDigits } from '@tallyui/core';
|
|
7
7
|
import { cn } from '@tallyui/theme';
|
|
8
|
+
import { errorText } from '../lib/error-text';
|
|
8
9
|
import { Button } from '../ui/button';
|
|
9
10
|
import { Input } from '../ui/input';
|
|
10
11
|
import { Label } from '../ui/label';
|
|
@@ -48,7 +49,7 @@ export function OpenRegisterCard({ register, currency, configuredFloatMinor, cla
|
|
|
48
49
|
try {
|
|
49
50
|
await register.actions.openSession({ expectedFloatMinor, countedFloatMinor: countedMinor });
|
|
50
51
|
} catch (e) {
|
|
51
|
-
setError(
|
|
52
|
+
setError(errorText(e));
|
|
52
53
|
} finally {
|
|
53
54
|
setBusy(false);
|
|
54
55
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
1
2
|
import { Pressable, View } from 'react-native';
|
|
2
3
|
import type { useRegisterSession } from '@tallyui/pos';
|
|
3
4
|
|
|
4
5
|
import { cn } from '@tallyui/theme';
|
|
6
|
+
import { useShell } from '../shell/shell-context';
|
|
7
|
+
import { Avatar } from '../ui/avatar';
|
|
5
8
|
import { Badge } from '../ui/badge';
|
|
6
9
|
import { Button } from '../ui/button';
|
|
7
10
|
import { HStack } from '../ui/hstack';
|
|
11
|
+
import { IconButton } from '../ui/icon-button';
|
|
12
|
+
import { MenuIcon } from '../ui/icon/menu-icon';
|
|
8
13
|
import { Text } from '../ui/text';
|
|
9
14
|
import { describeRegisterBarPill } from './register-bar.helpers';
|
|
10
15
|
|
|
@@ -21,17 +26,30 @@ export interface RegisterBarProps {
|
|
|
21
26
|
onOpenPanel: () => void;
|
|
22
27
|
/** Turns the pill into a button (opens the gate/picker or the panel) when given; the plain badge otherwise. */
|
|
23
28
|
onPressPill?: () => void;
|
|
29
|
+
/** The store's name. With `multiRegister` and a bound register the bar reads "Store · Register". */
|
|
30
|
+
storeName?: string;
|
|
31
|
+
/** The signed-in cashier: an initials avatar, pressable when `onPress` is given. */
|
|
32
|
+
cashier?: { name: string; onPress?: () => void };
|
|
33
|
+
/** The app's sync state (a badge or a line), drawn before the cashier. */
|
|
34
|
+
syncStatus?: ReactNode;
|
|
35
|
+
/** Opens the navigation; inside a phone `AppShell` the shell supplies it. Hidden when neither. */
|
|
36
|
+
onOpenMenu?: () => void;
|
|
24
37
|
className?: string;
|
|
25
38
|
}
|
|
26
39
|
|
|
40
|
+
function initials(name: string): string {
|
|
41
|
+
return name.split(/\s+/).filter(Boolean).slice(0, 2).map((word) => word[0].toUpperCase()).join('');
|
|
42
|
+
}
|
|
43
|
+
|
|
27
44
|
/**
|
|
28
|
-
* The till's one status bar:
|
|
29
|
-
* (LEDGER 48),
|
|
30
|
-
* 1): WCPOS `next` `3b5331b5c`
|
|
45
|
+
* The till's one status bar: the menu (phones), the place (the store, and the register for
|
|
46
|
+
* multi-register stores), one status pill (LEDGER 48), the sync state, the button that opens the
|
|
47
|
+
* register panel, and the cashier. Port provenance (ADR-032 amendment 1): WCPOS `next` `3b5331b5c`
|
|
48
|
+
* `register-bar.tsx`; the menu, the place and the cashier from v2 `main` `51e7c4351`
|
|
49
|
+
* `packages/core/src/screens/main/pos/cart/register-bar.tsx` and `components/bar-controls`, MIT, WCPOS.
|
|
31
50
|
*
|
|
32
|
-
* Dropped for this neutral port: the user
|
|
33
|
-
* WooCommerce OAuth-return rehosting — all app/backend concerns `useRegisterSession` never
|
|
34
|
-
* carries. The drawer/menu button is gone too: TallyUI has no fixed navigation shell to open.
|
|
51
|
+
* Dropped for this neutral port: the user sheet, switch-store, the notification bell and the
|
|
52
|
+
* WooCommerce OAuth-return rehosting — all app/backend concerns `useRegisterSession` never carries.
|
|
35
53
|
*/
|
|
36
54
|
export function RegisterBar({
|
|
37
55
|
register,
|
|
@@ -41,9 +59,15 @@ export function RegisterBar({
|
|
|
41
59
|
multiRegister,
|
|
42
60
|
onOpenPanel,
|
|
43
61
|
onPressPill,
|
|
62
|
+
storeName,
|
|
63
|
+
cashier,
|
|
64
|
+
syncStatus,
|
|
65
|
+
onOpenMenu,
|
|
44
66
|
className,
|
|
45
67
|
}: RegisterBarProps) {
|
|
46
68
|
const { session, overdue, enabled, lastClosure, closing } = register;
|
|
69
|
+
const shell = useShell();
|
|
70
|
+
const openMenu = onOpenMenu ?? shell?.openMenu;
|
|
47
71
|
const pill = describeRegisterBarPill({
|
|
48
72
|
registerId,
|
|
49
73
|
online,
|
|
@@ -53,14 +77,24 @@ export function RegisterBar({
|
|
|
53
77
|
sessionsOn: enabled,
|
|
54
78
|
closing,
|
|
55
79
|
});
|
|
80
|
+
const named = multiRegister && registerId !== null && registerName ? registerName : '';
|
|
81
|
+
// Store · Register: the larger container first, as every v2 line that names both reads.
|
|
82
|
+
const place = storeName ? (named ? `${storeName} · ${named}` : storeName) : named;
|
|
56
83
|
return (
|
|
57
|
-
<HStack testID="register-bar" className={cn('bg-card border-border h-12 border-b px-
|
|
84
|
+
<HStack testID="register-bar" className={cn('bg-card border-border h-12 gap-2 border-b px-2', className)}>
|
|
85
|
+
{openMenu && (
|
|
86
|
+
<IconButton testID="register-bar-menu" accessibilityLabel="Open menu" onPress={openMenu}>
|
|
87
|
+
<View className="text-foreground">
|
|
88
|
+
<MenuIcon size={24} />
|
|
89
|
+
</View>
|
|
90
|
+
</IconButton>
|
|
91
|
+
)}
|
|
58
92
|
<View className="min-w-0 flex-1 shrink">
|
|
59
|
-
{
|
|
60
|
-
<Text testID="register-bar-name" numberOfLines={1}>
|
|
61
|
-
{
|
|
93
|
+
{place ? (
|
|
94
|
+
<Text testID="register-bar-name" className={storeName ? 'font-semibold' : undefined} numberOfLines={1}>
|
|
95
|
+
{place}
|
|
62
96
|
</Text>
|
|
63
|
-
)}
|
|
97
|
+
) : null}
|
|
64
98
|
</View>
|
|
65
99
|
{pill && (onPressPill ? (
|
|
66
100
|
<Pressable testID="register-bar-pill" accessibilityRole="button" accessibilityLabel={pill} onPress={onPressPill}>
|
|
@@ -69,6 +103,7 @@ export function RegisterBar({
|
|
|
69
103
|
) : (
|
|
70
104
|
<Badge testID="register-bar-pill" label={pill} variant="warning" />
|
|
71
105
|
))}
|
|
106
|
+
{syncStatus}
|
|
72
107
|
{(session || lastClosure) && (
|
|
73
108
|
<Button
|
|
74
109
|
variant="ghost"
|
|
@@ -80,6 +115,17 @@ export function RegisterBar({
|
|
|
80
115
|
<Text className={overdue ? 'text-warning' : undefined}>Register ›</Text>
|
|
81
116
|
</Button>
|
|
82
117
|
)}
|
|
118
|
+
{cashier && (
|
|
119
|
+
<Pressable
|
|
120
|
+
testID="register-bar-cashier"
|
|
121
|
+
accessibilityRole={cashier.onPress ? 'button' : undefined}
|
|
122
|
+
accessibilityLabel={`Cashier: ${cashier.name}`}
|
|
123
|
+
disabled={!cashier.onPress}
|
|
124
|
+
onPress={cashier.onPress}
|
|
125
|
+
>
|
|
126
|
+
<Avatar size="sm" fallback={initials(cashier.name)} />
|
|
127
|
+
</Pressable>
|
|
128
|
+
)}
|
|
83
129
|
</HStack>
|
|
84
130
|
);
|
|
85
131
|
}
|
|
@@ -2,6 +2,7 @@ import { useState, type ReactNode } from 'react';
|
|
|
2
2
|
import { View } from 'react-native';
|
|
3
3
|
import type { useRegisterSession } from '@tallyui/pos';
|
|
4
4
|
|
|
5
|
+
import { errorText } from '../lib/error-text';
|
|
5
6
|
import { Button } from '../ui/button';
|
|
6
7
|
import { Text } from '../ui/text';
|
|
7
8
|
import { OpenRegisterCard } from './open-register-card';
|
|
@@ -96,7 +97,7 @@ function FinishClose({ register, busy, setBusy }: { register: ReturnType<typeof
|
|
|
96
97
|
// ignored for a session already closed), and the approval gate doesn't run again.
|
|
97
98
|
await register.actions.closeSession({ counted: register.session?.counted ?? {} });
|
|
98
99
|
} catch (e) {
|
|
99
|
-
setError(
|
|
100
|
+
setError(errorText(e));
|
|
100
101
|
} finally {
|
|
101
102
|
setBusy(false);
|
|
102
103
|
}
|