@licklist/design 0.78.11 → 0.78.14

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.
@@ -62,7 +62,7 @@ pipelines:
62
62
  name: Publish to NPM
63
63
  script:
64
64
  - printf "//`node -p \"require('url').parse(process.env.NPM_REGISTRY_URL || 'https://registry.npmjs.org').host\"`/:_authToken=${NPM_TOKEN}\nregistry=${NPM_REGISTRY_URL:-https://registry.npmjs.org}\n" >> ~/.npmrc
65
- - pipe: atlassian/npm-publish:0.2.0
65
+ - pipe: atlassian/npm-publish:1.1.1
66
66
  variables:
67
67
  NPM_TOKEN: $NPM_TOKEN
68
68
 
@@ -1 +1 @@
1
- {"version":3,"file":"useTableData.d.ts","sourceRoot":"","sources":["../../../../../src/iframe/payment/order-items-table/hooks/useTableData.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EAAE,oBAAoB,EAAe,MAAM,UAAU,CAAA;AAQ5D,eAAO,MAAM,2BAA2B;;;;CAIvC,CAAA;AAED,eAAO,MAAM,YAAY,oEAKtB,oBAAoB;;;;;IA+KtB,CAAA"}
1
+ {"version":3,"file":"useTableData.d.ts","sourceRoot":"","sources":["../../../../../src/iframe/payment/order-items-table/hooks/useTableData.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EAAE,oBAAoB,EAAe,MAAM,UAAU,CAAA;AAK5D,eAAO,MAAM,2BAA2B;;;;CAIvC,CAAA;AAED,eAAO,MAAM,YAAY,oEAKtB,oBAAoB;;;;;IA2KtB,CAAA"}
@@ -65,55 +65,52 @@ var useTableData = function(param) {
65
65
  });
66
66
  };
67
67
  var renderCategoryItem = function(products) {
68
- var _products__productCategory;
69
- var _products__productCategory_name;
68
+ var _products__productCategory, _products_;
69
+ var _products__productCategory_name, _order_orderProducts;
70
70
  return {
71
71
  key: uniqueId('category-id-'),
72
- name: wrapLabelContent((_products__productCategory_name = (_products__productCategory = products[0].productCategory) === null || _products__productCategory === void 0 ? void 0 : _products__productCategory.name) !== null && _products__productCategory_name !== void 0 ? _products__productCategory_name : ''),
72
+ name: wrapLabelContent((_products__productCategory_name = (_products_ = products[0]) === null || _products_ === void 0 ? void 0 : (_products__productCategory = _products_.productCategory) === null || _products__productCategory === void 0 ? void 0 : _products__productCategory.name) !== null && _products__productCategory_name !== void 0 ? _products__productCategory_name : ''),
73
73
  quantity: '',
74
- price: wrapLabelContent("".concat(t('total'), ": ").concat(formatPrice(getTotalSumByCategory(order.orderProducts, products))))
74
+ price: wrapLabelContent("".concat(t('total'), ": ").concat(formatPrice(getTotalSumByCategory((_order_orderProducts = order.orderProducts) !== null && _order_orderProducts !== void 0 ? _order_orderProducts : [], products))))
75
75
  };
76
76
  };
77
77
  var reworkProductStructure = function(order) {
78
- return order ? flatMap(order, function(item) {
79
- if (!item || !Array.isArray(item)) return [];
80
- return item.map(function(modGroup, idx) {
81
- var _order_deletedAt, _order_orderId, _order_price, _order_productId, _modGroup_productQuantity, _order_deposit;
82
- return {
83
- deletedAt: (_order_deletedAt = order.deletedAt) !== null && _order_deletedAt !== void 0 ? _order_deletedAt : null,
84
- id: "".concat(order.id, "-").concat(idx + 1),
85
- orderId: (_order_orderId = order.orderId) !== null && _order_orderId !== void 0 ? _order_orderId : null,
86
- price: (_order_price = order.price) !== null && _order_price !== void 0 ? _order_price : 0,
87
- productId: (_order_productId = order.productId) !== null && _order_productId !== void 0 ? _order_productId : '',
88
- quantity: (_modGroup_productQuantity = modGroup.productQuantity) !== null && _modGroup_productQuantity !== void 0 ? _modGroup_productQuantity : 1,
89
- deposit: (_order_deposit = order.deposit) !== null && _order_deposit !== void 0 ? _order_deposit : 0,
90
- orderProductModifiers: modGroup.modifiers.map(function(mod) {
91
- var _mod_modifierId, _mod_price, _mod_productId, _mod_quantity, _mod_modifierSetId, _mod_modifier;
92
- return {
93
- modifierId: (_mod_modifierId = mod.modifierId) !== null && _mod_modifierId !== void 0 ? _mod_modifierId : '',
94
- price: (_mod_price = mod.price) !== null && _mod_price !== void 0 ? _mod_price : 0,
95
- productId: (_mod_productId = mod.productId) !== null && _mod_productId !== void 0 ? _mod_productId : '',
96
- quantity: (_mod_quantity = mod.quantity) !== null && _mod_quantity !== void 0 ? _mod_quantity : 1,
97
- modifierSetId: (_mod_modifierSetId = mod.modifierSetId) !== null && _mod_modifierSetId !== void 0 ? _mod_modifierSetId : '',
98
- modifier: (_mod_modifier = mod.modifier) !== null && _mod_modifier !== void 0 ? _mod_modifier : null
99
- };
100
- })
101
- };
102
- });
103
- }) : [];
78
+ if (!order) return [];
79
+ var _order_orderProductModifiersGroups;
80
+ var groups = (_order_orderProductModifiersGroups = order === null || order === void 0 ? void 0 : order.orderProductModifiersGroups) !== null && _order_orderProductModifiersGroups !== void 0 ? _order_orderProductModifiersGroups : [];
81
+ if (!Array.isArray(groups) || !groups.length) return [
82
+ order
83
+ ];
84
+ return groups.flatMap(function(modGroup, idx) {
85
+ var _order_deletedAt, _order_orderId, _order_price, _order_productId, _modGroup_productQuantity, _order_deposit, _modGroup_modifiers, _map;
86
+ return {
87
+ deletedAt: (_order_deletedAt = order.deletedAt) !== null && _order_deletedAt !== void 0 ? _order_deletedAt : null,
88
+ id: "".concat(order.id, "-").concat(idx + 1),
89
+ orderId: (_order_orderId = order.orderId) !== null && _order_orderId !== void 0 ? _order_orderId : null,
90
+ price: (_order_price = order.price) !== null && _order_price !== void 0 ? _order_price : 0,
91
+ productId: (_order_productId = order.productId) !== null && _order_productId !== void 0 ? _order_productId : '',
92
+ quantity: (_modGroup_productQuantity = modGroup === null || modGroup === void 0 ? void 0 : modGroup.productQuantity) !== null && _modGroup_productQuantity !== void 0 ? _modGroup_productQuantity : 1,
93
+ deposit: (_order_deposit = order.deposit) !== null && _order_deposit !== void 0 ? _order_deposit : 0,
94
+ orderProductModifiers: (_map = ((_modGroup_modifiers = modGroup === null || modGroup === void 0 ? void 0 : modGroup.modifiers) !== null && _modGroup_modifiers !== void 0 ? _modGroup_modifiers : []).map(function(mod) {
95
+ var _mod_modifierId, _mod_price, _mod_productId, _mod_quantity, _mod_modifierSetId, _mod_modifier;
96
+ return {
97
+ modifierId: (_mod_modifierId = mod === null || mod === void 0 ? void 0 : mod.modifierId) !== null && _mod_modifierId !== void 0 ? _mod_modifierId : '',
98
+ price: (_mod_price = mod === null || mod === void 0 ? void 0 : mod.price) !== null && _mod_price !== void 0 ? _mod_price : 0,
99
+ productId: (_mod_productId = mod === null || mod === void 0 ? void 0 : mod.productId) !== null && _mod_productId !== void 0 ? _mod_productId : '',
100
+ quantity: (_mod_quantity = mod === null || mod === void 0 ? void 0 : mod.quantity) !== null && _mod_quantity !== void 0 ? _mod_quantity : 1,
101
+ modifierSetId: (_mod_modifierSetId = mod === null || mod === void 0 ? void 0 : mod.modifierSetId) !== null && _mod_modifierSetId !== void 0 ? _mod_modifierSetId : '',
102
+ modifier: (_mod_modifier = mod === null || mod === void 0 ? void 0 : mod.modifier) !== null && _mod_modifier !== void 0 ? _mod_modifier : null
103
+ };
104
+ })) !== null && _map !== void 0 ? _map : []
105
+ };
106
+ });
104
107
  };
105
- var renderProductItem = function(param) {
106
- var product = param.product, productsForCategory = param.productsForCategory;
107
- var _productsForCategory_find, _product_orderProductModifiers;
108
- if (product.quantity === 0) {
109
- return null;
110
- }
111
- var name = ((_productsForCategory_find = productsForCategory.find(function(item) {
112
- return item.id === product.productId;
113
- })) === null || _productsForCategory_find === void 0 ? void 0 : _productsForCategory_find.name) || '';
108
+ var renderModifierItem = function(orderModifier) {
109
+ if (!orderModifier || orderModifier.quantity === 0) return null;
110
+ var quantity = orderModifier.quantity, modifier = orderModifier.modifier, modifierId = orderModifier.modifierId, price = orderModifier.price;
114
111
  return {
115
- key: product.id,
116
- name: name,
112
+ key: modifierId,
113
+ name: " - ".concat((modifier === null || modifier === void 0 ? void 0 : modifier.name) || ''),
117
114
  quantity: /*#__PURE__*/ jsxs("div", {
118
115
  className: "quantity",
119
116
  children: [
@@ -121,21 +118,23 @@ var useTableData = function(param) {
121
118
  className: "multiplier",
122
119
  children: "x"
123
120
  }),
124
- product.quantity
121
+ quantity
125
122
  ]
126
123
  }),
127
- price: formatPrice(product.price),
128
- modifier: (product === null || product === void 0 ? void 0 : (_product_orderProductModifiers = product.orderProductModifiers) === null || _product_orderProductModifiers === void 0 ? void 0 : _product_orderProductModifiers.map(renderModifierItem)) || []
124
+ price: formatPrice(price !== null && price !== void 0 ? price : 0)
129
125
  };
130
126
  };
131
- var renderModifierItem = function(orderModifier) {
132
- var quantity = orderModifier.quantity, modifier = orderModifier.modifier, modifierId = orderModifier.modifierId, price = orderModifier.price;
133
- if (quantity === 0) {
134
- return null;
135
- }
127
+ var renderProductItem = function(param) {
128
+ var product = param.product, productsForCategory = param.productsForCategory;
129
+ var _productsForCategory_find, _product_orderProductModifiers;
130
+ if (!product || product.quantity === 0) return null;
131
+ var name = ((_productsForCategory_find = productsForCategory.find(function(item) {
132
+ return item.id === product.productId;
133
+ })) === null || _productsForCategory_find === void 0 ? void 0 : _productsForCategory_find.name) || '';
134
+ var _product_price, _product_orderProductModifiers_map;
136
135
  return {
137
- key: modifierId,
138
- name: " - ".concat((modifier === null || modifier === void 0 ? void 0 : modifier.name) || ''),
136
+ key: product.id,
137
+ name: name,
139
138
  quantity: /*#__PURE__*/ jsxs("div", {
140
139
  className: "quantity",
141
140
  children: [
@@ -143,47 +142,51 @@ var useTableData = function(param) {
143
142
  className: "multiplier",
144
143
  children: "x"
145
144
  }),
146
- quantity
145
+ product.quantity
147
146
  ]
148
147
  }),
149
- price: formatPrice(price)
148
+ price: formatPrice((_product_price = product.price) !== null && _product_price !== void 0 ? _product_price : 0),
149
+ modifier: ((_product_orderProductModifiers_map = product === null || product === void 0 ? void 0 : (_product_orderProductModifiers = product.orderProductModifiers) === null || _product_orderProductModifiers === void 0 ? void 0 : _product_orderProductModifiers.map(renderModifierItem)) !== null && _product_orderProductModifiers_map !== void 0 ? _product_orderProductModifiers_map : []).filter(Boolean)
150
150
  };
151
151
  };
152
152
  var renderProductsContent = function() {
153
153
  var productCategories = _to_consumable_array(new Set(order.products.map(function(product) {
154
154
  return product.productCategoryId;
155
155
  })));
156
- return productCategories.reduce(function(previousValues, categoryId) {
157
- var productsForCategory = order === null || order === void 0 ? void 0 : order.products.filter(function(product) {
158
- return product.productCategoryId === categoryId;
159
- });
160
- var products = order.orderProducts.filter(function(el) {
161
- return productsForCategory.map(function(product) {
162
- return product.id;
156
+ return productCategories.reduce(function(acc, categoryId) {
157
+ var _order_orderProducts;
158
+ var _order_products_filter;
159
+ var productsForCategory = (_order_products_filter = order === null || order === void 0 ? void 0 : order.products.filter(function(p) {
160
+ return p.productCategoryId === categoryId;
161
+ })) !== null && _order_products_filter !== void 0 ? _order_products_filter : [];
162
+ var _order_orderProducts_filter;
163
+ var products = (_order_orderProducts_filter = order === null || order === void 0 ? void 0 : (_order_orderProducts = order.orderProducts) === null || _order_orderProducts === void 0 ? void 0 : _order_orderProducts.filter(function(el) {
164
+ return productsForCategory.map(function(p) {
165
+ return p.id;
163
166
  }).includes(el.productId);
164
- });
165
- if (!products.length) {
166
- return previousValues;
167
- }
167
+ })) !== null && _order_orderProducts_filter !== void 0 ? _order_orderProducts_filter : [];
168
+ if (!products.length) return acc;
168
169
  var productsWithReworkedModifier = products.map(function(product) {
169
- if (!product.orderProductModifiers.length) return product;
170
+ var _product_orderProductModifiers;
171
+ if (!(product === null || product === void 0 ? void 0 : (_product_orderProductModifiers = product.orderProductModifiers) === null || _product_orderProductModifiers === void 0 ? void 0 : _product_orderProductModifiers.length)) return product;
170
172
  return reworkProductStructure(product);
171
173
  });
172
- var filteredProducts = flatten(productsWithReworkedModifier).map(function(product) {
174
+ var filteredProducts = flatten(productsWithReworkedModifier).map(function(p) {
173
175
  return renderProductItem({
174
- product: product,
176
+ product: p,
175
177
  productsForCategory: productsForCategory
176
178
  });
179
+ }).filter(function(row) {
180
+ return Boolean(row);
177
181
  });
178
- var productWithModifier = flatMap(filteredProducts, function(item) {
182
+ if (!filteredProducts.length) return acc;
183
+ var productWithModifier = flatMap(filteredProducts, function(row) {
184
+ var _row_modifier;
179
185
  return [
180
- item
181
- ].concat(_to_consumable_array(item.modifier));
186
+ row
187
+ ].concat(_to_consumable_array((_row_modifier = row.modifier) !== null && _row_modifier !== void 0 ? _row_modifier : []));
182
188
  });
183
- if (!filteredProducts.length) {
184
- return previousValues;
185
- }
186
- return _to_consumable_array(previousValues).concat([
189
+ return _to_consumable_array(acc).concat([
187
190
  renderCategoryItem(productsForCategory)
188
191
  ], _to_consumable_array(productWithModifier));
189
192
  }, []);
@@ -200,20 +203,18 @@ var useTableData = function(param) {
200
203
  });
201
204
  };
202
205
  var data = useMemo(function() {
203
- if (!order) {
204
- return [];
205
- }
206
+ if (!order) return [];
206
207
  return _to_consumable_array(renderProductsContent()).concat(_to_consumable_array(renderSummaryItems(getOrderSummaryItems({
207
208
  order: order,
208
209
  paymentDetail: paymentDetail,
209
210
  isPaymentProcessed: isPaymentProcessed,
210
211
  externalDiscount: externalDiscount
211
212
  }))));
212
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
213
- [
213
+ }, [
214
214
  order,
215
215
  externalDiscount,
216
- isPaymentProcessed
216
+ isPaymentProcessed,
217
+ paymentDetail
217
218
  ]);
218
219
  return data;
219
220
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@licklist/design",
3
- "version": "0.78.11",
3
+ "version": "0.78.14",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+ssh://git@bitbucket.org/artelogicsoft/licklist_design.git"
@@ -1,24 +1,22 @@
1
1
  import { useMemo } from 'react'
2
- import { uniqueId, flatMap, flatten, map } from 'lodash'
2
+ import { uniqueId, flatMap, flatten } from 'lodash'
3
3
  import { useIntl } from 'react-intl'
4
4
  import { useTranslation } from 'react-i18next'
5
5
  import { Product } from '@licklist/core/dist/DataMapper/Product/ProductDataMapper'
6
6
  import { OrderModifier } from '@licklist/core/dist/DataMapper/Order/OrderModifierDataMapper'
7
+ import { OrderProduct } from '@licklist/core/dist/DataMapper/Order/OrderProductDataMapper'
7
8
  import {
8
9
  PAYMENT_TYPE_VAT,
9
10
  PAYMENT_TYPE_FEE,
10
11
  PAYMENT_TYPE_NET_PROFIT,
11
12
  } from '@licklist/core/dist/DataMapper/Order/PaymentDataMapper'
12
13
  import { StaticTableData } from '../../../../table'
13
- import { getProductQuantityAndPrice, getTotalSumByCategory } from '../utils'
14
+ import { getTotalSumByCategory } from '../utils'
14
15
  import { OrderItemsTableProps, SummaryItem } from '../types'
15
16
  import { getOrderSummaryItems } from '../utils/paymentSummary'
16
- import { Order } from '@licklist/core/dist/DataMapper'
17
- import { OrderPayment } from '@licklist/core/dist/DataMapper/Order/OrderPaymentDataMapper'
18
- import { OrderProduct } from '@licklist/core/dist/DataMapper/Order/OrderProductDataMapper'
19
- import { OrderModifierByProduct } from '@licklist/core/dist/DataMapper/Order/OrderModifiierByProduct'
20
17
 
21
18
  const CURRENCY_DEFAULT = 'GBP'
19
+
22
20
  export const PAYMENT_TYPE_TRANSLATE_KEYS = {
23
21
  [PAYMENT_TYPE_NET_PROFIT]: 'netAmount',
24
22
  [PAYMENT_TYPE_FEE]: 'bookeditFee',
@@ -41,43 +39,62 @@ export const useTableData = ({
41
39
  })
42
40
 
43
41
  const wrapLabelContent = (string: string) => (
44
- <div className='label'>{string}</div>
42
+ <div className="label">{string}</div>
45
43
  )
46
44
 
47
45
  const renderCategoryItem = (products: Product[]) => ({
48
46
  key: uniqueId('category-id-'),
49
- name: wrapLabelContent(products[0].productCategory?.name ?? ''),
47
+ name: wrapLabelContent(products[0]?.productCategory?.name ?? ''),
50
48
  quantity: '',
51
49
  price: wrapLabelContent(
52
50
  `${t('total')}: ${formatPrice(
53
- getTotalSumByCategory(order.orderProducts, products),
51
+ getTotalSumByCategory(order.orderProducts ?? [], products),
54
52
  )}`,
55
53
  ),
56
54
  })
57
55
 
58
- const reworkProductStructure = (order: OrderProduct) =>
59
- order
60
- ? flatMap(order, (item) => {
61
- if (!item || !Array.isArray(item)) return []
62
- return item.map((modGroup, idx) => ({
63
- deletedAt: order.deletedAt ?? null,
64
- id: `${order.id}-${idx + 1}`, // Ensuring uniqueness with string concatenation
65
- orderId: order.orderId ?? null,
66
- price: order.price ?? 0,
67
- productId: order.productId ?? '',
68
- quantity: modGroup.productQuantity ?? 1,
69
- deposit: order.deposit ?? 0,
70
- orderProductModifiers: modGroup.modifiers.map((mod) => ({
71
- modifierId: mod.modifierId ?? '',
72
- price: mod.price ?? 0,
73
- productId: mod.productId ?? '',
74
- quantity: mod.quantity ?? 1,
75
- modifierSetId: mod.modifierSetId ?? '',
76
- modifier: mod.modifier ?? null,
77
- })),
78
- }))
79
- })
80
- : []
56
+ const reworkProductStructure = (order: OrderProduct) => {
57
+ if (!order) return []
58
+
59
+ const groups: any[] = (order as any)?.orderProductModifiersGroups ?? []
60
+ if (!Array.isArray(groups) || !groups.length) return [order]
61
+
62
+ return groups.flatMap((modGroup, idx) => ({
63
+ deletedAt: order.deletedAt ?? null,
64
+ id: `${order.id}-${idx + 1}`,
65
+ orderId: order.orderId ?? null,
66
+ price: order.price ?? 0,
67
+ productId: order.productId ?? '',
68
+ quantity: modGroup?.productQuantity ?? 1,
69
+ deposit: order.deposit ?? 0,
70
+ orderProductModifiers:
71
+ (modGroup?.modifiers ?? []).map((mod: any) => ({
72
+ modifierId: mod?.modifierId ?? '',
73
+ price: mod?.price ?? 0,
74
+ productId: mod?.productId ?? '',
75
+ quantity: mod?.quantity ?? 1,
76
+ modifierSetId: mod?.modifierSetId ?? '',
77
+ modifier: mod?.modifier ?? null,
78
+ })) ?? [],
79
+ }))
80
+ }
81
+
82
+ const renderModifierItem = (orderModifier: OrderModifier) => {
83
+ if (!orderModifier || orderModifier.quantity === 0) return null
84
+ const { quantity, modifier, modifierId, price } = orderModifier
85
+
86
+ return {
87
+ key: modifierId,
88
+ name: ` - ${modifier?.name || ''}`,
89
+ quantity: (
90
+ <div className="quantity">
91
+ <div className="multiplier">x</div>
92
+ {quantity}
93
+ </div>
94
+ ),
95
+ price: formatPrice(price ?? 0),
96
+ }
97
+ }
81
98
 
82
99
  const renderProductItem = ({
83
100
  product,
@@ -86,43 +103,26 @@ export const useTableData = ({
86
103
  product: OrderProduct
87
104
  productsForCategory: Product[]
88
105
  }) => {
89
- if (product.quantity === 0) {
90
- return null
91
- }
92
-
106
+ if (!product || product.quantity === 0) return null
107
+
93
108
  const name =
94
- productsForCategory.find((item) => item.id === product.productId)?.name || ''
109
+ productsForCategory.find((item) => item.id === product.productId)?.name ||
110
+ ''
95
111
 
96
112
  return {
97
113
  key: product.id,
98
114
  name,
99
115
  quantity: (
100
- <div className='quantity'>
101
- <div className='multiplier'>x</div>
116
+ <div className="quantity">
117
+ <div className="multiplier">x</div>
102
118
  {product.quantity}
103
119
  </div>
104
120
  ),
105
- price: formatPrice(product.price),
106
- modifier: product?.orderProductModifiers?.map(renderModifierItem) || [],
107
- }
108
- }
109
-
110
- const renderModifierItem = (orderModifier: OrderModifier) => {
111
- const { quantity, modifier, modifierId, price } = orderModifier
112
- if (quantity === 0) {
113
- return null
114
- }
115
-
116
- return {
117
- key: modifierId,
118
- name: ` - ${modifier?.name || ''}`,
119
- quantity: (
120
- <div className='quantity'>
121
- <div className='multiplier'>x</div>
122
- {quantity}
123
- </div>
124
- ),
125
- price: formatPrice(price),
121
+ price: formatPrice(product.price ?? 0),
122
+ modifier:
123
+ (product?.orderProductModifiers?.map(renderModifierItem) ?? []).filter(
124
+ Boolean,
125
+ ),
126
126
  }
127
127
  }
128
128
 
@@ -132,41 +132,40 @@ export const useTableData = ({
132
132
  ]
133
133
 
134
134
  return productCategories.reduce(
135
- (previousValues: StaticTableData[], categoryId) => {
136
- const productsForCategory = order?.products.filter(
137
- (product) => product.productCategoryId === categoryId,
138
- )
139
-
140
- const products = order.orderProducts.filter((el) =>
141
- productsForCategory
142
- .map((product) => product.id)
143
- .includes(el.productId),
144
- )
145
-
146
- if (!products.length) {
147
- return previousValues
148
- }
135
+ (acc: StaticTableData[], categoryId) => {
136
+ const productsForCategory =
137
+ order?.products.filter((p) => p.productCategoryId === categoryId) ?? []
138
+
139
+ const products =
140
+ order?.orderProducts?.filter((el) =>
141
+ productsForCategory.map((p) => p.id).includes(el.productId),
142
+ ) ?? []
143
+
144
+ if (!products.length) return acc
145
+
149
146
  const productsWithReworkedModifier = products.map((product) => {
150
- if (!product.orderProductModifiers.length) return product
147
+ if (!product?.orderProductModifiers?.length) return product
151
148
  return reworkProductStructure(product)
152
149
  })
153
150
 
154
- const filteredProducts = flatten(productsWithReworkedModifier).map(
155
- (product) =>
156
- renderProductItem({ product , productsForCategory }),
157
- )
158
-
159
- const productWithModifier = flatMap(filteredProducts, (item) => [
160
- item,
161
- ...item.modifier,
162
- ])
151
+ const filteredProducts = flatten(productsWithReworkedModifier)
152
+ .map((p) =>
153
+ renderProductItem({
154
+ product: p as OrderProduct,
155
+ productsForCategory,
156
+ }),
157
+ )
158
+ .filter((row): row is NonNullable<typeof row> => Boolean(row))
159
+
160
+ if (!filteredProducts.length) return acc
163
161
 
164
- if (!filteredProducts.length) {
165
- return previousValues
166
- }
162
+ const productWithModifier = flatMap(filteredProducts, (row) => [
163
+ row,
164
+ ...(row.modifier ?? []),
165
+ ])
167
166
 
168
167
  return [
169
- ...previousValues,
168
+ ...acc,
170
169
  renderCategoryItem(productsForCategory),
171
170
  ...productWithModifier,
172
171
  ]
@@ -183,26 +182,21 @@ export const useTableData = ({
183
182
  price: wrapLabelContent(formatPrice(price)),
184
183
  }))
185
184
 
186
- const data = useMemo(
187
- () => {
188
- if (!order) {
189
- return []
190
- }
191
-
192
- return [
193
- ...renderProductsContent(),
194
- ...renderSummaryItems(
195
- getOrderSummaryItems({
196
- order,
197
- paymentDetail,
198
- isPaymentProcessed,
199
- externalDiscount,
200
- }),
201
- ),
202
- ]
203
- },
204
- // eslint-disable-next-line react-hooks/exhaustive-deps
205
- [order, externalDiscount, isPaymentProcessed],
206
- )
185
+ const data = useMemo(() => {
186
+ if (!order) return []
187
+
188
+ return [
189
+ ...renderProductsContent(),
190
+ ...renderSummaryItems(
191
+ getOrderSummaryItems({
192
+ order,
193
+ paymentDetail,
194
+ isPaymentProcessed,
195
+ externalDiscount,
196
+ }),
197
+ ),
198
+ ]
199
+ }, [order, externalDiscount, isPaymentProcessed, paymentDetail])
200
+
207
201
  return data
208
202
  }