npm-pkg-hook 1.7.3 → 1.7.5

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/expire.json ADDED
@@ -0,0 +1 @@
1
+ eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSmVzdXMgSnV2aW5hbyIsImVtYWlsIjoianV2aW5hb2plc3VzZEBnbWFpbC5jb20iLCJ1c2VybmFtZSI6Ikplc3VzIEp1dmluYW8iLCJyZXN0YXVyYW50Ijp7ImlkU3RvcmUiOiIwMTNlNTM4Ny0zNGExLTZhNzgtMzAzZC01MDk4ZjE3YmY2NDAiLCJpZCI6IjAxM2U1Mzg3LTM0YTEtNmE3OC0zMDNkLTUwOThmMTdiZjY0MCJ9LCJpZCI6IjAxM2U1Mzg3LTM0YTEtNmE3OC0zMDNkLTUwOThmMTdiZjY0MCIsImlhdCI6MTcwNjY3MTkwOCwiZXhwIjoxNzA3MDA1MjA4fQ.V---HeOaEMX9tow6Yh-33ehM6HV-h-1YQ8dmxJfVcyE
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.3"
47
+ "version": "1.7.5"
48
48
  }
@@ -10,7 +10,8 @@ export const generateStoreURL = ({
10
10
  city,
11
11
  department,
12
12
  storeName,
13
- idStore
13
+ idStore,
14
+ rootMainPath = 'delivery'
14
15
  }) => {
15
16
  try {
16
17
  // Validate all necessary fields
@@ -30,7 +31,7 @@ export const generateStoreURL = ({
30
31
  // Replace spaces in storeName with hyphens
31
32
  const formattedStoreName = storeName.replace(/\s+/g, '-')
32
33
 
33
- return `${process.env.MAIN_URL_BASE}/delivery/${cityName}-${departmentName}/${formattedStoreName}/${idStore}`
34
+ return `${process.env.MAIN_URL_BASE}/${rootMainPath}/${cityName}-${departmentName}/${formattedStoreName}/${idStore}`
34
35
  } catch (_) {
35
36
  return '/'
36
37
  }
@@ -12,7 +12,11 @@ export const useCatWithProduct = ({
12
12
  gender,
13
13
  desc,
14
14
  speciality
15
- } = searchFilter || {}
15
+ } = searchFilter ?? {
16
+ gender: [],
17
+ desc: null,
18
+ speciality: []
19
+ }
16
20
  const {
17
21
  data,
18
22
  loading,
@@ -41,4 +45,4 @@ export const useCatWithProduct = ({
41
45
  totalCount
42
46
  }
43
47
  ]
44
- }
48
+ }
@@ -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 = ({ sendNotification = () => { } } = {}) => {
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 || 'Operación exitosa',
88
+ message: msgSuccess ?? 'Operación exitosa',
82
89
  description: 'Operación exitosa',
83
90
  backgroundColor: 'success'
84
91
  })
@@ -1,4 +1,3 @@
1
- // Hola mundo
2
1
  export const useManageQueryParams = ({
3
2
  location = {
4
3
  query: {},
@@ -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(50)
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,
@@ -101,6 +101,8 @@ export const GET_ALL_PRODUCT_STORE = gql`
101
101
  pId
102
102
  sizeId #Talla
103
103
  colorId #Color
104
+ carProId #Categoria a la cual pertenece el producto
105
+ caId
104
106
  cId #Country
105
107
  dId #Department
106
108
  ctId #Cuidad
@@ -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
- checkedItems,
75
- disabledItems,
76
- setCheckedItems,
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)
@@ -138,7 +137,7 @@ export const useSales = ({
138
137
  const [productFoodsOne, { data: dataProduct }] = useLazyQuery(
139
138
  GET_ONE_PRODUCTS_FOOD
140
139
  )
141
- const [ExtProductFoodsSubOptionalAll] = useLazyQuery(
140
+ const [ExtProductFoodsSubOptionalAll, { loading: loadingExtProductFoodsSubOptionalAll }] = useLazyQuery(
142
141
  GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
143
142
  {
144
143
  onError: () => {
@@ -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: arr || [],
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,7 +300,9 @@ export const useSales = ({
285
300
  return handleChangeNumber(state, action)
286
301
  }
287
302
  case 'REMOVE_ALL_PRODUCTS':
303
+ // @ts-ignore
288
304
  setValues({
305
+ ...values,
289
306
  comment: '',
290
307
  change: '',
291
308
  valueDelivery: ''
@@ -355,6 +372,7 @@ export const useSales = ({
355
372
  title: 'Comentario eliminado',
356
373
  description: 'Has eliminado el comentario!'
357
374
  })
375
+ // @ts-ignore
358
376
  return dispatch({
359
377
  type: 'PUT_COMMENT',
360
378
  payload: pId,
@@ -362,31 +380,41 @@ export const useSales = ({
362
380
  })
363
381
  }, [])
364
382
  useEffect(() => {
383
+ // @ts-ignore
365
384
  Cookies.set(keyToSaveData, JSON.stringify(data), { domain, path: '/' })
366
385
  }, [data, domain])
367
386
 
368
387
  const handleAddOptional = ({ exOptional = null, codeCategory = null }) => {
369
388
  if (!exOptional || !codeCategory) return
389
+ // @ts-ignore
370
390
  const item = dataOptional.find((item) => item.code === codeCategory)
371
391
  if (!item) return
392
+ // @ts-ignore
372
393
  const idx = item.ExtProductFoodsSubOptionalAll.findIndex(
373
394
  (el) => el.opSubExPid === exOptional
374
395
  )
375
396
  if (item && idx !== -1) {
376
397
  const updatedItem = {
398
+ // @ts-ignore
377
399
  ...item,
378
400
  ExtProductFoodsSubOptionalAll: [
401
+ // @ts-ignore
379
402
  ...item.ExtProductFoodsSubOptionalAll.slice(0, idx),
380
403
  {
404
+ // @ts-ignore
381
405
  ...item.ExtProductFoodsSubOptionalAll[idx],
406
+ // @ts-ignore
382
407
  check: !item.ExtProductFoodsSubOptionalAll[idx].check
383
408
  },
409
+ // @ts-ignore
384
410
  ...item.ExtProductFoodsSubOptionalAll.slice(idx + 1)
385
411
  ]
386
412
  }
387
413
  const newData = dataOptional.map((el) =>
414
+ // @ts-ignore
388
415
  el.code === codeCategory ? updatedItem : el
389
416
  )
417
+ // @ts-ignore
390
418
  setDataOptional(() => [...newData])
391
419
  }
392
420
  }
@@ -414,6 +442,7 @@ export const useSales = ({
414
442
  const arr =
415
443
  dataExtra?.length > 0
416
444
  ? dataExtra?.filter((p) => {
445
+ // @ts-ignore
417
446
  return p.quantity !== 0
418
447
  })
419
448
  : []
@@ -448,6 +477,7 @@ export const useSales = ({
448
477
  }
449
478
  const filteredDataOptional = dataOptional
450
479
  .map((obj) => {
480
+ // @ts-ignore
451
481
  const filteredSubOptions = obj?.ExtProductFoodsSubOptionalAll?.filter(
452
482
  (subObj) => subObj?.check === true
453
483
  )
@@ -455,17 +485,30 @@ export const useSales = ({
455
485
  if (filteredSubOptions?.length === 0) {
456
486
  return null
457
487
  }
488
+ // @ts-ignore
458
489
  return { ...obj, ExtProductFoodsSubOptionalAll: filteredSubOptions }
459
490
  })
460
491
  .filter((obj) => obj !== null) // Elimine todos los objetos nulos del arreglo
492
+ // @ts-ignore
461
493
  const filteredDataExtra = dataExtra?.filter((p) => p?.quantity !== undefined && p?.quantity !== 0)
462
494
  if (product?.PRODUCT?.pId) {
495
+ // @ts-ignore
463
496
  dispatch({
464
497
  type: 'PUT_EXTRA_PRODUCTS_AND_OPTIONAL_PRODUCT',
465
498
  payload: product.PRODUCT.pId,
466
499
  dataOptional: filteredDataOptional,
467
500
  dataExtra: filteredDataExtra
468
501
  })
502
+ const updatesOccurred = (
503
+ (dataExtra && dataExtra.length > 0)
504
+ )
505
+ if (updatesOccurred) {
506
+ return sendNotification({
507
+ title: 'Success',
508
+ backgroundColor: 'success',
509
+ description: 'Items subidos al producto'
510
+ })
511
+ }
469
512
  }
470
513
  } catch (_error) {
471
514
  return sendNotification({
@@ -476,18 +519,23 @@ export const useSales = ({
476
519
  }
477
520
  }
478
521
 
522
+ // @ts-ignore
479
523
  function handleIncrementExtra ({ Adicionales, index }) {
480
524
  const { pId } = product?.PRODUCT || {}
481
525
  const exPid = Adicionales?.exPid || null
482
526
 
483
527
  if (exPid && pId) {
484
528
  const newExtra = dataExtra.map((producto) => {
529
+ // @ts-ignore
485
530
  if (exPid === producto.exPid) {
531
+ // @ts-ignore
486
532
  const initialQuantity = producto?.quantity ? producto?.quantity : 0
487
533
  const newQuantity = initialQuantity + 1
534
+ // @ts-ignore
488
535
  const newExtraPrice = producto.extraPrice * newQuantity
489
536
 
490
537
  return {
538
+ // @ts-ignore
491
539
  ...producto,
492
540
  quantity: newQuantity,
493
541
  newExtraPrice
@@ -496,22 +544,27 @@ export const useSales = ({
496
544
  return producto
497
545
  })
498
546
 
547
+ // @ts-ignore
499
548
  setDataExtra(newExtra)
500
549
  }
501
550
  }
502
551
 
552
+ // @ts-ignore
503
553
  function handleDecrementExtra ({ Adicionales, index }) {
504
554
  const { pId } = product?.PRODUCT || {}
505
555
  const exPid = Adicionales?.exPid || null
506
556
 
507
557
  // Comprobar que el objeto Adicionales existe en dataExtra
558
+ // @ts-ignore
508
559
  const extraIndex = dataExtra.findIndex((extra) => extra.exPid === exPid)
509
560
  if (extraIndex === -1) {
510
561
  return
511
562
  }
512
563
 
513
564
  if (pId && exPid && extraIndex !== -1) {
565
+ // @ts-ignore
514
566
  const newExtra = dataExtra.map((producto, i) => {
567
+ // @ts-ignore
515
568
  if (exPid === producto.exPid) {
516
569
  // Desestructura la cantidad y el precio extra del producto o establece valores predeterminados
517
570
  const { quantity = 0, extraPrice = 0 } = producto
@@ -523,6 +576,7 @@ export const useSales = ({
523
576
  const newExtraPrice = newQuantity === 0 ? extraPrice : extraPrice * newQuantity
524
577
 
525
578
  return {
579
+ // @ts-ignore
526
580
  ...producto,
527
581
  quantity: newQuantity,
528
582
  newExtraPrice
@@ -532,21 +586,11 @@ export const useSales = ({
532
586
  })
533
587
 
534
588
  // Actualiza el estado de dataExtra con el nuevo array
589
+ // @ts-ignore
535
590
  setDataExtra(newExtra)
536
591
  }
537
592
  }
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
- */
593
+
550
594
  function addToCartFunc (state, action) {
551
595
  const {
552
596
  pId,
@@ -809,6 +853,7 @@ export const useSales = ({
809
853
  })
810
854
  }
811
855
  const decimal = parseFloat(percentage) / 100
856
+ // @ts-ignore
812
857
  const result = decimal * parseFloat(totalProductPrice)
813
858
  setDiscount({ price: result, discount: percentage })
814
859
 
@@ -819,6 +864,7 @@ export const useSales = ({
819
864
  const { getOnePedidoStore } = useGetSale()
820
865
 
821
866
  const handleSubmit = () => {
867
+ // @ts-ignore
822
868
  if (errors?.change || errors?.valueDelivery) {
823
869
  return sendNotification({
824
870
  title: 'error',
@@ -828,6 +874,7 @@ export const useSales = ({
828
874
  }
829
875
  setLoadingSale(true)
830
876
  const code = RandomCode(10)
877
+ // @ts-ignore
831
878
  setCode(code)
832
879
  function convertInteger (cadena) {
833
880
  if (typeof cadena === 'string') {
@@ -859,6 +906,7 @@ export const useSales = ({
859
906
  client.query({
860
907
  query: GET_ALL_COUNT_SALES,
861
908
  fetchPolicy: 'network-only',
909
+ // @ts-ignore
862
910
  onCompleted: (data) => {
863
911
  client.writeQuery({ query: GET_ALL_COUNT_SALES, data: { getTodaySales: data.countSales.todaySales } })
864
912
  }
@@ -1027,10 +1075,49 @@ export const useSales = ({
1027
1075
  }
1028
1076
  }
1029
1077
  const handleCleanFilter = () => {
1078
+ // @ts-ignore
1030
1079
  setValues({})
1031
1080
  setValuesDates({ fromDate: yearMonthDay, toDate: '' })
1032
1081
  }
1033
- const disabledModalItems = dataOptional?.length > 0 || dataExtra?.length > 0
1082
+
1083
+ const disabledModalItems = (dataOptional?.length > 0 || dataExtra?.length > 0) && !loadingExtProductFoodsSubOptionalAll
1084
+ /**
1085
+ * Filter products by carProId.
1086
+ * @param {Array} products - Array of products to filter.
1087
+ * @param {Array} carProIds - Array of carProId to filter by.
1088
+ * @returns {Array} - Filtered array of products or all products if no matches found.
1089
+ */
1090
+ function filterProductsByCarProId (products, carProIds) {
1091
+ if (!Array.isArray(products)) {
1092
+ return []
1093
+ }
1094
+
1095
+ if (!Array.isArray(carProIds) || carProIds.length === 0) {
1096
+ return products
1097
+ }
1098
+
1099
+ return products.filter(product => carProIds.includes(product.carProId))
1100
+ }
1101
+
1102
+ /**
1103
+ * Filter objects with checked property equal to true.
1104
+ * @param {Array} products - Array of objects.
1105
+ * @returns {Array} - Array of objects with checked property equal to true.
1106
+ */
1107
+ function filterChecked (products) {
1108
+ if (!Array.isArray(products)) {
1109
+ return []
1110
+ }
1111
+
1112
+ return products.filter(product => product?.checked === true).map(product => product.carProId)
1113
+ }
1114
+
1115
+ // Obtener los carProIds de productos con checked en true
1116
+ const carProIds = filterChecked(categories)
1117
+
1118
+ // Filtrar los productos de productsFood por los carProIds obtenidos
1119
+ const filteredProducts = filterProductsByCarProId(productsFood, carProIds)
1120
+
1034
1121
  return {
1035
1122
  loading: loading || loadingSale,
1036
1123
  loadingExtraProduct,
@@ -1055,7 +1142,7 @@ export const useSales = ({
1055
1142
  search,
1056
1143
  values,
1057
1144
  initialStateSales,
1058
- productsFood,
1145
+ productsFood: filteredProducts,
1059
1146
  modalItem,
1060
1147
  sumExtraProducts,
1061
1148
  oneProductToComment: oneProductToComment ?? null,
@@ -1064,10 +1151,8 @@ export const useSales = ({
1064
1151
  dataExtra: dataExtra || [],
1065
1152
  fetchMore,
1066
1153
  discount,
1067
- checkedItems,
1068
- datCat,
1069
- disabledItems,
1070
- setCheckedItems,
1154
+ datCat: categories,
1155
+ loadingProduct: loading,
1071
1156
  handleChangeCheck,
1072
1157
  errors,
1073
1158
  handleUpdateAllExtra,
package/src/index.jsx CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './hooks/index'
2
2
  export * from './utils'
3
3
  export * from './cookies'
4
- export * from './security'
4
+ export * from './security/index'
@@ -0,0 +1 @@
1
+ export const future = null