@pagamio/frontend-commons-lib 0.8.330 → 0.8.332
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/lib/components/ecommerce/ProductCard.js +5 -2
- package/lib/components/ecommerce/types.d.ts +7 -0
- package/lib/pagamio-table/utils/index.d.ts +1 -0
- package/lib/pagamio-table/utils/index.js +1 -0
- package/lib/pagamio-table/utils/withSyntheticId.d.ts +18 -0
- package/lib/pagamio-table/utils/withSyntheticId.js +16 -0
- package/package.json +1 -1
|
@@ -5,8 +5,11 @@ import { formatPrice } from '../../helpers/utils';
|
|
|
5
5
|
import ImageComponent from '../ui/ImageComponent';
|
|
6
6
|
const LOW_STOCK_THRESHOLD = 5;
|
|
7
7
|
export function ProductCard({ product, onAddToCart, isAddingToCart, storeId, basePath = '/shop', featured = false, linkSuffix, currency = 'ZAR', renderLink, onNavigate, }) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
// Non-stock products (services / fees / digital goods) have no
|
|
9
|
+
// StockItem rows by design — they're always available
|
|
10
|
+
const isNonStock = product.isStockItem === false;
|
|
11
|
+
const hasStock = isNonStock || product.totalStock > 0;
|
|
12
|
+
const isLowStock = !isNonStock && hasStock && product.totalStock <= LOW_STOCK_THRESHOLD;
|
|
10
13
|
const isBackorderable = product.allowBackorders === true;
|
|
11
14
|
const canAddToCart = (hasStock || isBackorderable) && !!storeId;
|
|
12
15
|
const hasVariants = product.variants && product.variants.length > 0;
|
|
@@ -33,6 +33,13 @@ export interface EcommerceProduct {
|
|
|
33
33
|
totalStock: number;
|
|
34
34
|
inStock?: boolean;
|
|
35
35
|
allowBackorders?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* False for services / fees / digital goods that don't hold inventory.
|
|
38
|
+
* The card treats these as always available — no out-of-stock badge,
|
|
39
|
+
* no low-stock warning. Defaults to true (or undefined) for stock
|
|
40
|
+
* products which retain the existing behaviour.
|
|
41
|
+
*/
|
|
42
|
+
isStockItem?: boolean;
|
|
36
43
|
variants?: ProductVariant[];
|
|
37
44
|
}
|
|
38
45
|
export interface CartItemBundleItem {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mirror a row's primary-key field into a top-level `id` so the row
|
|
3
|
+
* satisfies `BaseEntity` (and MRT's row keying) when the underlying entity
|
|
4
|
+
* has a composite PK or a non-`id`-named PK (e.g. `customerId`, `orderId`).
|
|
5
|
+
*
|
|
6
|
+
* Usage in a usePagamioTable queryFn:
|
|
7
|
+
*
|
|
8
|
+
* queryFn: async (params) => {
|
|
9
|
+
* const res = await getThings(params);
|
|
10
|
+
* return { ...res, data: withSyntheticId(res.data, 'customerId') };
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* The synthesized `id` is purely for the table layer — it never goes back
|
|
14
|
+
* to the server.
|
|
15
|
+
*/
|
|
16
|
+
export declare const withSyntheticId: <T extends Record<string, unknown>, K extends keyof T>(rows: T[], key: K) => Array<T & {
|
|
17
|
+
id: T[K];
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mirror a row's primary-key field into a top-level `id` so the row
|
|
3
|
+
* satisfies `BaseEntity` (and MRT's row keying) when the underlying entity
|
|
4
|
+
* has a composite PK or a non-`id`-named PK (e.g. `customerId`, `orderId`).
|
|
5
|
+
*
|
|
6
|
+
* Usage in a usePagamioTable queryFn:
|
|
7
|
+
*
|
|
8
|
+
* queryFn: async (params) => {
|
|
9
|
+
* const res = await getThings(params);
|
|
10
|
+
* return { ...res, data: withSyntheticId(res.data, 'customerId') };
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* The synthesized `id` is purely for the table layer — it never goes back
|
|
14
|
+
* to the server.
|
|
15
|
+
*/
|
|
16
|
+
export const withSyntheticId = (rows, key) => rows.map((row) => ({ ...row, id: row[key] }));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagamio/frontend-commons-lib",
|
|
3
3
|
"description": "Pagamio library for Frontend reusable components like the form engine and table container",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.332",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"provenance": false
|