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
|
@@ -27,7 +27,13 @@ export const useProductsFood = ({
|
|
|
27
27
|
}) => {
|
|
28
28
|
// const [productsFood, setProductsFood] = useState([])
|
|
29
29
|
const [showMore, setShowMore] = useState(500)
|
|
30
|
-
const {
|
|
30
|
+
const {
|
|
31
|
+
data,
|
|
32
|
+
loading,
|
|
33
|
+
fetchMore,
|
|
34
|
+
error,
|
|
35
|
+
called
|
|
36
|
+
} = useQuery(GET_ALL_PRODUCT_STORE, {
|
|
31
37
|
fetchPolicy,
|
|
32
38
|
notifyOnNetworkStatusChange: true,
|
|
33
39
|
nextFetchPolicy: 'cache-first',
|
|
@@ -202,6 +208,7 @@ export const useGetOneProductsFood = ({ fetchOnlyProduct = false } = {}) => {
|
|
|
202
208
|
loading,
|
|
203
209
|
error
|
|
204
210
|
}] = useLazyQuery(GET_ONE_PRODUCTS_FOOD)
|
|
211
|
+
|
|
205
212
|
const [handleGetExtProductFood, { data: dataOptional }] = useExtProductFoodsOptionalAll()
|
|
206
213
|
const [handleExtProductFoodsAll, { data: dataExtra }] = useExtProductFoodsAll()
|
|
207
214
|
const handleGetOneProduct = async (food) => {
|
|
@@ -101,6 +101,8 @@ export const GET_ALL_PRODUCT_STORE = gql`
|
|
|
101
101
|
pId
|
|
102
102
|
sizeId #Talla
|
|
103
103
|
colorId #Color
|
|
104
|
+
stock
|
|
105
|
+
manageStock
|
|
104
106
|
carProId #Categoria a la cual pertenece el producto
|
|
105
107
|
caId
|
|
106
108
|
cId #Country
|
|
@@ -315,14 +317,7 @@ export const UPDATE = gql`
|
|
|
315
317
|
}
|
|
316
318
|
}
|
|
317
319
|
`
|
|
318
|
-
|
|
319
|
-
mutation setImageProducts($input: IFileImageProductFood) {
|
|
320
|
-
setImageProducts(input: $input) {
|
|
321
|
-
success
|
|
322
|
-
message
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
`
|
|
320
|
+
|
|
326
321
|
export const UPDATE_PRODUCT_FOOD = gql`
|
|
327
322
|
mutation updateProductFoods($input: InputProductFood) {
|
|
328
323
|
updateProductFoods(input: $input) {
|
|
@@ -579,6 +574,8 @@ export const GET_ONE_PRODUCTS_FOOD = gql`
|
|
|
579
574
|
idStore
|
|
580
575
|
cId
|
|
581
576
|
caId
|
|
577
|
+
stock
|
|
578
|
+
manageStock
|
|
582
579
|
dId
|
|
583
580
|
ctId
|
|
584
581
|
tpId
|
|
@@ -850,7 +847,9 @@ export const GET_ALL_CATEGORIES_WITH_PRODUCT = gql`
|
|
|
850
847
|
pId
|
|
851
848
|
sizeId
|
|
852
849
|
colorId
|
|
850
|
+
stock
|
|
853
851
|
carProId
|
|
852
|
+
manageStock
|
|
854
853
|
cId
|
|
855
854
|
dId
|
|
856
855
|
ctId
|
|
@@ -281,7 +281,7 @@ export const useSales = ({
|
|
|
281
281
|
* @returns {Object} - The new state with the updated product quantity and editing status.
|
|
282
282
|
*/
|
|
283
283
|
const handleCancelUpdateQuantity = (state, payload) => {
|
|
284
|
-
|
|
284
|
+
// Validación de `state`
|
|
285
285
|
if (!state || typeof state !== 'object') {
|
|
286
286
|
sendNotification({
|
|
287
287
|
title: 'Error',
|
|
@@ -315,7 +315,7 @@ export const useSales = ({
|
|
|
315
315
|
return {
|
|
316
316
|
...state,
|
|
317
317
|
PRODUCT: state.PRODUCT.map((item) => {
|
|
318
|
-
|
|
318
|
+
// Validación de propiedades en cada item
|
|
319
319
|
if (item.pId === pId) {
|
|
320
320
|
if (typeof item.oldQuantity !== 'number' || typeof item.unitPrice !== 'number') {
|
|
321
321
|
sendNotification({
|
|
@@ -343,28 +343,48 @@ export const useSales = ({
|
|
|
343
343
|
(state, action) => {
|
|
344
344
|
const event = action.payload
|
|
345
345
|
const { value, index, id } = event || {}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
346
|
+
|
|
347
|
+
const productExist = productsFood?.find((items) => items.pId === id)
|
|
348
|
+
const OneProduct = state?.PRODUCT.find((items) => items.pId === id)
|
|
349
|
+
|
|
350
|
+
if (!productExist) return state // Validar si el producto existe
|
|
351
|
+
|
|
352
|
+
// Validar si el stock es 0
|
|
353
|
+
if (productExist.stock === 0) {
|
|
354
|
+
sendNotification({
|
|
355
|
+
title: 'Sin stock',
|
|
356
|
+
backgroundColor: 'warning',
|
|
357
|
+
description: `El producto ${OneProduct?.pName} está agotado y no puede ser modificado.`
|
|
358
|
+
})
|
|
359
|
+
return state
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Si el valor ingresado es menor o igual a 0, eliminar el producto del carrito
|
|
352
363
|
if (value <= 0) {
|
|
353
|
-
// @ts-ignore
|
|
354
364
|
dispatch({ type: 'REMOVE_PRODUCT_TO_CART', payload: OneProduct })
|
|
365
|
+
return state
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Validar si se intenta superar el stock disponible
|
|
369
|
+
const finalQuantity = Math.min(value, productExist.stock)
|
|
370
|
+
if (value > productExist.stock) {
|
|
371
|
+
sendNotification({
|
|
372
|
+
title: 'Stock insuficiente',
|
|
373
|
+
backgroundColor: 'warning',
|
|
374
|
+
description: `No puedes agregar más unidades de ${OneProduct?.pName}, stock disponible: ${productExist.stock}`
|
|
375
|
+
})
|
|
355
376
|
}
|
|
356
|
-
|
|
357
|
-
const ARR_PRODUCT = state?.PRODUCT?.map((items, i) =>
|
|
358
|
-
|
|
377
|
+
|
|
378
|
+
const ARR_PRODUCT = state?.PRODUCT?.map((items, i) =>
|
|
379
|
+
i === index
|
|
359
380
|
? {
|
|
360
381
|
...items,
|
|
361
382
|
ProQuantity: finalQuantity,
|
|
362
|
-
ProPrice:
|
|
363
|
-
? value * productExist?.ProPrice
|
|
364
|
-
: productExist?.ProPrice
|
|
383
|
+
ProPrice: finalQuantity * productExist?.ProPrice
|
|
365
384
|
}
|
|
366
385
|
: items
|
|
367
|
-
|
|
386
|
+
)
|
|
387
|
+
|
|
368
388
|
return {
|
|
369
389
|
...state,
|
|
370
390
|
PRODUCT: ARR_PRODUCT,
|
|
@@ -373,15 +393,14 @@ export const useSales = ({
|
|
|
373
393
|
},
|
|
374
394
|
[productsFood]
|
|
375
395
|
)
|
|
376
|
-
const PRODUCT = (state, action) => {
|
|
377
|
-
const productExist = state.PRODUCT.find((items) => {
|
|
378
|
-
return items.pId === action.id
|
|
379
|
-
})
|
|
380
|
-
const OurProduct = productsFood?.find((items) => {
|
|
381
|
-
return items.pId === action.id
|
|
382
|
-
})
|
|
383
|
-
const isFree = productExist?.free
|
|
384
396
|
|
|
397
|
+
const paymentMethod = (state, action) => {
|
|
398
|
+
return {
|
|
399
|
+
...state,
|
|
400
|
+
payMethodPState: action.payload
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
const PRODUCT = (state, action) => {
|
|
385
404
|
switch (action.type) {
|
|
386
405
|
case 'ADD_TO_CART':
|
|
387
406
|
return addToCartFunc(state, action) // https://www.npmjs.com/package/@sourcetoad/vision-camera-plugin-barcode-scanner
|
|
@@ -430,22 +449,46 @@ export const useSales = ({
|
|
|
430
449
|
case 'TOGGLE_EDITING_PRODUCT': {
|
|
431
450
|
return handleToggleEditingStatus(state, action)
|
|
432
451
|
}
|
|
433
|
-
case 'INCREMENT':
|
|
452
|
+
case 'INCREMENT': {
|
|
434
453
|
return {
|
|
435
454
|
...state,
|
|
436
455
|
counter: state.counter + 1,
|
|
437
456
|
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
457
|
+
if (items.pId === action.id) {
|
|
458
|
+
const OurProduct = productsFood?.find((item) => item.pId === action.id)
|
|
459
|
+
const isFree = items.free
|
|
460
|
+
const newQuantity = items.ProQuantity + 1
|
|
461
|
+
// Validar si el stock es 0
|
|
462
|
+
if (OurProduct?.stock === 0) {
|
|
463
|
+
sendNotification({
|
|
464
|
+
title: 'Sin stock',
|
|
465
|
+
backgroundColor: 'warning',
|
|
466
|
+
description: `El producto ${items.pName} está agotado y no puede ser añadido al carrito.`
|
|
467
|
+
})
|
|
468
|
+
return items // Retornar sin modificar
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// Validar si se supera el stock
|
|
472
|
+
if (newQuantity > OurProduct?.stock) {
|
|
473
|
+
sendNotification({
|
|
474
|
+
title: 'Stock insuficiente',
|
|
475
|
+
backgroundColor: 'warning',
|
|
476
|
+
description: `No puedes agregar más unidades de ${items.pName}, stock disponible: ${OurProduct?.stock}`
|
|
477
|
+
})
|
|
478
|
+
return items // Retornar el producto sin modificar
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
return {
|
|
482
|
+
...items,
|
|
483
|
+
ProQuantity: newQuantity,
|
|
484
|
+
ProPrice: isFree ? 0 : newQuantity * OurProduct?.ProPrice
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return items
|
|
447
488
|
})
|
|
448
489
|
}
|
|
490
|
+
}
|
|
491
|
+
|
|
449
492
|
case 'PUT_COMMENT':
|
|
450
493
|
return commentProducts(state, action)
|
|
451
494
|
case 'PUT_EXTRA_PRODUCTS_AND_OPTIONAL_PRODUCT':
|
|
@@ -461,22 +504,13 @@ export const useSales = ({
|
|
|
461
504
|
return {
|
|
462
505
|
...state
|
|
463
506
|
}
|
|
464
|
-
case '
|
|
465
|
-
|
|
466
|
-
...state,
|
|
467
|
-
payMethodPState: 1
|
|
468
|
-
}
|
|
469
|
-
case 'PAYMENT_METHOD_MONEY':
|
|
470
|
-
return {
|
|
471
|
-
...state,
|
|
472
|
-
payMethodPState: 0
|
|
473
|
-
}
|
|
507
|
+
case 'PAYMENT_METHOD': return paymentMethod(state, action)
|
|
508
|
+
|
|
474
509
|
default:
|
|
475
510
|
return state
|
|
476
511
|
}
|
|
477
512
|
}
|
|
478
513
|
const [data, dispatch] = useReducer(PRODUCT, initialStateSales, initializer)
|
|
479
|
-
console.log({ data })
|
|
480
514
|
|
|
481
515
|
const handleRemoveValue = useCallback(({ name, value, pId }) => {
|
|
482
516
|
setValues({
|
|
@@ -707,19 +741,46 @@ export const useSales = ({
|
|
|
707
741
|
}
|
|
708
742
|
}
|
|
709
743
|
|
|
744
|
+
function isStockInsufficient (currentQuantity, stock) {
|
|
745
|
+
return currentQuantity >= stock
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
function sendAlertStock (stock) {
|
|
749
|
+
return sendNotification({
|
|
750
|
+
title: 'Stock insuficiente',
|
|
751
|
+
backgroundColor: 'warning',
|
|
752
|
+
description: `Solo hay ${stock} unidades disponibles en el inventario`
|
|
753
|
+
})
|
|
754
|
+
}
|
|
755
|
+
|
|
710
756
|
function addToCartFunc (state, action) {
|
|
711
757
|
const {
|
|
712
758
|
pId,
|
|
713
759
|
pName,
|
|
714
760
|
getOneTags,
|
|
761
|
+
stock,
|
|
715
762
|
ProDescription,
|
|
716
763
|
ProImage,
|
|
717
764
|
ProPrice
|
|
718
|
-
} = action.payload
|
|
765
|
+
} = action.payload ?? {}
|
|
766
|
+
if (stock === 0) {
|
|
767
|
+
sendNotification({
|
|
768
|
+
title: 'Sin stock',
|
|
769
|
+
backgroundColor: 'warning',
|
|
770
|
+
description: 'Producto sin stock disponible en tu inventario'
|
|
771
|
+
})
|
|
772
|
+
return state
|
|
773
|
+
}
|
|
719
774
|
|
|
720
775
|
const productExist = state?.PRODUCT.find((item) => item.pId === pId)
|
|
721
776
|
const OurProduct = productsFood?.find((item) => item.pId === pId)
|
|
722
777
|
const isFree = productExist?.free
|
|
778
|
+
const currentQuantity = productExist?.ProQuantity || 0
|
|
779
|
+
console.log('currentQuantity', productExist)
|
|
780
|
+
if (productExist?.manageStock && isStockInsufficient(currentQuantity, stock)) {
|
|
781
|
+
sendAlertStock(stock)
|
|
782
|
+
return state
|
|
783
|
+
}
|
|
723
784
|
|
|
724
785
|
const updatedProduct = {
|
|
725
786
|
pId,
|
|
@@ -727,9 +788,11 @@ export const useSales = ({
|
|
|
727
788
|
editing: false,
|
|
728
789
|
getOneTags,
|
|
729
790
|
unitPrice: OurProduct?.ProPrice,
|
|
791
|
+
manageStock: OurProduct?.manageStock ?? false,
|
|
730
792
|
ProDescription,
|
|
731
793
|
ProImage,
|
|
732
794
|
ProPrice,
|
|
795
|
+
stock,
|
|
733
796
|
ProQuantity: 1
|
|
734
797
|
}
|
|
735
798
|
|
|
@@ -860,7 +923,7 @@ export const useSales = ({
|
|
|
860
923
|
const arrayProduct = data?.PRODUCT?.length > 0
|
|
861
924
|
? data?.PRODUCT?.map((product) => {
|
|
862
925
|
const filteredDataExtra =
|
|
863
|
-
|
|
926
|
+
product?.dataExtra?.map(({ __typename, ...rest }) => rest) ?? []
|
|
864
927
|
const dataOptional = product?.dataOptional?.map(
|
|
865
928
|
({ __typename, ...product }) => {
|
|
866
929
|
const { ExtProductFoodsSubOptionalAll, ...rest } = product
|
|
@@ -972,17 +1035,38 @@ export const useSales = ({
|
|
|
972
1035
|
}
|
|
973
1036
|
return cadena || 0
|
|
974
1037
|
}
|
|
1038
|
+
const {
|
|
1039
|
+
change,
|
|
1040
|
+
valueDelivery,
|
|
1041
|
+
tableId
|
|
1042
|
+
} = values || {
|
|
1043
|
+
change: 0,
|
|
1044
|
+
valueDelivery: 0,
|
|
1045
|
+
tableId: null,
|
|
1046
|
+
cliId: null
|
|
1047
|
+
}
|
|
975
1048
|
return registerSalesStore({
|
|
976
1049
|
variables: {
|
|
977
1050
|
input: finalArrayProduct || [],
|
|
978
1051
|
id: values?.cliId,
|
|
979
1052
|
pCodeRef: code,
|
|
980
|
-
|
|
981
|
-
|
|
1053
|
+
tableId,
|
|
1054
|
+
change: convertInteger(change),
|
|
1055
|
+
valueDelivery: convertInteger(valueDelivery),
|
|
982
1056
|
payMethodPState: data.payMethodPState,
|
|
983
1057
|
pickUp: 1,
|
|
984
1058
|
discount: discount.discount || 0,
|
|
985
1059
|
totalProductsPrice: convertInteger(totalProductsPrice) || 0
|
|
1060
|
+
},
|
|
1061
|
+
update (cache) {
|
|
1062
|
+
cache.modify({
|
|
1063
|
+
fields: {
|
|
1064
|
+
productFoodsAll (existingProductFoodsAll = []) {
|
|
1065
|
+
console.log('existingProductFoodsAll', existingProductFoodsAll)
|
|
1066
|
+
return existingProductFoodsAll
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
})
|
|
986
1070
|
}
|
|
987
1071
|
})
|
|
988
1072
|
.then((responseRegisterR) => {
|
|
@@ -1000,6 +1084,8 @@ export const useSales = ({
|
|
|
1000
1084
|
client.writeQuery({ query: GET_ALL_COUNT_SALES, data: { getTodaySales: data.countSales.todaySales } })
|
|
1001
1085
|
}
|
|
1002
1086
|
})
|
|
1087
|
+
setValues({})
|
|
1088
|
+
handleChange({ target: { name: 'tableId', value: '' } })
|
|
1003
1089
|
getOnePedidoStore({
|
|
1004
1090
|
variables: {
|
|
1005
1091
|
pCodeRef: code || ''
|
|
@@ -1072,9 +1158,9 @@ export const useSales = ({
|
|
|
1072
1158
|
? existOptionalCookies
|
|
1073
1159
|
?.map((obj) => {
|
|
1074
1160
|
const filteredSubOptions =
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1161
|
+
obj.ExtProductFoodsSubOptionalAll.filter(
|
|
1162
|
+
(subObj) => subObj.check === true
|
|
1163
|
+
)
|
|
1078
1164
|
// Excluya todo el objeto padre si filteredSubOptions está vacío
|
|
1079
1165
|
if (filteredSubOptions.length === 0) {
|
|
1080
1166
|
return null
|
|
@@ -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,30 @@
|
|
|
1
|
+
import { useMutation } from '@apollo/client'
|
|
2
|
+
import { UPDATE_IMAGE_PRODUCT_FOOD } from './queries'
|
|
3
|
+
|
|
4
|
+
const useSetImageProducts = () => {
|
|
5
|
+
const [setImageProducts, { data, loading, error }] = useMutation(UPDATE_IMAGE_PRODUCT_FOOD)
|
|
6
|
+
|
|
7
|
+
const updateImageProducts = async (variables) => {
|
|
8
|
+
try {
|
|
9
|
+
const response = await setImageProducts({
|
|
10
|
+
variables: {
|
|
11
|
+
input: {
|
|
12
|
+
...variables
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
return response
|
|
17
|
+
} catch (err) {
|
|
18
|
+
console.error('Error updating image products:', err)
|
|
19
|
+
throw err
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return [updateImageProducts, {
|
|
24
|
+
data,
|
|
25
|
+
loading,
|
|
26
|
+
error
|
|
27
|
+
}]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default useSetImageProducts
|
|
@@ -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()
|
|
@@ -29,11 +29,11 @@ export const updateExistingOrders = (
|
|
|
29
29
|
const updatedExistingOrders = { ...existingOrders } // Copiar el objeto existente
|
|
30
30
|
|
|
31
31
|
const statusKeys = {
|
|
32
|
-
1: '
|
|
32
|
+
1: 'ACCEPT',
|
|
33
33
|
2: 'PROCESSING',
|
|
34
34
|
3: 'READY',
|
|
35
35
|
4: 'CONCLUDES',
|
|
36
|
-
5: '
|
|
36
|
+
5: 'REJECTED'
|
|
37
37
|
}
|
|
38
38
|
const targetArray = statusKeys[pSState]
|
|
39
39
|
|
|
@@ -11,25 +11,36 @@ export const useUpdateMultipleProducts = ({
|
|
|
11
11
|
loading,
|
|
12
12
|
error
|
|
13
13
|
}] = useMutation(UPDATE_MULTIPLE_PRODUCTS)
|
|
14
|
+
|
|
14
15
|
const [dataCategoriesProducts] = useCategoriesProduct()
|
|
15
|
-
const findEmptyCategory = dataCategoriesProducts?.find(
|
|
16
|
+
const findEmptyCategory = dataCategoriesProducts?.find(({ pName }) => pName === CATEGORY_EMPTY)
|
|
16
17
|
const updateProducts = async (products) => {
|
|
17
18
|
const newProducts = products.map(product => {
|
|
19
|
+
const {
|
|
20
|
+
PRECIO_AL_PUBLICO: ProPrice,
|
|
21
|
+
DESCRIPCION: ProDescription,
|
|
22
|
+
NOMBRE: pName,
|
|
23
|
+
pCode,
|
|
24
|
+
CANTIDAD: stock = 0,
|
|
25
|
+
'IMPUESTO (%)': vat,
|
|
26
|
+
CODIGO_DE_BARRAS: ProBarCode
|
|
27
|
+
} = product
|
|
18
28
|
return {
|
|
19
29
|
idStore: '',
|
|
20
|
-
ProPrice
|
|
30
|
+
ProPrice,
|
|
21
31
|
ProDescuento: 0,
|
|
22
32
|
ValueDelivery: 0,
|
|
23
|
-
ProDescription
|
|
24
|
-
pName
|
|
25
|
-
pCode
|
|
33
|
+
ProDescription,
|
|
34
|
+
pName,
|
|
35
|
+
pCode,
|
|
26
36
|
carProId: findEmptyCategory?.carProId ?? null,
|
|
27
37
|
pState: 1,
|
|
28
38
|
sTateLogistic: 1,
|
|
29
39
|
ProStar: 0,
|
|
40
|
+
stock,
|
|
30
41
|
ProImage: null,
|
|
31
|
-
vat
|
|
32
|
-
ProBarCode:
|
|
42
|
+
vat,
|
|
43
|
+
ProBarCode: String(ProBarCode) || '',
|
|
33
44
|
ProHeight: null,
|
|
34
45
|
ProWeight: '',
|
|
35
46
|
ProOutstanding: 0,
|
|
@@ -39,6 +50,16 @@ export const useUpdateMultipleProducts = ({
|
|
|
39
50
|
)
|
|
40
51
|
try {
|
|
41
52
|
const response = await updateMultipleProducts({ variables: { input: newProducts } })
|
|
53
|
+
// sendNotification
|
|
54
|
+
for (const { errors } of response.data.updateMultipleProducts) {
|
|
55
|
+
if (errors) {
|
|
56
|
+
sendNotification({
|
|
57
|
+
backgroundColor: 'error',
|
|
58
|
+
description: errors[0].message,
|
|
59
|
+
title: 'Error'
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
}
|
|
42
63
|
return response.data.updateMultipleProducts
|
|
43
64
|
} catch (e) {
|
|
44
65
|
sendNotification({
|