npm-pkg-hook 1.7.3 → 1.7.4
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/package.json +3 -3
- package/src/hooks/useCatWithProduct/index.js +5 -2
- package/src/hooks/useFormTools/index.js +10 -3
- package/src/hooks/useProductsFood/index.js +1 -15
- package/src/hooks/useProductsFood/queriesStore.js +2 -0
- package/src/hooks/useSales/index.js +100 -27
- package/src/index.jsx +1 -1
- package/src/security/index.js +1 -0
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"js-cookie": "3.0.1",
|
|
7
7
|
"lodash": "^4.17.21",
|
|
8
8
|
"md5": "2.3.0",
|
|
9
|
-
"moment": "^2.29.4",
|
|
9
|
+
"moment": "^2.29.4",
|
|
10
10
|
"react": "18.1.0",
|
|
11
11
|
"react-dom": "18.1.0",
|
|
12
12
|
"react-query": "^3.39.2"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"license": "ISC",
|
|
32
32
|
"main": "/src/index.jsx",
|
|
33
|
-
"name": "npm-pkg-hook",
|
|
33
|
+
"name": "npm-pkg-hook",
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"registry": "https://registry.npmjs.org/"
|
|
36
36
|
},
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"rm": "rm -rf node_modules package-lock.json && npm i",
|
|
45
45
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
46
46
|
},
|
|
47
|
-
"version": "1.7.
|
|
47
|
+
"version": "1.7.4"
|
|
48
48
|
}
|
|
@@ -12,13 +12,16 @@ export const useCatWithProduct = ({
|
|
|
12
12
|
gender,
|
|
13
13
|
desc,
|
|
14
14
|
speciality
|
|
15
|
-
} = searchFilter
|
|
15
|
+
} = searchFilter ?? {}
|
|
16
16
|
const {
|
|
17
17
|
data,
|
|
18
18
|
loading,
|
|
19
19
|
error,
|
|
20
20
|
fetchMore
|
|
21
21
|
} = useQuery(GET_ALL_CATEGORIES_WITH_PRODUCT, {
|
|
22
|
+
onCompleted: (data) => {
|
|
23
|
+
console.log('data', data)
|
|
24
|
+
},
|
|
22
25
|
fetchPolicy: 'network-only',
|
|
23
26
|
variables:
|
|
24
27
|
{
|
|
@@ -41,4 +44,4 @@ export const useCatWithProduct = ({
|
|
|
41
44
|
totalCount
|
|
42
45
|
}
|
|
43
46
|
]
|
|
44
|
-
}
|
|
47
|
+
}
|
|
@@ -9,7 +9,14 @@ import { validationSubmitHooks } from '../../utils'
|
|
|
9
9
|
* @description Hook con herramientas de validación y eventos de cambio
|
|
10
10
|
* @return {Array} devuelve la función onChange a ejecutar y el estado de error de cada input
|
|
11
11
|
*/
|
|
12
|
-
export const useFormTools = ({
|
|
12
|
+
export const useFormTools = ({
|
|
13
|
+
sendNotification = ({
|
|
14
|
+
title = '',
|
|
15
|
+
description = '',
|
|
16
|
+
backgroundColor = ''
|
|
17
|
+
}) => { }
|
|
18
|
+
}
|
|
19
|
+
= {}) => {
|
|
13
20
|
const [dataForm, setDataForm] = useState({})
|
|
14
21
|
const [errorForm, setErrorForm] = useState({})
|
|
15
22
|
const [errorSubmit, setErrorSubmit] = useState(false)
|
|
@@ -40,7 +47,7 @@ export const useFormTools = ({ sendNotification = () => { } } = {}) => {
|
|
|
40
47
|
event,
|
|
41
48
|
msgError = '',
|
|
42
49
|
msgSuccess,
|
|
43
|
-
action = () => { },
|
|
50
|
+
action = () => { return Promise.resolve() },
|
|
44
51
|
actionAfterSuccess = () => { }
|
|
45
52
|
}) => {
|
|
46
53
|
event.preventDefault()
|
|
@@ -78,7 +85,7 @@ export const useFormTools = ({ sendNotification = () => { } } = {}) => {
|
|
|
78
85
|
action().then(res => {
|
|
79
86
|
if (res) {
|
|
80
87
|
sendNotification({
|
|
81
|
-
message: msgSuccess
|
|
88
|
+
message: msgSuccess ?? 'Operación exitosa',
|
|
82
89
|
description: 'Operación exitosa',
|
|
83
90
|
backgroundColor: 'success'
|
|
84
91
|
})
|
|
@@ -13,20 +13,6 @@ import {
|
|
|
13
13
|
} from './queriesStore'
|
|
14
14
|
export * from './useEditProduct'
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* Description
|
|
18
|
-
* @param {any} categories
|
|
19
|
-
* @param {any} desc
|
|
20
|
-
* @param {any} fetchPolicy='network-only'
|
|
21
|
-
* @param {any} fromDate
|
|
22
|
-
* @param {any} gender
|
|
23
|
-
* @param {any} max=50
|
|
24
|
-
* @param {any} min
|
|
25
|
-
* @param {any} pState
|
|
26
|
-
* @param {any} search=null
|
|
27
|
-
* @param {any} toDate
|
|
28
|
-
* @returns {any}
|
|
29
|
-
*/
|
|
30
16
|
export const useProductsFood = ({
|
|
31
17
|
categories,
|
|
32
18
|
desc,
|
|
@@ -40,7 +26,7 @@ export const useProductsFood = ({
|
|
|
40
26
|
toDate
|
|
41
27
|
}) => {
|
|
42
28
|
// const [productsFood, setProductsFood] = useState([])
|
|
43
|
-
const [showMore, setShowMore] = useState(
|
|
29
|
+
const [showMore, setShowMore] = useState(500)
|
|
44
30
|
const { data, loading, fetchMore, error, called } = useQuery(GET_ALL_PRODUCT_STORE, {
|
|
45
31
|
fetchPolicy: fetchPolicy ?? 'cache-and-network',
|
|
46
32
|
notifyOnNetworkStatusChange: true,
|
|
@@ -27,7 +27,6 @@ import {
|
|
|
27
27
|
import { updateExistingOrders } from '../useUpdateExistingOrders'
|
|
28
28
|
import { useGetSale } from './useGetSale'
|
|
29
29
|
import { useCatWithProduct } from './../useCatWithProduct/index'
|
|
30
|
-
import { useCheckboxState } from '../useCheckbox'
|
|
31
30
|
import { useLogout } from '../useLogout'
|
|
32
31
|
export * from './useGetAllSales'
|
|
33
32
|
export { GET_ALL_COUNT_SALES } from './queries'
|
|
@@ -48,6 +47,7 @@ const initialState = {
|
|
|
48
47
|
const initializer = (initialValue = initialState) => {
|
|
49
48
|
return (
|
|
50
49
|
JSON.parse(
|
|
50
|
+
// @ts-ignore
|
|
51
51
|
Cookies.get(process.env.LOCAL_SALES_STORE) || JSON.stringify(initialState)
|
|
52
52
|
) || initialValue
|
|
53
53
|
)
|
|
@@ -57,7 +57,7 @@ export const useSales = ({
|
|
|
57
57
|
disabled = false,
|
|
58
58
|
router,
|
|
59
59
|
sendNotification = (arsg) => { return arsg },
|
|
60
|
-
setAlertBox = () => { return }
|
|
60
|
+
setAlertBox = (arsg) => { return arsg }
|
|
61
61
|
}) => {
|
|
62
62
|
const domain = getCurrentDomain()
|
|
63
63
|
const [loadingSale, setLoadingSale] = useState(false)
|
|
@@ -67,16 +67,14 @@ export const useSales = ({
|
|
|
67
67
|
const [modalItem, setModalItem] = useState(false)
|
|
68
68
|
const [openCommentModal, setOpenCommentModal] = useState(false)
|
|
69
69
|
const keyToSaveData = process.env.LOCAL_SALES_STORE
|
|
70
|
+
// @ts-ignore
|
|
70
71
|
const saveDataState = JSON.parse(Cookies.get(keyToSaveData) || '[]')
|
|
71
72
|
const [search, setSearch] = useState('')
|
|
72
73
|
const [datCat] = useCatWithProduct({})
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
handleChangeCheck
|
|
78
|
-
} = useCheckboxState(datCat, [], [])
|
|
79
|
-
const arr = checkedItems ? Array.from(checkedItems) : []
|
|
74
|
+
const [categories, setCategories] = useState([])
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
setCategories(datCat)
|
|
77
|
+
}, [datCat])
|
|
80
78
|
const [totalProductPrice, setTotalProductPrice] = useState(0)
|
|
81
79
|
const [showMore, setShowMore] = useState(100)
|
|
82
80
|
const [inputValue, setInputValue] = useState('')
|
|
@@ -119,6 +117,7 @@ export const useSales = ({
|
|
|
119
117
|
})
|
|
120
118
|
setAlertBox({ message, type: 'success' })
|
|
121
119
|
if (message === 'Token expired') {
|
|
120
|
+
// @ts-ignore
|
|
122
121
|
onClickLogout()
|
|
123
122
|
}
|
|
124
123
|
setOpenCurrentSale(data?.registerSalesStore?.Response.success)
|
|
@@ -152,15 +151,29 @@ export const useSales = ({
|
|
|
152
151
|
}
|
|
153
152
|
})
|
|
154
153
|
const [productsFood, { loading, fetchMore }] = useProductsFood({
|
|
154
|
+
// @ts-ignore
|
|
155
155
|
search: search?.length >= 4 ? search : '',
|
|
156
156
|
gender: [],
|
|
157
157
|
desc: [],
|
|
158
|
-
categories:
|
|
158
|
+
categories: [],
|
|
159
159
|
toDate: valuesDates?.toDate,
|
|
160
160
|
fromDate: valuesDates?.fromDate,
|
|
161
161
|
max: showMore,
|
|
162
162
|
min: 0
|
|
163
163
|
})
|
|
164
|
+
const handleChangeCheck = (caId) => {
|
|
165
|
+
// @ts-ignore
|
|
166
|
+
setCategories((prev) => {
|
|
167
|
+
return prev.map((item) => {
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
return item.carProId === caId
|
|
170
|
+
// @ts-ignore
|
|
171
|
+
? { ...item, checked: !item?.checked }
|
|
172
|
+
: item
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
|
|
164
177
|
const max = productsFood?.reduce(function (a, b) {
|
|
165
178
|
return Math.max(a, b?.ProPrice || 0)
|
|
166
179
|
}, 0)
|
|
@@ -178,6 +191,7 @@ export const useSales = ({
|
|
|
178
191
|
}
|
|
179
192
|
// HANDLESS
|
|
180
193
|
// FILTER PRODUCT DATA_DB
|
|
194
|
+
// @ts-ignore
|
|
181
195
|
const handlePrint = ({ callback }) => {
|
|
182
196
|
if (disabled) {
|
|
183
197
|
return sendNotification({
|
|
@@ -231,6 +245,7 @@ export const useSales = ({
|
|
|
231
245
|
return items.pId === id
|
|
232
246
|
})
|
|
233
247
|
if (value <= 0) {
|
|
248
|
+
// @ts-ignore
|
|
234
249
|
dispatch({ type: 'REMOVE_PRODUCT_TO_CART', payload: OneProduct })
|
|
235
250
|
}
|
|
236
251
|
const finalQuantity = (state.PRODUCT.ProQuantity = value || 0)
|
|
@@ -285,6 +300,7 @@ export const useSales = ({
|
|
|
285
300
|
return handleChangeNumber(state, action)
|
|
286
301
|
}
|
|
287
302
|
case 'REMOVE_ALL_PRODUCTS':
|
|
303
|
+
// @ts-ignore
|
|
288
304
|
setValues({
|
|
289
305
|
comment: '',
|
|
290
306
|
change: '',
|
|
@@ -355,6 +371,7 @@ export const useSales = ({
|
|
|
355
371
|
title: 'Comentario eliminado',
|
|
356
372
|
description: 'Has eliminado el comentario!'
|
|
357
373
|
})
|
|
374
|
+
// @ts-ignore
|
|
358
375
|
return dispatch({
|
|
359
376
|
type: 'PUT_COMMENT',
|
|
360
377
|
payload: pId,
|
|
@@ -362,31 +379,41 @@ export const useSales = ({
|
|
|
362
379
|
})
|
|
363
380
|
}, [])
|
|
364
381
|
useEffect(() => {
|
|
382
|
+
// @ts-ignore
|
|
365
383
|
Cookies.set(keyToSaveData, JSON.stringify(data), { domain, path: '/' })
|
|
366
384
|
}, [data, domain])
|
|
367
385
|
|
|
368
386
|
const handleAddOptional = ({ exOptional = null, codeCategory = null }) => {
|
|
369
387
|
if (!exOptional || !codeCategory) return
|
|
388
|
+
// @ts-ignore
|
|
370
389
|
const item = dataOptional.find((item) => item.code === codeCategory)
|
|
371
390
|
if (!item) return
|
|
391
|
+
// @ts-ignore
|
|
372
392
|
const idx = item.ExtProductFoodsSubOptionalAll.findIndex(
|
|
373
393
|
(el) => el.opSubExPid === exOptional
|
|
374
394
|
)
|
|
375
395
|
if (item && idx !== -1) {
|
|
376
396
|
const updatedItem = {
|
|
397
|
+
// @ts-ignore
|
|
377
398
|
...item,
|
|
378
399
|
ExtProductFoodsSubOptionalAll: [
|
|
400
|
+
// @ts-ignore
|
|
379
401
|
...item.ExtProductFoodsSubOptionalAll.slice(0, idx),
|
|
380
402
|
{
|
|
403
|
+
// @ts-ignore
|
|
381
404
|
...item.ExtProductFoodsSubOptionalAll[idx],
|
|
405
|
+
// @ts-ignore
|
|
382
406
|
check: !item.ExtProductFoodsSubOptionalAll[idx].check
|
|
383
407
|
},
|
|
408
|
+
// @ts-ignore
|
|
384
409
|
...item.ExtProductFoodsSubOptionalAll.slice(idx + 1)
|
|
385
410
|
]
|
|
386
411
|
}
|
|
387
412
|
const newData = dataOptional.map((el) =>
|
|
413
|
+
// @ts-ignore
|
|
388
414
|
el.code === codeCategory ? updatedItem : el
|
|
389
415
|
)
|
|
416
|
+
// @ts-ignore
|
|
390
417
|
setDataOptional(() => [...newData])
|
|
391
418
|
}
|
|
392
419
|
}
|
|
@@ -414,6 +441,7 @@ export const useSales = ({
|
|
|
414
441
|
const arr =
|
|
415
442
|
dataExtra?.length > 0
|
|
416
443
|
? dataExtra?.filter((p) => {
|
|
444
|
+
// @ts-ignore
|
|
417
445
|
return p.quantity !== 0
|
|
418
446
|
})
|
|
419
447
|
: []
|
|
@@ -448,6 +476,7 @@ export const useSales = ({
|
|
|
448
476
|
}
|
|
449
477
|
const filteredDataOptional = dataOptional
|
|
450
478
|
.map((obj) => {
|
|
479
|
+
// @ts-ignore
|
|
451
480
|
const filteredSubOptions = obj?.ExtProductFoodsSubOptionalAll?.filter(
|
|
452
481
|
(subObj) => subObj?.check === true
|
|
453
482
|
)
|
|
@@ -455,11 +484,14 @@ export const useSales = ({
|
|
|
455
484
|
if (filteredSubOptions?.length === 0) {
|
|
456
485
|
return null
|
|
457
486
|
}
|
|
487
|
+
// @ts-ignore
|
|
458
488
|
return { ...obj, ExtProductFoodsSubOptionalAll: filteredSubOptions }
|
|
459
489
|
})
|
|
460
490
|
.filter((obj) => obj !== null) // Elimine todos los objetos nulos del arreglo
|
|
491
|
+
// @ts-ignore
|
|
461
492
|
const filteredDataExtra = dataExtra?.filter((p) => p?.quantity !== undefined && p?.quantity !== 0)
|
|
462
493
|
if (product?.PRODUCT?.pId) {
|
|
494
|
+
// @ts-ignore
|
|
463
495
|
dispatch({
|
|
464
496
|
type: 'PUT_EXTRA_PRODUCTS_AND_OPTIONAL_PRODUCT',
|
|
465
497
|
payload: product.PRODUCT.pId,
|
|
@@ -476,18 +508,23 @@ export const useSales = ({
|
|
|
476
508
|
}
|
|
477
509
|
}
|
|
478
510
|
|
|
511
|
+
// @ts-ignore
|
|
479
512
|
function handleIncrementExtra ({ Adicionales, index }) {
|
|
480
513
|
const { pId } = product?.PRODUCT || {}
|
|
481
514
|
const exPid = Adicionales?.exPid || null
|
|
482
515
|
|
|
483
516
|
if (exPid && pId) {
|
|
484
517
|
const newExtra = dataExtra.map((producto) => {
|
|
518
|
+
// @ts-ignore
|
|
485
519
|
if (exPid === producto.exPid) {
|
|
520
|
+
// @ts-ignore
|
|
486
521
|
const initialQuantity = producto?.quantity ? producto?.quantity : 0
|
|
487
522
|
const newQuantity = initialQuantity + 1
|
|
523
|
+
// @ts-ignore
|
|
488
524
|
const newExtraPrice = producto.extraPrice * newQuantity
|
|
489
525
|
|
|
490
526
|
return {
|
|
527
|
+
// @ts-ignore
|
|
491
528
|
...producto,
|
|
492
529
|
quantity: newQuantity,
|
|
493
530
|
newExtraPrice
|
|
@@ -496,22 +533,27 @@ export const useSales = ({
|
|
|
496
533
|
return producto
|
|
497
534
|
})
|
|
498
535
|
|
|
536
|
+
// @ts-ignore
|
|
499
537
|
setDataExtra(newExtra)
|
|
500
538
|
}
|
|
501
539
|
}
|
|
502
540
|
|
|
541
|
+
// @ts-ignore
|
|
503
542
|
function handleDecrementExtra ({ Adicionales, index }) {
|
|
504
543
|
const { pId } = product?.PRODUCT || {}
|
|
505
544
|
const exPid = Adicionales?.exPid || null
|
|
506
545
|
|
|
507
546
|
// Comprobar que el objeto Adicionales existe en dataExtra
|
|
547
|
+
// @ts-ignore
|
|
508
548
|
const extraIndex = dataExtra.findIndex((extra) => extra.exPid === exPid)
|
|
509
549
|
if (extraIndex === -1) {
|
|
510
550
|
return
|
|
511
551
|
}
|
|
512
552
|
|
|
513
553
|
if (pId && exPid && extraIndex !== -1) {
|
|
554
|
+
// @ts-ignore
|
|
514
555
|
const newExtra = dataExtra.map((producto, i) => {
|
|
556
|
+
// @ts-ignore
|
|
515
557
|
if (exPid === producto.exPid) {
|
|
516
558
|
// Desestructura la cantidad y el precio extra del producto o establece valores predeterminados
|
|
517
559
|
const { quantity = 0, extraPrice = 0 } = producto
|
|
@@ -523,6 +565,7 @@ export const useSales = ({
|
|
|
523
565
|
const newExtraPrice = newQuantity === 0 ? extraPrice : extraPrice * newQuantity
|
|
524
566
|
|
|
525
567
|
return {
|
|
568
|
+
// @ts-ignore
|
|
526
569
|
...producto,
|
|
527
570
|
quantity: newQuantity,
|
|
528
571
|
newExtraPrice
|
|
@@ -532,21 +575,11 @@ export const useSales = ({
|
|
|
532
575
|
})
|
|
533
576
|
|
|
534
577
|
// Actualiza el estado de dataExtra con el nuevo array
|
|
578
|
+
// @ts-ignore
|
|
535
579
|
setDataExtra(newExtra)
|
|
536
580
|
}
|
|
537
581
|
}
|
|
538
|
-
|
|
539
|
-
* Agrega un producto al carrito de compras.
|
|
540
|
-
* @param {Object} state - Estado actual del carrito.
|
|
541
|
-
* @param {Object} action - Acción que contiene los datos del producto a agregar.
|
|
542
|
-
* @param {string} action.payload.pId - ID del producto.
|
|
543
|
-
* @param {string} action.payload.pName - Nombre del producto.
|
|
544
|
-
* @param {string[]} action.payload.getOneTags - Etiquetas del producto.
|
|
545
|
-
* @param {string} action.payload.ProDescription - Descripción del producto.
|
|
546
|
-
* @param {string} action.payload.ProImage - URL de la imagen del producto.
|
|
547
|
-
* @param {number} action.payload.ProPrice - Precio del producto.
|
|
548
|
-
* @returns {Object} Nuevo estado del carrito con el producto agregado.
|
|
549
|
-
*/
|
|
582
|
+
|
|
550
583
|
function addToCartFunc (state, action) {
|
|
551
584
|
const {
|
|
552
585
|
pId,
|
|
@@ -809,6 +842,7 @@ export const useSales = ({
|
|
|
809
842
|
})
|
|
810
843
|
}
|
|
811
844
|
const decimal = parseFloat(percentage) / 100
|
|
845
|
+
// @ts-ignore
|
|
812
846
|
const result = decimal * parseFloat(totalProductPrice)
|
|
813
847
|
setDiscount({ price: result, discount: percentage })
|
|
814
848
|
|
|
@@ -819,6 +853,7 @@ export const useSales = ({
|
|
|
819
853
|
const { getOnePedidoStore } = useGetSale()
|
|
820
854
|
|
|
821
855
|
const handleSubmit = () => {
|
|
856
|
+
// @ts-ignore
|
|
822
857
|
if (errors?.change || errors?.valueDelivery) {
|
|
823
858
|
return sendNotification({
|
|
824
859
|
title: 'error',
|
|
@@ -828,6 +863,7 @@ export const useSales = ({
|
|
|
828
863
|
}
|
|
829
864
|
setLoadingSale(true)
|
|
830
865
|
const code = RandomCode(10)
|
|
866
|
+
// @ts-ignore
|
|
831
867
|
setCode(code)
|
|
832
868
|
function convertInteger (cadena) {
|
|
833
869
|
if (typeof cadena === 'string') {
|
|
@@ -859,6 +895,7 @@ export const useSales = ({
|
|
|
859
895
|
client.query({
|
|
860
896
|
query: GET_ALL_COUNT_SALES,
|
|
861
897
|
fetchPolicy: 'network-only',
|
|
898
|
+
// @ts-ignore
|
|
862
899
|
onCompleted: (data) => {
|
|
863
900
|
client.writeQuery({ query: GET_ALL_COUNT_SALES, data: { getTodaySales: data.countSales.todaySales } })
|
|
864
901
|
}
|
|
@@ -1027,10 +1064,48 @@ export const useSales = ({
|
|
|
1027
1064
|
}
|
|
1028
1065
|
}
|
|
1029
1066
|
const handleCleanFilter = () => {
|
|
1067
|
+
// @ts-ignore
|
|
1030
1068
|
setValues({})
|
|
1031
1069
|
setValuesDates({ fromDate: yearMonthDay, toDate: '' })
|
|
1032
1070
|
}
|
|
1033
1071
|
const disabledModalItems = dataOptional?.length > 0 || dataExtra?.length > 0
|
|
1072
|
+
/**
|
|
1073
|
+
* Filter products by carProId.
|
|
1074
|
+
* @param {Array} products - Array of products to filter.
|
|
1075
|
+
* @param {Array} carProIds - Array of carProId to filter by.
|
|
1076
|
+
* @returns {Array} - Filtered array of products or all products if no matches found.
|
|
1077
|
+
*/
|
|
1078
|
+
function filterProductsByCarProId (products, carProIds) {
|
|
1079
|
+
if (!Array.isArray(products)) {
|
|
1080
|
+
return []
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
if (!Array.isArray(carProIds) || carProIds.length === 0) {
|
|
1084
|
+
return products
|
|
1085
|
+
}
|
|
1086
|
+
|
|
1087
|
+
return products.filter(product => carProIds.includes(product.carProId))
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Filter objects with checked property equal to true.
|
|
1092
|
+
* @param {Array} products - Array of objects.
|
|
1093
|
+
* @returns {Array} - Array of objects with checked property equal to true.
|
|
1094
|
+
*/
|
|
1095
|
+
function filterChecked (products) {
|
|
1096
|
+
if (!Array.isArray(products)) {
|
|
1097
|
+
return []
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
return products.filter(product => product?.checked === true).map(product => product.carProId)
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
// Obtener los carProIds de productos con checked en true
|
|
1104
|
+
const carProIds = filterChecked(categories)
|
|
1105
|
+
|
|
1106
|
+
// Filtrar los productos de productsFood por los carProIds obtenidos
|
|
1107
|
+
const filteredProducts = filterProductsByCarProId(productsFood, carProIds)
|
|
1108
|
+
|
|
1034
1109
|
return {
|
|
1035
1110
|
loading: loading || loadingSale,
|
|
1036
1111
|
loadingExtraProduct,
|
|
@@ -1055,7 +1130,7 @@ export const useSales = ({
|
|
|
1055
1130
|
search,
|
|
1056
1131
|
values,
|
|
1057
1132
|
initialStateSales,
|
|
1058
|
-
productsFood,
|
|
1133
|
+
productsFood: filteredProducts,
|
|
1059
1134
|
modalItem,
|
|
1060
1135
|
sumExtraProducts,
|
|
1061
1136
|
oneProductToComment: oneProductToComment ?? null,
|
|
@@ -1064,10 +1139,8 @@ export const useSales = ({
|
|
|
1064
1139
|
dataExtra: dataExtra || [],
|
|
1065
1140
|
fetchMore,
|
|
1066
1141
|
discount,
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
disabledItems,
|
|
1070
|
-
setCheckedItems,
|
|
1142
|
+
datCat: categories,
|
|
1143
|
+
loadingProduct: loading,
|
|
1071
1144
|
handleChangeCheck,
|
|
1072
1145
|
errors,
|
|
1073
1146
|
handleUpdateAllExtra,
|
package/src/index.jsx
CHANGED
package/src/security/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const future = null
|