npm-pkg-hook 1.2.1 → 1.2.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 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.4"
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
@@ -50,15 +50,16 @@ export const useDessert = ({
50
50
  }
51
51
  })
52
52
 
53
- // Transform initialData using useMemo to prevent unnecessary re-computation
54
- const transformedData = useMemo(() => transformDataToDessert(initialData), [initialData])
55
-
56
53
  // Use useEffect to update the data state when the initialData prop changes
57
54
  useEffect(() => {
58
55
  if (initialData) {
59
- setData(transformedData)
56
+ // Only update the data state if it's different from initialData
57
+ if (JSON.stringify(data) !== JSON.stringify(transformDataToDessert(initialData))) {
58
+ const transformedInitialData = transformDataToDessert(initialData);
59
+ setData(transformedInitialData);
60
+ }
60
61
  }
61
- }, [])
62
+ }, [initialData]); // Include data as a dependency
62
63
 
63
64
  // Filter the 'listIds' from 'data' and store the filtered result in 'dataListIds'
64
65
  // Here, it seems to exclude a specific list ID ('01list') from the listIds.
@@ -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
  })
@@ -1,9 +1,8 @@
1
1
  export function convertToIntegerOrFloat(numberString) {
2
2
  if (!numberString) return 0;
3
-
3
+
4
4
  // Convierte a número (entero o flotante)
5
5
  const numericValue = parseFloat(numberString);
6
-
6
+
7
7
  return isNaN(numericValue) ? 0 : numericValue; // Maneja valores no numéricos como 0
8
8
  }
9
-
@@ -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',
@@ -339,6 +347,11 @@ export const useSales = ({
339
347
  ...values,
340
348
  [name]: value ?? ''
341
349
  })
350
+ sendNotification({
351
+ backgroundColor: 'sucess',
352
+ title: 'Comentario eliminado',
353
+ description: 'Has eliminado el comentario!'
354
+ })
342
355
  return dispatch({
343
356
  type: 'PUT_COMMENT',
344
357
  payload: pId,
@@ -427,22 +440,24 @@ export const useSales = ({
427
440
  return sendNotification({
428
441
  title: 'Error',
429
442
  backgroundColor: 'error',
430
- description: 'No se puede actualizar el producto sin pId'
443
+ description: 'Ha ocurrido un error'
431
444
  })
432
445
  }
433
446
  const filteredDataOptional = dataOptional
434
447
  .map((obj) => {
435
- const filteredSubOptions = obj.ExtProductFoodsSubOptionalAll.filter(
436
- (subObj) => subObj.check === true
448
+ const filteredSubOptions = obj?.ExtProductFoodsSubOptionalAll?.filter(
449
+ (subObj) => subObj?.check === true
437
450
  )
438
451
  // Excluya todo el objeto padre si filteredSubOptions está vacío
439
- if (filteredSubOptions.length === 0) {
452
+ if (filteredSubOptions?.length === 0) {
440
453
  return null
441
454
  }
442
455
  return { ...obj, ExtProductFoodsSubOptionalAll: filteredSubOptions }
443
456
  })
444
457
  .filter((obj) => obj !== null) // Elimine todos los objetos nulos del arreglo
445
- const filteredDataExtra = dataExtra.filter((p) => p.quantity !== 0)
458
+ const filteredDataExtra = dataExtra?.filter((p) => p?.quantity !== undefined && p?.quantity !== 0);
459
+
460
+ console.log(filteredDataExtra)
446
461
  dispatch({
447
462
  type: 'PUT_EXTRA_PRODUCTS_AND_OPTIONAL_PRODUCT',
448
463
  payload: product.PRODUCT.pId,
@@ -458,25 +473,31 @@ export const useSales = ({
458
473
  }
459
474
  }
460
475
 
461
- function handleIncrementExtra ({ Adicionales, index }) {
462
- const { pId } = product?.PRODUCT || {}
463
- const exPid = Adicionales.exPid || null
476
+ function handleIncrementExtra({ Adicionales, index }) {
477
+ const { pId } = product?.PRODUCT || {};
478
+ const exPid = Adicionales.exPid || null;
479
+
464
480
  if (exPid && pId) {
465
481
  const newExtra = dataExtra.map((producto) => {
466
482
  if (exPid === producto.exPid) {
467
- const initialQuantity = producto?.quantity ? producto?.quantity : 0
483
+ const initialQuantity = producto?.quantity ? producto?.quantity : 0;
484
+ const newQuantity = initialQuantity + 1;
485
+ const newExtraPrice = producto.extraPrice * newQuantity;
486
+
468
487
  return {
469
488
  ...producto,
470
- quantity: initialQuantity + 1,
471
- newExtraPrice: producto.extraPrice * (initialQuantity + 1)
472
- }
489
+ quantity: newQuantity,
490
+ newExtraPrice: newExtraPrice,
491
+ };
473
492
  }
474
- return producto
475
- })
476
- return setDataExtra(newExtra)
493
+ return producto;
494
+ });
495
+
496
+ setDataExtra(newExtra);
477
497
  }
478
498
  }
479
499
 
500
+
480
501
  function handleDecrementExtra ({ Adicionales, index }) {
481
502
  const { pId } = product?.PRODUCT || {}
482
503
  const exPid = Adicionales.exPid || null
@@ -487,18 +508,28 @@ export const useSales = ({
487
508
  return
488
509
  }
489
510
 
490
- if (pId && exPid) {
511
+ if (pId && exPid && extraIndex !== -1) {
491
512
  const newExtra = dataExtra.map((producto, i) => {
492
513
  if (exPid === producto.exPid) {
493
- const initialQuantity = producto?.quantity
514
+ // Desestructura la cantidad y el precio extra del producto o establece valores predeterminados
515
+ const { quantity = 0, extraPrice = 0 } = producto
516
+
517
+ // Calcula la nueva cantidad, evitando que sea negativa
518
+ const newQuantity = Math.max(quantity - 1, 0)
519
+
520
+ // Calcula el nuevo precio extra
521
+ const newExtraPrice = newQuantity === 0 ? extraPrice : extraPrice * newQuantity
522
+
494
523
  return {
495
524
  ...producto,
496
- quantity: initialQuantity - 1,
497
- newExtraPrice: producto.extraPrice * (initialQuantity - 1)
525
+ quantity: newQuantity,
526
+ newExtraPrice
498
527
  }
499
528
  }
500
529
  return producto
501
530
  })
531
+
532
+ // Actualiza el estado de dataExtra con el nuevo array
502
533
  setDataExtra(newExtra)
503
534
  }
504
535
  }
@@ -515,10 +546,17 @@ export const useSales = ({
515
546
  * @returns {Object} Nuevo estado del carrito con el producto agregado.
516
547
  */
517
548
  function addToCartFunc (state, action) {
518
- const { pId, pName, getOneTags, ProDescription, ProImage, ProPrice } = action.payload
549
+ const {
550
+ pId,
551
+ pName,
552
+ getOneTags,
553
+ ProDescription,
554
+ ProImage,
555
+ ProPrice
556
+ } = action.payload
519
557
 
520
- const productExist = state.PRODUCT.find((item) => item.pId === pId)
521
- const OurProduct = productsFood.find((item) => item.pId === pId)
558
+ const productExist = state?.PRODUCT.find((item) => item.pId === pId)
559
+ const OurProduct = productsFood?.find((item) => item.pId === pId)
522
560
  const isFree = productExist?.free
523
561
 
524
562
  const updatedProduct = {
@@ -541,7 +579,6 @@ export const useSales = ({
541
579
  PRODUCT: [...state.PRODUCT, updatedProduct]
542
580
  }
543
581
  }
544
-
545
582
  return {
546
583
  ...state,
547
584
  counter: state.counter + 1,
@@ -554,7 +591,7 @@ export const useSales = ({
554
591
  getOneTags: OurProduct.genderTags,
555
592
  unitPrice: OurProduct?.ProPrice,
556
593
  ProPrice: isFree ? 0 : (productExist.ProQuantity + 1) * OurProduct?.ProPrice,
557
- ProQuantity: productExist.ProQuantity + 1,
594
+ ProQuantity: productExist.ProQuantity + +1,
558
595
  free: !!isFree
559
596
  }
560
597
  }
@@ -564,7 +601,7 @@ export const useSales = ({
564
601
  }
565
602
 
566
603
  function removeFunc (state, action) {
567
- const productExist = state.PRODUCT.find((items) => {
604
+ const productExist = state?.PRODUCT.find((items) => {
568
605
  return items.pId === action.payload.pId
569
606
  })
570
607
  const OurProduct = productsFood.find((items) => {
@@ -615,6 +652,14 @@ export const useSales = ({
615
652
 
616
653
  // COMMENT_FREE_PRODUCT
617
654
  function commentProducts (state, action, deleteValue) {
655
+ if (values.comment) {
656
+ sendNotification({
657
+ backgroundColor: 'success',
658
+ title: deleteValue ? 'Comentario eliminado' : 'Producto comentado',
659
+ description: deleteValue ? 'Has eliminado el comentario!' : 'Has comentado!'
660
+ })
661
+ }
662
+ setOpenCommentModal(!openCommentModal)
618
663
  return {
619
664
  ...state,
620
665
  PRODUCT: state?.PRODUCT?.map((items) => {
@@ -654,6 +699,7 @@ export const useSales = ({
654
699
  const sortedProduct = useMemo(() => {
655
700
  return getSortedProduct(data.PRODUCT, data.sortBy)
656
701
  }, [data.PRODUCT, data.sortBy, getSortedProduct])
702
+
657
703
  const finalFilter = PriceRangeFunc(sortedProduct, data.priceRange)
658
704
 
659
705
  const handleList = (text) => {
@@ -801,7 +847,9 @@ export const useSales = ({
801
847
  const { registerSalesStore } = data || {}
802
848
  const { Response } = registerSalesStore || {}
803
849
  if (Response && Response.success === true) {
804
- // dispatch({ type: 'REMOVE_ALL_PRODUCTS' })
850
+ dispatch({ type: 'REMOVE_ALL_PRODUCTS' })
851
+ setValues({})
852
+ setPrint(false)
805
853
  client.query({
806
854
  query: GET_ALL_COUNT_SALES,
807
855
  fetchPolicy: 'network-only',
@@ -822,7 +870,8 @@ export const useSales = ({
822
870
  fields: {
823
871
  getAllOrdersFromStore (existingOrders = []) {
824
872
  try {
825
- return updateExistingOrders(existingOrders, inComingCodeRef, 1, currentSale)
873
+ const newGetAllOrdersFromStore = updateExistingOrders(existingOrders, inComingCodeRef, 4, currentSale)
874
+ return newGetAllOrdersFromStore
826
875
  } catch (e) {
827
876
  return existingOrders
828
877
  }
@@ -841,7 +890,6 @@ export const useSales = ({
841
890
  undefined,
842
891
  { shallow: true }
843
892
  )
844
- setValues({})
845
893
  }
846
894
  }
847
895
  setLoadingSale(false)
@@ -849,8 +897,10 @@ export const useSales = ({
849
897
  .catch(() => {
850
898
  setLoadingSale(false)
851
899
  setErrorSale(true)
900
+ setPrint(false)
852
901
  })
853
902
  .finally(() => {
903
+ setPrint(false)
854
904
  setLoadingSale(false)
855
905
  })
856
906
  }
@@ -966,7 +1016,6 @@ export const useSales = ({
966
1016
  }
967
1017
  }
968
1018
  const handleCleanFilter = () => {
969
- setArrayCategory([])
970
1019
  setValues({})
971
1020
  setValuesDates({ fromDate: yearMonthDay, toDate: '' })
972
1021
  }
@@ -1004,9 +1053,13 @@ export const useSales = ({
1004
1053
  dataExtra: dataExtra || [],
1005
1054
  fetchMore,
1006
1055
  discount,
1056
+ checkedItems,
1057
+ datCat,
1058
+ disabledItems,
1059
+ setCheckedItems,
1060
+ handleChangeCheck,
1007
1061
  handleUpdateAllExtra,
1008
1062
  dispatch,
1009
- setArrayCategory,
1010
1063
  handleComment,
1011
1064
  setModalItem,
1012
1065
  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