npm-pkg-hook 1.1.5 → 1.1.8

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.
Files changed (140) hide show
  1. package/.eslintrc.js +19 -113
  2. package/.eslintrc.json +127 -108
  3. package/next.config.js +2 -5
  4. package/package.json +27 -24
  5. package/src/config/client/errors.js +14 -14
  6. package/src/config/client/index.js +1 -1
  7. package/src/hooks/getCategoriesWithProduct/helpers/index.js +7 -0
  8. package/src/hooks/getCategoriesWithProduct/index.js +62 -0
  9. package/src/hooks/getSession/index.js +18 -18
  10. package/src/hooks/index.js +13 -9
  11. package/src/hooks/useAcumulateDate/index.js +1 -1
  12. package/src/hooks/useAnimationFrame/index.js +45 -45
  13. package/src/hooks/useAsideCart/helpers/index.js +22 -0
  14. package/src/hooks/useAsideCart/index.js +156 -0
  15. package/src/hooks/useAsideCart/queries.js +10 -0
  16. package/src/hooks/useBanner/index.js +11 -11
  17. package/src/hooks/useCart/index.js +2 -0
  18. package/src/hooks/useCart/queries.js +164 -0
  19. package/src/hooks/useCart/useCart/helpers/index.js +75 -0
  20. package/src/hooks/useCart/useCart/index.js +411 -0
  21. package/src/hooks/useCart/useGetCart/index.js +31 -0
  22. package/src/hooks/useCatWithProduct/index.js +15 -15
  23. package/src/hooks/useCatWithProduct/queries.js +1 -1
  24. package/src/hooks/useCatWithProductClient/index.js +48 -0
  25. package/src/hooks/useCatWithProductClient/queries.js +55 -0
  26. package/src/hooks/useCategoriesProduct/index.js +12 -12
  27. package/src/hooks/useCategoriesProduct/queries.js +16 -16
  28. package/src/hooks/useCategoryInStore/index.js +39 -36
  29. package/src/hooks/useCategoryInStore/queries.js +78 -78
  30. package/src/hooks/useCategoryStore/index.js +2 -2
  31. package/src/hooks/useChartData/index.js +159 -156
  32. package/src/hooks/useChartData/useChartData/index.js +199 -197
  33. package/src/hooks/useChartData/useChartDataAllOrders/index.js +94 -94
  34. package/src/hooks/useCheckbox/index.js +115 -115
  35. package/src/hooks/useClients/index.js +12 -14
  36. package/src/hooks/useClients/queries.js +1 -1
  37. package/src/hooks/useConnection/index.js +20 -21
  38. package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +6 -2
  39. package/src/hooks/useCreateProduct/index.js +22 -19
  40. package/src/hooks/useDeleteSubProductOptional/index.js +31 -30
  41. package/src/hooks/useDeleteSubProductOptional/queries.js +10 -10
  42. package/src/hooks/useDessert/helpers/index.js +51 -51
  43. package/src/hooks/useDessert/index.js +56 -65
  44. package/src/hooks/useDevices/index.js +35 -36
  45. package/src/hooks/useDevices/queries.js +19 -19
  46. package/src/hooks/useDropzone/index.js +94 -79
  47. package/src/hooks/useDynamicAuth/index.js +13 -13
  48. package/src/hooks/useDynamicAuth/queries.js +24 -24
  49. package/src/hooks/useEmployee/queries.js +1 -1
  50. package/src/hooks/useEvent/index.js +33 -33
  51. package/src/hooks/useFavoriteStores/index.js +19 -0
  52. package/src/hooks/useFavoriteStores/queries.js +47 -0
  53. package/src/hooks/useFetchJson/index.js +25 -25
  54. package/src/hooks/useFingerprintjs/index.js +172 -176
  55. package/src/hooks/useFormTools/index.js +12 -11
  56. package/src/hooks/useFormatDate/index.js +20 -21
  57. package/src/hooks/useFormatNumberPhone/index.js +9 -9
  58. package/src/hooks/useFullScreenMode/index.js +65 -65
  59. package/src/hooks/useGenerateNumberArray/index.js +17 -17
  60. package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.js +14 -0
  61. package/src/hooks/useGetFoodRecomended/index.js +33 -0
  62. package/src/hooks/useGetFoodRecomended/queries.js +47 -0
  63. package/src/hooks/useGetMinPrice/index.js +8 -0
  64. package/src/hooks/useGetMinPrice/queries.js +7 -0
  65. package/src/hooks/useGetOneStoreRating/index.js +40 -0
  66. package/src/hooks/useGetOneStoreRating/queries.js +18 -0
  67. package/src/hooks/useGoogleLogin/index.js +160 -161
  68. package/src/hooks/useHover/index.js +29 -29
  69. package/src/hooks/useImageOptimization/index.js +15 -15
  70. package/src/hooks/useImageWeight/index.js +18 -19
  71. package/src/hooks/useImagesStore/index.js +139 -140
  72. package/src/hooks/useImagesStore/queries.js +19 -18
  73. package/src/hooks/useInnerHtml/index.js +39 -38
  74. package/src/hooks/useIntersection/index.js +4 -4
  75. package/src/hooks/useKeypress/index.js +28 -28
  76. package/src/hooks/useLazyScript/index.js +35 -36
  77. package/src/hooks/useLocalSorage/index.js +2 -2
  78. package/src/hooks/useLogout/index.js +23 -23
  79. package/src/hooks/useManageQueryParams/index.js +36 -37
  80. package/src/hooks/useMobile/index.js +39 -38
  81. package/src/hooks/useMutateHeight/index.js +15 -16
  82. package/src/hooks/useOrderClient/index.js +5 -0
  83. package/src/hooks/useOrders/index.js +10 -16
  84. package/src/hooks/useOrders/queries.js +1 -1
  85. package/src/hooks/useProductsFood/index.js +32 -32
  86. package/src/hooks/useProductsFood/queriesStore.js +49 -48
  87. package/src/hooks/useProductsFood/useEditProduct.js +2 -4
  88. package/src/hooks/useProductsFood/usetagsProducts.js +83 -83
  89. package/src/hooks/useProviders/index.js +3 -3
  90. package/src/hooks/useProviders/queries.js +31 -31
  91. package/src/hooks/useProviders/useProvidersCreateStore/index.js +12 -13
  92. package/src/hooks/useProviders/useProvidersDataStore/index.js +24 -24
  93. package/src/hooks/useProvidersStore/index.js +24 -24
  94. package/src/hooks/useProvidersStore/queries.js +31 -31
  95. package/src/hooks/useRatingArrayData/index.js +54 -0
  96. package/src/hooks/{useRatingData → useRatingArrayData}/queries.js +19 -18
  97. package/src/hooks/useReactToPrint/index.js +1120 -1098
  98. package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -23
  99. package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -48
  100. package/src/hooks/useReport/index.js +9 -9
  101. package/src/hooks/useReport/queries.js +1 -1
  102. package/src/hooks/useRestaurant/index.js +19 -19
  103. package/src/hooks/useRestaurant/queries.js +80 -80
  104. package/src/hooks/useSales/index.js +476 -451
  105. package/src/hooks/useSales/queries.js +14 -15
  106. package/src/hooks/useSales/useGetAllSales/index.js +25 -25
  107. package/src/hooks/useSales/useTotalSales.js +18 -18
  108. package/src/hooks/useSaveAvailableProduct/helpers/index.js +29 -29
  109. package/src/hooks/useSaveAvailableProduct/index.js +16 -16
  110. package/src/hooks/useSaveAvailableProduct/queries.js +1 -1
  111. package/src/hooks/useSchedule/index.js +33 -36
  112. package/src/hooks/useSchedule/index.jsx +22 -22
  113. package/src/hooks/useSchedule/queries.js +34 -35
  114. package/src/hooks/useScheduleData/index.js +123 -171
  115. package/src/hooks/useScroll/index.js +56 -57
  116. package/src/hooks/useScrollRotate/index.js +16 -14
  117. package/src/hooks/useSetSession/index.js +16 -16
  118. package/src/hooks/useSetState/index.js +3 -3
  119. package/src/hooks/useStatusOpenStore/helpers/index.js +101 -102
  120. package/src/hooks/useStatusOpenStore/index.js +172 -173
  121. package/src/hooks/useStatusOrdersClient/helpers/index.js +14 -0
  122. package/src/hooks/useStatusOrdersClient/index.js +17 -0
  123. package/src/hooks/useStatusOrdersClient/queries.js +80 -0
  124. package/src/hooks/useStore/index.js +40 -25
  125. package/src/hooks/useStore/queries.js +162 -136
  126. package/src/hooks/useStoreCalendar/index.js +5 -7
  127. package/src/hooks/useStoreContacts/index.js +16 -16
  128. package/src/hooks/useStoreContacts/queries.js +1 -1
  129. package/src/hooks/useTimeAgo/useTimeAgo.js +39 -39
  130. package/src/hooks/useUpdateCart/index.js +34 -28
  131. package/src/hooks/useUpdateExistingOrders/index.js +35 -35
  132. package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +38 -37
  133. package/src/hooks/useUser/index.js +1 -1
  134. package/src/hooks/useUser/queries.js +1 -1
  135. package/src/hooks/useWindowSize/index.js +38 -38
  136. package/src/mock/dessert/index.js +16 -16
  137. package/src/mock/index.js +1 -2
  138. package/src/utils/index.js +42 -45
  139. package/src/hooks/useRatingData/index.js +0 -53
  140. package/src/hooks/useSalesClient/index.js +0 -1
@@ -1,102 +1,101 @@
1
- export const getDayFromOpeningKey = (key) => {
2
- const days = {
3
- openingSun: 0,
4
- openingMon: 1,
5
- openingTue: 2,
6
- openingWed: 3,
7
- openingThu: 4,
8
- openingFri: 5,
9
- openingSat: 6
10
- };
11
- return days[key] !== undefined ? days[key] : -1
12
- }
13
-
14
- // Función para convertir el objeto de tiempo en una cadena de tiempo
15
- export function getTimeString(timeStr) {
16
- return timeStr || '00:00'; // Return '00:00' for empty time strings
17
- }
18
-
19
-
20
- export function getCurrentDayAndTime() {
21
- try {
22
- const date = new Date();
23
- const currentTime = date.getHours() * 60 + date.getMinutes();
24
- const currentDayOfWeek = date.getDay();
25
- return { currentTime, currentDayOfWeek };
26
- } catch (error) {
27
- return {
28
-
29
- }
30
- }
31
- }
32
-
33
- export function getTimeObject(timeStr) {
34
- try {
35
- if (!timeStr || !/\d{2}:\d{2}/.test(timeStr)) {
36
- return { hours: 0, minutes: 0 }; // Return default values for invalid input
37
- }
38
- const [hours, minutes] = timeStr.split(':').map(str => parseInt(str));
39
- return { hours, minutes };
40
- } catch (e) {
41
- return { hours: 0, minutes: 0 }; // Return default values on error
42
- }
43
- }
44
-
45
- export function sortOpeningsByDay(openings) {
46
- const days = [
47
- 'openingSun',
48
- 'openingMon',
49
- 'openingTue',
50
- 'openingWed',
51
- 'openingThu',
52
- 'openingFri',
53
- 'openingSat'
54
- ]
55
- const sortedOpenings = {};
56
-
57
- days.forEach((day) => {
58
- sortedOpenings[day] = openings[day] || '00:00 - 00:00'; // Agregar horario vacío para los días faltantes
59
- });
60
-
61
- return sortedOpenings;
62
- }
63
-
64
- // Función para obtener la clave de openings a partir del día de la semana
65
- export function getOpeningKeyFromDay(day) {
66
- const days = {
67
- 0: 'openingSun',
68
- 1: 'openingMon',
69
- 2: 'openingTue',
70
- 3: 'openingWed',
71
- 4: 'openingThu',
72
- 5: 'openingFri',
73
- 6: 'openingSat'
74
- };
75
- return days[day];
76
- }
77
-
78
- export const weekDays = [
79
- 'Domingo',
80
- 'Lunes',
81
- 'Martes',
82
- 'Miércoles',
83
- 'Jueves',
84
- 'Viernes',
85
- 'Sábado'
86
- ]
87
-
88
- export function timeToInt(text) {
89
- let hour = parseInt(text.substring(0, 2));
90
- let minute = parseInt(text.substring(3));
91
- return hour * 60 + minute;
92
- }
93
-
94
- export const days = {
95
- Monday: 'Lunes',
96
- Tuesday: 'Martes',
97
- Wednesday: 'Miércoles',
98
- Thursday: 'Jueves',
99
- Friday: 'Viernes',
100
- Saturday: 'Sábado',
101
- Sunday: 'Domingo'
102
- };
1
+ export const getDayFromOpeningKey = (key) => {
2
+ const days = {
3
+ openingSun: 0,
4
+ openingMon: 1,
5
+ openingTue: 2,
6
+ openingWed: 3,
7
+ openingThu: 4,
8
+ openingFri: 5,
9
+ openingSat: 6
10
+ }
11
+ return days[key] !== undefined ? days[key] : -1
12
+ }
13
+
14
+ // Función para convertir el objeto de tiempo en una cadena de tiempo
15
+ export function getTimeString (timeStr) {
16
+ return timeStr || '00:00' // Return '00:00' for empty time strings
17
+ }
18
+
19
+ export function getCurrentDayAndTime () {
20
+ try {
21
+ const date = new Date()
22
+ const currentTime = date.getHours() * 60 + date.getMinutes()
23
+ const currentDayOfWeek = date.getDay()
24
+ return { currentTime, currentDayOfWeek }
25
+ } catch (error) {
26
+ return {
27
+
28
+ }
29
+ }
30
+ }
31
+
32
+ export function getTimeObject (timeStr) {
33
+ try {
34
+ if (!timeStr || !/\d{2}:\d{2}/.test(timeStr)) {
35
+ return { hours: 0, minutes: 0 } // Return default values for invalid input
36
+ }
37
+ const [hours, minutes] = timeStr.split(':').map(str => parseInt(str))
38
+ return { hours, minutes }
39
+ } catch (e) {
40
+ return { hours: 0, minutes: 0 } // Return default values on error
41
+ }
42
+ }
43
+
44
+ export function sortOpeningsByDay (openings) {
45
+ const days = [
46
+ 'openingSun',
47
+ 'openingMon',
48
+ 'openingTue',
49
+ 'openingWed',
50
+ 'openingThu',
51
+ 'openingFri',
52
+ 'openingSat'
53
+ ]
54
+ const sortedOpenings = {}
55
+
56
+ days.forEach((day) => {
57
+ sortedOpenings[day] = openings[day] || '00:00 - 00:00' // Agregar horario vacío para los días faltantes
58
+ })
59
+
60
+ return sortedOpenings
61
+ }
62
+
63
+ // Función para obtener la clave de openings a partir del día de la semana
64
+ export function getOpeningKeyFromDay (day) {
65
+ const days = {
66
+ 0: 'openingSun',
67
+ 1: 'openingMon',
68
+ 2: 'openingTue',
69
+ 3: 'openingWed',
70
+ 4: 'openingThu',
71
+ 5: 'openingFri',
72
+ 6: 'openingSat'
73
+ }
74
+ return days[day]
75
+ }
76
+
77
+ export const weekDays = [
78
+ 'Domingo',
79
+ 'Lunes',
80
+ 'Martes',
81
+ 'Miércoles',
82
+ 'Jueves',
83
+ 'Viernes',
84
+ 'Sábado'
85
+ ]
86
+
87
+ export function timeToInt (text) {
88
+ const hour = parseInt(text.substring(0, 2))
89
+ const minute = parseInt(text.substring(3))
90
+ return hour * 60 + minute
91
+ }
92
+
93
+ export const days = {
94
+ Monday: 'Lunes',
95
+ Tuesday: 'Martes',
96
+ Wednesday: 'Miércoles',
97
+ Thursday: 'Jueves',
98
+ Friday: 'Viernes',
99
+ Saturday: 'Sábado',
100
+ Sunday: 'Domingo'
101
+ }
@@ -1,173 +1,172 @@
1
- import { useEffect, useState } from 'react'
2
- import {
3
- getDayFromOpeningKey,
4
- getCurrentDayAndTime,
5
- getOpeningKeyFromDay,
6
- getTimeString,
7
- sortOpeningsByDay,
8
- weekDays,
9
- timeToInt,
10
- days,
11
- getTimeObject
12
- } from './helpers';
13
- import { useFormatDate } from '../useFormatDate';
14
-
15
- export const useStatusOpenStore = ({ dataSchedules = [] } = {}) => {
16
- const [open, setOpen] = useState('')
17
- const [openNow, setOpenNow] = useState(false)
18
- const { handleHourPmAM } = useFormatDate({})
19
-
20
- const handleMessageHour = (message, open) => {
21
- setOpen(message)
22
- setOpenNow(open)
23
- }
24
-
25
- function getNextDaySchedule(dataSchedules, currentDayOfWeek) {
26
- const today = new Date();
27
- const tomorrow = new Date(today);
28
- tomorrow.setDate(today.getDate() + 1);
29
- const dayOfWeekTomorrow = tomorrow.getDay();
30
-
31
- const findNextDay = dataSchedules?.length
32
- ? dataSchedules?.some((schedule) => schedule?.schDay === dayOfWeekTomorrow)
33
- : false;
34
-
35
- const findDataNextDay = dataSchedules?.length
36
- ? dataSchedules?.find((schedule) => schedule?.schDay === dayOfWeekTomorrow)
37
- : {};
38
-
39
- return { findNextDay, findDataNextDay, dayOfWeekTomorrow };
40
- }
41
-
42
- function getOpeningStatus(openings, currentTime, currentDayOfWeek) {
43
- const weekDayLookup = [
44
- 'Sunday',
45
- 'Monday',
46
- 'Tuesday',
47
- 'Wednesday',
48
- 'Thursday',
49
- 'Friday',
50
- 'Saturday',
51
- ];
52
-
53
- const ceroHours = '00:00 - 00:00';
54
- let dayOfWeek = currentDayOfWeek;
55
-
56
- for (let i = 0; i < 7; i++) {
57
- const dayName = weekDayLookup[dayOfWeek % 7];
58
- const opening = openings && openings['opening' + dayName.substring(0, 3)];
59
- const timeSpans = opening?.split(';').map((item) => item.trim());
60
-
61
- for (let span of timeSpans) {
62
- const hours = span.split('-').map((item) => item.trim());
63
- const openTime = timeToInt(hours[0]);
64
- const closeTime = timeToInt(hours[1]);
65
-
66
- if (currentTime >= openTime && currentTime <= closeTime) {
67
- return handleMessageHour(
68
- 'Abierto Ahora - Cierra a las: ' + handleHourPmAM(hours[1]),
69
- true
70
- );
71
- }
72
-
73
- if (currentTime < openTime && dayOfWeek === currentDayOfWeek) {
74
- return handleMessageHour(
75
- 'Aun temprano - Abre hoy a las: ' + handleHourPmAM(hours[0]),
76
- false
77
- );
78
- }
79
-
80
- if (currentTime >= closeTime - 30 * 60000 && currentTime < closeTime && dayOfWeek === currentDayOfWeek) {
81
- return handleMessageHour(
82
- 'Pronto por cerrar - Cierra hoy a las: ' + handleHourPmAM(hours[1]),
83
- true
84
- );
85
- }
86
-
87
- const { findNextDay, findDataNextDay, dayOfWeekTomorrow } = getNextDaySchedule(
88
- dataSchedules,
89
- currentDayOfWeek
90
- );
91
-
92
- if (findNextDay && findDataNextDay?.schHoSta) {
93
- const nameOfDayTomorrow = weekDays[dayOfWeekTomorrow];
94
- return handleMessageHour(
95
- `Cerrado - Mañana ${nameOfDayTomorrow} ${!!findDataNextDay?.schHoSta && 'a las'} ${
96
- !!findDataNextDay?.schHoSta ? findDataNextDay?.schHoSta : ''
97
- }`,
98
- false
99
- );
100
- }
101
-
102
- const nextDayName = weekDayLookup[(dayOfWeek + 1) % 7];
103
- const nextOpening = openings && openings['opening' + nextDayName.substring(0, 3)];
104
- const nextHours = nextOpening?.split(';')?.map((item) => item?.trim());
105
-
106
- if (nextHours[0] !== ceroHours) {
107
- return handleMessageHour(
108
- 'Cerrado - Abre el ' + days[nextDayName] + ' a las ' + nextHours[0],
109
- false
110
- );
111
- }
112
- }
113
-
114
- dayOfWeek++;
115
- }
116
-
117
- return handleMessageHour('Cerrado', false);
118
- }
119
-
120
- function getIsOpening(openings) {
121
- const { currentTime, currentDayOfWeek } = getCurrentDayAndTime();
122
- return getOpeningStatus(openings, currentTime, currentDayOfWeek);
123
- }
124
-
125
-
126
- useEffect(() => {
127
- (() => {
128
- // Crear el objeto openings a partir del existStoreSchedule
129
- const openings = {};
130
- const existStoreSchedule = dataSchedules || []
131
- existStoreSchedule?.forEach((schedule) => {
132
- const day = schedule.schDay;
133
- const openingKey = getOpeningKeyFromDay(day);
134
- const schHoSta = getTimeString(schedule?.schHoSta);
135
- const schHoEnd = getTimeString(schedule?.schHoEnd);
136
- openings[openingKey] = `${schHoSta} - ${schHoEnd}`;
137
- });
138
-
139
- for (let i = 0; i < 7; i++) {
140
- const openingKey = getOpeningKeyFromDay(i);
141
- if (!openings.hasOwnProperty(openingKey)) {
142
- openings[openingKey] = '00:00 - 00:00'; // Horario vacío para el día faltante
143
- }
144
- }
145
-
146
-
147
- // Ejemplo de uso con el objeto proporcionado
148
- const sortedOpenings = sortOpeningsByDay(openings);
149
-
150
-
151
- // Crear el array completo con objetos de tiempo
152
- const fullArray = Object.keys(sortedOpenings).map((key) => {
153
- const day = getDayFromOpeningKey(key);
154
- const [schHoSta, schHoEnd] = openings[key].split(' - ').map(timeStr => getTimeObject(timeStr));
155
- return {
156
- "__typename": "StoreSchedule",
157
- "schId": "",
158
- "idStore": "",
159
- "schDay": day,
160
- "schHoSta": `${schHoSta?.hours?.toString().padStart(2, '0')}:${schHoSta?.minutes?.toString().padStart(2, '0')}`,
161
- "schHoEnd": `${schHoEnd?.hours?.toString().padStart(2, '0')}:${schHoEnd?.minutes?.toString().padStart(2, '0')}`,
162
- "schState": 1
163
- };
164
- })
165
- getIsOpening(sortedOpenings)
166
- })()
167
- }, [dataSchedules])
168
-
169
- return {
170
- open,
171
- openNow
172
- }
173
- }
1
+ import { useEffect, useState } from 'react'
2
+ import {
3
+ getDayFromOpeningKey,
4
+ getCurrentDayAndTime,
5
+ getOpeningKeyFromDay,
6
+ getTimeString,
7
+ sortOpeningsByDay,
8
+ weekDays,
9
+ timeToInt,
10
+ days,
11
+ getTimeObject
12
+ } from './helpers'
13
+ import { useFormatDate } from '../useFormatDate'
14
+
15
+ export const useStatusOpenStore = ({ dataSchedules = [] } = {}) => {
16
+ const [open, setOpen] = useState('')
17
+ const [openNow, setOpenNow] = useState(false)
18
+ const { handleHourPmAM } = useFormatDate({})
19
+
20
+ const handleMessageHour = (message, open) => {
21
+ setOpen(message)
22
+ setOpenNow(open)
23
+ }
24
+
25
+ function getNextDaySchedule (dataSchedules, currentDayOfWeek) {
26
+ const today = new Date()
27
+ const tomorrow = new Date(today)
28
+ tomorrow.setDate(today.getDate() + 1)
29
+ const dayOfWeekTomorrow = tomorrow.getDay()
30
+
31
+ const findNextDay = dataSchedules?.length
32
+ ? dataSchedules?.some((schedule) => schedule?.schDay === dayOfWeekTomorrow)
33
+ : false
34
+
35
+ const findDataNextDay = dataSchedules?.length
36
+ ? dataSchedules?.find((schedule) => schedule?.schDay === dayOfWeekTomorrow)
37
+ : {}
38
+
39
+ return { findNextDay, findDataNextDay, dayOfWeekTomorrow }
40
+ }
41
+
42
+ function getOpeningStatus (openings, currentTime, currentDayOfWeek) {
43
+ const weekDayLookup = [
44
+ 'Sunday',
45
+ 'Monday',
46
+ 'Tuesday',
47
+ 'Wednesday',
48
+ 'Thursday',
49
+ 'Friday',
50
+ 'Saturday'
51
+ ]
52
+
53
+ const ceroHours = '00:00 - 00:00'
54
+ let dayOfWeek = currentDayOfWeek
55
+
56
+ for (let i = 0; i < 7; i++) {
57
+ const dayName = weekDayLookup[dayOfWeek % 7]
58
+ const opening = openings && openings['opening' + dayName.substring(0, 3)]
59
+ const timeSpans = opening?.split(';').map((item) => item.trim())
60
+
61
+ for (const span of timeSpans) {
62
+ const hours = span.split('-').map((item) => item.trim())
63
+ const openTime = timeToInt(hours[0])
64
+ const closeTime = timeToInt(hours[1])
65
+
66
+ if (currentTime >= openTime && currentTime <= closeTime) {
67
+ return handleMessageHour(
68
+ 'Abierto Ahora - Cierra a las: ' + handleHourPmAM(hours[1]),
69
+ true
70
+ )
71
+ }
72
+
73
+ if (currentTime < openTime && dayOfWeek === currentDayOfWeek) {
74
+ return handleMessageHour(
75
+ 'Aun temprano - Abre hoy a las: ' + handleHourPmAM(hours[0]),
76
+ false
77
+ )
78
+ }
79
+
80
+ if (currentTime >= closeTime - 30 * 60000 && currentTime < closeTime && dayOfWeek === currentDayOfWeek) {
81
+ return handleMessageHour(
82
+ 'Pronto por cerrar - Cierra hoy a las: ' + handleHourPmAM(hours[1]),
83
+ true
84
+ )
85
+ }
86
+
87
+ const { findNextDay, findDataNextDay, dayOfWeekTomorrow } = getNextDaySchedule(
88
+ dataSchedules,
89
+ currentDayOfWeek
90
+ )
91
+
92
+ if (findNextDay && findDataNextDay?.schHoSta) {
93
+ const nameOfDayTomorrow = weekDays[dayOfWeekTomorrow]
94
+ return handleMessageHour(
95
+ `Cerrado - Mañana ${nameOfDayTomorrow} ${!!findDataNextDay?.schHoSta && 'a las'} ${
96
+ findDataNextDay?.schHoSta ? findDataNextDay?.schHoSta : ''
97
+ }`,
98
+ false
99
+ )
100
+ }
101
+
102
+ const nextDayName = weekDayLookup[(dayOfWeek + 1) % 7]
103
+ const nextOpening = openings && openings['opening' + nextDayName.substring(0, 3)]
104
+ const nextHours = nextOpening?.split(';')?.map((item) => item?.trim())
105
+
106
+ if (nextHours[0] !== ceroHours) {
107
+ return handleMessageHour(
108
+ 'Cerrado - Abre el ' + days[nextDayName] + ' a las ' + nextHours[0],
109
+ false
110
+ )
111
+ }
112
+ }
113
+
114
+ dayOfWeek++
115
+ }
116
+
117
+ return handleMessageHour('Cerrado', false)
118
+ }
119
+
120
+ function getIsOpening (openings) {
121
+ const { currentTime, currentDayOfWeek } = getCurrentDayAndTime()
122
+ return getOpeningStatus(openings, currentTime, currentDayOfWeek)
123
+ }
124
+
125
+ useEffect(() => {
126
+ (() => {
127
+ // Crear el objeto openings a partir del existStoreSchedule
128
+ const openings = {}
129
+ const existStoreSchedule = dataSchedules || []
130
+ existStoreSchedule?.forEach((schedule) => {
131
+ const day = schedule.schDay
132
+ const openingKey = getOpeningKeyFromDay(day)
133
+ const schHoSta = getTimeString(schedule?.schHoSta)
134
+ const schHoEnd = getTimeString(schedule?.schHoEnd)
135
+ openings[openingKey] = `${schHoSta} - ${schHoEnd}`
136
+ })
137
+
138
+ for (let i = 0; i < 7; i++) {
139
+ const openingKey = getOpeningKeyFromDay(i)
140
+ // eslint-disable-next-line no-prototype-builtins
141
+ if (!openings.hasOwnProperty(openingKey)) {
142
+ openings[openingKey] = '00:00 - 00:00' // Horario vacío para el día faltante
143
+ }
144
+ }
145
+
146
+ // Ejemplo de uso con el objeto proporcionado
147
+ const sortedOpenings = sortOpeningsByDay(openings)
148
+
149
+ // Crear el array completo con objetos de tiempo
150
+ // eslint-disable-next-line no-unused-vars
151
+ const fullArray = Object.keys(sortedOpenings).map((key) => {
152
+ const day = getDayFromOpeningKey(key)
153
+ const [schHoSta, schHoEnd] = openings[key].split(' - ').map(timeStr => getTimeObject(timeStr))
154
+ return {
155
+ __typename: 'StoreSchedule',
156
+ schId: '',
157
+ idStore: '',
158
+ schDay: day,
159
+ schHoSta: `${schHoSta?.hours?.toString().padStart(2, '0')}:${schHoSta?.minutes?.toString().padStart(2, '0')}`,
160
+ schHoEnd: `${schHoEnd?.hours?.toString().padStart(2, '0')}:${schHoEnd?.minutes?.toString().padStart(2, '0')}`,
161
+ schState: 1
162
+ }
163
+ })
164
+ getIsOpening(sortedOpenings)
165
+ })()
166
+ }, [dataSchedules])
167
+
168
+ return {
169
+ open,
170
+ openNow
171
+ }
172
+ }
@@ -0,0 +1,14 @@
1
+ export const filterOrders = (orders = []) => {
2
+ const filteredOrders = orders?.filter((order) => {
3
+ if (order.pSState === 5) {
4
+ const tenMinutesAgo = new Date()
5
+ tenMinutesAgo.setMinutes(tenMinutesAgo.getMinutes() - 10)
6
+ const pDatMod = new Date(order.pDatMod)
7
+
8
+ return pDatMod > tenMinutesAgo
9
+ }
10
+ return true
11
+ })
12
+
13
+ return filteredOrders
14
+ }
@@ -0,0 +1,17 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { GET_ALL_PEDIDOS_STATUS } from './queries'
3
+ import { filterOrders } from './helpers'
4
+
5
+ export const useStatusOrdersClient = () => {
6
+ const { data, loading, error } = useQuery(GET_ALL_PEDIDOS_STATUS, {
7
+ pollInterval: 60000,
8
+ fetchPolicy: 'cache-and-network',
9
+ onError: () => {}
10
+ })
11
+
12
+ return {
13
+ data: loading ? [] : filterOrders(data?.getAllPedidoUserFinal || []),
14
+ loading,
15
+ error
16
+ }
17
+ }