npm-pkg-hook 1.6.8 → 1.7.0

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
@@ -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.6.8"
47
+ "version": "1.7.0"
48
48
  }
@@ -0,0 +1,22 @@
1
+ export const completeSchedules = (dataSchedules) => {
2
+ // Días de la semana
3
+ const daysSemana = ['Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado', 'Domingo']
4
+
5
+ // Mapear los horarios existentes para crear un mapa por día
6
+ const horariosPorDia = dataSchedules.reduce((mapa, horario) => {
7
+ const day = daysSemana[horario.schDay]
8
+ if (!mapa[day]) {
9
+ mapa[day] = []
10
+ }
11
+ mapa[day].push({ horaInicio: horario.schHoSta, horaFin: horario.schHoEnd })
12
+ return mapa
13
+ }, {})
14
+
15
+ // Completar los días que faltan y formatear el objeto
16
+ const horariosFormateados = daysSemana.map((day, index) => ({
17
+ day,
18
+ horarios: horariosPorDia[day] || [{ horaInicio: '', horaFin: '' }]
19
+ }))
20
+
21
+ return horariosFormateados
22
+ }
@@ -7,6 +7,7 @@ export * from './useCatWithProduct'
7
7
  export * from './useManageQueryParams'
8
8
  export * from './useDeliveryTime'
9
9
  export * from './statusOpenStores'
10
+ export * from './completeSchedules'
10
11
  export * from './useLogout/helpers/BroadcastChannel'
11
12
  export * from './newMessageSubscription'
12
13
  export * from './isTokenExpired'
@@ -13,32 +13,25 @@ import {
13
13
  } from './helpers'
14
14
  import { useManageQueryParams } from '../../useManageQueryParams'
15
15
 
16
- /**
17
- * Custom hook for managing cart functionality.
18
- *
19
- * @param {Object} options - Options object.
20
- * @param {Function} options.setAlertBox - Function to set an alert message.
21
- * @returns {Object} - Object containing cart state and functions.
22
- */
23
- /**
24
- * The `useCart` function is a custom hook in JavaScript that handles the management of a shopping
25
- * cart, including adding products, managing quantities, and handling optional extras.
26
- * @param [] - - `openModalProduct`: A boolean indicating whether the modal for the product is open or
27
- * not. Default value is `false`.
28
- * @returns The `useCart` function returns an object with the following properties and methods:
29
- */
30
16
  export const useCart = ({
31
- location = {},
17
+ location = {
18
+ push: (props, state, { shallow }) => {
19
+ return { ...props, state, shallow }
20
+ },
21
+ query: {
22
+ plato: ''
23
+ }
24
+ },
32
25
  openModalProduct = false,
33
- handleMenu = () => { },
34
- setOpenModalProduct = () => { },
35
- setAlertBox = () => { }
26
+ handleMenu = (number) => { return number },
27
+ setOpenModalProduct = (boolean) => { return boolean },
28
+ setAlertBox = (args) => { return args }
36
29
  } = {}) => {
37
30
  // sub products
38
31
  const { handleCleanQuery } = useManageQueryParams({
39
32
  location
40
33
  })
41
-
34
+ const [loadingButton, setLoadingButton] = useState(false)
42
35
  const [dataOptional, setDataOptional] = useState([])
43
36
  const [dataExtra, setDataExtra] = useState([])
44
37
  const [quantity, setQuantity] = useState(1)
@@ -62,8 +55,8 @@ export const useCart = ({
62
55
  ] = useGetOneProductsFood({ fetchOnlyProduct: true })
63
56
 
64
57
  const getOneProduct = async food => {
65
- const { pId, intoCart } = food || {}
66
- const isEditing = intoCart
58
+ const { pId } = food || {}
59
+
67
60
  if (!pId) return {}
68
61
  setOpenModalProduct(true)
69
62
  const product = await handleGetOneProduct({ variables: { pId } })
@@ -81,7 +74,7 @@ export const useCart = ({
81
74
  })
82
75
  const comments = matchingItemInShoppingCart?.comments
83
76
  if (comments) {
84
- setComments(comments || '')
77
+ setComments(comments)
85
78
  }
86
79
  const quantityProduct = matchingItemInShoppingCart?.cantProducts
87
80
  if (quantityProduct) {
@@ -170,7 +163,7 @@ export const useCart = ({
170
163
  }
171
164
  })
172
165
 
173
- setDataExtra(fetchedDataExtra || [])
166
+ setDataExtra(fetchedDataExtra)
174
167
  }
175
168
  }
176
169
 
@@ -310,13 +303,13 @@ export const useCart = ({
310
303
  *
311
304
  * @param {Object} food - The selected food item.
312
305
  */
313
-
314
306
  const handleAddProducts = async (food) => {
315
307
  if (!food) return
316
308
  const idStore = food?.getStore?.idStore
317
309
  if (!idStore) {
318
310
  return
319
311
  }
312
+ setLoadingButton(true)
320
313
  const isExistItemInShoppingCart = dataShoppingCard?.find((item) => {
321
314
  return item?.productFood && item?.productFood?.pId === food.pId
322
315
  }) ?? null
@@ -360,11 +353,18 @@ export const useCart = ({
360
353
  })
361
354
 
362
355
  if (response?.data) {
356
+ if (!idShoppingCart) {
357
+ setAlertBox({ message: 'producto agregado al carrito' })
358
+ }
359
+ if (idShoppingCart) {
360
+ setAlertBox({ message: 'producto actualizado' })
361
+ }
363
362
  // Perform actions after adding products to cart
364
363
  }
365
364
  } catch (error) {
366
365
  setAlertBox({ message: 'Ocurrió un error al añadir el producto al carrito' })
367
366
  }
367
+ setLoadingButton(false)
368
368
  }
369
369
 
370
370
  const handleShowModalProduct = () => {
@@ -394,6 +394,7 @@ export const useCart = ({
394
394
  comments,
395
395
  loading: loadingProduct || loading,
396
396
  dataOneProduct,
397
+ loadingButton,
397
398
  dataExtra,
398
399
  dataOptional,
399
400
  setQuantity,
@@ -19,15 +19,16 @@ export const useSchedule = ({ day = null, idStore = '' }) => {
19
19
  export const useSetScheduleOpenAll = () => {
20
20
  const [setStoreSchedule, { loading, error }] = useMutation(SET_STATUS_ALL_SCHEDULE_STORE, {
21
21
  onError: (e) => {
22
- console.error(e);
22
+ console.error(e)
23
23
  }
24
- });
24
+ })
25
25
 
26
26
  const handleSetStoreSchedule = (scheduleOpenAll) => {
27
27
  setStoreSchedule({
28
28
  variables: {
29
- scheduleOpenAll: scheduleOpenAll
30
- }, update: (cache, { data }) => {
29
+ scheduleOpenAll
30
+ },
31
+ update: (cache, { data }) => {
31
32
  const success = data?.setScheduleOpenAll?.success
32
33
  if (success) {
33
34
  cache.modify({
@@ -36,20 +37,19 @@ export const useSetScheduleOpenAll = () => {
36
37
  const store = readField('getStore')
37
38
  const updatedCart = {
38
39
  ...store,
39
- scheduleOpenAll: scheduleOpenAll
40
- }
41
- return updatedCart
40
+ scheduleOpenAll
41
+ }
42
+ return updatedCart
42
43
  }
43
44
  }
44
45
  })
45
46
  }
46
47
  }
47
- });
48
- };
49
-
50
- return [handleSetStoreSchedule, { loading, error }];
51
- };
48
+ })
49
+ }
52
50
 
51
+ return [handleSetStoreSchedule, { loading, error }]
52
+ }
53
53
 
54
54
  export const useSchedules = ({ schDay = 1, idStore = '' }) => {
55
55
  const {
@@ -16,8 +16,7 @@ export const useSchedules = ({ schDay = 1, idStore = '' }) => {
16
16
  data,
17
17
  loading,
18
18
  error
19
- } = useQuery(GET_SCHEDULE_STORE, { variables: { schDay: schDay, idStore } })
20
-
19
+ } = useQuery(GET_SCHEDULE_STORE, { variables: { schDay, idStore } })
21
20
 
22
21
  return [data?.getStoreSchedules, { loading, error }]
23
- }
22
+ }
@@ -42,7 +42,7 @@ export function useScheduleData (data) {
42
42
  * Calcula la duración en horas entre dos horas de inicio y final.
43
43
  * @param {string} startTime - Hora de inicio en formato 'HH:mm'.
44
44
  * @param {string} endTime - Hora de fin en formato 'HH:mm'.
45
- * @returns {number} Duración en horas con dos decimales.
45
+ * @returns {number|string} Duración en horas con dos decimales.
46
46
  */
47
47
 
48
48
  // Función para calcular la duración en horas de un horario