npm-pkg-hook 1.2.1 → 1.2.2

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 CHANGED
@@ -43,5 +43,5 @@
43
43
  "rm": "rm -rf node_modules package-lock.json && npm i",
44
44
  "test": "echo \"Error: no test specified\" && exit 1"
45
45
  },
46
- "version": "1.2.1"
46
+ "version": "1.2.2"
47
47
  }
@@ -15,7 +15,7 @@ import { useCallback, useState } from 'react'
15
15
  * - clearAll (callback)
16
16
  */
17
17
 
18
- export const useCheckboxState = (elem, selectedIds = [], disabledIds = []) => {
18
+ export const useCheckboxState = (elem, selectedIds = [], disabledIds = [], setArray = () => { return }) => {
19
19
  const numTotalItems = elem?.length
20
20
  const [checkedItems, setCheckedItems] = useState(new Set(selectedIds))
21
21
  const [disabledItems, setDisabledItems] = useState(new Set(disabledIds))
@@ -98,7 +98,7 @@ mutation registerShoppingCard($input: IShoppingCard, $idSubArray: IID_SUB_ITEMS
98
98
  }
99
99
  `
100
100
  export const CREATE_SHOPPING_CARD_TO_USER_STORE = gql`
101
- mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $pCodeRef: String, $change: Int, $valueDelivery: Float, $payMethodPState: Int, $pickUp: Int, $totalProductsPrice: Float, $idSubArray: IID_SUB_ITEMS){
101
+ mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $pCodeRef: String, $change: Float, $valueDelivery: Float, $payMethodPState: Int, $pickUp: Int, $totalProductsPrice: Float, $idSubArray: IID_SUB_ITEMS){
102
102
  registerSalesStore(input: $input, id: $id, idStore: $idStore, pCodeRef: $pCodeRef, change: $change, valueDelivery: $valueDelivery, payMethodPState: $payMethodPState, pickUp: $pickUp, totalProductsPrice: $totalProductsPrice, idSubArray: $idSubArray){
103
103
  ShoppingCard {
104
104
  ShoppingCard
@@ -84,19 +84,45 @@ export const useDeleteProductsFood = ({ sendNotification = () => { } } = {}) =>
84
84
  pId,
85
85
  pState
86
86
  }
87
- },
88
- update (cache) {
87
+ }, update (cache) {
89
88
  cache.modify({
90
89
  fields: {
91
90
  productFoodsAll (dataOld = []) {
92
- return cache.writeQuery({ query: GET_ALL_PRODUCT_STORE, data: dataOld })
91
+ if (Array.isArray(dataOld) && dataOld?.length) {
92
+ const product = dataOld?.find((product) => {
93
+ return product.pId === pId
94
+ })
95
+ if (product) {
96
+ const newProductList = dataOld?.filter((product) => {
97
+ return product?.pId !== pId
98
+ })
99
+ return newProductList
100
+ }
101
+ return dataOld
102
+ } else {
103
+ return []
104
+ }
93
105
  }
94
106
  }
95
107
  })
96
108
  cache.modify({
97
109
  fields: {
98
110
  getCatProductsWithProduct (dataOld = []) {
99
- return cache.writeQuery({ query: GET_ALL_CATEGORIES_WITH_PRODUCT, data: dataOld })
111
+ if (Array.isArray(dataOld?.catProductsWithProduct) && dataOld?.catProductsWithProduct?.length) {
112
+ const newListCatProducts = dataOld?.catProductsWithProduct?.map((categories) => {
113
+ return {
114
+ ...categories,
115
+ productFoodsAll: categories?.productFoodsAll?.length ? categories?.productFoodsAll?.filter((product) => {
116
+ return product?.pId !== pId
117
+ }) : []
118
+ }
119
+ })
120
+ return {
121
+ catProductsWithProduct: newListCatProducts,
122
+ totalCount: newListCatProducts?.length,
123
+ }
124
+ }
125
+ return dataOld
100
126
  }
101
127
  }
102
128
  })
@@ -27,6 +27,8 @@ import {
27
27
  import { updateExistingOrders } from '../useUpdateExistingOrders'
28
28
  import { useGetSale } from './useGetSale'
29
29
  import { convertToIntegerOrFloat } from './helpers'
30
+ import { useCatWithProduct } from './../useCatWithProduct/index';
31
+ import { useCheckboxState } from '../useCheckbox';
30
32
  export * from './useGetAllSales'
31
33
  export { GET_ALL_COUNT_SALES } from './queries'
32
34
 
@@ -65,7 +67,14 @@ export const useSales = ({
65
67
  const keyToSaveData = process.env.LOCAL_SALES_STORE
66
68
  const saveDataState = JSON.parse(Cookies.get(keyToSaveData) || '[]')
67
69
  const [search, setSearch] = useState('')
68
- const [arr, setArrayCategory] = useState([])
70
+ const [datCat] = useCatWithProduct({})
71
+ const {
72
+ checkedItems,
73
+ disabledItems,
74
+ setCheckedItems,
75
+ handleChangeCheck
76
+ } = useCheckboxState(datCat, [], [])
77
+ const arr = checkedItems ? Array.from(checkedItems) : []
69
78
  const [totalProductPrice, setTotalProductPrice] = useState(0)
70
79
  const [showMore, setShowMore] = useState(100)
71
80
  const [inputValue, setInputValue] = useState('')
@@ -109,7 +118,6 @@ export const useSales = ({
109
118
  setOpenCurrentSale(data?.registerSalesStore?.Response.success)
110
119
  },
111
120
  onError: (error) => {
112
- console.log(error)
113
121
  sendNotification({
114
122
  backgroundColor: 'error',
115
123
  title: error || 'Lo sentimo',
@@ -427,22 +435,24 @@ export const useSales = ({
427
435
  return sendNotification({
428
436
  title: 'Error',
429
437
  backgroundColor: 'error',
430
- description: 'No se puede actualizar el producto sin pId'
438
+ description: 'Ha ocurrido un error'
431
439
  })
432
440
  }
433
441
  const filteredDataOptional = dataOptional
434
442
  .map((obj) => {
435
- const filteredSubOptions = obj.ExtProductFoodsSubOptionalAll.filter(
436
- (subObj) => subObj.check === true
443
+ const filteredSubOptions = obj?.ExtProductFoodsSubOptionalAll?.filter(
444
+ (subObj) => subObj?.check === true
437
445
  )
438
446
  // Excluya todo el objeto padre si filteredSubOptions está vacío
439
- if (filteredSubOptions.length === 0) {
447
+ if (filteredSubOptions?.length === 0) {
440
448
  return null
441
449
  }
442
450
  return { ...obj, ExtProductFoodsSubOptionalAll: filteredSubOptions }
443
451
  })
444
452
  .filter((obj) => obj !== null) // Elimine todos los objetos nulos del arreglo
445
- const filteredDataExtra = dataExtra.filter((p) => p.quantity !== 0)
453
+ const filteredDataExtra = dataExtra?.filter((p) => p?.quantity !== undefined && p?.quantity !== 0);
454
+
455
+ console.log(filteredDataExtra)
446
456
  dispatch({
447
457
  type: 'PUT_EXTRA_PRODUCTS_AND_OPTIONAL_PRODUCT',
448
458
  payload: product.PRODUCT.pId,
@@ -458,25 +468,31 @@ export const useSales = ({
458
468
  }
459
469
  }
460
470
 
461
- function handleIncrementExtra ({ Adicionales, index }) {
462
- const { pId } = product?.PRODUCT || {}
463
- const exPid = Adicionales.exPid || null
471
+ function handleIncrementExtra({ Adicionales, index }) {
472
+ const { pId } = product?.PRODUCT || {};
473
+ const exPid = Adicionales.exPid || null;
474
+
464
475
  if (exPid && pId) {
465
476
  const newExtra = dataExtra.map((producto) => {
466
477
  if (exPid === producto.exPid) {
467
- const initialQuantity = producto?.quantity ? producto?.quantity : 0
478
+ const initialQuantity = producto?.quantity ? producto?.quantity : 0;
479
+ const newQuantity = initialQuantity + 1;
480
+ const newExtraPrice = producto.extraPrice * newQuantity;
481
+
468
482
  return {
469
483
  ...producto,
470
- quantity: initialQuantity + 1,
471
- newExtraPrice: producto.extraPrice * (initialQuantity + 1)
472
- }
484
+ quantity: newQuantity,
485
+ newExtraPrice: newExtraPrice,
486
+ };
473
487
  }
474
- return producto
475
- })
476
- return setDataExtra(newExtra)
488
+ return producto;
489
+ });
490
+
491
+ setDataExtra(newExtra);
477
492
  }
478
493
  }
479
494
 
495
+
480
496
  function handleDecrementExtra ({ Adicionales, index }) {
481
497
  const { pId } = product?.PRODUCT || {}
482
498
  const exPid = Adicionales.exPid || null
@@ -487,18 +503,28 @@ export const useSales = ({
487
503
  return
488
504
  }
489
505
 
490
- if (pId && exPid) {
506
+ if (pId && exPid && extraIndex !== -1) {
491
507
  const newExtra = dataExtra.map((producto, i) => {
492
508
  if (exPid === producto.exPid) {
493
- const initialQuantity = producto?.quantity
509
+ // Desestructura la cantidad y el precio extra del producto o establece valores predeterminados
510
+ const { quantity = 0, extraPrice = 0 } = producto
511
+
512
+ // Calcula la nueva cantidad, evitando que sea negativa
513
+ const newQuantity = Math.max(quantity - 1, 0)
514
+
515
+ // Calcula el nuevo precio extra
516
+ const newExtraPrice = newQuantity === 0 ? extraPrice : extraPrice * newQuantity
517
+
494
518
  return {
495
519
  ...producto,
496
- quantity: initialQuantity - 1,
497
- newExtraPrice: producto.extraPrice * (initialQuantity - 1)
520
+ quantity: newQuantity,
521
+ newExtraPrice
498
522
  }
499
523
  }
500
524
  return producto
501
525
  })
526
+
527
+ // Actualiza el estado de dataExtra con el nuevo array
502
528
  setDataExtra(newExtra)
503
529
  }
504
530
  }
@@ -515,10 +541,17 @@ export const useSales = ({
515
541
  * @returns {Object} Nuevo estado del carrito con el producto agregado.
516
542
  */
517
543
  function addToCartFunc (state, action) {
518
- const { pId, pName, getOneTags, ProDescription, ProImage, ProPrice } = action.payload
544
+ const {
545
+ pId,
546
+ pName,
547
+ getOneTags,
548
+ ProDescription,
549
+ ProImage,
550
+ ProPrice
551
+ } = action.payload
519
552
 
520
- const productExist = state.PRODUCT.find((item) => item.pId === pId)
521
- const OurProduct = productsFood.find((item) => item.pId === pId)
553
+ const productExist = state?.PRODUCT.find((item) => item.pId === pId)
554
+ const OurProduct = productsFood?.find((item) => item.pId === pId)
522
555
  const isFree = productExist?.free
523
556
 
524
557
  const updatedProduct = {
@@ -541,7 +574,6 @@ export const useSales = ({
541
574
  PRODUCT: [...state.PRODUCT, updatedProduct]
542
575
  }
543
576
  }
544
-
545
577
  return {
546
578
  ...state,
547
579
  counter: state.counter + 1,
@@ -554,7 +586,7 @@ export const useSales = ({
554
586
  getOneTags: OurProduct.genderTags,
555
587
  unitPrice: OurProduct?.ProPrice,
556
588
  ProPrice: isFree ? 0 : (productExist.ProQuantity + 1) * OurProduct?.ProPrice,
557
- ProQuantity: productExist.ProQuantity + 1,
589
+ ProQuantity: productExist.ProQuantity + +1,
558
590
  free: !!isFree
559
591
  }
560
592
  }
@@ -564,7 +596,7 @@ export const useSales = ({
564
596
  }
565
597
 
566
598
  function removeFunc (state, action) {
567
- const productExist = state.PRODUCT.find((items) => {
599
+ const productExist = state?.PRODUCT.find((items) => {
568
600
  return items.pId === action.payload.pId
569
601
  })
570
602
  const OurProduct = productsFood.find((items) => {
@@ -654,6 +686,7 @@ export const useSales = ({
654
686
  const sortedProduct = useMemo(() => {
655
687
  return getSortedProduct(data.PRODUCT, data.sortBy)
656
688
  }, [data.PRODUCT, data.sortBy, getSortedProduct])
689
+
657
690
  const finalFilter = PriceRangeFunc(sortedProduct, data.priceRange)
658
691
 
659
692
  const handleList = (text) => {
@@ -966,7 +999,6 @@ export const useSales = ({
966
999
  }
967
1000
  }
968
1001
  const handleCleanFilter = () => {
969
- setArrayCategory([])
970
1002
  setValues({})
971
1003
  setValuesDates({ fromDate: yearMonthDay, toDate: '' })
972
1004
  }
@@ -1004,9 +1036,13 @@ export const useSales = ({
1004
1036
  dataExtra: dataExtra || [],
1005
1037
  fetchMore,
1006
1038
  discount,
1039
+ checkedItems,
1040
+ datCat,
1041
+ disabledItems,
1042
+ setCheckedItems,
1043
+ handleChangeCheck,
1007
1044
  handleUpdateAllExtra,
1008
1045
  dispatch,
1009
- setArrayCategory,
1010
1046
  handleComment,
1011
1047
  setModalItem,
1012
1048
  handleChangeFilter,
@@ -343,7 +343,7 @@ export const CREATE_SHOPPING_CARD_TO_USER_STORE = gql`
343
343
  $idStore: ID
344
344
  $pCodeRef: String
345
345
  $discount: Int
346
- $change: String
346
+ $change: Float
347
347
  $valueDelivery: Float
348
348
  $payMethodPState: Int
349
349
  $pickUp: Int