@tallyui/components 3.12.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 +466 -28
- package/dist/index.js +3194 -1574
- 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/fonts/font-provider.tsx +65 -0
- package/src/fonts/index.ts +1 -0
- package/src/index.ts +40 -2
- package/src/lib/error-text.ts +5 -0
- package/src/order/index.ts +2 -0
- package/src/order/refund-form.tsx +205 -0
- package/src/order/refund-modal.tsx +32 -0
- 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 +13 -2
- 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/reports/cards.tsx +197 -0
- package/src/reports/filters-bar.tsx +95 -0
- package/src/reports/hero.tsx +111 -0
- package/src/reports/index.ts +4 -0
- package/src/reports/sales-room.tsx +28 -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 +5 -2
- package/src/sale/open-sale-tabs.tsx +67 -0
- package/src/sale/order-reference.ts +3 -0
- package/src/sale/orders-list.tsx +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/receipt.tsx +8 -2
- package/src/sale/tender-pane.tsx +179 -0
- package/src/sale/tender.tsx +20 -35
- package/src/scale/index.ts +3 -0
- package/src/scale/scale-provider.tsx +70 -0
- package/src/scale/use-pointer.ts +23 -0
- package/src/settings/display-settings.tsx +122 -0
- package/src/settings/index.ts +1 -0
- 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/ui/text/font-text.tsx +25 -0
- package/src/ui/text/index.tsx +5 -4
- 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({
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Port of WCPOS v2 packages/core/src/contexts/theme-traits/index.tsx (useThemeType).
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import {
|
|
4
|
+
SYSTEM_TYPE, TYPE_SETS, familiesForType, resolveTypeSet,
|
|
5
|
+
type ThemeFontFamily, type ThemeType, type TypeSetId,
|
|
6
|
+
} from '@tallyui/theme';
|
|
7
|
+
|
|
8
|
+
export type FontStatus = 'loading' | 'loaded' | 'failed';
|
|
9
|
+
export interface FontState { setId: TypeSetId; type: ThemeType; status: FontStatus }
|
|
10
|
+
export interface FontProviderProps {
|
|
11
|
+
/** The app's stored `ui.font` setting (from `useAppSettings` in `@tallyui/pos`); missing or unknown means Auto. */
|
|
12
|
+
font?: string | null;
|
|
13
|
+
/** The set Auto resolves to. Default `'system'`: TallyUI themes carry no type set. */
|
|
14
|
+
autoTypeSet?: TypeSetId;
|
|
15
|
+
/**
|
|
16
|
+
* Registers the bundled faces of these families, e.g. with expo-font `loadAsync`. The app owns
|
|
17
|
+
* the OFL files. Without a loader the faces are taken as already registered (e.g. web @font-face).
|
|
18
|
+
*/
|
|
19
|
+
loadFonts?: (families: ThemeFontFamily[]) => Promise<void>;
|
|
20
|
+
children?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const FontContext = React.createContext<FontState>({ setId: 'system', type: SYSTEM_TYPE, status: 'loaded' });
|
|
24
|
+
|
|
25
|
+
export function FontProvider({ font, autoTypeSet, loadFonts, children }: FontProviderProps): React.JSX.Element {
|
|
26
|
+
const setId = resolveTypeSet(font, autoTypeSet);
|
|
27
|
+
const [loadState, setLoadState] = React.useState<{ setId: TypeSetId; status: FontStatus }>();
|
|
28
|
+
const hasLoader = loadFonts !== undefined;
|
|
29
|
+
const loaderRef = React.useRef(loadFonts);
|
|
30
|
+
|
|
31
|
+
React.useLayoutEffect(() => {
|
|
32
|
+
loaderRef.current = loadFonts;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
React.useEffect(() => {
|
|
36
|
+
const loadFonts = loaderRef.current;
|
|
37
|
+
const families = familiesForType(TYPE_SETS[setId]);
|
|
38
|
+
if (!families.length || !loadFonts) return;
|
|
39
|
+
let stale = false;
|
|
40
|
+
loadFonts(families).then(
|
|
41
|
+
() => {
|
|
42
|
+
if (!stale) setLoadState({ setId, status: 'loaded' });
|
|
43
|
+
},
|
|
44
|
+
(error: unknown) => {
|
|
45
|
+
if (stale) return;
|
|
46
|
+
console.warn('Failed to load fonts', error);
|
|
47
|
+
setLoadState({ setId, status: 'failed' });
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
return () => { stale = true; };
|
|
51
|
+
}, [setId, hasLoader]);
|
|
52
|
+
|
|
53
|
+
const status: FontStatus = !loadFonts || !familiesForType(TYPE_SETS[setId]).length
|
|
54
|
+
? 'loaded'
|
|
55
|
+
: loadState?.setId === setId ? loadState.status : 'loading';
|
|
56
|
+
const value = React.useMemo<FontState>(() => ({
|
|
57
|
+
setId, status, type: status === 'loaded' ? TYPE_SETS[setId] : SYSTEM_TYPE,
|
|
58
|
+
}), [setId, status]);
|
|
59
|
+
|
|
60
|
+
return <FontContext.Provider value={value}>{children}</FontContext.Provider>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function useFontType(): FontState {
|
|
64
|
+
return React.useContext(FontContext);
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FontProvider, useFontType, type FontProviderProps, type FontState, type FontStatus } from './font-provider';
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
// Generic UI components
|
|
4
4
|
export * from './ui';
|
|
5
5
|
|
|
6
|
+
// Scale
|
|
7
|
+
export {
|
|
8
|
+
ScaleProvider, useScale, usePointer,
|
|
9
|
+
type ScaleProviderProps, type ScaleScopeProps, type ScaleState,
|
|
10
|
+
} from './scale';
|
|
11
|
+
|
|
6
12
|
// Product components
|
|
7
13
|
export {
|
|
8
14
|
ProductTitle,
|
|
@@ -34,6 +40,10 @@ export {
|
|
|
34
40
|
ProductVariantPicker,
|
|
35
41
|
type ProductVariantPickerProps,
|
|
36
42
|
type VariantOption,
|
|
43
|
+
InCartBadge,
|
|
44
|
+
type InCartBadgeProps,
|
|
45
|
+
CategoryTile,
|
|
46
|
+
type CategoryTileProps,
|
|
37
47
|
} from './product';
|
|
38
48
|
|
|
39
49
|
// Cart components
|
|
@@ -51,6 +61,8 @@ export {
|
|
|
51
61
|
CartLineActions,
|
|
52
62
|
type CartLineActionsProps,
|
|
53
63
|
type CartAction,
|
|
64
|
+
CartColumnHeads,
|
|
65
|
+
type CartColumnHeadsProps,
|
|
54
66
|
} from './cart';
|
|
55
67
|
|
|
56
68
|
// Input components
|
|
@@ -114,6 +126,11 @@ export {
|
|
|
114
126
|
OrderDetail,
|
|
115
127
|
type OrderDetailProps,
|
|
116
128
|
type OrderDetailLineItem,
|
|
129
|
+
RefundForm,
|
|
130
|
+
type RefundFormProps,
|
|
131
|
+
type RefundFormValue,
|
|
132
|
+
RefundModal,
|
|
133
|
+
type RefundModalProps,
|
|
117
134
|
} from './order';
|
|
118
135
|
|
|
119
136
|
// Register components
|
|
@@ -146,6 +163,10 @@ export {
|
|
|
146
163
|
type RegisterCountProps,
|
|
147
164
|
ClosureSheet,
|
|
148
165
|
type ClosureSheetProps,
|
|
166
|
+
SwitchConfirm,
|
|
167
|
+
type SwitchConfirmProps,
|
|
168
|
+
HandoverSlip,
|
|
169
|
+
type HandoverSlipProps,
|
|
149
170
|
} from './register';
|
|
150
171
|
|
|
151
172
|
// Settings components
|
|
@@ -157,15 +178,18 @@ export {
|
|
|
157
178
|
ConnectorStatus,
|
|
158
179
|
type ConnectorStatusProps,
|
|
159
180
|
type ConnectionStatus,
|
|
181
|
+
DisplaySettings,
|
|
182
|
+
type DisplaySettingsProps,
|
|
160
183
|
} from './settings';
|
|
161
184
|
|
|
162
185
|
// Sale components
|
|
163
186
|
export {
|
|
164
|
-
Cart, CartBar, Tender, SplitTender, DiscountForm, DiscountChips, parseDiscount, discountLabel,
|
|
187
|
+
Cart, CartBar, Tender, SplitTender, TenderPane, type TenderPaneProps, DiscountForm, DiscountChips, parseDiscount, discountLabel,
|
|
165
188
|
PriceForm, parsePrice,
|
|
166
189
|
ChargeForm, type ChargeFormProps,
|
|
167
190
|
Catalogue, formatStockSyncTime, Receipt, injectPrintStyle, SyncStatus, OrdersList, type OrderHistoryRow, orderReference,
|
|
168
|
-
ParkedSales, type ParkedSalesProps,
|
|
191
|
+
ParkedSales, type ParkedSalesProps, OpenSaleTabs, type OpenSaleTabsProps, CustomerDisplayScreen,
|
|
192
|
+
ProductFilterBar, DEFAULT_PRODUCT_FILTERS, PRODUCT_FILTER_CHIPS, type ProductFilterBarProps, type ProductFilterChip, type ProductFilters,
|
|
169
193
|
} from './sale';
|
|
170
194
|
|
|
171
195
|
// Layout components
|
|
@@ -182,3 +206,17 @@ export {
|
|
|
182
206
|
StoreSettingsChoiceScreen,
|
|
183
207
|
type StoreSettingsChoiceScreenProps,
|
|
184
208
|
} from './layout';
|
|
209
|
+
|
|
210
|
+
// App shell
|
|
211
|
+
export {
|
|
212
|
+
AppShell, type AppShellProps, NavRail, type NavRailProps, NavDrawer, type NavDrawerProps, type ShellNavItem,
|
|
213
|
+
} from './shell';
|
|
214
|
+
|
|
215
|
+
// Reports components
|
|
216
|
+
export {
|
|
217
|
+
SalesRoom, type SalesRoomProps, SalesHero, type SalesHeroProps, SalesCards, type SalesCardsProps, type SalesCardId,
|
|
218
|
+
SalesFiltersBar, type SalesFiltersBarProps, type SalesFilters, type SalesOption,
|
|
219
|
+
} from './reports';
|
|
220
|
+
|
|
221
|
+
// Fonts
|
|
222
|
+
export { FontProvider, useFontType, type FontProviderProps, type FontState, type FontStatus } from './fonts';
|
|
@@ -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
|
+
}
|
package/src/order/index.ts
CHANGED
|
@@ -2,3 +2,5 @@ export { OrderStatusBadge, type OrderStatusBadgeProps, type OrderStatus } from '
|
|
|
2
2
|
export { OrderCard, type OrderCardProps } from './order-card';
|
|
3
3
|
export { OrderList, type OrderListProps } from './order-list';
|
|
4
4
|
export { OrderDetail, type OrderDetailProps, type OrderDetailLineItem } from './order-detail';
|
|
5
|
+
export { RefundForm, type RefundFormProps, type RefundFormValue } from './refund-form';
|
|
6
|
+
export { RefundModal, type RefundModalProps } from './refund-modal';
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { useRef, useState, type JSX } from 'react';
|
|
2
|
+
import { Pressable, ScrollView, View } from 'react-native';
|
|
3
|
+
import { formatMoney, type OrderRefundPayload } from '@tallyui/core';
|
|
4
|
+
import { priceRefund, refundableLines, type EarlierRefund, type RefundableOrderLine } from '@tallyui/pos';
|
|
5
|
+
import { QuantityStepper } from '../input/quantity-stepper';
|
|
6
|
+
import { errorText } from '../lib/error-text';
|
|
7
|
+
import { parsePrice } from '../sale/price-form';
|
|
8
|
+
import { Button } from '../ui/button';
|
|
9
|
+
import { Checkbox } from '../ui/checkbox';
|
|
10
|
+
import { Input } from '../ui/input';
|
|
11
|
+
import { Label } from '../ui/label';
|
|
12
|
+
import { Text } from '../ui/text';
|
|
13
|
+
|
|
14
|
+
/** What the form hands back: the order.refund v1 payload minus the ids, session and clock the caller adds. */
|
|
15
|
+
export type RefundFormValue = Pick<OrderRefundPayload,
|
|
16
|
+
'lines' | 'shippingMinor' | 'adjustmentMinor' | 'totalMinor' | 'destination' | 'reason'>;
|
|
17
|
+
|
|
18
|
+
export interface RefundFormProps {
|
|
19
|
+
/** The order's lines; a StoreOrderLine fits. */
|
|
20
|
+
lines: ReadonlyArray<RefundableOrderLine & { name: string }>;
|
|
21
|
+
/** Earlier refunds' lines, subtracted by order line id. */
|
|
22
|
+
refunds: readonly EarlierRefund[];
|
|
23
|
+
currency: string;
|
|
24
|
+
/** The order number the store shows, for the confirmation. */
|
|
25
|
+
orderReference: string;
|
|
26
|
+
/** The order total with tax. */
|
|
27
|
+
orderTotalMinor: number;
|
|
28
|
+
/** Money already refunded on the order, positive; default 0. */
|
|
29
|
+
refundedMinor?: number;
|
|
30
|
+
/** Shipping still refundable, with tax; 0 or absent hides the shipping field. */
|
|
31
|
+
refundableShippingMinor?: number;
|
|
32
|
+
/** The sale's payment method; omit for a cash sale, which always refunds in cash. */
|
|
33
|
+
originalMethod?: { title: string; available: boolean };
|
|
34
|
+
/** Each line's restock starting value; default true. */
|
|
35
|
+
defaultRestock?: boolean;
|
|
36
|
+
/** Refunds are online only (ADR-080); false disables confirming. Default true. */
|
|
37
|
+
online?: boolean;
|
|
38
|
+
/** A refusal from the caller's last attempt, shown above the actions. */
|
|
39
|
+
error?: string;
|
|
40
|
+
/** Called once per confirmation; the form stays busy until a returned promise settles. */
|
|
41
|
+
onConfirm: (refund: RefundFormValue) => void | Promise<unknown>;
|
|
42
|
+
onCancel: () => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function parseAmount(text: string, currency: string, signed = false): number | string {
|
|
46
|
+
const trimmed = text.trim();
|
|
47
|
+
if (!trimmed) return 0;
|
|
48
|
+
const negative = signed && trimmed.startsWith('-');
|
|
49
|
+
const parsed = parsePrice(negative ? trimmed.slice(1) : trimmed, currency);
|
|
50
|
+
return negative && typeof parsed === 'number' && parsed !== 0 ? -parsed : parsed;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Ports WCPOS v2 form.tsx, monorepo main 5ac185b0e; the till never prices lines itself (priceRefund). */
|
|
54
|
+
export function RefundForm({
|
|
55
|
+
lines, refunds, currency, orderReference, orderTotalMinor, refundedMinor = 0,
|
|
56
|
+
refundableShippingMinor = 0, originalMethod, defaultRestock = true, online = true,
|
|
57
|
+
error, onConfirm, onCancel,
|
|
58
|
+
}: RefundFormProps): JSX.Element {
|
|
59
|
+
const [quantities, setQuantities] = useState<Record<string, number>>({});
|
|
60
|
+
const [restock, setRestock] = useState<Record<string, boolean>>({});
|
|
61
|
+
const [shippingText, setShippingText] = useState('');
|
|
62
|
+
const [adjustmentText, setAdjustmentText] = useState('');
|
|
63
|
+
const [reason, setReason] = useState('');
|
|
64
|
+
const [picked, setPicked] = useState<'original_method' | 'cash' | null>(null);
|
|
65
|
+
const [confirming, setConfirming] = useState(false);
|
|
66
|
+
const [busy, setBusy] = useState(false);
|
|
67
|
+
const busyRef = useRef(false);
|
|
68
|
+
const [thrown, setThrown] = useState('');
|
|
69
|
+
const fmt = (amount: number) => formatMoney({ amount, currency }) ?? '';
|
|
70
|
+
const available = refundableLines(lines, refunds);
|
|
71
|
+
const request = available.map(({ orderLineId, refundableQuantity }) => ({
|
|
72
|
+
orderLineId,
|
|
73
|
+
quantity: Math.min(quantities[orderLineId] ?? 0, refundableQuantity),
|
|
74
|
+
restock: restock[orderLineId] ?? defaultRestock,
|
|
75
|
+
})).filter(({ quantity }) => quantity > 0);
|
|
76
|
+
const priced = priceRefund(lines, refunds, request);
|
|
77
|
+
const shippingMinor = refundableShippingMinor > 0 ? parseAmount(shippingText, currency) : 0;
|
|
78
|
+
const adjustmentMinor = parseAmount(adjustmentText, currency, true);
|
|
79
|
+
const totalMinor = typeof shippingMinor === 'number' && typeof adjustmentMinor === 'number'
|
|
80
|
+
? priced.totalMinor + shippingMinor + adjustmentMinor : undefined;
|
|
81
|
+
const destination = originalMethod?.available ? (picked ?? 'original_method') : 'cash';
|
|
82
|
+
const invalid = typeof shippingMinor === 'string' ? shippingMinor
|
|
83
|
+
: typeof adjustmentMinor === 'string' ? adjustmentMinor
|
|
84
|
+
: shippingMinor > refundableShippingMinor ? `Shipping can be at most ${fmt(refundableShippingMinor)}.`
|
|
85
|
+
: priced.lines.length === 0 && shippingMinor === 0 && adjustmentMinor === 0 ? 'Choose something to refund.'
|
|
86
|
+
: totalMinor! <= 0 ? 'The refund total must be more than 0.'
|
|
87
|
+
: totalMinor! > orderTotalMinor - refundedMinor ? `You can refund at most ${fmt(orderTotalMinor - refundedMinor)}.`
|
|
88
|
+
: reason.trim() === '' ? 'Enter a reason.' : null;
|
|
89
|
+
const disabled = !!invalid || online === false || busy;
|
|
90
|
+
const confirm = async () => {
|
|
91
|
+
if (invalid || online === false || busyRef.current) return;
|
|
92
|
+
busyRef.current = true;
|
|
93
|
+
setBusy(true);
|
|
94
|
+
setThrown('');
|
|
95
|
+
// The parse errors above prevent confirmation until all three amounts are numbers.
|
|
96
|
+
const value: RefundFormValue = {
|
|
97
|
+
lines: priced.lines,
|
|
98
|
+
shippingMinor: shippingMinor as number,
|
|
99
|
+
adjustmentMinor: adjustmentMinor as number,
|
|
100
|
+
totalMinor: totalMinor!,
|
|
101
|
+
destination,
|
|
102
|
+
reason: reason.trim(),
|
|
103
|
+
};
|
|
104
|
+
try {
|
|
105
|
+
await onConfirm(value);
|
|
106
|
+
} catch (e) {
|
|
107
|
+
setThrown(errorText(e));
|
|
108
|
+
} finally {
|
|
109
|
+
busyRef.current = false;
|
|
110
|
+
setBusy(false);
|
|
111
|
+
setConfirming(false);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<View testID="refund-form" className="flex-1 flex-col gap-4">
|
|
117
|
+
<ScrollView className="flex-1" contentContainerClassName="gap-4">
|
|
118
|
+
<View className="flex-row justify-between gap-2">
|
|
119
|
+
<Text>Total</Text><Text testID="refund-order-total">{fmt(orderTotalMinor)}</Text>
|
|
120
|
+
</View>
|
|
121
|
+
{refundedMinor > 0 && <View className="flex-row justify-between gap-2">
|
|
122
|
+
<Text>Previously Refunded</Text><Text testID="refund-previously-refunded">{fmt(-refundedMinor)}</Text>
|
|
123
|
+
</View>}
|
|
124
|
+
<View className="flex-row flex-wrap items-center gap-2">
|
|
125
|
+
<Text className="flex-[3]">Product</Text><Text>Qty</Text><Text>Refund Qty</Text>
|
|
126
|
+
<Text>Refund Amount</Text><Text>Restock</Text>
|
|
127
|
+
</View>
|
|
128
|
+
{lines.map(({ id, name }, index) => {
|
|
129
|
+
const { refundableQuantity } = available[index];
|
|
130
|
+
return <View key={id} testID={`refund-line-${id}`} className="flex-row flex-wrap items-center gap-2 border-b border-border py-2">
|
|
131
|
+
<Text className="flex-[3]" numberOfLines={1}>{name}</Text>
|
|
132
|
+
<Text testID={`refund-remaining-${id}`}>{refundableQuantity}</Text>
|
|
133
|
+
<QuantityStepper testID={`refund-qty-${id}`} min={0} max={refundableQuantity}
|
|
134
|
+
quantity={Math.min(quantities[id] ?? 0, refundableQuantity)}
|
|
135
|
+
onChangeQuantity={(quantity) => setQuantities((current) => ({ ...current, [id]: quantity }))} />
|
|
136
|
+
<Text testID={`refund-line-amount-${id}`}>{fmt(priced.priced.find((line) => line.orderLineId === id)?.totalMinor ?? 0)}</Text>
|
|
137
|
+
<Checkbox testID={`refund-restock-${id}`} accessibilityLabel={`Restock ${name}`}
|
|
138
|
+
checked={restock[id] ?? defaultRestock}
|
|
139
|
+
onCheckedChange={(checked) => setRestock((current) => ({ ...current, [id]: checked }))} />
|
|
140
|
+
</View>;
|
|
141
|
+
})}
|
|
142
|
+
{refundableShippingMinor > 0 && <View className="gap-2">
|
|
143
|
+
<Label nativeID="refund-shipping-label">Shipping</Label>
|
|
144
|
+
<Input><Input.Field testID="refund-shipping" accessibilityLabel="Shipping"
|
|
145
|
+
accessibilityLabelledBy="refund-shipping-label" keyboardType="decimal-pad" placeholder={fmt(0)}
|
|
146
|
+
value={shippingText} onChangeText={setShippingText} /></Input>
|
|
147
|
+
<Text className="text-muted-foreground">{`Up to ${fmt(refundableShippingMinor)}`}</Text>
|
|
148
|
+
</View>}
|
|
149
|
+
<View className="gap-2">
|
|
150
|
+
<Label nativeID="refund-adjustment-label">Adjustment</Label>
|
|
151
|
+
<Input><Input.Field testID="refund-adjustment" accessibilityLabel="Adjustment"
|
|
152
|
+
accessibilityLabelledBy="refund-adjustment-label" placeholder={fmt(0)}
|
|
153
|
+
value={adjustmentText} onChangeText={setAdjustmentText} /></Input>
|
|
154
|
+
<Text className="text-muted-foreground">A minus sign takes the amount off the refund.</Text>
|
|
155
|
+
</View>
|
|
156
|
+
<View className="gap-2">
|
|
157
|
+
<Label nativeID="refund-reason-label">Reason</Label>
|
|
158
|
+
<Input><Input.Field testID="refund-reason" accessibilityLabel="Reason"
|
|
159
|
+
accessibilityLabelledBy="refund-reason-label" placeholder="Reason for refund" maxLength={500}
|
|
160
|
+
value={reason} onChangeText={setReason} /></Input>
|
|
161
|
+
</View>
|
|
162
|
+
{originalMethod && <View className="gap-2">
|
|
163
|
+
<Text>Refund destination</Text>
|
|
164
|
+
<View className="flex-row flex-wrap gap-2">
|
|
165
|
+
{(['original_method', 'cash'] as const).map((option) => <Pressable key={option}
|
|
166
|
+
testID={`refund-destination-${option}`} accessibilityRole="button"
|
|
167
|
+
accessibilityState={{ selected: destination === option }} aria-selected={destination === option}
|
|
168
|
+
disabled={option === 'original_method' && !originalMethod.available} onPress={() => setPicked(option)}
|
|
169
|
+
className={`rounded-md border border-border px-3 py-2 min-h-11 ${destination === option ? 'bg-primary' : 'bg-card'}`}>
|
|
170
|
+
<Text className={destination === option ? 'text-primary-foreground' : 'text-foreground'}>
|
|
171
|
+
{option === 'original_method' ? `Refund to ${originalMethod.title}` : 'Refund via cash'}
|
|
172
|
+
</Text>
|
|
173
|
+
</Pressable>)}
|
|
174
|
+
</View>
|
|
175
|
+
{!originalMethod.available && <Text className="text-muted-foreground">
|
|
176
|
+
Original payment method refunds are unavailable for this order.
|
|
177
|
+
</Text>}
|
|
178
|
+
</View>}
|
|
179
|
+
<View className="flex-row justify-between gap-2">
|
|
180
|
+
<Text className="font-semibold">Refund Total</Text>
|
|
181
|
+
<Text testID="refund-total" className="font-semibold">{fmt(totalMinor ?? 0)}</Text>
|
|
182
|
+
</View>
|
|
183
|
+
</ScrollView>
|
|
184
|
+
{online === false && <Text testID="refund-offline-reason" className="text-muted-foreground">Refunds need a connection</Text>}
|
|
185
|
+
{invalid && online !== false && <Text testID="refund-invalid" className="text-muted-foreground">{invalid}</Text>}
|
|
186
|
+
{!!(error ?? thrown) && <Text testID="refund-error" className="text-destructive">{error ?? thrown}</Text>}
|
|
187
|
+
{!confirming ? <View className="flex-row gap-2">
|
|
188
|
+
<Button testID="refund-cancel" variant="outline" onPress={onCancel}><Text>Cancel</Text></Button>
|
|
189
|
+
<Button testID="refund-submit" disabled={disabled} onPress={() => setConfirming(true)}>
|
|
190
|
+
<Text>{disabled ? 'Process Refund'
|
|
191
|
+
: `Refund ${fmt(totalMinor ?? 0)} ${destination === 'cash' ? 'in cash' : 'to the original method'}`}</Text>
|
|
192
|
+
</Button>
|
|
193
|
+
</View> : <>
|
|
194
|
+
<Text className="font-semibold">Confirm Refund</Text>
|
|
195
|
+
<Text testID="refund-confirm-text">{`Refund ${fmt(totalMinor ?? 0)} for Order #${orderReference}?`}</Text>
|
|
196
|
+
<View className="flex-row gap-2">
|
|
197
|
+
<Button testID="refund-confirm" variant="destructive" disabled={disabled} onPress={confirm}>
|
|
198
|
+
<Text>{busy ? 'Refunding…' : 'Process Refund'}</Text>
|
|
199
|
+
</Button>
|
|
200
|
+
<Button testID="refund-confirm-cancel" variant="outline" onPress={() => setConfirming(false)}><Text>Cancel</Text></Button>
|
|
201
|
+
</View>
|
|
202
|
+
</>}
|
|
203
|
+
</View>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { JSX } from 'react';
|
|
2
|
+
import { useWindowDimensions, View } from 'react-native';
|
|
3
|
+
import { Dialog, DialogClose, DialogContent, DialogTitle } from '../ui/dialog';
|
|
4
|
+
import { IconButton } from '../ui/icon-button';
|
|
5
|
+
import { XIcon } from '../ui/icon/x-icon';
|
|
6
|
+
import { RefundForm, type RefundFormProps } from './refund-form';
|
|
7
|
+
|
|
8
|
+
export interface RefundModalProps extends Omit<RefundFormProps, 'onCancel'> {
|
|
9
|
+
open: boolean;
|
|
10
|
+
onOpenChange: (open: boolean) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Ports WCPOS v2 modal.tsx: a bounded panel around the refund form. */
|
|
14
|
+
export function RefundModal({ open, onOpenChange, ...formProps }: RefundModalProps): JSX.Element {
|
|
15
|
+
const { height: windowHeight } = useWindowDimensions();
|
|
16
|
+
const maxHeight = Math.max(320, windowHeight - 64);
|
|
17
|
+
return (
|
|
18
|
+
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
19
|
+
<DialogContent testID="refund-modal" className="flex-col overflow-hidden" style={{ maxHeight }}>
|
|
20
|
+
<View className="flex-row items-center justify-between gap-2">
|
|
21
|
+
<DialogTitle>{`Refund Order #${formProps.orderReference}`}</DialogTitle>
|
|
22
|
+
<DialogClose asChild>
|
|
23
|
+
<IconButton variant="ghost" size="sm" testID="refund-modal-dismiss" accessibilityLabel="Close panel">
|
|
24
|
+
<XIcon size={16} />
|
|
25
|
+
</IconButton>
|
|
26
|
+
</DialogClose>
|
|
27
|
+
</View>
|
|
28
|
+
<RefundForm {...formProps} onCancel={() => onOpenChange(false)} />
|
|
29
|
+
</DialogContent>
|
|
30
|
+
</Dialog>
|
|
31
|
+
);
|
|
32
|
+
}
|