npm-pkg-hook 1.10.1 → 1.10.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/package.json +1 -1
- package/src/hooks/handleLogin/index.js +0 -1
- package/src/hooks/index.js +2 -0
- package/src/hooks/useCatWithProduct/queries.js +3 -2
- package/src/hooks/useCatWithProductClient/queries.js +1 -0
- package/src/hooks/useChartData/useChartDataAllOrders/index.js +2 -2
- package/src/hooks/useClients/queries.js +2 -2
- package/src/hooks/useCreateProduct/index.js +49 -12
- package/src/hooks/useDepartments/queries.js +5 -4
- 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/useImagesStore/queries.js +2 -0
- package/src/hooks/useInventory/index.js +2 -0
- package/src/hooks/useInventory/queries.js +58 -0
- package/src/hooks/useInventory/useGetProductsInStock.js +15 -0
- package/src/hooks/useInventory/useUpdateManageStock.js +41 -0
- package/src/hooks/useLocationManager/index.js +2 -2
- 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 +2 -2
- package/src/hooks/useProductsFood/index.js +8 -1
- package/src/hooks/useProductsFood/queriesStore.js +7 -8
- package/src/hooks/useSales/index.js +138 -52
- package/src/hooks/useSales/queries.js +2 -0
- package/src/hooks/useSetImageProducts/index.js +30 -0
- package/src/hooks/useSetImageProducts/queries.js +13 -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 +2 -2
- package/src/hooks/useUpdateMultipleProducts/index.js +28 -7
- package/src/hooks/useUpdateMultipleProducts/queries.js +1 -1
- package/src/hooks/useUploadProducts/helpers/validateProductDataExcel.js +24 -16
- package/src/hooks/useUploadProducts/index.js +7 -4
- package/src/hooks/useUser/queries.js +6 -0
- package/src/index.jsx +3 -1
- package/src/utils/index.js +6 -6
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'
|
|
@@ -121,3 +122,4 @@ export * from './useCart'
|
|
|
121
122
|
export * from './useGetStoreCookie'
|
|
122
123
|
export * from './getGlobalSession'
|
|
123
124
|
export * from './handleLogin'
|
|
125
|
+
export * from './useInventory'
|
|
@@ -119,7 +119,7 @@ query ExtProductFoodsAll($search: String, $min: Int, $max: Int, $pId: ID) {
|
|
|
119
119
|
export const GET_ALL_CATEGORIES_WITH_PRODUCT = gql`
|
|
120
120
|
query getCatProductsWithProduct($search: String, $productName: String, $min: Int, $max: Int, $gender: [String], $desc: [String], $categories: [ID], ) {
|
|
121
121
|
getCatProductsWithProduct(search: $search, min: $min, productName:$productName, max: $max, gender: $gender, desc: $desc, categories: $categories,) {
|
|
122
|
-
|
|
122
|
+
totalCount,
|
|
123
123
|
catProductsWithProduct {
|
|
124
124
|
carProId
|
|
125
125
|
pState
|
|
@@ -135,8 +135,9 @@ query getCatProductsWithProduct($search: String, $productName: String, $min: Int
|
|
|
135
135
|
pDatMod
|
|
136
136
|
productFoodsAll {
|
|
137
137
|
pId
|
|
138
|
+
stock
|
|
139
|
+
manageStock
|
|
138
140
|
sizeId
|
|
139
|
-
|
|
140
141
|
colorId
|
|
141
142
|
carProId
|
|
142
143
|
cId
|
|
@@ -9,11 +9,11 @@ export const useChartDataAllOrders = ({
|
|
|
9
9
|
|
|
10
10
|
// Objeto para mapear los códigos de estado a sus nombres
|
|
11
11
|
const statusMap = {
|
|
12
|
-
1: '
|
|
12
|
+
1: 'ACCEPT',
|
|
13
13
|
2: 'PROCESSING',
|
|
14
14
|
3: 'READY',
|
|
15
15
|
4: 'CONCLUDES',
|
|
16
|
-
5: '
|
|
16
|
+
5: 'REJECTED'
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// Objeto para almacenar los totales por estado
|
|
@@ -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
|
|
@@ -5,13 +5,15 @@ import { convertBase64, RandomCode } from '../../utils'
|
|
|
5
5
|
import { useLocalStorage } from '../useLocalSorage'
|
|
6
6
|
import {
|
|
7
7
|
GET_ALL_FOOD_PRODUCTS,
|
|
8
|
-
UPDATE_IMAGE_PRODUCT_FOOD,
|
|
9
8
|
UPDATE_PRODUCT_FOOD
|
|
10
9
|
} from '../useProductsFood/queriesStore'
|
|
11
10
|
import { useStore } from '../useStore'
|
|
12
11
|
import { useTagsProducts } from './../useProductsFood/usetagsProducts'
|
|
13
12
|
import { useEditImageProduct } from './helpers/useEditImageProduct'
|
|
14
13
|
import { getCatProductsWithProduct } from './helpers/manageCacheDataCatProduct'
|
|
14
|
+
import { assignWith } from 'lodash'
|
|
15
|
+
import { UPDATE_IMAGE_PRODUCT_FOOD } from '../useSetImageProducts/queries'
|
|
16
|
+
import useSetImageProducts from '../useSetImageProducts'
|
|
15
17
|
export * from './helpers'
|
|
16
18
|
|
|
17
19
|
export const useCreateProduct = ({
|
|
@@ -37,6 +39,7 @@ export const useCreateProduct = ({
|
|
|
37
39
|
ValueDelivery: 0,
|
|
38
40
|
carProId: ''
|
|
39
41
|
})
|
|
42
|
+
const [updateImageProducts] = useSetImageProducts()
|
|
40
43
|
const [names, setName] = useLocalStorage('namefood', '')
|
|
41
44
|
const [showMore, setShowMore] = useState(50)
|
|
42
45
|
const [search, setSearch] = useState('')
|
|
@@ -51,7 +54,25 @@ export const useCreateProduct = ({
|
|
|
51
54
|
const [{ alt, src }, setPreviewImg] = useState(initialState)
|
|
52
55
|
const fileInputRef = useRef(null)
|
|
53
56
|
const [arrTags, setTags] = useState([])
|
|
57
|
+
const [stock, setStock] = useState(1)
|
|
58
|
+
// Manage stock optional value boolean
|
|
59
|
+
const [checkStock, setCheckStock] = useState(false)
|
|
54
60
|
|
|
61
|
+
const handleIncreaseStock = () => {
|
|
62
|
+
setStock(prevStock => prevStock + 1)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const handleDecreaseStock = () => {
|
|
66
|
+
setStock(prevStock => (prevStock > 1 ? prevStock - 1 : 1))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const handleCheckStock = () => {
|
|
70
|
+
setCheckStock(prev => {
|
|
71
|
+
const newCheckStock = !prev
|
|
72
|
+
setStock(newCheckStock ? 1 : stock)
|
|
73
|
+
return newCheckStock
|
|
74
|
+
})
|
|
75
|
+
}
|
|
55
76
|
const [dataStore] = useStore()
|
|
56
77
|
const {
|
|
57
78
|
data,
|
|
@@ -122,9 +143,7 @@ export const useCreateProduct = ({
|
|
|
122
143
|
|
|
123
144
|
const [updateProductFoods, { loading }] = useMutation(UPDATE_PRODUCT_FOOD, {
|
|
124
145
|
})
|
|
125
|
-
const [setImageProducts] = useMutation(UPDATE_IMAGE_PRODUCT_FOOD
|
|
126
|
-
context: { clientName: 'admin-server' }
|
|
127
|
-
})
|
|
146
|
+
const [setImageProducts] = useMutation(UPDATE_IMAGE_PRODUCT_FOOD)
|
|
128
147
|
|
|
129
148
|
const onFileInputChange = async event => {
|
|
130
149
|
const { files } = event.target
|
|
@@ -171,7 +190,7 @@ export const useCreateProduct = ({
|
|
|
171
190
|
}
|
|
172
191
|
const formatPrice = ProPrice ?? 0
|
|
173
192
|
if (!carProId && !names) return setErrors({ ...errors, carProId: true })
|
|
174
|
-
const ProImage =
|
|
193
|
+
const ProImage = '/images/placeholder-image.webp'
|
|
175
194
|
const pCode = RandomCode(9)
|
|
176
195
|
try {
|
|
177
196
|
const res = await updateProductFoods({
|
|
@@ -183,8 +202,10 @@ export const useCreateProduct = ({
|
|
|
183
202
|
ValueDelivery: check?.desc ? 0 : ValueDelivery,
|
|
184
203
|
ProDescription,
|
|
185
204
|
pName: names,
|
|
205
|
+
manageStock: checkStock,
|
|
186
206
|
pCode,
|
|
187
207
|
carProId,
|
|
208
|
+
stock,
|
|
188
209
|
pState: 1,
|
|
189
210
|
sTateLogistic: 1,
|
|
190
211
|
ProStar: 0,
|
|
@@ -219,15 +240,25 @@ export const useCreateProduct = ({
|
|
|
219
240
|
carProId: ''
|
|
220
241
|
})
|
|
221
242
|
})
|
|
243
|
+
const { errors } = res ?? {
|
|
244
|
+
errors: []
|
|
245
|
+
}
|
|
246
|
+
if (errors?.length > 0) {
|
|
247
|
+
errors.forEach(error => {
|
|
248
|
+
sendNotification({
|
|
249
|
+
backgroundColor: 'error',
|
|
250
|
+
title: 'Error',
|
|
251
|
+
description: error.message
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
return
|
|
255
|
+
}
|
|
222
256
|
if (image !== null) {
|
|
257
|
+
console.log(image)
|
|
223
258
|
try {
|
|
224
|
-
await
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
file: image,
|
|
228
|
-
pCode
|
|
229
|
-
}
|
|
230
|
-
}
|
|
259
|
+
await updateImageProducts({
|
|
260
|
+
pId: res?.data?.updateProductFoods?.data?.pId,
|
|
261
|
+
image
|
|
231
262
|
})
|
|
232
263
|
} catch {
|
|
233
264
|
sendNotification({
|
|
@@ -240,6 +271,7 @@ export const useCreateProduct = ({
|
|
|
240
271
|
setPid(res?.data?.updateProductFoods?.data?.pId ?? null)
|
|
241
272
|
return res
|
|
242
273
|
} catch (error) {
|
|
274
|
+
console.log('🚀 ~ handleRegister ~ error:', error)
|
|
243
275
|
setAlertBox({ message: 'Ha ocurrido un error', duration: 7000 })
|
|
244
276
|
}
|
|
245
277
|
}
|
|
@@ -268,9 +300,11 @@ export const useCreateProduct = ({
|
|
|
268
300
|
fileInputRef,
|
|
269
301
|
values,
|
|
270
302
|
search,
|
|
303
|
+
stock,
|
|
271
304
|
pId,
|
|
272
305
|
dataTags: data,
|
|
273
306
|
tags,
|
|
307
|
+
checkStock,
|
|
274
308
|
loading,
|
|
275
309
|
active,
|
|
276
310
|
idStore: dataStore?.getStore?.idStore || '',
|
|
@@ -282,6 +316,8 @@ export const useCreateProduct = ({
|
|
|
282
316
|
handleChangeFilter,
|
|
283
317
|
handleUpdateBanner,
|
|
284
318
|
onClickSearch,
|
|
319
|
+
handleDecreaseStock,
|
|
320
|
+
handleIncreaseStock,
|
|
285
321
|
changeHandler,
|
|
286
322
|
setErrors,
|
|
287
323
|
setCheck,
|
|
@@ -290,6 +326,7 @@ export const useCreateProduct = ({
|
|
|
290
326
|
onFileInputChange,
|
|
291
327
|
handleRegisterTags,
|
|
292
328
|
setShowMore,
|
|
329
|
+
handleCheckStock,
|
|
293
330
|
onTargetClick,
|
|
294
331
|
handleAddTag,
|
|
295
332
|
handleCheck,
|
|
@@ -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
|
+
}
|
|
@@ -108,6 +108,7 @@ export const GET_ALL_PRODUCT_STORE = gql`
|
|
|
108
108
|
ProPrice
|
|
109
109
|
ProDescuento
|
|
110
110
|
free
|
|
111
|
+
manageStock
|
|
111
112
|
ProUniDisponibles
|
|
112
113
|
ProDescription
|
|
113
114
|
ProProtegido
|
|
@@ -126,6 +127,7 @@ export const GET_ALL_PRODUCT_STORE = gql`
|
|
|
126
127
|
pDatMod
|
|
127
128
|
ProDelivery
|
|
128
129
|
ProVoltaje
|
|
130
|
+
stock
|
|
129
131
|
pState
|
|
130
132
|
feat {
|
|
131
133
|
fId
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useQuery, gql } from "@apollo/client";
|
|
2
|
+
|
|
3
|
+
export const GET_PRODUCTS_IN_STOCK = gql`
|
|
4
|
+
query getProductsInStock($limit: Int, $offset: Int) {
|
|
5
|
+
getProductsInStock(limit: $limit, offset: $offset) {
|
|
6
|
+
pId
|
|
7
|
+
sizeId #Talla
|
|
8
|
+
colorId #Color
|
|
9
|
+
carProId #Categoria a la cual pertenece el producto
|
|
10
|
+
caId
|
|
11
|
+
cId #Country
|
|
12
|
+
dId #Department
|
|
13
|
+
ctId #Cuidad
|
|
14
|
+
fId #Características
|
|
15
|
+
pName
|
|
16
|
+
getOneTags {
|
|
17
|
+
tPsId
|
|
18
|
+
idUser
|
|
19
|
+
idStore
|
|
20
|
+
pId
|
|
21
|
+
nameTag
|
|
22
|
+
}
|
|
23
|
+
ProPrice
|
|
24
|
+
ProDescuento
|
|
25
|
+
free
|
|
26
|
+
ProUniDisponibles
|
|
27
|
+
ProDescription
|
|
28
|
+
ProProtegido
|
|
29
|
+
ProAssurance
|
|
30
|
+
ValueDelivery
|
|
31
|
+
ProStar
|
|
32
|
+
sTateLogistic
|
|
33
|
+
ProImage
|
|
34
|
+
ProWidth
|
|
35
|
+
ProHeight
|
|
36
|
+
ProLength
|
|
37
|
+
ProWeight
|
|
38
|
+
ProQuantity
|
|
39
|
+
ProOutstanding
|
|
40
|
+
pDatCre
|
|
41
|
+
pDatMod
|
|
42
|
+
ProDelivery
|
|
43
|
+
ProVoltaje
|
|
44
|
+
pState
|
|
45
|
+
feat {
|
|
46
|
+
fId
|
|
47
|
+
thpId
|
|
48
|
+
hpqrQuestion
|
|
49
|
+
}
|
|
50
|
+
area {
|
|
51
|
+
aId
|
|
52
|
+
aName
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
`
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useQuery } from '@apollo/client'
|
|
2
|
+
import { GET_PRODUCTS_IN_STOCK } from './queries'
|
|
3
|
+
|
|
4
|
+
export const useGetProductsInStock = (storeId) => {
|
|
5
|
+
const { data, loading, error } = useQuery(GET_PRODUCTS_IN_STOCK, {
|
|
6
|
+
variables: { storeId },
|
|
7
|
+
skip: !storeId
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
data: data?.getProductsInStock || [],
|
|
12
|
+
loading,
|
|
13
|
+
error
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { gql, useMutation } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL Mutation for updating stock and manageStock
|
|
5
|
+
*/
|
|
6
|
+
const UPDATE_MANAGE_STOCK = gql`
|
|
7
|
+
mutation UpdateManageStock($input: InputManageStock) {
|
|
8
|
+
updateManageStock(input: $input) {
|
|
9
|
+
success
|
|
10
|
+
message
|
|
11
|
+
data {
|
|
12
|
+
pId
|
|
13
|
+
manageStock
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
`
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Custom hook to update stock and manageStock
|
|
21
|
+
* @returns {object} { updateManageStock, data, loading, error }
|
|
22
|
+
*/
|
|
23
|
+
export const useUpdateManageStock = () => {
|
|
24
|
+
const [updateManageStockMutation, { data, loading, error }] = useMutation(UPDATE_MANAGE_STOCK)
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Function to call the mutation with given input
|
|
28
|
+
* @param {Object} input - { pId, stock, manageStock }
|
|
29
|
+
* @returns {Promise<Object>} Mutation response
|
|
30
|
+
*/
|
|
31
|
+
const updateManageStock = async (input) => {
|
|
32
|
+
try {
|
|
33
|
+
const { data } = await updateManageStockMutation({ variables: { input } })
|
|
34
|
+
return data?.updateManageStock
|
|
35
|
+
} catch (err) {
|
|
36
|
+
return { success: false, message: err.message }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return [updateManageStock, { data, loading, error }]
|
|
41
|
+
}
|
|
@@ -26,7 +26,7 @@ export function useLocationManager (getDepartments, getCities) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const handleDepartmentSearch = (value) => {
|
|
29
|
-
getCities({ variables: { dId:
|
|
29
|
+
getCities({ variables: { dId: 'ddd5a096-efc6-4541-a568-c91895bc219e' } })
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const handleChangeLocation = (e, error) => {
|
|
@@ -41,7 +41,7 @@ export function useLocationManager (getDepartments, getCities) {
|
|
|
41
41
|
case 'countryId':
|
|
42
42
|
handleCountrySearch(value)
|
|
43
43
|
break
|
|
44
|
-
case '
|
|
44
|
+
case 'code_dId':
|
|
45
45
|
handleDepartmentSearch(value)
|
|
46
46
|
break
|
|
47
47
|
default:
|
|
@@ -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
|
+
if (!Array.isArray(modules) || module.length <= 0) return []
|
|
11
|
+
return modules?.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
|
}
|
|
@@ -86,7 +86,7 @@ query getAllOrdersFromStore(
|
|
|
86
86
|
max: $max
|
|
87
87
|
statusOrder: $statusOrder
|
|
88
88
|
) {
|
|
89
|
-
|
|
89
|
+
ACCEPT {
|
|
90
90
|
pdpId
|
|
91
91
|
idStore
|
|
92
92
|
pCodeRef
|
|
@@ -274,7 +274,7 @@ query getAllOrdersFromStore(
|
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
|
-
|
|
277
|
+
REJECTED {
|
|
278
278
|
pdpId
|
|
279
279
|
idStore
|
|
280
280
|
pCodeRef
|