npm-pkg-hook 1.1.2 → 1.1.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/.eslintrc.js +132 -132
- package/.vscode/extensions.json +6 -0
- package/.vscode/settings.json +8 -0
- package/next.config.js +1 -0
- package/package.json +43 -46
- package/src/config/client/errors.js +1 -2
- package/src/hooks/index.js +20 -25
- package/src/hooks/useAnimationText/index.jsx +13 -11
- package/src/hooks/useCatWithProduct/index.js +4 -37
- package/src/hooks/useCatWithProduct/queries.js +16 -0
- package/src/hooks/useChartData/index.js +156 -182
- package/src/hooks/useChartData/useChartData/index.js +197 -0
- package/src/hooks/useChartData/useChartDataAllOrders/index.js +94 -0
- package/src/hooks/useCheckbox/index.js +2 -5
- package/src/hooks/useClients/index.js +8 -17
- package/src/hooks/useCreateProduct/index.js +64 -94
- package/src/hooks/useDrag/index.js +1 -0
- package/src/hooks/useEmployee/index.js +8 -11
- package/src/hooks/useFormTools/index.js +1 -1
- package/src/hooks/useFullScreenMode/index.js +8 -8
- package/src/hooks/useGoogleLogin/index.js +161 -0
- package/src/hooks/useGoogleLogin/loadScript.js +15 -0
- package/src/hooks/useGoogleLogin/removeScript.js +7 -0
- package/src/hooks/useHover/index.js +1 -1
- package/src/hooks/useImagesStore/index.js +144 -176
- package/src/hooks/useImagesStore/queries.js +28 -1
- package/src/hooks/useKeypress/index.js +1 -7
- package/src/hooks/useLogout/index.js +27 -22
- package/src/hooks/useManageQueryParams/index.js +1 -1
- package/src/hooks/useProductsFood/queriesStore.js +16 -3
- package/src/hooks/useReport/index.js +30 -26
- package/src/hooks/useReport/queries.js +32 -47
- package/src/hooks/useSales/index.js +21 -52
- package/src/hooks/useSales/queries.js +38 -48
- package/src/hooks/useSales/useGetSale.js +2 -16
- package/src/hooks/useSchedule/index.jsx +23 -0
- package/src/hooks/useUpdateExistingOrders/index.js +8 -8
- package/src/hooks/useUser/index.js +2 -2
- package/src/hooks/useUser/queries.js +40 -40
- package/src/hooks/useWindowSize/index.js +1 -1
- package/src/index.jsx +1 -2
- package/src/security/index.js +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useMutation } from '@apollo/client';
|
|
2
2
|
import {
|
|
3
3
|
useRef,
|
|
4
|
-
useCallback,
|
|
5
4
|
useState
|
|
6
5
|
} from 'react';
|
|
7
6
|
import {
|
|
@@ -12,191 +11,159 @@ import {
|
|
|
12
11
|
GET_ONE_BANNER_STORE
|
|
13
12
|
} from '../useProductsFood/queriesStore';
|
|
14
13
|
import { GET_ONE_STORE } from '../useStore/queries';
|
|
15
|
-
|
|
16
|
-
* Custom hook to handle image upload and management for a store's banner and logo.
|
|
17
|
-
* @typedef {Object} ImageStoreHookResult
|
|
18
|
-
* @property {React.RefObject} fileInputRefLogo - Reference to the logo file input element.
|
|
19
|
-
* @property {string} src - Source URL of the store's banner image.
|
|
20
|
-
* @property {string} alt - Alternate text for the store's banner image.
|
|
21
|
-
* @property {Object} initialState - Initial state for the store's banner image.
|
|
22
|
-
* @property {string} srcLogo - Source URL of the store's logo image.
|
|
23
|
-
* @property {string} altLogo - Alternate text for the store's logo image.
|
|
24
|
-
* @property {React.RefObject} fileInputRef - Reference to the banner file input element.
|
|
25
|
-
* @property {function} handleDeleteLogo - Callback function to handle logo deletion.
|
|
26
|
-
* @property {function} onTargetClick - Callback function to trigger banner file input click.
|
|
27
|
-
* @property {function} onTargetClickLogo - Callback function to trigger logo file input click.
|
|
28
|
-
* @property {function} HandleDeleteBanner - Callback function to handle banner deletion.
|
|
29
|
-
* @property {function} handleInputChangeLogo - Callback function to handle logo file input change.
|
|
30
|
-
* @property {function} handleUpdateBanner - Callback function to handle banner file input change.
|
|
31
|
-
* @param {Object} options - Options for the hook.
|
|
32
|
-
* @param {string} options.idStore - ID of the store.
|
|
33
|
-
* @param {Function} options.sendNotification - Function to send a notification (optional).
|
|
34
|
-
* @returns {ImageStoreHookResult} Object containing image handling functions and state.
|
|
35
|
-
*/
|
|
36
|
-
export const useImageStore = ({ idStore, sendNotification = () => {} } = {}) => {
|
|
37
|
-
// STATES
|
|
38
|
-
const fileInputRef = useRef(null);
|
|
39
|
-
const [{ altLogo, srcLogo }, setPreviewImgLogo] = useState({});
|
|
40
|
-
const initialState = { alt: '/images/DEFAULTBANNER.png', src: '/images/DEFAULTBANNER.png' };
|
|
41
|
-
const [{ alt, src }, setPreviewImg] = useState(initialState);
|
|
42
|
-
const fileInputRefLogo = useRef(null);
|
|
43
|
-
// HOOKS
|
|
44
|
-
const [registerBanner] = useMutation(CREATE_BANNER_STORE, {
|
|
45
|
-
onCompleted: (data) => console.log({ message: data?.registerBanner?.message }),
|
|
46
|
-
context: { clientName: 'admin-server' },
|
|
47
|
-
});
|
|
48
|
-
const [setALogoStore] = useMutation(CREATE_LOGO, {
|
|
49
|
-
onCompleted: (data) => console.log({ message: data?.setALogoStore?.message }),
|
|
50
|
-
context: { clientName: 'admin-server' },
|
|
51
|
-
});
|
|
52
|
-
const [DeleteOneBanner] = useMutation(DELETE_ONE_BANNER_STORE, {
|
|
53
|
-
onCompleted: (data) => console.log({ message: data?.DeleteOneBanner?.message }),
|
|
54
|
-
context: { clientName: 'admin-server' },
|
|
55
|
-
});
|
|
56
|
-
const [deleteALogoStore] = useMutation(DELETE_ONE_LOGO_STORE, {
|
|
57
|
-
onCompleted: (data) => {
|
|
58
|
-
console.log({ message: data.deleteALogoStore.message });
|
|
59
|
-
setPreviewImgLogo(initialState);
|
|
60
|
-
},
|
|
61
|
-
context: { clientName: 'admin-server' },
|
|
62
|
-
update(cache) {
|
|
63
|
-
cache.modify({
|
|
64
|
-
fields: {
|
|
65
|
-
getStore(dataOld = []) {
|
|
66
|
-
return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld });
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
});
|
|
14
|
+
export { GET_MIN_PEDIDO } from './queries'
|
|
72
15
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
16
|
+
export const useImageStore = ({ idStore, sendNotification = () => { return } } = {}) => {
|
|
17
|
+
// STATES
|
|
18
|
+
const fileInputRef = useRef(null)
|
|
19
|
+
const [{ altLogo, srcLogo }, setPreviewImgLogo] = useState({})
|
|
20
|
+
const initialState = { alt: '/images/DEFAULTBANNER.png', src: '/images/DEFAULTBANNER.png' }
|
|
21
|
+
const [{ alt, src }, setPreviewImg] = useState(initialState)
|
|
22
|
+
const fileInputRefLogo = useRef(null)
|
|
23
|
+
// HOOKS
|
|
24
|
+
const [registerBanner] = useMutation(CREATE_BANNER_STORE, {
|
|
25
|
+
onCompleted: (data) => { return console.log({ message: data?.registerBanner?.message }) },
|
|
26
|
+
context: { clientName: 'admin-server' }
|
|
27
|
+
})
|
|
28
|
+
const [setALogoStore] = useMutation(CREATE_LOGO, {
|
|
29
|
+
onCompleted: (data) => { return console.log({ message: data?.setALogoStore?.message }) },
|
|
30
|
+
context: { clientName: 'admin-server' }
|
|
31
|
+
})
|
|
32
|
+
const [DeleteOneBanner] = useMutation(DELETE_ONE_BANNER_STORE, {
|
|
33
|
+
onCompleted: (data) => { return console.log({ message: data?.DeleteOneBanner?.message }) },
|
|
34
|
+
context: { clientName: 'admin-server' }
|
|
35
|
+
})
|
|
36
|
+
const [deleteALogoStore] = useMutation(DELETE_ONE_LOGO_STORE, {
|
|
37
|
+
onCompleted: (data) => {
|
|
38
|
+
console.log({
|
|
39
|
+
message: data.deleteALogoStore.message
|
|
40
|
+
})
|
|
41
|
+
setPreviewImgLogo(initialState)
|
|
42
|
+
},
|
|
43
|
+
context: { clientName: 'admin-server' },
|
|
44
|
+
update(cache) {
|
|
45
|
+
cache.modify({
|
|
46
|
+
fields: {
|
|
47
|
+
getStore(dataOld = []) {
|
|
48
|
+
return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld })
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
// HANDLESS
|
|
55
|
+
const handleDeleteLogo = () => {
|
|
56
|
+
return deleteALogoStore({
|
|
57
|
+
variables: {
|
|
58
|
+
Image: ImageName || null
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
}
|
|
81
62
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
? {
|
|
63
|
+
const handleUpdateBanner = event => {
|
|
64
|
+
try {
|
|
65
|
+
const { files } = event.target
|
|
66
|
+
setPreviewImg(
|
|
67
|
+
files.length
|
|
68
|
+
? {
|
|
89
69
|
src: URL.createObjectURL(files[0]),
|
|
90
|
-
alt: files[0].name
|
|
70
|
+
alt: files[0].name
|
|
71
|
+
}
|
|
72
|
+
: initialState
|
|
73
|
+
)
|
|
74
|
+
registerBanner({
|
|
75
|
+
variables: {
|
|
76
|
+
input: {
|
|
77
|
+
bnImage: files[0],
|
|
78
|
+
idStore: idStore
|
|
91
79
|
}
|
|
80
|
+
}, update(cache) {
|
|
81
|
+
cache.modify({
|
|
82
|
+
fields: {
|
|
83
|
+
getOneBanners(dataOld = []) {
|
|
84
|
+
return cache.writeQuery({ query: GET_ONE_BANNER_STORE, data: dataOld })
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
}).catch(() => {
|
|
90
|
+
sendNotification({
|
|
91
|
+
title: 'No pudimos cargar la imagen',
|
|
92
|
+
description: 'Error',
|
|
93
|
+
backgroundColor: 'error'
|
|
94
|
+
})
|
|
95
|
+
setPreviewImg(initialState)
|
|
96
|
+
})
|
|
97
|
+
} catch {
|
|
98
|
+
setPreviewImg(initialState)
|
|
99
|
+
sendNotification({
|
|
100
|
+
title: 'No pudimos cargar la imagen',
|
|
101
|
+
description: 'Error',
|
|
102
|
+
backgroundColor: 'error'
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const handleInputChangeLogo = event => {
|
|
107
|
+
const { files } = event.target
|
|
108
|
+
setPreviewImgLogo(
|
|
109
|
+
files.length
|
|
110
|
+
? {
|
|
111
|
+
srcLogo: URL.createObjectURL(files[0]),
|
|
112
|
+
altLogo: files[0].name
|
|
113
|
+
}
|
|
92
114
|
: initialState
|
|
93
|
-
)
|
|
94
|
-
|
|
115
|
+
)
|
|
116
|
+
setALogoStore({
|
|
95
117
|
variables: {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
update(cache) {
|
|
118
|
+
logo: files[0],
|
|
119
|
+
idStore: idStore
|
|
120
|
+
}, update(cache) {
|
|
102
121
|
cache.modify({
|
|
103
122
|
fields: {
|
|
104
|
-
|
|
105
|
-
return cache.writeQuery({ query:
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
}
|
|
123
|
+
getStore(dataOld = []) {
|
|
124
|
+
return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld })
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
}
|
|
110
129
|
}).catch(() => {
|
|
111
130
|
sendNotification({
|
|
112
131
|
title: 'No pudimos cargar la imagen',
|
|
113
132
|
description: 'Error',
|
|
114
|
-
backgroundColor: 'error'
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
})
|
|
118
|
-
} catch {
|
|
119
|
-
setPreviewImg(initialState);
|
|
120
|
-
sendNotification({
|
|
121
|
-
title: 'No pudimos cargar la imagen',
|
|
122
|
-
description: 'Error',
|
|
123
|
-
backgroundColor: 'error',
|
|
124
|
-
});
|
|
133
|
+
backgroundColor: 'error'
|
|
134
|
+
})
|
|
135
|
+
setPreviewImgLogo(initialState)
|
|
136
|
+
})
|
|
125
137
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}).catch(() => {
|
|
156
|
-
sendNotification({
|
|
157
|
-
title: 'No pudimos cargar la imagen',
|
|
158
|
-
description: 'Error',
|
|
159
|
-
backgroundColor: 'error',
|
|
160
|
-
});
|
|
161
|
-
setPreviewImgLogo(initialState);
|
|
162
|
-
});
|
|
163
|
-
},
|
|
164
|
-
[setPreviewImgLogo, initialState, idStore, setALogoStore]
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
const HandleDeleteBanner = useCallback(async () => {
|
|
168
|
-
setPreviewImg(initialState);
|
|
169
|
-
DeleteOneBanner({
|
|
170
|
-
variables: {
|
|
171
|
-
bnState: bnState, // You should provide bnState and bnImageFileName
|
|
172
|
-
bnImageFileName: bnImageFileName,
|
|
173
|
-
idStore,
|
|
174
|
-
bnId,
|
|
175
|
-
},
|
|
176
|
-
update(cache) {
|
|
177
|
-
cache.modify({
|
|
178
|
-
fields: {
|
|
179
|
-
getOneBanners(dataOld = []) {
|
|
180
|
-
return cache.writeQuery({ query: GET_ONE_BANNER_STORE, data: dataOld });
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
});
|
|
184
|
-
},
|
|
185
|
-
}).then(() => {
|
|
186
|
-
setPreviewImg(initialState);
|
|
187
|
-
});
|
|
188
|
-
}, [setPreviewImg, initialState, DeleteOneBanner]);
|
|
189
|
-
|
|
190
|
-
const onTargetClickLogo = useCallback((e) => {
|
|
191
|
-
e.preventDefault();
|
|
192
|
-
fileInputRefLogo.current.click();
|
|
193
|
-
}, []);
|
|
194
|
-
|
|
195
|
-
const onTargetClick = useCallback((e) => {
|
|
196
|
-
e.preventDefault();
|
|
197
|
-
fileInputRef.current.click();
|
|
198
|
-
}, []);
|
|
199
|
-
|
|
138
|
+
const HandleDeleteBanner = async () => {
|
|
139
|
+
setPreviewImg(initialState)
|
|
140
|
+
DeleteOneBanner({
|
|
141
|
+
variables: {
|
|
142
|
+
bnState: bnState,
|
|
143
|
+
bnImageFileName: bnImageFileName,
|
|
144
|
+
idStore,
|
|
145
|
+
bnId
|
|
146
|
+
}, update(cache) {
|
|
147
|
+
cache.modify({
|
|
148
|
+
fields: {
|
|
149
|
+
getOneBanners(dataOld = []) {
|
|
150
|
+
return cache.writeQuery({ query: GET_ONE_BANNER_STORE, data: dataOld })
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
}).then(() => {
|
|
156
|
+
setPreviewImg(initialState)
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
const onTargetClickLogo = e => {
|
|
160
|
+
e.preventDefault()
|
|
161
|
+
fileInputRefLogo.current.click()
|
|
162
|
+
}
|
|
163
|
+
const onTargetClick = e => {
|
|
164
|
+
e.preventDefault()
|
|
165
|
+
fileInputRef.current.click()
|
|
166
|
+
}
|
|
200
167
|
return {
|
|
201
168
|
fileInputRefLogo,
|
|
202
169
|
src,
|
|
@@ -210,6 +177,7 @@ export const useImageStore = ({ idStore, sendNotification = () => {} } = {}) =>
|
|
|
210
177
|
onTargetClickLogo,
|
|
211
178
|
HandleDeleteBanner,
|
|
212
179
|
handleInputChangeLogo,
|
|
213
|
-
handleUpdateBanner
|
|
214
|
-
}
|
|
215
|
-
}
|
|
180
|
+
handleUpdateBanner
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
@@ -8,7 +8,29 @@ export const CREATE_SCHEDULE_STORE = gql`
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
`;
|
|
11
|
-
|
|
11
|
+
export const GET_SCHEDULE_STORE = gql`
|
|
12
|
+
query getStoreSchedules($schDay: Int, $idStore: ID) {
|
|
13
|
+
getStoreSchedules(schDay: $schDay, idStore: $idStore) {
|
|
14
|
+
schId
|
|
15
|
+
idStore
|
|
16
|
+
schDay
|
|
17
|
+
schHoSta
|
|
18
|
+
schHoEnd
|
|
19
|
+
schState
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
export const GET_ONE_SCHEDULE_STORE = gql`
|
|
24
|
+
query getOneStoreSchedules($schDay: Int, $idStore: ID) {
|
|
25
|
+
getOneStoreSchedules(schDay: $schDay, idStore: $idStore) {
|
|
26
|
+
schId
|
|
27
|
+
schDay
|
|
28
|
+
schHoSta
|
|
29
|
+
schHoEnd
|
|
30
|
+
schState
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
12
34
|
export const GET_CAT_OF_PRODUCTS = gql`
|
|
13
35
|
query getAllCatOfProducts($idStore: ID) {
|
|
14
36
|
getAllCatOfProducts(idStore: $idStore) {
|
|
@@ -152,6 +174,11 @@ export const GET_ALL_VISITOR_STORE = gql`
|
|
|
152
174
|
}
|
|
153
175
|
}
|
|
154
176
|
`;
|
|
177
|
+
export const GET_MIN_PEDIDO = gql`
|
|
178
|
+
query getMinPrice($idStore: ID) {
|
|
179
|
+
getMinPrice(idStore: $idStore)
|
|
180
|
+
}
|
|
181
|
+
`;
|
|
155
182
|
|
|
156
183
|
export const GET_All_RATING_STORE = gql`
|
|
157
184
|
query getAllRating($idStore: ID) {
|
|
@@ -25,10 +25,4 @@ export const useKeyPress = (targetKey) => {
|
|
|
25
25
|
}, [targetKey])
|
|
26
26
|
|
|
27
27
|
return keyPressed
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function useMultiKeyPress(targetKeyA, targetKeyB) {
|
|
31
|
-
const keyPressedA = useKeyPress(targetKeyA)
|
|
32
|
-
const keyPressedB = useKeyPress(targetKeyB)
|
|
33
|
-
return keyPressedA && keyPressedB
|
|
34
|
-
}
|
|
28
|
+
}
|
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
import { useApolloClient } from '@apollo/client'
|
|
1
|
+
import { useApolloClient } from '@apollo/client';
|
|
2
2
|
import { useState, useCallback } from 'react'
|
|
3
|
-
import { useRouter } from 'next/router'
|
|
4
|
-
import { Cookies } from '../../cookies'
|
|
5
|
-
import { fetchJson } from '../../hooks/useFetchJson'
|
|
3
|
+
import { useRouter } from 'next/router';
|
|
4
|
+
import { Cookies } from '../../cookies';
|
|
6
5
|
|
|
7
6
|
export const useLogout = ({ setAlertBox = () => { } } = {}) => {
|
|
8
7
|
const [loading, setLoading] = useState(false)
|
|
9
8
|
const [error, setError] = useState(false)
|
|
10
|
-
const router = useRouter()
|
|
11
|
-
const client = useApolloClient()
|
|
9
|
+
const router = useRouter();
|
|
10
|
+
const client = useApolloClient();
|
|
12
11
|
|
|
13
12
|
const onClickLogout = async () => {
|
|
14
13
|
setLoading(true)
|
|
15
|
-
await
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
14
|
+
await window
|
|
15
|
+
.fetch(`${process.env.URL_BASE}api/auth/logout/`, {})
|
|
16
|
+
.then(res => {
|
|
17
|
+
if (res) {
|
|
18
|
+
localStorage.removeItem('session');
|
|
19
|
+
localStorage.removeItem('usuario');
|
|
20
|
+
localStorage.removeItem('location');
|
|
21
|
+
localStorage.removeItem('sessionGoogle');
|
|
22
|
+
localStorage.removeItem('namefood');
|
|
23
|
+
localStorage.removeItem('longitude');
|
|
24
|
+
localStorage.removeItem('latitude');
|
|
25
|
+
localStorage.removeItem('userlogin');
|
|
26
|
+
localStorage.removeItem('restaurant');
|
|
27
|
+
Cookies.remove('vp.store');
|
|
28
|
+
Cookies.remove('app.cart.sales');
|
|
29
|
+
Cookies.remove('restaurant');
|
|
30
|
+
client?.clearStore();
|
|
31
|
+
router.replace('/entrar');
|
|
32
|
+
setLoading(false);
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
.catch(() => {
|
|
31
36
|
setError(true)
|
|
32
37
|
setAlertBox({ message: 'Ocurrió un error al cerrar session' })
|
|
33
38
|
})
|
|
@@ -420,7 +420,6 @@ export const GET_EXTRAS_PRODUCT_FOOD_OPTIONAL = gql`
|
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
422
|
`;
|
|
423
|
-
|
|
424
423
|
export const GET_EXTRAS_PRODUCT_FOOD_SUB_OPTIONAL = gql`
|
|
425
424
|
mutation updateExtProductFoodsSubOptional(
|
|
426
425
|
$input: InputExtProductFoodSubOptional
|
|
@@ -702,6 +701,14 @@ export const GET_BANNER_PROMO_DASHBOARD = gql`
|
|
|
702
701
|
}
|
|
703
702
|
`;
|
|
704
703
|
|
|
704
|
+
export const CREATE_STORE_CALENDAR = gql`
|
|
705
|
+
mutation setStoreSchedule($input: ITstoreSchedule!) {
|
|
706
|
+
setStoreSchedule(input: $input) {
|
|
707
|
+
message
|
|
708
|
+
success
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
`;
|
|
705
712
|
export const DELETE_ONE_CAT_PRODUCTS = gql`
|
|
706
713
|
mutation deleteCatOfProducts($idPc: ID!, $pState: Int) {
|
|
707
714
|
deleteCatOfProducts(idPc: $idPc, pState: $pState) {
|
|
@@ -734,8 +741,14 @@ export const EDIT_EXTRA_PRODUCTS = gql`
|
|
|
734
741
|
}
|
|
735
742
|
}
|
|
736
743
|
`;
|
|
737
|
-
|
|
738
|
-
|
|
744
|
+
export const DELETE_CAT_EXTRA_PRODUCTS = gql`
|
|
745
|
+
mutation DeleteExtProductFoodsOptional($opExPid: ID, $state: Int) {
|
|
746
|
+
DeleteExtProductFoodsOptional(opExPid: $opExPid, state: $state) {
|
|
747
|
+
success
|
|
748
|
+
message
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
`;
|
|
739
752
|
export const DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS = gql`
|
|
740
753
|
mutation DeleteExtFoodSubsOptional($opSubExPid: ID, $state: Int) {
|
|
741
754
|
DeleteExtFoodSubsOptional(opSubExPid: $opSubExPid, state: $state) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useQuery, useLazyQuery } from '@apollo/client'
|
|
2
|
-
import { GET_ALL_SALES, GET_ALL_TOTAL_SALES } from './queries'
|
|
1
|
+
import { useQuery, useLazyQuery } from '@apollo/client';
|
|
2
|
+
import { GET_ALL_SALES, GET_ALL_TOTAL_SALES } from './queries';
|
|
3
3
|
|
|
4
4
|
export const useReport = ({
|
|
5
5
|
fromDate = '',
|
|
@@ -9,36 +9,40 @@ export const useReport = ({
|
|
|
9
9
|
toDate = '',
|
|
10
10
|
lazyQuery = false
|
|
11
11
|
}) => {
|
|
12
|
-
const [getAllSalesStore, { data: lazyDataSales, loading: lazyLoading }] = useLazyQuery(GET_ALL_SALES)
|
|
12
|
+
const [getAllSalesStore, { data: lazyDataSales, loading: lazyLoading }] = useLazyQuery(GET_ALL_SALES);
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
// Combine both queries to reduce separate requests
|
|
15
|
+
const { data, fetchMore, loading } = useQuery(GET_ALL_SALES, {
|
|
16
|
+
fetchPolicy: lazyQuery ? 'cache-and-network' : 'network-only',
|
|
16
17
|
skip: lazyQuery,
|
|
17
18
|
variables: {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
min: 0,
|
|
20
|
+
fromDate,
|
|
21
|
+
channel,
|
|
22
|
+
search,
|
|
23
|
+
toDate,
|
|
24
|
+
max: more
|
|
24
25
|
}
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Get total sales in the same query
|
|
29
|
+
const { data: totalSalesData } = useQuery(GET_ALL_TOTAL_SALES, {
|
|
28
30
|
variables: {
|
|
29
31
|
fromDate,
|
|
30
|
-
toDate
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
toDate
|
|
33
|
+
},
|
|
34
|
+
skip: !data || data?.getAllSalesStore?.length === 0 // Skip if main query hasn't loaded or has no data
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const totalSales = totalSalesData?.getAllSalesStoreTotal ?? {};
|
|
34
38
|
|
|
35
39
|
return {
|
|
36
|
-
getAllSalesStore,
|
|
37
|
-
data: data,
|
|
38
|
-
loading: lazyLoading || loading,
|
|
39
|
-
totalSales: totalSales
|
|
40
|
-
restaurant: totalSales
|
|
41
|
-
delivery: totalSales
|
|
40
|
+
getAllSalesStore: lazyQuery ? getAllSalesStore : () => { return }, // Return function only if in lazy mode
|
|
41
|
+
data: lazyQuery ? data || lazyDataSales : data, // Use data from lazy query if available
|
|
42
|
+
loading: lazyQuery ? lazyLoading || loading : loading,
|
|
43
|
+
totalSales: totalSales.TOTAL || 0,
|
|
44
|
+
restaurant: totalSales.restaurant || 0,
|
|
45
|
+
delivery: totalSales.delivery || 0,
|
|
42
46
|
fetchMore
|
|
43
|
-
}
|
|
44
|
-
}
|
|
47
|
+
};
|
|
48
|
+
};
|