npm-pkg-hook 1.10.0 → 1.10.2
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/handleLogin/index.js +0 -1
- package/src/hooks/index.js +1 -0
- package/src/hooks/useChartData/useChartDataAllOrders/index.js +1 -1
- package/src/hooks/useClients/queries.js +2 -2
- package/src/hooks/useCreateProduct/index.js +15 -0
- package/src/hooks/useDevices/index.js +2 -35
- package/src/hooks/useDevices/useGetDevices.js +35 -0
- package/src/hooks/useDevices/useRegisterDevices.js +75 -0
- package/src/hooks/useLogout/helpers/index.js +0 -1
- package/src/hooks/useModules/helpers/index.js +1 -0
- package/src/hooks/useModules/helpers/validateModules.js +29 -0
- package/src/hooks/useModules/index.js +19 -3
- package/src/hooks/useOrders/queries.js +1 -1
- package/src/hooks/useSales/index.js +173 -48
- package/src/hooks/useSales/queries.js +2 -0
- package/src/hooks/useStoreTable/index.js +2 -0
- package/src/hooks/useStoreTable/queries.js +47 -0
- package/src/hooks/useStoreTable/useStoreTableCreate.js +76 -0
- package/src/hooks/useStoreTable/useStoreTables.js +14 -0
- package/src/hooks/useSubscriptionValidation/index.js +0 -1
- package/src/hooks/useUpdateExistingOrders/index.js +1 -1
- package/src/hooks/useUpdateMultipleProducts/index.js +0 -1
- package/src/hooks/useUploadProducts/index.js +0 -1
- package/src/hooks/useUser/queries.js +7 -0
- package/src/utils/index.js +4 -1
package/package.json
CHANGED
package/src/hooks/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from './useModules'
|
|
|
10
10
|
export * from './getTotalHours'
|
|
11
11
|
export * from './useUpdateMultipleProducts'
|
|
12
12
|
export * from './useTokenCards'
|
|
13
|
+
export * from './useStoreTable/index'
|
|
13
14
|
export * from './useSubscriptionValidation'
|
|
14
15
|
export * from './convertToMilitaryTime'
|
|
15
16
|
export * from './useRoles'
|
|
@@ -134,8 +134,8 @@ mutation registerShoppingCard($input: IShoppingCard, $idSubArray: IID_SUB_ITEMS
|
|
|
134
134
|
}
|
|
135
135
|
`
|
|
136
136
|
export const CREATE_SHOPPING_CARD_TO_USER_STORE = gql`
|
|
137
|
-
mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $pCodeRef: String, $change: Float, $valueDelivery: Float, $payMethodPState: Int, $pickUp: Int, $totalProductsPrice: Float, $idSubArray: IID_SUB_ITEMS){
|
|
138
|
-
registerSalesStore(input: $input, id: $id, idStore: $idStore, pCodeRef: $pCodeRef, change: $change, valueDelivery: $valueDelivery, payMethodPState: $payMethodPState, pickUp: $pickUp, totalProductsPrice: $totalProductsPrice, idSubArray: $idSubArray){
|
|
137
|
+
mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $tableId: ID, $pCodeRef: String, $change: Float, $valueDelivery: Float, $payMethodPState: Int, $pickUp: Int, $totalProductsPrice: Float, $idSubArray: IID_SUB_ITEMS){
|
|
138
|
+
registerSalesStore(input: $input, id: $id, idStore: $idStore, tableId: $tableId, pCodeRef: $pCodeRef, change: $change, valueDelivery: $valueDelivery, payMethodPState: $payMethodPState, pickUp: $pickUp, totalProductsPrice: $totalProductsPrice, idSubArray: $idSubArray){
|
|
139
139
|
ShoppingCard {
|
|
140
140
|
ShoppingCard
|
|
141
141
|
id
|
|
@@ -12,6 +12,7 @@ import { useStore } from '../useStore'
|
|
|
12
12
|
import { useTagsProducts } from './../useProductsFood/usetagsProducts'
|
|
13
13
|
import { useEditImageProduct } from './helpers/useEditImageProduct'
|
|
14
14
|
import { getCatProductsWithProduct } from './helpers/manageCacheDataCatProduct'
|
|
15
|
+
import { assignWith } from 'lodash'
|
|
15
16
|
export * from './helpers'
|
|
16
17
|
|
|
17
18
|
export const useCreateProduct = ({
|
|
@@ -219,6 +220,19 @@ export const useCreateProduct = ({
|
|
|
219
220
|
carProId: ''
|
|
220
221
|
})
|
|
221
222
|
})
|
|
223
|
+
const { errors } = res ?? {
|
|
224
|
+
errors: []
|
|
225
|
+
}
|
|
226
|
+
if (errors?.length > 0) {
|
|
227
|
+
errors.forEach(error => {
|
|
228
|
+
sendNotification({
|
|
229
|
+
backgroundColor: 'error',
|
|
230
|
+
title: 'Error',
|
|
231
|
+
description: error.message
|
|
232
|
+
})
|
|
233
|
+
})
|
|
234
|
+
return
|
|
235
|
+
}
|
|
222
236
|
if (image !== null) {
|
|
223
237
|
try {
|
|
224
238
|
await setImageProducts({
|
|
@@ -240,6 +254,7 @@ export const useCreateProduct = ({
|
|
|
240
254
|
setPid(res?.data?.updateProductFoods?.data?.pId ?? null)
|
|
241
255
|
return res
|
|
242
256
|
} catch (error) {
|
|
257
|
+
console.log("🚀 ~ handleRegister ~ error:", error)
|
|
243
258
|
setAlertBox({ message: 'Ha ocurrido un error', duration: 7000 })
|
|
244
259
|
}
|
|
245
260
|
}
|
|
@@ -1,35 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { GET_ALL_DEVICES } from './queries'
|
|
4
|
-
import { useFormatDate } from '../useFormatDate'
|
|
5
|
-
|
|
6
|
-
export const useDevices = () => {
|
|
7
|
-
const { data, loading } = useQuery(GET_ALL_DEVICES, {
|
|
8
|
-
onError: (error) => {
|
|
9
|
-
console.error(error)
|
|
10
|
-
}
|
|
11
|
-
})
|
|
12
|
-
const [deviceId, setDeviceId] = useState(false)
|
|
13
|
-
const [date, setDate] = useState('')
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (window) {
|
|
17
|
-
setDeviceId(window.localStorage.getItem('deviceid'))
|
|
18
|
-
}
|
|
19
|
-
}, [])
|
|
20
|
-
|
|
21
|
-
// Función para formatear la fecha
|
|
22
|
-
const formatDate = useFormatDate({ date })
|
|
23
|
-
|
|
24
|
-
const updateDate = (newDate) => {
|
|
25
|
-
setDate(newDate)
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
data: data?.getDeviceUsers || [],
|
|
29
|
-
date,
|
|
30
|
-
deviceId,
|
|
31
|
-
formatDate,
|
|
32
|
-
loading,
|
|
33
|
-
updateDate
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
export * from './useGetDevices'
|
|
2
|
+
export * from './useRegisterDevices'
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react'
|
|
2
|
+
import { useQuery } from '@apollo/client'
|
|
3
|
+
import { GET_ALL_DEVICES } from './queries'
|
|
4
|
+
import { useFormatDate } from '../useFormatDate'
|
|
5
|
+
|
|
6
|
+
export const useDevices = () => {
|
|
7
|
+
const { data, loading } = useQuery(GET_ALL_DEVICES, {
|
|
8
|
+
onError: (error) => {
|
|
9
|
+
console.error(error)
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
const [deviceId, setDeviceId] = useState(false)
|
|
13
|
+
const [date, setDate] = useState('')
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (window) {
|
|
17
|
+
setDeviceId(window.localStorage.getItem('deviceid'))
|
|
18
|
+
}
|
|
19
|
+
}, [])
|
|
20
|
+
|
|
21
|
+
// Función para formatear la fecha
|
|
22
|
+
const formatDate = useFormatDate({ date })
|
|
23
|
+
|
|
24
|
+
const updateDate = (newDate) => {
|
|
25
|
+
setDate(newDate)
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
data: data?.getDeviceUsers || [],
|
|
29
|
+
date,
|
|
30
|
+
deviceId,
|
|
31
|
+
formatDate,
|
|
32
|
+
loading,
|
|
33
|
+
updateDate
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useMutation, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL mutation para registrar un nuevo dispositivo
|
|
5
|
+
*/
|
|
6
|
+
const REGISTER_DEVICE_USER = gql`
|
|
7
|
+
mutation RegisterDeviceUser($input: DeviceUserInput!) {
|
|
8
|
+
newRegisterDeviceUser(input: $input) {
|
|
9
|
+
success
|
|
10
|
+
message
|
|
11
|
+
data {
|
|
12
|
+
dId
|
|
13
|
+
id
|
|
14
|
+
deviceId
|
|
15
|
+
deviceName
|
|
16
|
+
locationFormat
|
|
17
|
+
type
|
|
18
|
+
short_name
|
|
19
|
+
platform
|
|
20
|
+
version
|
|
21
|
+
dState
|
|
22
|
+
DatCre
|
|
23
|
+
DatMod
|
|
24
|
+
}
|
|
25
|
+
errors {
|
|
26
|
+
path
|
|
27
|
+
message
|
|
28
|
+
type
|
|
29
|
+
context {
|
|
30
|
+
limit
|
|
31
|
+
value
|
|
32
|
+
label
|
|
33
|
+
key
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
`
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Custom hook para la mutación RegisterDeviceUser
|
|
42
|
+
* @returns {Object} - Función para registrar el dispositivo y el estado de la operación
|
|
43
|
+
*/
|
|
44
|
+
export const useRegisterDeviceUser = () => {
|
|
45
|
+
const [registerDeviceUser, { loading, error, data }] = useMutation(REGISTER_DEVICE_USER)
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Función para manejar la mutación
|
|
49
|
+
* @param {Object} input - Datos del dispositivo a registrar
|
|
50
|
+
* @returns {Promise<Object>} - Resultado de la operación
|
|
51
|
+
*/
|
|
52
|
+
const handleRegisterDeviceUser = async (input) => {
|
|
53
|
+
try {
|
|
54
|
+
const result = await registerDeviceUser({ variables: { input } })
|
|
55
|
+
|
|
56
|
+
if (result.data?.newRegisterDeviceUser?.success) {
|
|
57
|
+
return { success: true, data: result.data.newRegisterDeviceUser.data }
|
|
58
|
+
} else {
|
|
59
|
+
return {
|
|
60
|
+
success: false,
|
|
61
|
+
errors: result.data?.newRegisterDeviceUser?.errors || []
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.error('Error while registering device user:', err)
|
|
66
|
+
return { success: false, errors: [{ message: err.message }] }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return [handleRegisterDeviceUser, {
|
|
71
|
+
loading,
|
|
72
|
+
error,
|
|
73
|
+
data
|
|
74
|
+
}]
|
|
75
|
+
}
|
|
@@ -23,7 +23,6 @@ export const __NEXTAUTH = {
|
|
|
23
23
|
|
|
24
24
|
export async function signOutAuth (options) {
|
|
25
25
|
const { callbackUrl = window.location.href, reload = true } = options ?? {}
|
|
26
|
-
console.log('🚀 ~ signOutAuth ~ options:', options)
|
|
27
26
|
const baseUrl = apiBaseUrl(__NEXTAUTH)
|
|
28
27
|
const fetchOptions = {
|
|
29
28
|
method: 'post',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './validateModules'
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates and filters modules based on the "read" permission.
|
|
3
|
+
* If a module's view does not have "read" permission in the permissions object, the module is removed.
|
|
4
|
+
*
|
|
5
|
+
* @param {Array} modules - List of modules to validate.
|
|
6
|
+
* @param {Object} permissions - Permissions object mapping views to their allowed actions.
|
|
7
|
+
* @returns {Array} - Filtered list of valid modules.
|
|
8
|
+
*/
|
|
9
|
+
export const validateModules = (modules = [], permissions = {}) => {
|
|
10
|
+
return modules
|
|
11
|
+
.map(module => {
|
|
12
|
+
// Check if the main module's view has "read" permission
|
|
13
|
+
const hasReadPermission = permissions[module.view]?.includes('read')
|
|
14
|
+
|
|
15
|
+
// Validate and filter subModules if they exist
|
|
16
|
+
const validSubModules = module.subModules?.filter(subModule =>
|
|
17
|
+
permissions[subModule.view]?.includes('read')
|
|
18
|
+
) || []
|
|
19
|
+
|
|
20
|
+
// If the module or its subModules don't have read permission, exclude it
|
|
21
|
+
if (!hasReadPermission && validSubModules.length === 0) {
|
|
22
|
+
return null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Return the module with its valid subModules
|
|
26
|
+
return { ...module, subModules: validSubModules }
|
|
27
|
+
})
|
|
28
|
+
.filter(Boolean) // Remove null values
|
|
29
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { gql, useQuery } from '@apollo/client'
|
|
2
|
+
import { validateModules } from './helpers/validateModules'
|
|
2
3
|
|
|
3
4
|
const GET_MODULES = gql`
|
|
4
5
|
query GetModules {
|
|
@@ -8,22 +9,37 @@ const GET_MODULES = gql`
|
|
|
8
9
|
mPath
|
|
9
10
|
mPriority
|
|
10
11
|
mIcon
|
|
12
|
+
view
|
|
11
13
|
subModules {
|
|
12
14
|
smId
|
|
13
15
|
smName
|
|
14
16
|
smPath
|
|
17
|
+
view
|
|
15
18
|
smState
|
|
16
19
|
}
|
|
17
20
|
}
|
|
18
21
|
}
|
|
19
22
|
`
|
|
20
23
|
|
|
21
|
-
export const useModules = () => {
|
|
22
|
-
const {
|
|
24
|
+
export const useModules = (dataUser = {}) => {
|
|
25
|
+
const { role } = dataUser ?? {
|
|
26
|
+
role: {
|
|
27
|
+
permissions: {}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const {
|
|
31
|
+
loading,
|
|
32
|
+
error,
|
|
33
|
+
data
|
|
34
|
+
} = useQuery(GET_MODULES)
|
|
35
|
+
|
|
36
|
+
const permissions = role?.permissions ?? {}
|
|
37
|
+
|
|
38
|
+
const filteredModules = validateModules(data ? data.modules : [], permissions)
|
|
23
39
|
|
|
24
40
|
return {
|
|
25
41
|
loading,
|
|
26
42
|
error,
|
|
27
|
-
modules: data ?
|
|
43
|
+
modules: data ? filteredModules : []
|
|
28
44
|
}
|
|
29
45
|
}
|
|
@@ -59,8 +59,8 @@ export const initializer = (initialValue = initialState) => {
|
|
|
59
59
|
export const useSales = ({
|
|
60
60
|
disabled = false,
|
|
61
61
|
router,
|
|
62
|
-
sendNotification = (
|
|
63
|
-
setAlertBox = (
|
|
62
|
+
sendNotification = (args) => { return args },
|
|
63
|
+
setAlertBox = (args) => { return args }
|
|
64
64
|
}) => {
|
|
65
65
|
const domain = getCurrentDomain()
|
|
66
66
|
const [loadingSale, setLoadingSale] = useState(false)
|
|
@@ -195,11 +195,11 @@ export const useSales = ({
|
|
|
195
195
|
// HANDLESS
|
|
196
196
|
// FILTER PRODUCT DATA_DB
|
|
197
197
|
// @ts-ignore
|
|
198
|
-
const handlePrint = (
|
|
198
|
+
const handlePrint = () => {
|
|
199
199
|
if (disabled) {
|
|
200
200
|
return sendNotification({
|
|
201
201
|
title: 'Error',
|
|
202
|
-
description: 'Esta es la
|
|
202
|
+
description: 'Esta es la descripción',
|
|
203
203
|
backgroundColor: 'error'
|
|
204
204
|
})
|
|
205
205
|
}
|
|
@@ -219,6 +219,25 @@ export const useSales = ({
|
|
|
219
219
|
const onChangeInput = (e) => {
|
|
220
220
|
return setValuesDates({ ...valuesDates, [e.target.name]: e.target.value })
|
|
221
221
|
}
|
|
222
|
+
const handleToggleEditingStatus = (state, action) => {
|
|
223
|
+
const { PRODUCT } = state ?? {
|
|
224
|
+
PRODUCT: []
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
...state,
|
|
228
|
+
PRODUCT: PRODUCT.map((item) => {
|
|
229
|
+
if (item.pId === action.payload.pId) {
|
|
230
|
+
return {
|
|
231
|
+
...item,
|
|
232
|
+
editing: !item.editing,
|
|
233
|
+
oldQuantity: item.ProQuantity
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return item
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
222
241
|
const handleChangeFilterProduct = (e) => {
|
|
223
242
|
const text = searchedInput(e.target.value)
|
|
224
243
|
if (text === undefined || text === '') {
|
|
@@ -232,11 +251,94 @@ export const useSales = ({
|
|
|
232
251
|
setOneProductToComment(product)
|
|
233
252
|
setValues({
|
|
234
253
|
...values,
|
|
235
|
-
comment: product?.comment
|
|
254
|
+
comment: product?.comment ?? ''
|
|
236
255
|
})
|
|
237
256
|
}
|
|
238
257
|
setOpenCommentModal(!openCommentModal)
|
|
239
258
|
}
|
|
259
|
+
const handleSuccessUpdateQuantity = (state, payload) => {
|
|
260
|
+
const { pId } = payload.payload || {
|
|
261
|
+
pId: null
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
...state,
|
|
265
|
+
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
266
|
+
return items.pId === pId
|
|
267
|
+
? {
|
|
268
|
+
...items,
|
|
269
|
+
editing: false,
|
|
270
|
+
oldQuantity: items.ProQuantity
|
|
271
|
+
}
|
|
272
|
+
: items
|
|
273
|
+
})
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Cancels the update of a product's quantity, resetting it to the previous value.
|
|
279
|
+
* @param {Object} state - The current state.
|
|
280
|
+
* @param {Object} payload - The payload containing the product ID.
|
|
281
|
+
* @returns {Object} - The new state with the updated product quantity and editing status.
|
|
282
|
+
*/
|
|
283
|
+
const handleCancelUpdateQuantity = (state, payload) => {
|
|
284
|
+
// Validación de `state`
|
|
285
|
+
if (!state || typeof state !== 'object') {
|
|
286
|
+
sendNotification({
|
|
287
|
+
title: 'Error',
|
|
288
|
+
backgroundColor: 'error',
|
|
289
|
+
description: 'Ha ocurrido un error al actualizar la cantidad del producto.'
|
|
290
|
+
})
|
|
291
|
+
return state // Retorna el estado sin cambios si es inválido.
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Validación de `PRODUCT`
|
|
295
|
+
if (!Array.isArray(state.PRODUCT)) {
|
|
296
|
+
sendNotification({
|
|
297
|
+
title: 'Error',
|
|
298
|
+
backgroundColor: 'error',
|
|
299
|
+
description: 'Ha ocurrido un error al actualizar la cantidad del producto.'
|
|
300
|
+
})
|
|
301
|
+
return state // Retorna el estado sin cambios si `PRODUCT` no es un array.
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Validación de `payload`
|
|
305
|
+
const { pId } = payload.payload || {}
|
|
306
|
+
if (!pId) {
|
|
307
|
+
sendNotification({
|
|
308
|
+
title: 'Error',
|
|
309
|
+
backgroundColor: 'error',
|
|
310
|
+
description: 'Ha ocurrido un error al actualizar la cantidad del producto.'
|
|
311
|
+
})
|
|
312
|
+
return state // Retorna el estado sin cambios si falta `pId`.
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return {
|
|
316
|
+
...state,
|
|
317
|
+
PRODUCT: state.PRODUCT.map((item) => {
|
|
318
|
+
// Validación de propiedades en cada item
|
|
319
|
+
if (item.pId === pId) {
|
|
320
|
+
if (typeof item.oldQuantity !== 'number' || typeof item.unitPrice !== 'number') {
|
|
321
|
+
sendNotification({
|
|
322
|
+
title: 'Error',
|
|
323
|
+
backgroundColor: 'error',
|
|
324
|
+
description: 'Ha ocurrido un error al actualizar la cantidad del producto.'
|
|
325
|
+
})
|
|
326
|
+
return item // Retorna el item sin cambios si las propiedades son inválidas.
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return {
|
|
330
|
+
...item,
|
|
331
|
+
editing: false,
|
|
332
|
+
ProQuantity: item.oldQuantity,
|
|
333
|
+
ProPrice: item.oldQuantity * item.unitPrice
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return item
|
|
338
|
+
})
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
240
342
|
const handleChangeNumber = useCallback(
|
|
241
343
|
(state, action) => {
|
|
242
344
|
const event = action.payload
|
|
@@ -271,6 +373,12 @@ export const useSales = ({
|
|
|
271
373
|
},
|
|
272
374
|
[productsFood]
|
|
273
375
|
)
|
|
376
|
+
const paymentMethod = (state, action) => {
|
|
377
|
+
return {
|
|
378
|
+
...state,
|
|
379
|
+
payMethodPState: action.payload
|
|
380
|
+
}
|
|
381
|
+
}
|
|
274
382
|
const PRODUCT = (state, action) => {
|
|
275
383
|
const productExist = state.PRODUCT.find((items) => {
|
|
276
384
|
return items.pId === action.id
|
|
@@ -302,6 +410,12 @@ export const useSales = ({
|
|
|
302
410
|
case 'ON_CHANGE': {
|
|
303
411
|
return handleChangeNumber(state, action)
|
|
304
412
|
}
|
|
413
|
+
case 'UPDATE_SUCCESS_QUANTITY_EDITING_PRODUCT': {
|
|
414
|
+
return handleSuccessUpdateQuantity(state, action)
|
|
415
|
+
}
|
|
416
|
+
case 'CANCEL_UPDATE_QUANTITY_EDITING_PRODUCT': {
|
|
417
|
+
return handleCancelUpdateQuantity(state, action)
|
|
418
|
+
}
|
|
305
419
|
case 'REMOVE_ALL_PRODUCTS':
|
|
306
420
|
// @ts-ignore
|
|
307
421
|
setValues({
|
|
@@ -319,6 +433,9 @@ export const useSales = ({
|
|
|
319
433
|
|
|
320
434
|
case 'TOGGLE_FREE_PRODUCT':
|
|
321
435
|
return toggleFreeProducts(state, action)
|
|
436
|
+
case 'TOGGLE_EDITING_PRODUCT': {
|
|
437
|
+
return handleToggleEditingStatus(state, action)
|
|
438
|
+
}
|
|
322
439
|
case 'INCREMENT':
|
|
323
440
|
return {
|
|
324
441
|
...state,
|
|
@@ -350,21 +467,14 @@ export const useSales = ({
|
|
|
350
467
|
return {
|
|
351
468
|
...state
|
|
352
469
|
}
|
|
353
|
-
case '
|
|
354
|
-
|
|
355
|
-
...state,
|
|
356
|
-
payMethodPState: 1
|
|
357
|
-
}
|
|
358
|
-
case 'PAYMENT_METHOD_MONEY':
|
|
359
|
-
return {
|
|
360
|
-
...state,
|
|
361
|
-
payMethodPState: 0
|
|
362
|
-
}
|
|
470
|
+
case 'PAYMENT_METHOD': return paymentMethod(state, action)
|
|
471
|
+
|
|
363
472
|
default:
|
|
364
473
|
return state
|
|
365
474
|
}
|
|
366
475
|
}
|
|
367
476
|
const [data, dispatch] = useReducer(PRODUCT, initialStateSales, initializer)
|
|
477
|
+
|
|
368
478
|
const handleRemoveValue = useCallback(({ name, value, pId }) => {
|
|
369
479
|
setValues({
|
|
370
480
|
...values,
|
|
@@ -611,6 +721,7 @@ export const useSales = ({
|
|
|
611
721
|
const updatedProduct = {
|
|
612
722
|
pId,
|
|
613
723
|
pName,
|
|
724
|
+
editing: false,
|
|
614
725
|
getOneTags,
|
|
615
726
|
unitPrice: OurProduct?.ProPrice,
|
|
616
727
|
ProDescription,
|
|
@@ -639,6 +750,8 @@ export const useSales = ({
|
|
|
639
750
|
...item,
|
|
640
751
|
getOneTags: OurProduct?.genderTags,
|
|
641
752
|
unitPrice: OurProduct?.ProPrice,
|
|
753
|
+
editing: false,
|
|
754
|
+
oldQuantity: productExist.ProQuantity + +1,
|
|
642
755
|
ProPrice: isFree ? 0 : (productExist.ProQuantity + 1) * OurProduct?.ProPrice,
|
|
643
756
|
ProQuantity: productExist.ProQuantity + +1,
|
|
644
757
|
free: !!isFree
|
|
@@ -741,41 +854,40 @@ export const useSales = ({
|
|
|
741
854
|
}
|
|
742
855
|
return ''
|
|
743
856
|
}
|
|
744
|
-
const arrayProduct =
|
|
745
|
-
data?.PRODUCT?.
|
|
746
|
-
|
|
747
|
-
const filteredDataExtra =
|
|
857
|
+
const arrayProduct = data?.PRODUCT?.length > 0
|
|
858
|
+
? data?.PRODUCT?.map((product) => {
|
|
859
|
+
const filteredDataExtra =
|
|
748
860
|
product?.dataExtra?.map(({ __typename, ...rest }) => rest) ?? []
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
)
|
|
758
|
-
return {
|
|
759
|
-
...rest,
|
|
760
|
-
ExtProductFoodsSubOptionalAll: adjustedSubOptionalAll
|
|
861
|
+
const dataOptional = product?.dataOptional?.map(
|
|
862
|
+
({ __typename, ...product }) => {
|
|
863
|
+
const { ExtProductFoodsSubOptionalAll, ...rest } = product
|
|
864
|
+
const adjustedSubOptionalAll = ExtProductFoodsSubOptionalAll?.map(
|
|
865
|
+
(subOption) => {
|
|
866
|
+
const { __typename, ...subOptionRest } = subOption
|
|
867
|
+
return subOptionRest
|
|
761
868
|
}
|
|
869
|
+
)
|
|
870
|
+
return {
|
|
871
|
+
...rest,
|
|
872
|
+
ExtProductFoodsSubOptionalAll: adjustedSubOptionalAll
|
|
762
873
|
}
|
|
763
|
-
)
|
|
764
|
-
const refCodePid = RandomCode(20)
|
|
765
|
-
return {
|
|
766
|
-
pId: product?.pId,
|
|
767
|
-
refCodePid,
|
|
768
|
-
id: values?.cliId,
|
|
769
|
-
cantProducts: parseInt(
|
|
770
|
-
product?.ProQuantity ? product?.ProQuantity : 0
|
|
771
|
-
),
|
|
772
|
-
comments: product?.comment ?? '',
|
|
773
|
-
dataOptional: dataOptional ?? [],
|
|
774
|
-
dataExtra: filteredDataExtra || [],
|
|
775
|
-
ProPrice: product.ProPrice
|
|
776
874
|
}
|
|
777
|
-
|
|
778
|
-
|
|
875
|
+
)
|
|
876
|
+
const refCodePid = RandomCode(20)
|
|
877
|
+
return {
|
|
878
|
+
pId: product?.pId,
|
|
879
|
+
refCodePid,
|
|
880
|
+
id: values?.cliId,
|
|
881
|
+
cantProducts: parseInt(
|
|
882
|
+
product?.ProQuantity ? product?.ProQuantity : 0
|
|
883
|
+
),
|
|
884
|
+
comments: product?.comment ?? '',
|
|
885
|
+
dataOptional: dataOptional ?? [],
|
|
886
|
+
dataExtra: filteredDataExtra || [],
|
|
887
|
+
ProPrice: product.ProPrice
|
|
888
|
+
}
|
|
889
|
+
})
|
|
890
|
+
: []
|
|
779
891
|
const finalArrayProduct = arrayProduct.map((item) => {
|
|
780
892
|
const totalExtra = item.dataExtra.reduce(
|
|
781
893
|
(accumulator, extra) => accumulator + extra.newExtraPrice,
|
|
@@ -857,13 +969,24 @@ export const useSales = ({
|
|
|
857
969
|
}
|
|
858
970
|
return cadena || 0
|
|
859
971
|
}
|
|
972
|
+
const {
|
|
973
|
+
change,
|
|
974
|
+
valueDelivery,
|
|
975
|
+
tableId
|
|
976
|
+
} = values || {
|
|
977
|
+
change: 0,
|
|
978
|
+
valueDelivery: 0,
|
|
979
|
+
tableId: null,
|
|
980
|
+
cliId: null
|
|
981
|
+
}
|
|
860
982
|
return registerSalesStore({
|
|
861
983
|
variables: {
|
|
862
984
|
input: finalArrayProduct || [],
|
|
863
985
|
id: values?.cliId,
|
|
864
986
|
pCodeRef: code,
|
|
865
|
-
|
|
866
|
-
|
|
987
|
+
tableId,
|
|
988
|
+
change: convertInteger(change),
|
|
989
|
+
valueDelivery: convertInteger(valueDelivery),
|
|
867
990
|
payMethodPState: data.payMethodPState,
|
|
868
991
|
pickUp: 1,
|
|
869
992
|
discount: discount.discount || 0,
|
|
@@ -885,6 +1008,8 @@ export const useSales = ({
|
|
|
885
1008
|
client.writeQuery({ query: GET_ALL_COUNT_SALES, data: { getTodaySales: data.countSales.todaySales } })
|
|
886
1009
|
}
|
|
887
1010
|
})
|
|
1011
|
+
setValues({})
|
|
1012
|
+
handleChange({ target: { name: 'tableId', value: '' } })
|
|
888
1013
|
getOnePedidoStore({
|
|
889
1014
|
variables: {
|
|
890
1015
|
pCodeRef: code || ''
|
|
@@ -345,6 +345,7 @@ export const CREATE_SHOPPING_CARD_TO_USER_STORE = gql`
|
|
|
345
345
|
$pCodeRef: String
|
|
346
346
|
$discount: Int
|
|
347
347
|
$change: Float
|
|
348
|
+
$tableId: ID
|
|
348
349
|
$valueDelivery: Float
|
|
349
350
|
$payMethodPState: Int
|
|
350
351
|
$pickUp: Int
|
|
@@ -357,6 +358,7 @@ export const CREATE_SHOPPING_CARD_TO_USER_STORE = gql`
|
|
|
357
358
|
idStore: $idStore
|
|
358
359
|
pCodeRef: $pCodeRef
|
|
359
360
|
change: $change
|
|
361
|
+
tableId: $tableId
|
|
360
362
|
discount: $discount
|
|
361
363
|
valueDelivery: $valueDelivery
|
|
362
364
|
payMethodPState: $payMethodPState
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL Mutation for creating a store table
|
|
5
|
+
*/
|
|
6
|
+
export const CREATE_TABLE_MUTATION = gql`
|
|
7
|
+
mutation storeTableCreate($tableName: String!, $seats: Int, $section: String, $tableState: Int) {
|
|
8
|
+
storeTableCreate(tableName: $tableName, seats: $seats, section: $section, tableState: $tableState) {
|
|
9
|
+
success
|
|
10
|
+
message
|
|
11
|
+
errors {
|
|
12
|
+
message
|
|
13
|
+
path
|
|
14
|
+
type
|
|
15
|
+
context {
|
|
16
|
+
limit
|
|
17
|
+
value
|
|
18
|
+
label
|
|
19
|
+
key
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
data {
|
|
23
|
+
tableId
|
|
24
|
+
tableName
|
|
25
|
+
seats
|
|
26
|
+
section
|
|
27
|
+
tableState
|
|
28
|
+
createdAt
|
|
29
|
+
updatedAt
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`
|
|
34
|
+
|
|
35
|
+
export const STORE_TABLES_QUERY = gql`
|
|
36
|
+
query {
|
|
37
|
+
storeTables {
|
|
38
|
+
tableId
|
|
39
|
+
tableName
|
|
40
|
+
seats
|
|
41
|
+
section
|
|
42
|
+
tableState
|
|
43
|
+
createdAt
|
|
44
|
+
updatedAt
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { gql, useMutation } from '@apollo/client'
|
|
3
|
+
import { CREATE_TABLE_MUTATION } from './queries'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Custom hook to handle table creation with validation and mutation logic
|
|
7
|
+
* @param {string} tableName Name of the table
|
|
8
|
+
* @param {number} seats Number of seats at the table
|
|
9
|
+
* @param {string} section Section where the table is located
|
|
10
|
+
* @param {number} tableState Current state of the table (e.g., Active, Occupied)
|
|
11
|
+
* @returns {Object} The state of the mutation including success, message, errors, and data
|
|
12
|
+
*/
|
|
13
|
+
export const useStoreTableCreate = ({
|
|
14
|
+
sendNotification = () => {}
|
|
15
|
+
} = {}) => {
|
|
16
|
+
const [loading, setLoading] = useState(false)
|
|
17
|
+
const [createTableMutation] = useMutation(CREATE_TABLE_MUTATION)
|
|
18
|
+
/**
|
|
19
|
+
* Function to create a table with validation and mutation
|
|
20
|
+
* @param {string} tableName Table name
|
|
21
|
+
* @param {number} seats Number of seats
|
|
22
|
+
* @param {string} section Table section
|
|
23
|
+
* @param {number} tableState Table state (e.g., 0 = Unavailable, 1 = Active, 2 = Occupied)
|
|
24
|
+
*/
|
|
25
|
+
const storeTableCreate = async (tableName, seats, section, tableState) => {
|
|
26
|
+
setLoading(true) // Start loading
|
|
27
|
+
try {
|
|
28
|
+
// Call the mutation to create the table
|
|
29
|
+
const result = await createTableMutation({
|
|
30
|
+
variables: {
|
|
31
|
+
tableName,
|
|
32
|
+
seats,
|
|
33
|
+
section,
|
|
34
|
+
tableState
|
|
35
|
+
},
|
|
36
|
+
update (cache, { data: { storeTableCreate } }) {
|
|
37
|
+
if (storeTableCreate.success) {
|
|
38
|
+
// Actualizar la lista de mesas en la caché
|
|
39
|
+
cache.modify({
|
|
40
|
+
fields: {
|
|
41
|
+
storeTables (existingTables = []) {
|
|
42
|
+
const newTableRef = {
|
|
43
|
+
tableId: null,
|
|
44
|
+
tableName,
|
|
45
|
+
seats,
|
|
46
|
+
section,
|
|
47
|
+
tableState: 1
|
|
48
|
+
}
|
|
49
|
+
return [...existingTables, newTableRef]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
sendNotification({
|
|
58
|
+
backgroundColor: result.data.storeTableCreate.success ? 'success' : 'error',
|
|
59
|
+
description: result.data.storeTableCreate.message || '',
|
|
60
|
+
title: result.data.storeTableCreate.success ? 'Success' : 'Error'
|
|
61
|
+
})
|
|
62
|
+
return result
|
|
63
|
+
} catch (error) {
|
|
64
|
+
sendNotification({
|
|
65
|
+
backgroundColor: 'error',
|
|
66
|
+
description: error.message || 'Error occurred while creating the table.',
|
|
67
|
+
title: 'Creation Failed'
|
|
68
|
+
})
|
|
69
|
+
return { success: false, message: error.message }
|
|
70
|
+
} finally {
|
|
71
|
+
setLoading(false)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return [storeTableCreate, { loading }]
|
|
76
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useQuery } from '@apollo/client'
|
|
2
|
+
import { STORE_TABLES_QUERY } from './queries' // Ajusta la ruta a tu archivo de queries
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Custom hook to fetch store tables data
|
|
6
|
+
* @param {Object} args - Arguments for fetching store tables, e.g., info field.
|
|
7
|
+
* @param {Object} ctx - Context that provides restaurant-related information.
|
|
8
|
+
* @returns {Object} - Object containing tables data, loading state, and error.
|
|
9
|
+
*/
|
|
10
|
+
export const useStoreTables = () => {
|
|
11
|
+
const { data, loading, error } = useQuery(STORE_TABLES_QUERY)
|
|
12
|
+
|
|
13
|
+
return [data, { loading, error }]
|
|
14
|
+
}
|
|
@@ -21,7 +21,6 @@ export const useSubscriptionValidation = (idStore) => {
|
|
|
21
21
|
const [daysElapsed, setDaysElapsed] = useState(null)
|
|
22
22
|
|
|
23
23
|
useEffect(() => {
|
|
24
|
-
console.log(data)
|
|
25
24
|
if (data && data.validateFreeSubscription) {
|
|
26
25
|
const { currentPeriodEnd, currentPeriodStart } = data.validateFreeSubscription
|
|
27
26
|
const currentDate = new Date()
|
|
@@ -14,7 +14,6 @@ export const useUpdateMultipleProducts = ({
|
|
|
14
14
|
const [dataCategoriesProducts] = useCategoriesProduct()
|
|
15
15
|
const findEmptyCategory = dataCategoriesProducts?.find(category => category.pName === CATEGORY_EMPTY)
|
|
16
16
|
const updateProducts = async (products) => {
|
|
17
|
-
console.log("🚀 ~ updateProducts ~ products:", products)
|
|
18
17
|
const newProducts = products.map(product => {
|
|
19
18
|
return {
|
|
20
19
|
idStore: '',
|
|
@@ -239,7 +239,6 @@ export const useUploadProducts = ({
|
|
|
239
239
|
|
|
240
240
|
// Crear una nueva copia de los datos actualizando solo el producto específico
|
|
241
241
|
return prevData.map((product, index) => {
|
|
242
|
-
console.log(index === productIndex)
|
|
243
242
|
return index === productIndex
|
|
244
243
|
? {
|
|
245
244
|
...product,
|
|
@@ -56,6 +56,7 @@ username
|
|
|
56
56
|
lastName
|
|
57
57
|
email
|
|
58
58
|
avatar
|
|
59
|
+
idRole
|
|
59
60
|
uToken
|
|
60
61
|
uPhoNum
|
|
61
62
|
ULocation
|
|
@@ -69,6 +70,12 @@ associateStore
|
|
|
69
70
|
createAt
|
|
70
71
|
role {
|
|
71
72
|
name
|
|
73
|
+
idRole,
|
|
74
|
+
permissions
|
|
75
|
+
description
|
|
76
|
+
createdAt
|
|
77
|
+
updatedAt
|
|
78
|
+
|
|
72
79
|
}
|
|
73
80
|
}
|
|
74
81
|
}
|
package/src/utils/index.js
CHANGED
|
@@ -19,7 +19,7 @@ export const statusOrder = {
|
|
|
19
19
|
2: 'PROCESO',
|
|
20
20
|
3: 'LISTOS',
|
|
21
21
|
4: 'CONCLUIDOS',
|
|
22
|
-
5: '
|
|
22
|
+
5: 'REJECTED'
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export const statusProduct = {
|
|
@@ -28,6 +28,9 @@ export const statusProduct = {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export const validationSubmitHooks = elements => {
|
|
31
|
+
if (!elements || elements.length === 0) {
|
|
32
|
+
return {}
|
|
33
|
+
}
|
|
31
34
|
let errorForm = {}
|
|
32
35
|
|
|
33
36
|
for (const element of elements) {
|