@homefile/components-v2 2.36.18 → 2.36.20

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.
@@ -2,12 +2,15 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { t } from 'i18next';
3
3
  import { Checkbox, Flex, Stack, Image, Text } from '@chakra-ui/react';
4
4
  import { getReceiptOrigin } from '../../helpers';
5
- import { formatCurrency, formatDateWithAt } from '../../utils';
5
+ import { formatCurrency, formatDateWithAt, toQuantity } from '../../utils';
6
6
  export const AssignableReceiptCard = ({ isChecked, itemQuantity = 1, onChange, purchaseDate = new Date(), origin = '', total = '0', }) => {
7
7
  const date = formatDateWithAt({ date: purchaseDate });
8
- const totalFormatted = formatCurrency({ value: total });
9
- const totalItems = Number(itemQuantity) > 1
10
- ? `${itemQuantity} ${t('receipts.items')}`
11
- : `${itemQuantity} ${t('receipts.item')}`;
12
- return (_jsxs(Flex, { bg: "lightBlue.2", gap: "4", borderTop: "1px solid", borderColor: "lightBlue.2", children: [_jsx(Checkbox, { isChecked: isChecked, onChange: onChange }), _jsx(Stack, { w: "100%", p: "base", bg: isChecked ? 'lightGreen.1' : 'neutral.white', spacing: "1", children: _jsxs(Flex, { align: "center", gap: "base", children: [_jsx(Image, { src: getReceiptOrigin(origin), w: "auto", h: ["40px", "69px"], fit: "contain" }), _jsxs(Stack, { w: "100%", spacing: "1", children: [_jsx(Text, { fontSize: "xxs", children: date }), _jsx(Text, { textTransform: "capitalize", children: `${origin} ${t('receipts.receipt')}` }), _jsxs(Flex, { align: "baseline", justify: "flex-end", gap: "4", children: [_jsx(Text, { fontSize: "xs", fontFamily: "secondary", textTransform: "uppercase", children: totalItems }), _jsx(Text, { children: totalFormatted })] })] })] }) })] }));
8
+ const numericTotal = total !== null ? total.replace(/[^0-9.-]/g, "") : "";
9
+ const totalFormatted = formatCurrency({ value: numericTotal });
10
+ const originCheck = origin === null ? "" : origin;
11
+ const formatQtty = toQuantity(itemQuantity);
12
+ const totalItems = Number(formatQtty) > 1
13
+ ? `${formatQtty} ${t('receipts.items')}`
14
+ : `${formatQtty} ${t('receipts.item')}`;
15
+ return (_jsxs(Flex, { bg: "lightBlue.2", gap: "4", borderTop: "1px solid", borderColor: "lightBlue.2", children: [_jsx(Checkbox, { isChecked: isChecked, onChange: onChange }), _jsx(Stack, { w: "100%", p: "base", bg: isChecked ? 'lightGreen.1' : 'neutral.white', spacing: "1", children: _jsxs(Flex, { align: "center", gap: "base", children: [_jsx(Image, { src: getReceiptOrigin(originCheck), w: "auto", h: ["40px", "69px"], fit: "contain" }), _jsxs(Stack, { w: "100%", spacing: "1", children: [_jsx(Text, { fontSize: "xxs", children: date }), _jsx(Text, { textTransform: "capitalize", children: `${originCheck} ${t('receipts.receipt')}` }), _jsxs(Flex, { align: "baseline", justify: "flex-end", gap: "4", children: [_jsx(Text, { fontSize: "xs", fontFamily: "secondary", textTransform: "uppercase", children: totalItems }), _jsx(Text, { children: totalFormatted })] })] })] }) })] }));
13
16
  };
@@ -1,10 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { t } from 'i18next';
3
3
  import { Box, Divider, Flex, IconButton, Image, Text } from '@chakra-ui/react';
4
- import { formatDate } from '../../../utils';
4
+ import { formatDate, toQuantity } from '../../../utils';
5
5
  import { DetailsColumn, Edit, PdfButton } from '../../../components';
6
6
  import { getReceiptOrigin } from '../../../helpers';
7
7
  export const ReceiptDetails = ({ name, cashier = '', itemQuantity, paymentMethod, purchaseDate, tax, store, origin = "", storePhone = '', total, onEdit, onFileClick }) => {
8
+ const quantity = toQuantity(itemQuantity);
8
9
  const storeImage = getReceiptOrigin(origin);
9
10
  const leftLabels = t('receipts.columnLeft').split(',');
10
11
  const rightLabels = t('receipts.columnRight').split(',');
@@ -25,7 +26,7 @@ export const ReceiptDetails = ({ name, cashier = '', itemQuantity, paymentMethod
25
26
  const rightColumn = [
26
27
  {
27
28
  label: rightLabels[0],
28
- value: itemQuantity,
29
+ value: quantity,
29
30
  },
30
31
  {
31
32
  label: rightLabels[1],
@@ -7,7 +7,7 @@ export const receiptOrigins = {
7
7
  "": DefaultReceipt
8
8
  };
9
9
  function normalize(input) {
10
- return input.trim().toLowerCase().replace(/['\s]+/g, '');
10
+ return input === null || input === undefined ? "" : input.trim().toLowerCase().replace(/['\s]+/g, '');
11
11
  }
12
12
  export const getReceiptOrigin = (key) => {
13
13
  var _a;
@@ -5,13 +5,13 @@ interface UseDisplayReceiptsI {
5
5
  export declare const useDisplayReceipts: ({ receipts }: UseDisplayReceiptsI) => {
6
6
  formattedReceipts: {
7
7
  total: string;
8
+ itemQuantity: number | "";
8
9
  __v?: number;
9
10
  _id: string;
10
11
  assignStatus?: import("../../interfaces").ReceiptAssignStatusProps;
11
12
  cashier?: string;
12
13
  createAt?: Date;
13
14
  home?: string | null;
14
- itemQuantity: number | string;
15
15
  name?: string;
16
16
  paymentMethod: string;
17
17
  purchaseDate?: Date;
@@ -1,10 +1,11 @@
1
- import { formatCurrency } from '../../utils';
1
+ import { formatCurrency, toQuantity } from '../../utils';
2
2
  export const useDisplayReceipts = ({ receipts }) => {
3
3
  const formattedReceipts = receipts.map((receipt) => {
4
- const { total } = receipt;
4
+ const { total, itemQuantity } = receipt;
5
5
  const numericTotal = total.replace(/[^0-9.-]/g, "");
6
6
  const totalFormatted = formatCurrency({ value: numericTotal });
7
- return Object.assign(Object.assign({}, receipt), { total: totalFormatted });
7
+ const quantity = toQuantity(itemQuantity);
8
+ return Object.assign(Object.assign({}, receipt), { total: totalFormatted, itemQuantity: quantity });
8
9
  });
9
10
  return { formattedReceipts };
10
11
  };
@@ -6,8 +6,9 @@ export declare const AssignableReceiptCardComponent: {
6
6
  (args: AssignableReceiptCardI): import("react/jsx-runtime").JSX.Element;
7
7
  args: {
8
8
  _id: string;
9
- total: string;
10
- purchaseDate: Date;
11
- itemQuantity: number;
9
+ total: null;
10
+ purchaseDate: null;
11
+ itemQuantity: null;
12
+ origin: null;
12
13
  };
13
14
  };
@@ -10,7 +10,8 @@ export const AssignableReceiptCardComponent = (args) => {
10
10
  };
11
11
  AssignableReceiptCardComponent.args = {
12
12
  _id: '123',
13
- total: '120.45',
14
- purchaseDate: new Date(),
15
- itemQuantity: 10,
13
+ total: null,
14
+ purchaseDate: null,
15
+ itemQuantity: null,
16
+ origin: null
16
17
  };
@@ -25,6 +25,7 @@ interface FormatCurrencyI {
25
25
  value: string | number;
26
26
  }
27
27
  export declare const formatISODate: (value: string) => string;
28
+ export declare const toQuantity: (q: string | number | null | undefined) => number | "";
28
29
  export declare const formatCurrency: ({ country, currrency, value, }: FormatCurrencyI) => string;
29
30
  export declare const formatCurrencyWithoutDigits: ({ country, currrency, value, }: FormatCurrencyI) => string;
30
31
  export declare const formatNumber: (value: string | number) => string | 0;
@@ -109,6 +109,17 @@ export const formatISODate = (value) => {
109
109
  : '';
110
110
  return displayValue;
111
111
  };
112
+ export const toQuantity = (q) => {
113
+ if (typeof q === "number")
114
+ return Number.isFinite(q) ? q : "";
115
+ const cleaned = (q !== null && q !== void 0 ? q : "")
116
+ .toString()
117
+ .replace(/\D/g, ""); // remove all non-digits
118
+ if (!cleaned)
119
+ return ""; // no digits found
120
+ const n = Number(cleaned);
121
+ return Number.isInteger(n) && n > 0 ? n : "";
122
+ };
112
123
  export const formatCurrency = ({ country = 'en-US', currrency = 'USD', value, }) => {
113
124
  if (!value) {
114
125
  return Number(0).toLocaleString(country, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homefile/components-v2",
3
- "version": "2.36.18",
3
+ "version": "2.36.20",
4
4
  "author": "Homefile",
5
5
  "license": "UNLICENSED",
6
6
  "typings": "dist/index.d.ts",