npm-pkg-hook 1.7.6 → 1.7.9
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 +1 -1
- package/src/hooks/convertToMilitaryTime/index.js +14 -0
- package/src/hooks/getTotalHours/index.js +48 -0
- package/src/hooks/index.js +4 -0
- package/src/hooks/useDessert/index.js +6 -5
- package/src/hooks/useMouse/index.ts +51 -0
- package/src/hooks/useProductsFood/index.js +10 -10
- package/src/hooks/useSales/helpers/index.js +23 -5
- package/src/hooks/useSales/index.js +3 -17
- package/src/hooks/useSchedule/index.js +8 -2
- package/src/hooks/useSetupSchedule/helpers/index.js +85 -0
- package/src/hooks/useSetupSchedule/index.js +230 -0
- package/src/utils/index.js +24 -0
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function convertToMilitaryTime (time12Hour) {
|
|
2
|
+
const [time, period] = time12Hour.split(' ')
|
|
3
|
+
let [hours, minutes] = time.split(':')
|
|
4
|
+
|
|
5
|
+
if (period === 'PM' && hours !== '12') {
|
|
6
|
+
hours = String(Number(hours) + 12)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (period === 'AM' && hours === '12') {
|
|
10
|
+
hours = '00'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return `${hours}:${minutes}`
|
|
14
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export const getTotalHours = (days) => {
|
|
2
|
+
const totalMinutesArray = days.map((day) => {
|
|
3
|
+
const { schHoSta, schHoEnd } = day
|
|
4
|
+
|
|
5
|
+
// Handle potential invalid time strings
|
|
6
|
+
if (!isValidTimeString(schHoSta) || !isValidTimeString(schHoEnd)) {
|
|
7
|
+
return 0 // Ignore invalid time strings and return 0
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const [startHours, startMinutes] = schHoSta.split(':')
|
|
11
|
+
const [endHours, endMinutes] = schHoEnd.split(':')
|
|
12
|
+
|
|
13
|
+
// Convert hours and minutes to integers for calculations
|
|
14
|
+
let totalHoursInt = parseInt(endHours, 10) - parseInt(startHours, 10)
|
|
15
|
+
const totalMinutesInt = parseInt(endMinutes, 10) - parseInt(startMinutes, 10)
|
|
16
|
+
|
|
17
|
+
// Handle negative total minutes (occurs when endMinutes < startMinutes)
|
|
18
|
+
let totalMinutes = totalMinutesInt
|
|
19
|
+
if (totalMinutes < 0) {
|
|
20
|
+
totalHoursInt-- // Decrement total hours for negative minutes
|
|
21
|
+
totalMinutes += 60 // Add 60 minutes to account for borrowing from previous hour
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Calculate total time in minutes
|
|
25
|
+
const totalTimeMinutes = totalHoursInt * 60 + totalMinutes
|
|
26
|
+
|
|
27
|
+
return totalTimeMinutes
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
// Calculate the sum of total minutes for all days
|
|
31
|
+
const totalMinutes = totalMinutesArray.reduce((acc, curr) => acc + curr, 0)
|
|
32
|
+
|
|
33
|
+
// Convert total minutes to hours and minutes format
|
|
34
|
+
const totalHours = Math.floor(totalMinutes / 60)
|
|
35
|
+
const remainingMinutes = totalMinutes % 60
|
|
36
|
+
|
|
37
|
+
// Format the total time as "00:00"
|
|
38
|
+
const formattedHours = totalHours.toString().padStart(2, '0')
|
|
39
|
+
const formattedMinutes = remainingMinutes.toString().padStart(2, '0')
|
|
40
|
+
|
|
41
|
+
return `${formattedHours}:${formattedMinutes}`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Function to validate time string format (HH:MM)
|
|
45
|
+
export const isValidTimeString = (timeString) => {
|
|
46
|
+
const timeRegex = /^([0-1][0-9]|2[0-3]):([0-5][0-9])$/
|
|
47
|
+
return timeRegex.test(timeString)
|
|
48
|
+
}
|
package/src/hooks/index.js
CHANGED
|
@@ -6,6 +6,8 @@ export * from './useCategoryStore'
|
|
|
6
6
|
export * from './useCatWithProduct'
|
|
7
7
|
export * from './useManageQueryParams'
|
|
8
8
|
export * from './useDeliveryTime'
|
|
9
|
+
export * from './getTotalHours'
|
|
10
|
+
export * from './convertToMilitaryTime'
|
|
9
11
|
export * from './statusOpenStores'
|
|
10
12
|
export * from './completeSchedules'
|
|
11
13
|
export * from './useLogout/helpers/BroadcastChannel'
|
|
@@ -15,6 +17,8 @@ export * from './useCreateDeliveryTime'
|
|
|
15
17
|
export * from './addTenMinutes'
|
|
16
18
|
export * from './useCategoriesProduct'
|
|
17
19
|
export * from './useLogout'
|
|
20
|
+
export * from './useSetupSchedule'
|
|
21
|
+
export * from './useMouse'
|
|
18
22
|
export * from './useStatusOpenStore'
|
|
19
23
|
export * from './usePushNotificationOrder'
|
|
20
24
|
export * from './newStoreOrderSubscription'
|
|
@@ -413,6 +413,7 @@ export const useDessert = ({
|
|
|
413
413
|
title: 'Error',
|
|
414
414
|
backgroundColor: 'warning'
|
|
415
415
|
})
|
|
416
|
+
return // Termina la función si el título está vacío
|
|
416
417
|
}
|
|
417
418
|
|
|
418
419
|
// Generate a new list ID using the RandomCode function (must be implemented elsewhere)
|
|
@@ -421,11 +422,11 @@ export const useDessert = ({
|
|
|
421
422
|
// Determine if the list is required based on the setCheck.exState state
|
|
422
423
|
const required = setCheck.exState ? 1 : 0
|
|
423
424
|
|
|
424
|
-
// Add the new list to the data state
|
|
425
|
-
setData({
|
|
426
|
-
listIds: [...
|
|
425
|
+
// Add the new list to the beginning of the data state
|
|
426
|
+
setData(prevData => ({
|
|
427
|
+
listIds: [newListId, ...prevData.listIds], // Agrega el nuevo ID al principio del array
|
|
427
428
|
lists: {
|
|
428
|
-
...
|
|
429
|
+
...prevData.lists,
|
|
429
430
|
[newListId]: {
|
|
430
431
|
id: newListId,
|
|
431
432
|
title,
|
|
@@ -435,7 +436,7 @@ export const useDessert = ({
|
|
|
435
436
|
cards: []
|
|
436
437
|
}
|
|
437
438
|
}
|
|
438
|
-
})
|
|
439
|
+
}))
|
|
439
440
|
|
|
440
441
|
// Update the external product with the information of the new list
|
|
441
442
|
handleUpdateExtProduct({
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import type { MouseEvent } from "react";
|
|
3
|
+
|
|
4
|
+
export function useMouse<T extends HTMLElement = any>(
|
|
5
|
+
options: { resetOnExit?: boolean } = { resetOnExit: false }
|
|
6
|
+
) {
|
|
7
|
+
const [position, setPosition] = useState({ x: 0, y: 0 });
|
|
8
|
+
|
|
9
|
+
const ref = useRef<T>();
|
|
10
|
+
|
|
11
|
+
const setMousePosition = (event: MouseEvent<HTMLElement>) => {
|
|
12
|
+
if (ref.current) {
|
|
13
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
14
|
+
|
|
15
|
+
const x = Math.max(
|
|
16
|
+
0,
|
|
17
|
+
Math.round(
|
|
18
|
+
event.pageX - rect.left - (window.pageXOffset || window.scrollX)
|
|
19
|
+
)
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const y = Math.max(
|
|
23
|
+
0,
|
|
24
|
+
Math.round(
|
|
25
|
+
event.pageY - rect.top - (window.pageYOffset || window.scrollY)
|
|
26
|
+
)
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
setPosition({ x, y });
|
|
30
|
+
} else {
|
|
31
|
+
setPosition({ x: event.clientX, y: event.clientY });
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const resetMousePosition = () => setPosition({ x: 0, y: 0 });
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
const element = ref?.current ? ref.current : document;
|
|
39
|
+
element.addEventListener("mousemove", setMousePosition as any);
|
|
40
|
+
if (options.resetOnExit)
|
|
41
|
+
element.addEventListener("mouseleave", resetMousePosition as any);
|
|
42
|
+
|
|
43
|
+
return () => {
|
|
44
|
+
element.removeEventListener("mousemove", setMousePosition as any);
|
|
45
|
+
if (options.resetOnExit)
|
|
46
|
+
element.removeEventListener("mouseleave", resetMousePosition as any);
|
|
47
|
+
};
|
|
48
|
+
}, [ref.current]);
|
|
49
|
+
|
|
50
|
+
return { ref, ...position };
|
|
51
|
+
}
|
|
@@ -16,10 +16,10 @@ export * from './useEditProduct'
|
|
|
16
16
|
export const useProductsFood = ({
|
|
17
17
|
categories,
|
|
18
18
|
desc,
|
|
19
|
-
fetchPolicy = 'network
|
|
19
|
+
fetchPolicy = 'cache-and-network',
|
|
20
20
|
fromDate,
|
|
21
21
|
gender,
|
|
22
|
-
max =
|
|
22
|
+
max = 100,
|
|
23
23
|
min,
|
|
24
24
|
pState,
|
|
25
25
|
search = null,
|
|
@@ -28,7 +28,7 @@ export const useProductsFood = ({
|
|
|
28
28
|
// const [productsFood, setProductsFood] = useState([])
|
|
29
29
|
const [showMore, setShowMore] = useState(500)
|
|
30
30
|
const { data, loading, fetchMore, error, called } = useQuery(GET_ALL_PRODUCT_STORE, {
|
|
31
|
-
fetchPolicy
|
|
31
|
+
fetchPolicy,
|
|
32
32
|
notifyOnNetworkStatusChange: true,
|
|
33
33
|
nextFetchPolicy: 'cache-first',
|
|
34
34
|
refetchWritePolicy: 'merge',
|
|
@@ -40,7 +40,7 @@ export const useProductsFood = ({
|
|
|
40
40
|
gender: gender || [],
|
|
41
41
|
max: max || null,
|
|
42
42
|
min: min || null,
|
|
43
|
-
pState
|
|
43
|
+
pState,
|
|
44
44
|
search: search ?? search,
|
|
45
45
|
toDate: toDate || null
|
|
46
46
|
}
|
|
@@ -59,11 +59,11 @@ export const useProductsFood = ({
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export const useDeleteProductsFood = ({
|
|
62
|
-
sendNotification = (
|
|
63
|
-
onSuccess = (
|
|
62
|
+
sendNotification = (arg) => { return arg },
|
|
63
|
+
onSuccess = (arg) => { return arg }
|
|
64
64
|
} = {
|
|
65
|
-
sendNotification: (
|
|
66
|
-
onSuccess: (
|
|
65
|
+
sendNotification: (arg) => { return arg },
|
|
66
|
+
onSuccess: (arg) => { return arg }
|
|
67
67
|
}) => {
|
|
68
68
|
const [updateProductFoods, { data, loading, error }] = useMutation(UPDATE_PRODUCT_FOOD)
|
|
69
69
|
|
|
@@ -124,8 +124,8 @@ export const useDeleteProductsFood = ({
|
|
|
124
124
|
}).then(() => {
|
|
125
125
|
onSuccess()
|
|
126
126
|
return sendNotification({
|
|
127
|
-
title: '
|
|
128
|
-
description: 'El producto se ha eliminado correctamente',
|
|
127
|
+
title: 'Éxito',
|
|
128
|
+
description: pState === 1 ? 'El producto se ha eliminado correctamente' : 'El producto se ha restaurando correctamente',
|
|
129
129
|
backgroundColor: 'success'
|
|
130
130
|
})
|
|
131
131
|
}).catch((e) => {
|
|
@@ -1,8 +1,26 @@
|
|
|
1
|
-
export function convertToIntegerOrFloat(numberString) {
|
|
2
|
-
|
|
1
|
+
export function convertToIntegerOrFloat (numberString) {
|
|
2
|
+
if (!numberString) return 0
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// Convierte a número (entero o flotante)
|
|
5
|
+
const numericValue = parseFloat(numberString)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
return isNaN(numericValue) ? 0 : numericValue // Maneja valores no numéricos como 0
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Filter products by carProId.
|
|
12
|
+
* @param {Array} products - Array of products to filter.
|
|
13
|
+
* @param {Array} carProIds - Array of carProId to filter by.
|
|
14
|
+
* @returns {Array} - Filtered array of products or all products if no matches found.
|
|
15
|
+
*/
|
|
16
|
+
export function filterProductsByCarProId (products, carProIds) {
|
|
17
|
+
if (!Array.isArray(products)) {
|
|
18
|
+
return []
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!Array.isArray(carProIds) || carProIds.length === 0) {
|
|
22
|
+
return products
|
|
8
23
|
}
|
|
24
|
+
|
|
25
|
+
return products.filter(product => carProIds.includes(product.carProId))
|
|
26
|
+
}
|
|
@@ -28,7 +28,10 @@ import { updateExistingOrders } from '../useUpdateExistingOrders'
|
|
|
28
28
|
import { useGetSale } from './useGetSale'
|
|
29
29
|
import { useCatWithProduct } from './../useCatWithProduct/index'
|
|
30
30
|
import { useLogout } from '../useLogout'
|
|
31
|
+
import { filterProductsByCarProId } from './helpers'
|
|
31
32
|
export * from './useGetAllSales'
|
|
33
|
+
export * from './helpers'
|
|
34
|
+
|
|
32
35
|
export { GET_ALL_COUNT_SALES } from './queries'
|
|
33
36
|
|
|
34
37
|
const initialState = {
|
|
@@ -1081,23 +1084,6 @@ export const useSales = ({
|
|
|
1081
1084
|
}
|
|
1082
1085
|
|
|
1083
1086
|
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
1087
|
|
|
1102
1088
|
/**
|
|
1103
1089
|
* Filter objects with checked property equal to true.
|
|
@@ -51,12 +51,18 @@ export const useSetScheduleOpenAll = () => {
|
|
|
51
51
|
return [handleSetStoreSchedule, { loading, error }]
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
export const useSchedules = ({ schDay = 1, idStore = '' }) => {
|
|
54
|
+
export const useSchedules = ({ schDay = 1, idStore = '', onCompleted = (data) => { return data } }) => {
|
|
55
55
|
const {
|
|
56
56
|
data,
|
|
57
57
|
loading,
|
|
58
58
|
error
|
|
59
|
-
} = useQuery(GET_SCHEDULE_STORE, {
|
|
59
|
+
} = useQuery(GET_SCHEDULE_STORE, {
|
|
60
|
+
variables: { schDay, idStore },
|
|
61
|
+
onCompleted: (data) => {
|
|
62
|
+
onCompleted(data)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
)
|
|
60
66
|
|
|
61
67
|
return [data?.getStoreSchedules, { loading, error }]
|
|
62
68
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export const dateEnum = {
|
|
2
|
+
schHoEnd: 'schHoEnd',
|
|
3
|
+
schHoSta: 'schHoSta'
|
|
4
|
+
|
|
5
|
+
}
|
|
6
|
+
export const initialDays = [
|
|
7
|
+
{
|
|
8
|
+
name: 'Lunes',
|
|
9
|
+
day: 1,
|
|
10
|
+
checked: false,
|
|
11
|
+
schHoSta: '00:00',
|
|
12
|
+
schHoEnd: '00:00',
|
|
13
|
+
selected: false,
|
|
14
|
+
loading: false
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: 'Martes',
|
|
18
|
+
day: 2,
|
|
19
|
+
checked: false,
|
|
20
|
+
schHoSta: '00:00',
|
|
21
|
+
schHoEnd: '00:00',
|
|
22
|
+
selected: false,
|
|
23
|
+
loading: false
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'Miércoles',
|
|
27
|
+
day: 3,
|
|
28
|
+
checked: false,
|
|
29
|
+
schHoSta: '00:00',
|
|
30
|
+
schHoEnd: '00:00',
|
|
31
|
+
selected: false,
|
|
32
|
+
loading: false
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'Jueves',
|
|
36
|
+
day: 4,
|
|
37
|
+
checked: false,
|
|
38
|
+
schHoSta: '00:00',
|
|
39
|
+
schHoEnd: '00:00',
|
|
40
|
+
selected: false,
|
|
41
|
+
loading: false
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'Viernes',
|
|
45
|
+
day: 5,
|
|
46
|
+
checked: false,
|
|
47
|
+
schHoSta: '00:00',
|
|
48
|
+
schHoEnd: '00:00',
|
|
49
|
+
selected: false,
|
|
50
|
+
loading: false
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'Sábado',
|
|
54
|
+
day: 6,
|
|
55
|
+
checked: false,
|
|
56
|
+
schHoSta: '00:00',
|
|
57
|
+
schHoEnd: '00:00',
|
|
58
|
+
selected: false,
|
|
59
|
+
loading: false
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'Domingo',
|
|
63
|
+
day: 0,
|
|
64
|
+
checked: false,
|
|
65
|
+
schHoSta: '00:00',
|
|
66
|
+
schHoEnd: '00:00',
|
|
67
|
+
selected: false,
|
|
68
|
+
loading: false
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
export const timeSuggestions = [
|
|
73
|
+
'00:00', '00:15', '00:30', '00:45', '01:00', '01:15', '01:30', '01:45',
|
|
74
|
+
'02:00', '02:15', '02:30', '02:45', '03:00', '03:15', '03:30', '03:45',
|
|
75
|
+
'04:00', '04:15', '04:30', '04:45', '05:00', '05:15', '05:30', '05:45',
|
|
76
|
+
'06:00', '06:15', '06:30', '06:45', '07:00', '07:15', '07:30', '07:45',
|
|
77
|
+
'08:00', '08:15', '08:30', '08:45', '09:00', '09:15', '09:30', '09:45',
|
|
78
|
+
'10:00', '10:15', '10:30', '10:45', '11:00', '11:15', '11:30', '11:45',
|
|
79
|
+
'12:00', '12:15', '12:30', '12:45', '13:00', '13:15', '13:30', '13:45',
|
|
80
|
+
'14:00', '14:15', '14:30', '14:45', '15:00', '15:15', '15:30', '15:45',
|
|
81
|
+
'16:00', '16:15', '16:30', '16:45', '17:00', '17:15', '17:30', '17:45',
|
|
82
|
+
'18:00', '18:15', '18:30', '18:45', '19:00', '19:15', '19:30', '19:45',
|
|
83
|
+
'20:00', '20:15', '20:30', '20:45', '21:00', '21:15', '21:30', '21:45',
|
|
84
|
+
'22:00', '22:15', '22:30', '22:45', '23:00', '23:15', '23:30', '23:45'
|
|
85
|
+
]
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { dateEnum, initialDays, timeSuggestions } from './helpers'
|
|
3
|
+
import { useCreateSchedules, useSchedules } from '../useSchedule'
|
|
4
|
+
import { days as NameDays } from '../../utils'
|
|
5
|
+
import { convertToMilitaryTime } from '../convertToMilitaryTime'
|
|
6
|
+
import { GET_ONE_SCHEDULE_STORE, GET_SCHEDULE_STORE } from '../useSchedule/queries'
|
|
7
|
+
export * from './helpers/index'
|
|
8
|
+
|
|
9
|
+
export const useSetupSchedule = ({
|
|
10
|
+
idStore = null, sendNotification = (args) => {
|
|
11
|
+
return args
|
|
12
|
+
}
|
|
13
|
+
} = {}) => {
|
|
14
|
+
const [days, setDays] = useState(initialDays)
|
|
15
|
+
const [alertModal, setAlertModal] = useState(false)
|
|
16
|
+
const [selectedDay, setSelectedDay] = useState({})
|
|
17
|
+
const [setStoreSchedule, { loading }] = useCreateSchedules()
|
|
18
|
+
|
|
19
|
+
const onCompleted = (data) => {
|
|
20
|
+
if (Array.isArray(data) && data.length > 0) {
|
|
21
|
+
// Mapeamos los datos recibidos y los convertimos en un objeto con la estructura deseada
|
|
22
|
+
const newSchedules = data.map((day) => ({
|
|
23
|
+
day: day.schDay,
|
|
24
|
+
name: NameDays[day.schDay],
|
|
25
|
+
selected: day.schHoEnd !== '00:00' || day.schHoSta !== '00:00',
|
|
26
|
+
...day
|
|
27
|
+
}))
|
|
28
|
+
|
|
29
|
+
// Actualizamos el estado days
|
|
30
|
+
setDays(prevDays => {
|
|
31
|
+
// Creamos un nuevo array combinando los elementos existentes en days con los nuevos datos
|
|
32
|
+
const updatedDays = prevDays.map(existingDay => {
|
|
33
|
+
// Buscamos si hay un elemento con el mismo día en los nuevos datos
|
|
34
|
+
const newData = newSchedules.find(newDay => newDay.day === existingDay.day)
|
|
35
|
+
// Si encontramos el día en los nuevos datos, lo fusionamos con el día existente
|
|
36
|
+
if (newData) {
|
|
37
|
+
return { ...existingDay, ...newData }
|
|
38
|
+
}
|
|
39
|
+
// Si no encontramos el día en los nuevos datos, simplemente devolvemos el día existente
|
|
40
|
+
return existingDay
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
// Ahora, buscamos los nuevos días que no están en days y los agregamos al array
|
|
44
|
+
newSchedules.forEach(newDay => {
|
|
45
|
+
if (!updatedDays.some(existingDay => existingDay.day === newDay.day)) {
|
|
46
|
+
updatedDays.push(newDay)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
// Devolvemos el nuevo array actualizado
|
|
51
|
+
return updatedDays
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const [data, { loading: lsc }] = useSchedules({ schDay: 1 })
|
|
57
|
+
|
|
58
|
+
const toggleCheck = (index) => {
|
|
59
|
+
const updatedDays = [...days]
|
|
60
|
+
updatedDays[index].checked = !updatedDays[index].checked
|
|
61
|
+
setDays(updatedDays)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const duplicateDay = (index) => {
|
|
65
|
+
const selectedDay = days[index]
|
|
66
|
+
// Lógica para desplegar el modal y seleccionar los días donde se replicará
|
|
67
|
+
const selectedDaysToDuplicate = days.filter((day) => day.checked)
|
|
68
|
+
const updatedDays = [...days]
|
|
69
|
+
selectedDaysToDuplicate.forEach((dayToDuplicate) => {
|
|
70
|
+
const duplicatedDay = { ...selectedDay, checked: false }
|
|
71
|
+
updatedDays.push(duplicatedDay)
|
|
72
|
+
})
|
|
73
|
+
setDays(updatedDays)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const handleSelectedDay = (day) => {
|
|
77
|
+
const isSaved = days.find((data) => {
|
|
78
|
+
return data.day === day
|
|
79
|
+
})
|
|
80
|
+
if (isSaved?.schId && isSaved?.selected) {
|
|
81
|
+
setSelectedDay(isSaved)
|
|
82
|
+
return setAlertModal(true)
|
|
83
|
+
}
|
|
84
|
+
const updatedDays = days.map((d) => {
|
|
85
|
+
if (d.day === day) {
|
|
86
|
+
return { ...d, selected: !d.selected }
|
|
87
|
+
} else {
|
|
88
|
+
return { ...d }
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
setDays(updatedDays)
|
|
92
|
+
}
|
|
93
|
+
const selectedDays = days?.filter((day) => Boolean(day.selected)).map((day) => {
|
|
94
|
+
return day.day
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const onChangeSaveHour = async ({ time, name, day }) => {
|
|
98
|
+
setDays(prevDays => {
|
|
99
|
+
const updatedDays = prevDays.map((d) => {
|
|
100
|
+
if (d.day === day) {
|
|
101
|
+
return { ...d, [name]: time, loading: Boolean(name === dateEnum.schHoEnd) }
|
|
102
|
+
} else {
|
|
103
|
+
return { ...d }
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
if (name === dateEnum.schHoEnd) {
|
|
108
|
+
const findHour = updatedDays.find((d) => {
|
|
109
|
+
return d.day === day
|
|
110
|
+
})
|
|
111
|
+
const schHoSta = findHour?.schHoSta
|
|
112
|
+
const schHoEnd = findHour?.schHoEnd
|
|
113
|
+
const startHour = convertToMilitaryTime(schHoSta)
|
|
114
|
+
const endHour = convertToMilitaryTime(schHoEnd)
|
|
115
|
+
// Comparar solo las horas y minutos
|
|
116
|
+
if (startHour === endHour) {
|
|
117
|
+
// eslint-disable-next-line consistent-return
|
|
118
|
+
sendNotification({
|
|
119
|
+
description: 'Error, la hora de salida no debe ser igual a la hora final',
|
|
120
|
+
title: 'Error',
|
|
121
|
+
backgroundColor: 'error'
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
if (startHour > endHour) {
|
|
125
|
+
// eslint-disable-next-line consistent-return
|
|
126
|
+
sendNotification({
|
|
127
|
+
description: 'Error, la hora de salida debe ser mayor que la de entrada',
|
|
128
|
+
title: 'Error',
|
|
129
|
+
backgroundColor: 'error'
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
if (startHour !== endHour && startHour < endHour) {
|
|
133
|
+
setStoreSchedule({
|
|
134
|
+
variables: {
|
|
135
|
+
input: {
|
|
136
|
+
schHoSta: schHoSta ?? '00:00',
|
|
137
|
+
schHoEnd: schHoEnd ?? '00:00',
|
|
138
|
+
schState: 1,
|
|
139
|
+
schDay: day
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
update (cache) {
|
|
143
|
+
cache.modify({
|
|
144
|
+
fields: {
|
|
145
|
+
getStoreSchedules (dataOld = []) {
|
|
146
|
+
return cache.writeQuery({ query: GET_SCHEDULE_STORE, data: dataOld })
|
|
147
|
+
},
|
|
148
|
+
getOneStoreSchedules (dataOld = []) {
|
|
149
|
+
return cache.writeQuery({ query: GET_ONE_SCHEDULE_STORE, data: dataOld })
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
const newUpdatedDays = updatedDays.map((d) => {
|
|
157
|
+
if (d.day === day) {
|
|
158
|
+
return { ...d, loading: false }
|
|
159
|
+
} else {
|
|
160
|
+
return { ...d }
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
// Devolver el nuevo estado actualizado
|
|
164
|
+
return newUpdatedDays
|
|
165
|
+
}
|
|
166
|
+
// Devolver el nuevo estado
|
|
167
|
+
return updatedDays
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const handleDeleteSchedule = async (day) => {
|
|
172
|
+
await setStoreSchedule({
|
|
173
|
+
variables: {
|
|
174
|
+
input: {
|
|
175
|
+
schHoSta: '00:00',
|
|
176
|
+
schHoEnd: '00:00',
|
|
177
|
+
schState: 1,
|
|
178
|
+
schDay: day,
|
|
179
|
+
idStore
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
update (cache) {
|
|
183
|
+
cache.modify({
|
|
184
|
+
fields: {
|
|
185
|
+
getStoreSchedules (dataOld = []) {
|
|
186
|
+
return cache.writeQuery({ query: GET_SCHEDULE_STORE, data: dataOld })
|
|
187
|
+
},
|
|
188
|
+
getOneStoreSchedules (dataOld = []) {
|
|
189
|
+
return cache.writeQuery({ query: GET_ONE_SCHEDULE_STORE, data: dataOld })
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
setDays(prevDays => {
|
|
196
|
+
const updatedDays = prevDays.map((d) => {
|
|
197
|
+
if (d.day === day) {
|
|
198
|
+
return {
|
|
199
|
+
...d,
|
|
200
|
+
[dateEnum.schHoEnd]: dateEnum.schHoEnd,
|
|
201
|
+
[dateEnum.schHoSta]: dateEnum.schHoSta,
|
|
202
|
+
selected: false
|
|
203
|
+
}
|
|
204
|
+
} else {
|
|
205
|
+
return { ...d }
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
return updatedDays
|
|
209
|
+
})
|
|
210
|
+
setAlertModal(false)
|
|
211
|
+
}
|
|
212
|
+
useEffect(() => {
|
|
213
|
+
onCompleted(data)
|
|
214
|
+
}, [data])
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
duplicateDay,
|
|
218
|
+
alertModal,
|
|
219
|
+
toggleCheck,
|
|
220
|
+
handleSelectedDay,
|
|
221
|
+
onChangeSaveHour,
|
|
222
|
+
handleDeleteSchedule,
|
|
223
|
+
setAlertModal,
|
|
224
|
+
days,
|
|
225
|
+
selectedDays,
|
|
226
|
+
selectedDay,
|
|
227
|
+
loading: lsc || loading,
|
|
228
|
+
times: timeSuggestions
|
|
229
|
+
}
|
|
230
|
+
}
|
package/src/utils/index.js
CHANGED
|
@@ -13,6 +13,20 @@ const validTypes = {
|
|
|
13
13
|
textarea: true
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
export const statusOrder = {
|
|
17
|
+
0: '',
|
|
18
|
+
1: 'ENTRANTE',
|
|
19
|
+
2: 'PROCESO',
|
|
20
|
+
3: 'LISTOS',
|
|
21
|
+
4: 'CONCLUIDOS',
|
|
22
|
+
5: 'RECHAZADOS'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const statusProduct = {
|
|
26
|
+
deleted: 0,
|
|
27
|
+
active: 1
|
|
28
|
+
}
|
|
29
|
+
|
|
16
30
|
export const validationSubmitHooks = elements => {
|
|
17
31
|
let errorForm = {}
|
|
18
32
|
|
|
@@ -150,6 +164,16 @@ export const SPANISH_MONTHS = {
|
|
|
150
164
|
11: 'Diciembre'
|
|
151
165
|
}
|
|
152
166
|
|
|
167
|
+
export const days = {
|
|
168
|
+
1: 'Lunes',
|
|
169
|
+
2: 'Martes',
|
|
170
|
+
3: 'Miércoles',
|
|
171
|
+
4: 'Jueves',
|
|
172
|
+
5: 'Viernes',
|
|
173
|
+
6: 'Sábado',
|
|
174
|
+
0: 'Domingo'
|
|
175
|
+
}
|
|
176
|
+
|
|
153
177
|
export const convertBase64 = file => {
|
|
154
178
|
return new Promise((resolve, reject) => {
|
|
155
179
|
const reader = new FileReader()
|