npm-pkg-hook 1.11.3 → 1.11.7
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/.env +5 -1
- package/package.json +3 -2
- package/src/config/client/errors.js +1 -1
- package/src/config/content/en.json +5 -0
- package/src/config/content/es.json +5 -0
- package/src/config/content/index.js +16 -0
- package/src/hooks/index.js +6 -0
- package/src/hooks/newStoreOrderSubscription/index.js +1 -12
- package/src/hooks/updateExtProductFoodsOptional/index.js +2 -2
- package/src/hooks/useCatWithProduct/queries.js +50 -24
- package/src/hooks/useCategoriesProduct/index.js +1 -0
- package/src/hooks/useCategoriesProduct/queries.js +2 -2
- package/src/hooks/useCategoryInStore/queries.js +2 -2
- package/src/hooks/useClients/queries.js +72 -23
- package/src/hooks/useCreateProduct/helpers/index.js +2 -2
- package/src/hooks/useCreateProduct/index.js +45 -46
- package/src/hooks/useDessert/index.js +20 -3
- package/src/hooks/useDessertWithPrice/helpers/index.js +2 -2
- package/src/hooks/useDessertWithPrice/index.js +70 -60
- package/src/hooks/useDessertWithPrice/queries.js +2 -2
- package/src/hooks/useDevices/queries.js +16 -7
- package/src/hooks/useDevices/useGetDevices.js +12 -19
- package/src/hooks/useDevices/useRegisterDevices.js +3 -3
- package/src/hooks/useDownloadReports/helpers/downloadFileFromResponse.ts +21 -0
- package/src/hooks/useDownloadReports/index.ts +2 -0
- package/src/hooks/useDownloadReports/useDownloadReportByDay/index.ts +103 -0
- package/src/hooks/useDownloadReports/useGetReportByDateRange/index.ts +115 -0
- package/src/hooks/useEditCategory/index.js +10 -10
- package/src/hooks/useFormTools/index.js +2 -1
- package/src/hooks/useFormatDate/index.js +56 -3
- package/src/hooks/useGetStoreCookie/index.js +1 -1
- package/src/hooks/useImageUploaderProduct/helper/canvasUtils.ts +130 -0
- package/src/hooks/useImageUploaderProduct/helper/getOrientation.ts +53 -0
- package/src/hooks/useImageUploaderProduct/helper/index.ts +5 -0
- package/src/hooks/useImageUploaderProduct/index.ts +292 -0
- package/src/hooks/useImagesStore/index.js +100 -58
- package/src/hooks/useImagesStore/queries.js +2 -2
- package/src/hooks/useImagesStore/utils/index.js +4 -0
- package/src/hooks/useInventory/queries.js +1 -1
- package/src/hooks/useLocationManager/index.js +3 -1
- package/src/hooks/useLogout/helpers/fetchData.js +1 -1
- package/src/hooks/useLogout/helpers/logger.js +8 -8
- package/src/hooks/useLogout/index.js +6 -4
- package/src/hooks/useManageNewOrder/index.js +3 -3
- package/src/hooks/useManageQueryParams/index.js +28 -28
- package/src/hooks/useMobile/index.js +38 -8
- package/src/hooks/useOrderStatusTypes/index.ts +2 -0
- package/src/hooks/useOrderStatusTypes/useOrderStatusTypes/index.ts +52 -0
- package/src/hooks/useOrderStatusTypes/useUpdateOrderStatusPriorities/index.ts +97 -0
- package/src/hooks/useOrders/index.js +2 -74
- package/src/hooks/useOrders/queries.js +31 -195
- package/src/hooks/useOrders/useChangeOrderState/index.ts +125 -0
- package/src/hooks/useOrders/useOrdersFromStore/index.ts +83 -0
- package/src/hooks/usePortFetcher/index.ts +33 -0
- package/src/hooks/useProductsFood/index.js +3 -3
- package/src/hooks/useProductsFood/queriesStore.js +120 -64
- package/src/hooks/useProductsFood/useEditProduct.js +42 -2
- package/src/hooks/useProductsFood/usetagsProducts.js +47 -43
- package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +4 -4
- package/src/hooks/useSales/index.js +29 -19
- package/src/hooks/useSales/queries.js +140 -162
- package/src/hooks/useSales/useGetSale.js +3 -3
- package/src/hooks/useSaveAvailableProduct/index.js +1 -0
- package/src/hooks/useSetImageProducts/index.js +42 -13
- package/src/hooks/useSetImageProducts/queries.js +5 -0
- package/src/hooks/useStore/index.js +5 -1
- package/src/hooks/useStore/queries.js +71 -72
- package/src/hooks/useTagProducts/index.ts +3 -0
- package/src/hooks/useTagProducts/useDeleteOneTag.ts +106 -0
- package/src/hooks/useTagProducts/useGetAllTags.ts +68 -0
- package/src/hooks/useTagProducts/useRegisterMultipleTags.ts +156 -0
- package/src/hooks/useUpdateDashboardComponent/index.ts +91 -0
- package/src/hooks/useUpdateExistingOrders/index.js +3 -9
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +25 -3
- package/src/hooks/useUpdateMultipleExtProduct/index.js +33 -0
- package/src/hooks/useUpdateMultipleExtProduct/queries.js +33 -0
- package/src/hooks/useUploadProducts/index.js +0 -1
- package/src/hooks/useUser/queries.js +0 -1
- package/src/utils/index.js +97 -5
- package/tsconfig.json +5 -0
- package/src/hooks/useUpdateMultipleExtProductFoods/index.js +0 -21
- package/src/hooks/useUpdateMultipleExtProductFoods/queries.js +0 -19
|
@@ -11,41 +11,81 @@ import {
|
|
|
11
11
|
GET_ONE_BANNER_STORE
|
|
12
12
|
} from '../useProductsFood/queriesStore'
|
|
13
13
|
import { GET_ONE_STORE } from '../useStore/queries'
|
|
14
|
-
|
|
14
|
+
import { color } from './utils'
|
|
15
15
|
export * from './queries'
|
|
16
16
|
|
|
17
17
|
export const useImageStore = ({ idStore, sendNotification = () => { } } = {}) => {
|
|
18
18
|
// STATES
|
|
19
19
|
const fileInputRef = useRef(null)
|
|
20
|
-
const [{ altLogo, srcLogo }, setPreviewImgLogo] = useState({})
|
|
21
20
|
const initialState = { alt: '/images/DEFAULTBANNER.png', src: '/images/DEFAULTBANNER.png' }
|
|
21
|
+
const initialStateLogo = { altLogo: '/images/DEFAULTLOGO.png', srcLogo: '/images/DEFAULTLOGO.png' }
|
|
22
|
+
const [{ altLogo, srcLogo }, setPreviewImgLogo] = useState(initialStateLogo)
|
|
22
23
|
const [{ alt, src }, setPreviewImg] = useState(initialState)
|
|
23
24
|
const fileInputRefLogo = useRef(null)
|
|
25
|
+
|
|
24
26
|
// HOOKS
|
|
25
27
|
const [registerBanner] = useMutation(CREATE_BANNER_STORE, {
|
|
26
|
-
onCompleted: (data) => {
|
|
27
|
-
|
|
28
|
+
onCompleted: (data) => {
|
|
29
|
+
const { registerBanner } = data || {}
|
|
30
|
+
const { message = '', success = false } = registerBanner || {}
|
|
31
|
+
if (!success) {
|
|
32
|
+
setPreviewImg(initialState)
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
sendNotification({
|
|
36
|
+
title: success ? 'Banner subido' : 'Error al subir banner',
|
|
37
|
+
description: message,
|
|
38
|
+
backgroundColor: success ? color.success : color.error
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
28
42
|
})
|
|
29
|
-
const [
|
|
30
|
-
onCompleted: (data) => {
|
|
31
|
-
|
|
43
|
+
const [registerLogo] = useMutation(CREATE_LOGO, {
|
|
44
|
+
onCompleted: (data) => {
|
|
45
|
+
const { registerLogo } = data || {}
|
|
46
|
+
const { message = '', success = false } = registerLogo ?? {
|
|
47
|
+
message: 'Error al subir logo',
|
|
48
|
+
success: false,
|
|
49
|
+
data: null
|
|
50
|
+
}
|
|
51
|
+
if (!success) {
|
|
52
|
+
setPreviewImgLogo(initialStateLogo)
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
sendNotification({
|
|
57
|
+
title: success ? 'Logo creado con exito' : color.error,
|
|
58
|
+
description: message,
|
|
59
|
+
backgroundColor: success ? color.success : color.error
|
|
60
|
+
})
|
|
61
|
+
}
|
|
32
62
|
})
|
|
33
|
-
const [
|
|
34
|
-
onCompleted: (data) => {
|
|
35
|
-
|
|
63
|
+
const [deleteOneBanner] = useMutation(DELETE_ONE_BANNER_STORE, {
|
|
64
|
+
onCompleted: (data) => {
|
|
65
|
+
const { deleteOneBanner } = data || {}
|
|
66
|
+
const { message = '', success = false } = deleteOneBanner || {}
|
|
67
|
+
return sendNotification({
|
|
68
|
+
title: success ? 'Logo subido' : color.error,
|
|
69
|
+
description: message,
|
|
70
|
+
backgroundColor: success ? color.success : color.error
|
|
71
|
+
})
|
|
72
|
+
}
|
|
36
73
|
})
|
|
37
74
|
const [deleteALogoStore] = useMutation(DELETE_ONE_LOGO_STORE, {
|
|
38
75
|
onCompleted: (data) => {
|
|
76
|
+
const { deleteALogoStore } = data || {}
|
|
77
|
+
const { message = '', success = false } = deleteALogoStore || {}
|
|
39
78
|
sendNotification({
|
|
40
|
-
|
|
79
|
+
title: success ? 'Logo Eliminado' : 'Error al eliminar el logo',
|
|
80
|
+
description: message,
|
|
81
|
+
backgroundColor: success ? color.success : color.error
|
|
41
82
|
})
|
|
42
|
-
setPreviewImgLogo(
|
|
83
|
+
setPreviewImgLogo(initialStateLogo)
|
|
43
84
|
},
|
|
44
|
-
context: { clientName: 'admin-server' },
|
|
45
85
|
update (cache) {
|
|
46
86
|
cache.modify({
|
|
47
87
|
fields: {
|
|
48
|
-
getStore (dataOld =
|
|
88
|
+
getStore (dataOld = {}) {
|
|
49
89
|
return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld })
|
|
50
90
|
}
|
|
51
91
|
}
|
|
@@ -82,65 +122,64 @@ export const useImageStore = ({ idStore, sendNotification = () => { } } = {}) =>
|
|
|
82
122
|
update (cache) {
|
|
83
123
|
cache.modify({
|
|
84
124
|
fields: {
|
|
85
|
-
|
|
86
|
-
return cache.writeQuery({ query:
|
|
125
|
+
getStore (dataOld = {}) {
|
|
126
|
+
return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld })
|
|
87
127
|
}
|
|
88
128
|
}
|
|
89
129
|
})
|
|
90
130
|
}
|
|
91
|
-
}).catch(() => {
|
|
92
|
-
sendNotification({
|
|
93
|
-
title: 'No pudimos cargar la imagen',
|
|
94
|
-
description: 'Error',
|
|
95
|
-
backgroundColor: 'error'
|
|
96
|
-
})
|
|
97
|
-
setPreviewImg(initialState)
|
|
98
131
|
})
|
|
99
132
|
} catch {
|
|
100
133
|
setPreviewImg(initialState)
|
|
101
|
-
sendNotification({
|
|
102
|
-
title: 'No pudimos cargar la imagen',
|
|
103
|
-
description: 'Error',
|
|
104
|
-
backgroundColor: 'error'
|
|
105
|
-
})
|
|
106
134
|
}
|
|
107
135
|
}
|
|
108
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Handle store logo upload and update cache Image field
|
|
138
|
+
* @param {React.ChangeEvent<HTMLInputElement>} event - File input change event
|
|
139
|
+
* @returns {void}
|
|
140
|
+
*/
|
|
141
|
+
const handleInputChangeLogo = async (event) => {
|
|
109
142
|
const { files } = event.target
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
? {
|
|
113
|
-
srcLogo: URL.createObjectURL(files[0]),
|
|
114
|
-
altLogo: files[0].name
|
|
115
|
-
}
|
|
116
|
-
: initialState
|
|
117
|
-
)
|
|
118
|
-
setALogoStore({
|
|
119
|
-
variables: {
|
|
120
|
-
logo: files[0],
|
|
121
|
-
idStore
|
|
122
|
-
},
|
|
123
|
-
update (cache) {
|
|
124
|
-
cache.modify({
|
|
125
|
-
fields: {
|
|
126
|
-
getStore (dataOld = []) {
|
|
127
|
-
return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld })
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
}).catch(() => {
|
|
143
|
+
|
|
144
|
+
if (!files || files.length === 0) {
|
|
133
145
|
sendNotification({
|
|
134
|
-
title: '
|
|
135
|
-
description:
|
|
136
|
-
backgroundColor:
|
|
146
|
+
title: 'Debes seleccionar un archivo',
|
|
147
|
+
description: color.error,
|
|
148
|
+
backgroundColor: color.error
|
|
137
149
|
})
|
|
138
|
-
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const file = files[0]
|
|
154
|
+
|
|
155
|
+
const result = await registerLogo({
|
|
156
|
+
variables: { logo: file, idStore }
|
|
157
|
+
})
|
|
158
|
+
const {
|
|
159
|
+
data: {
|
|
160
|
+
registerLogo: {
|
|
161
|
+
success = false,
|
|
162
|
+
data: url = ''
|
|
163
|
+
} = {}
|
|
164
|
+
} = {}
|
|
165
|
+
} = result ?? {
|
|
166
|
+
data: '',
|
|
167
|
+
success: false,
|
|
168
|
+
message: ''
|
|
169
|
+
}
|
|
170
|
+
if (!success) {
|
|
171
|
+
setPreviewImgLogo(initialStateLogo)
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
setPreviewImgLogo({
|
|
175
|
+
srcLogo: URL.createObjectURL(file),
|
|
176
|
+
altLogo: url
|
|
139
177
|
})
|
|
140
178
|
}
|
|
179
|
+
|
|
141
180
|
const HandleDeleteBanner = async () => {
|
|
142
|
-
setPreviewImg(
|
|
143
|
-
|
|
181
|
+
setPreviewImg(initialStateLogo)
|
|
182
|
+
deleteOneBanner({
|
|
144
183
|
variables: {
|
|
145
184
|
idStore
|
|
146
185
|
},
|
|
@@ -165,6 +204,7 @@ export const useImageStore = ({ idStore, sendNotification = () => { } } = {}) =>
|
|
|
165
204
|
e.preventDefault()
|
|
166
205
|
fileInputRef.current.click()
|
|
167
206
|
}
|
|
207
|
+
|
|
168
208
|
return {
|
|
169
209
|
fileInputRefLogo,
|
|
170
210
|
src,
|
|
@@ -174,6 +214,8 @@ export const useImageStore = ({ idStore, sendNotification = () => { } } = {}) =>
|
|
|
174
214
|
altLogo,
|
|
175
215
|
fileInputRef,
|
|
176
216
|
handleDeleteLogo,
|
|
217
|
+
setPreviewImgLogo,
|
|
218
|
+
setPreviewImg,
|
|
177
219
|
onTargetClick,
|
|
178
220
|
onTargetClickLogo,
|
|
179
221
|
HandleDeleteBanner,
|
|
@@ -134,8 +134,8 @@ export const GET_All_RATING_STORE = gql`
|
|
|
134
134
|
}
|
|
135
135
|
`
|
|
136
136
|
export const CREATE_LOGO = gql`
|
|
137
|
-
mutation
|
|
138
|
-
|
|
137
|
+
mutation registerLogo($logo: Upload, $idStore: ID) {
|
|
138
|
+
registerLogo(logo: $logo, idStore: $idStore) {
|
|
139
139
|
success
|
|
140
140
|
message
|
|
141
141
|
}
|
|
@@ -10,6 +10,7 @@ import { useState } from 'react'
|
|
|
10
10
|
*/
|
|
11
11
|
export function useLocationManager (getDepartments, getCities) {
|
|
12
12
|
const [values, setValues] = useState({})
|
|
13
|
+
console.log('🚀 ~ useLocationManager ~ values:', values)
|
|
13
14
|
const [errors, setErrors] = useState({})
|
|
14
15
|
const [showLocation, setShowLocation] = useState(true)
|
|
15
16
|
|
|
@@ -26,7 +27,8 @@ export function useLocationManager (getDepartments, getCities) {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
const handleDepartmentSearch = (value) => {
|
|
29
|
-
|
|
30
|
+
setValues(prevValues => ({ ...prevValues, ctId: '' }))
|
|
31
|
+
getCities({ variables: { dId: value } })
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
const handleChangeLocation = (e, error) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { apiBaseUrl } from './apiBaseUrl'
|
|
2
2
|
|
|
3
|
-
async function fetchData
|
|
3
|
+
async function fetchData(path, __NEXTAUTH, logger, { ctx, req } = {}) {
|
|
4
4
|
const url = `${apiBaseUrl(__NEXTAUTH)}/${path}`
|
|
5
5
|
try {
|
|
6
6
|
const options = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function formatError
|
|
1
|
+
function formatError(o) {
|
|
2
2
|
if (hasErrorProperty(o)) {
|
|
3
3
|
o.error = formatError(o.error)
|
|
4
4
|
o.message = o.message ?? o.error.message
|
|
@@ -6,12 +6,12 @@ function formatError (o) {
|
|
|
6
6
|
return o
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
function hasErrorProperty
|
|
9
|
+
function hasErrorProperty(x) {
|
|
10
10
|
return !!(x?.error)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
const _logger = {
|
|
14
|
-
error
|
|
14
|
+
error(code, metadata) {
|
|
15
15
|
metadata = formatError(metadata)
|
|
16
16
|
console.error(
|
|
17
17
|
`[next-auth][error][${code}]`,
|
|
@@ -20,26 +20,26 @@ const _logger = {
|
|
|
20
20
|
metadata
|
|
21
21
|
)
|
|
22
22
|
},
|
|
23
|
-
warn
|
|
23
|
+
warn(code) {
|
|
24
24
|
console.warn(
|
|
25
25
|
`[next-auth][warn][${code}]`,
|
|
26
26
|
`\nhttps://next-auth.js.org/warnings#${code.toLowerCase()}`
|
|
27
27
|
)
|
|
28
28
|
},
|
|
29
|
-
debug
|
|
29
|
+
debug(code, metadata) {
|
|
30
30
|
console.log(`[next-auth][debug][${code}]`, metadata)
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export function setLogger
|
|
35
|
-
if (!debug) _logger.debug = () => {}
|
|
34
|
+
export function setLogger(newLogger = {}, debug) {
|
|
35
|
+
if (!debug) _logger.debug = () => { }
|
|
36
36
|
|
|
37
37
|
if (newLogger.error) _logger.error = newLogger.error
|
|
38
38
|
if (newLogger.warn) _logger.warn = newLogger.warn
|
|
39
39
|
if (newLogger.debug) _logger.debug = newLogger.debug
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export function proxyLogger
|
|
42
|
+
export function proxyLogger(logger = _logger, basePath) {
|
|
43
43
|
try {
|
|
44
44
|
if (typeof window === 'undefined') {
|
|
45
45
|
return logger
|
|
@@ -37,7 +37,7 @@ export const useLogout = ({
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
const deleteCookie = async () => {
|
|
40
|
-
await eliminarCookie(process.env.
|
|
40
|
+
await eliminarCookie(process.env.NEXT_PUBLIC_SESSION_NAME)
|
|
41
41
|
await eliminarCookie(process.env.LOCAL_SALES_STORE)
|
|
42
42
|
await eliminarCookie('restaurant')
|
|
43
43
|
await eliminarCookie('usuario')
|
|
@@ -50,7 +50,9 @@ export const useLogout = ({
|
|
|
50
50
|
setLoading(true)
|
|
51
51
|
await deleteCookie()
|
|
52
52
|
// Logout from the server
|
|
53
|
-
const
|
|
53
|
+
const port = window.location.port ? `:${window.location.port}` : ''
|
|
54
|
+
const baseUrl = `${window.location.protocol}//${window.location.hostname}${port}`
|
|
55
|
+
const logoutResponse = await fetch(`${baseUrl}/api/auth/signout/`, {
|
|
54
56
|
method: 'POST',
|
|
55
57
|
headers: {
|
|
56
58
|
'Content-Type': 'application/json'
|
|
@@ -66,8 +68,8 @@ export const useLogout = ({
|
|
|
66
68
|
await logoutResponse.json()
|
|
67
69
|
console.log('Intentando borrar cookies...')
|
|
68
70
|
|
|
69
|
-
// Eliminar la cookie process.env.
|
|
70
|
-
await eliminarCookie(process.env.
|
|
71
|
+
// Eliminar la cookie process.env.NEXT_PUBLIC_SESSION_NAME
|
|
72
|
+
await eliminarCookie(process.env.NEXT_PUBLIC_SESSION_NAME)
|
|
71
73
|
Cookies.remove(process.env.LOCAL_SALES_STORE)
|
|
72
74
|
Cookies.remove('restaurant')
|
|
73
75
|
Cookies.remove('usuario')
|
|
@@ -47,7 +47,7 @@ export const useManageNewOrder = ({
|
|
|
47
47
|
}
|
|
48
48
|
}, [data])
|
|
49
49
|
|
|
50
|
-
const {
|
|
50
|
+
const { getOneSalesStore } = useGetSale()
|
|
51
51
|
|
|
52
52
|
const handleNewOrder = (order) => {
|
|
53
53
|
const dataOrder = data[KEY_STATUS_ORDER]
|
|
@@ -59,13 +59,13 @@ export const useManageNewOrder = ({
|
|
|
59
59
|
return
|
|
60
60
|
}
|
|
61
61
|
setIsOpenOrder(true)
|
|
62
|
-
|
|
62
|
+
getOneSalesStore({
|
|
63
63
|
variables: {
|
|
64
64
|
pCodeRef: pCodeRef ?? ''
|
|
65
65
|
}
|
|
66
66
|
}).then((response) => {
|
|
67
67
|
console.log(response)
|
|
68
|
-
const currentSale = response?.data?.
|
|
68
|
+
const currentSale = response?.data?.getOneSalesStore || {}
|
|
69
69
|
client.cache.modify({
|
|
70
70
|
fields: {
|
|
71
71
|
getAllOrdersFromStore (existingOrders = []) {
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { useRouter, useSearchParams } from 'next/navigation'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Hook to manage query parameters in Next.js 13+ (App Router),
|
|
6
|
+
* with support for custom router/query injection.
|
|
7
|
+
* @param {Object} [options] - Optional parameters.
|
|
8
|
+
* @param {Object} [options.location] - Custom location object with query and push method
|
|
9
|
+
*/
|
|
1
10
|
export const useManageQueryParams = ({
|
|
2
|
-
location
|
|
3
|
-
query: {},
|
|
4
|
-
push: (props, state, { shallow }) => {
|
|
5
|
-
return { ...props, state, shallow }
|
|
6
|
-
}
|
|
7
|
-
}
|
|
11
|
+
location
|
|
8
12
|
} = {}) => {
|
|
13
|
+
const router = useRouter()
|
|
14
|
+
const searchParams = useSearchParams()
|
|
15
|
+
|
|
16
|
+
const activeQuery = location?.query || Object.fromEntries(searchParams.entries())
|
|
17
|
+
const pushFn = location?.push || ((url) => router.push(url))
|
|
18
|
+
|
|
9
19
|
const handleQuery = (name, value = '') => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
)
|
|
20
|
+
const params = new URLSearchParams(activeQuery)
|
|
21
|
+
params.set(name, value)
|
|
22
|
+
pushFn(`?${params.toString()}`)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const handleCleanQuery = (name) => {
|
|
26
|
+
const params = new URLSearchParams(activeQuery)
|
|
27
|
+
params.delete(name)
|
|
28
|
+
pushFn(`?${params.toString()}`)
|
|
20
29
|
}
|
|
21
30
|
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
...location.query,
|
|
25
|
-
[name]: value || ''
|
|
26
|
-
}
|
|
27
|
-
location.push(
|
|
28
|
-
{
|
|
29
|
-
query: updatedQuery
|
|
30
|
-
},
|
|
31
|
-
undefined,
|
|
32
|
-
{ shallow: true }
|
|
33
|
-
)
|
|
31
|
+
const getQuery = (name) => {
|
|
32
|
+
return activeQuery?.[name] || ''
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
return {
|
|
36
|
+
getQuery,
|
|
37
37
|
handleQuery,
|
|
38
38
|
handleCleanQuery
|
|
39
39
|
}
|
|
@@ -1,35 +1,65 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
1
|
+
import { useEffect, useRef, useState } from 'react'
|
|
2
2
|
|
|
3
3
|
export const MEDIA_QUERY = {
|
|
4
4
|
MOBILE: '(max-width: 768px)',
|
|
5
|
-
TABLET: '(max-width: 960px)'
|
|
5
|
+
TABLET: '(max-width: 960px)',
|
|
6
|
+
DESKTOP: '(min-width: 961px)'
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
export const useMobile = () => {
|
|
9
|
+
export const useMobile = ({ callback } = {}) => {
|
|
9
10
|
const [isMobile, setIsMobile] = useState(false)
|
|
10
11
|
const [isTablet, setIsTablet] = useState(false)
|
|
12
|
+
const [isDesktop, setIsDesktop] = useState(false)
|
|
13
|
+
|
|
14
|
+
const prevValues = useRef({
|
|
15
|
+
isMobile: false,
|
|
16
|
+
isTablet: false,
|
|
17
|
+
isDesktop: false
|
|
18
|
+
})
|
|
11
19
|
|
|
12
20
|
useEffect(() => {
|
|
13
21
|
if (typeof window === 'undefined') return
|
|
14
22
|
|
|
15
23
|
const mobileQuery = window.matchMedia(MEDIA_QUERY.MOBILE)
|
|
16
24
|
const tabletQuery = window.matchMedia(MEDIA_QUERY.TABLET)
|
|
25
|
+
const desktopQuery = window.matchMedia(MEDIA_QUERY.DESKTOP)
|
|
17
26
|
|
|
18
27
|
const updateMatches = () => {
|
|
19
|
-
|
|
20
|
-
|
|
28
|
+
const newIsMobile = mobileQuery.matches
|
|
29
|
+
const newIsTablet = tabletQuery.matches
|
|
30
|
+
const newIsDesktop = desktopQuery.matches
|
|
31
|
+
|
|
32
|
+
const hasChanged =
|
|
33
|
+
newIsMobile !== prevValues.current.isMobile ||
|
|
34
|
+
newIsTablet !== prevValues.current.isTablet ||
|
|
35
|
+
newIsDesktop !== prevValues.current.isDesktop
|
|
36
|
+
|
|
37
|
+
if (hasChanged) {
|
|
38
|
+
prevValues.current = {
|
|
39
|
+
isMobile: newIsMobile,
|
|
40
|
+
isTablet: newIsTablet,
|
|
41
|
+
isDesktop: newIsDesktop
|
|
42
|
+
}
|
|
43
|
+
callback?.(prevValues.current)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
setIsMobile(newIsMobile)
|
|
47
|
+
setIsTablet(newIsTablet)
|
|
48
|
+
setIsDesktop(newIsDesktop)
|
|
21
49
|
}
|
|
22
50
|
|
|
23
|
-
updateMatches()
|
|
51
|
+
updateMatches()
|
|
24
52
|
|
|
25
53
|
mobileQuery.addEventListener('change', updateMatches)
|
|
26
54
|
tabletQuery.addEventListener('change', updateMatches)
|
|
55
|
+
desktopQuery.addEventListener('change', updateMatches)
|
|
27
56
|
|
|
28
57
|
return () => {
|
|
29
58
|
mobileQuery.removeEventListener('change', updateMatches)
|
|
30
59
|
tabletQuery.removeEventListener('change', updateMatches)
|
|
60
|
+
desktopQuery.removeEventListener('change', updateMatches)
|
|
31
61
|
}
|
|
32
|
-
}, [])
|
|
62
|
+
}, [callback])
|
|
33
63
|
|
|
34
|
-
return { isMobile, isTablet }
|
|
64
|
+
return { isMobile, isTablet, isDesktop }
|
|
35
65
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useQuery, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL query to fetch order status types.
|
|
5
|
+
*/
|
|
6
|
+
const GET_ORDER_STATUS_TYPES = gql`
|
|
7
|
+
query getAllOrderStatusTypes {
|
|
8
|
+
getAllOrderStatusTypes {
|
|
9
|
+
idStatus
|
|
10
|
+
name
|
|
11
|
+
priority
|
|
12
|
+
backgroundColor
|
|
13
|
+
color
|
|
14
|
+
state
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
`
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {Object} OrderStatusType
|
|
21
|
+
* @property {string} idStatus - Unique identifier for the status
|
|
22
|
+
* @property {string} name - Name of the status
|
|
23
|
+
* @property {number} priority - Priority level
|
|
24
|
+
* @property {string} backgroundColor - Background color in hex
|
|
25
|
+
* @property {string} color - Text color in hex
|
|
26
|
+
* @property {number} state - Status state (e.g. active/inactive)
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Custom hook to fetch order status types.
|
|
31
|
+
*
|
|
32
|
+
* @returns {{
|
|
33
|
+
* statusTypes: OrderStatusType[] | null,
|
|
34
|
+
* loading: boolean,
|
|
35
|
+
* error: Error | undefined,
|
|
36
|
+
* refetch: () => void
|
|
37
|
+
* }}
|
|
38
|
+
*/
|
|
39
|
+
export const useOrderStatusTypes = () => {
|
|
40
|
+
const { data, loading, error, refetch } = useQuery(GET_ORDER_STATUS_TYPES, {
|
|
41
|
+
fetchPolicy: 'cache-and-network'
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const statusTypes = data?.getAllOrderStatusTypes ?? null
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
statusTypes,
|
|
48
|
+
loading,
|
|
49
|
+
error,
|
|
50
|
+
refetch
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { gql, useMutation } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL mutation to update the priority of order statuses.
|
|
5
|
+
*/
|
|
6
|
+
const UPDATE_ORDER_STATUS_PRIORITIES = gql`
|
|
7
|
+
mutation UpdateOrderStatusPriorities($data: [OrderStatusPriorityInput!]!) {
|
|
8
|
+
updateOrderStatusPriorities(data: $data) {
|
|
9
|
+
success
|
|
10
|
+
message
|
|
11
|
+
errors {
|
|
12
|
+
path
|
|
13
|
+
message
|
|
14
|
+
}
|
|
15
|
+
data {
|
|
16
|
+
idStatus
|
|
17
|
+
name
|
|
18
|
+
priority
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
`
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Custom hook to update the priority of order statuses.
|
|
26
|
+
*
|
|
27
|
+
* @returns {{
|
|
28
|
+
* updatePriorities: (input: OrderStatusPriorityInput[]) => Promise<UpdateStatusPriorityResponse>,
|
|
29
|
+
* loading: boolean,
|
|
30
|
+
* error: any
|
|
31
|
+
* }}
|
|
32
|
+
*/
|
|
33
|
+
export const useUpdateOrderStatusPriorities = ({
|
|
34
|
+
sendNotification = (...res) => { }
|
|
35
|
+
} = {}) => {
|
|
36
|
+
const [mutate, { loading, error }] = useMutation(UPDATE_ORDER_STATUS_PRIORITIES)
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Executes the mutation to update order status priorities.
|
|
40
|
+
*
|
|
41
|
+
* @param {OrderStatusPriorityInput[]} input - Array of objects containing idStatus and priority.
|
|
42
|
+
* @returns {Promise<UpdateStatusPriorityResponse>} Response from the server.
|
|
43
|
+
*/
|
|
44
|
+
const updatePriorities = async (input) => {
|
|
45
|
+
if (!Array.isArray(input) || input.length === 0) {
|
|
46
|
+
return {
|
|
47
|
+
success: false,
|
|
48
|
+
message: 'Input must be a non-empty array.',
|
|
49
|
+
data: [],
|
|
50
|
+
errors: [{ path: 'input', message: 'Invalid or empty input array.' }],
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const isValid = input.every(
|
|
55
|
+
({ idStatus, priority }) =>
|
|
56
|
+
typeof idStatus === 'string' &&
|
|
57
|
+
idStatus.length > 0 &&
|
|
58
|
+
typeof priority === 'number' &&
|
|
59
|
+
priority >= 0
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
if (!isValid) {
|
|
63
|
+
return {
|
|
64
|
+
success: false,
|
|
65
|
+
message: 'Validation failed for one or more input items.',
|
|
66
|
+
data: [],
|
|
67
|
+
errors: [{ path: 'input', message: 'Each item must have a valid idStatus and priority.' }],
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const { data } = await mutate({ variables: { data: input } })
|
|
73
|
+
if (data) {
|
|
74
|
+
const { updateOrderStatusPriorities } = data ?? {}
|
|
75
|
+
const { success, message } = updateOrderStatusPriorities ?? {
|
|
76
|
+
success: false,
|
|
77
|
+
message: ''
|
|
78
|
+
}
|
|
79
|
+
return sendNotification({
|
|
80
|
+
title: success ? 'Exitoso' : 'Error',
|
|
81
|
+
description: message,
|
|
82
|
+
backgroundColor: success ? 'success' : 'error'
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
return data.updateOrderStatusPriorities
|
|
86
|
+
} catch (err) {
|
|
87
|
+
return {
|
|
88
|
+
success: false,
|
|
89
|
+
message: 'Unexpected error while updating priorities.',
|
|
90
|
+
data: [],
|
|
91
|
+
errors: [{ path: 'mutation', message: err.message }],
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return [updatePriorities, { loading, error }]
|
|
97
|
+
}
|