npm-pkg-hook 1.2.0 → 1.2.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/config/client/errors.js +11 -9
- package/src/hooks/useCart/useCart/index.js +1 -1
- package/src/hooks/useCheckbox/index.js +1 -1
- package/src/hooks/useClients/queries.js +2 -2
- package/src/hooks/useProductsFood/index.js +30 -4
- package/src/hooks/useSales/helpers/index.js +9 -0
- package/src/hooks/useSales/index.js +83 -35
- package/src/hooks/useSales/queries.js +1 -1
- package/src/hooks/useSales/useGetSale.js +1 -1
- package/src/hooks/useSchedule/index.js +41 -2
- package/src/hooks/useSchedule/queries.js +9 -0
- package/src/hooks/useStore/index.js +5 -13
- package/src/hooks/useStore/queries.js +2 -1
- package/src/hooks/useUser/queries.js +0 -1
package/package.json
CHANGED
|
@@ -2,14 +2,16 @@ import { onError } from '@apollo/client/link/error'
|
|
|
2
2
|
|
|
3
3
|
export const errorHandler = (error) => {
|
|
4
4
|
let logout = null
|
|
5
|
-
if (error) {
|
|
6
|
-
error.errors?.length && error
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
if (error && Array.isArray(error?.errors)) {
|
|
6
|
+
error.errors?.length && error?.errors?.forEach(err => {
|
|
7
|
+
if (err?.extensions) {
|
|
8
|
+
const { code, message: { message } } = err?.extensions || {}
|
|
9
|
+
if (code === 'UNAUTHENTICATED' || code === 'FORBIDDEN') {
|
|
10
|
+
logout = true
|
|
11
|
+
return {
|
|
12
|
+
status: 'FORBIDDEN',
|
|
13
|
+
message
|
|
14
|
+
}
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
})
|
|
@@ -21,4 +23,4 @@ export const errorLink = onError(({ graphQLErrors, networkError }) => {
|
|
|
21
23
|
if (graphQLErrors)graphQLErrors.map(({ message, location, path }) => { return console.log(`[GraphQL error]: Message: ${message}, Location: ${location}, Path: ${path}`) })
|
|
22
24
|
|
|
23
25
|
if (networkError) console.log(`[Network error]: ${networkError}`)
|
|
24
|
-
})
|
|
26
|
+
})
|
|
@@ -15,7 +15,7 @@ import { useCallback, useState } from 'react'
|
|
|
15
15
|
* - clearAll (callback)
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
export const useCheckboxState = (elem, selectedIds = [], disabledIds = []) => {
|
|
18
|
+
export const useCheckboxState = (elem, selectedIds = [], disabledIds = [], setArray = () => { return }) => {
|
|
19
19
|
const numTotalItems = elem?.length
|
|
20
20
|
const [checkedItems, setCheckedItems] = useState(new Set(selectedIds))
|
|
21
21
|
const [disabledItems, setDisabledItems] = useState(new Set(disabledIds))
|
|
@@ -98,7 +98,7 @@ mutation registerShoppingCard($input: IShoppingCard, $idSubArray: IID_SUB_ITEMS
|
|
|
98
98
|
}
|
|
99
99
|
`
|
|
100
100
|
export const CREATE_SHOPPING_CARD_TO_USER_STORE = gql`
|
|
101
|
-
mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $pCodeRef: String, $change:
|
|
101
|
+
mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $pCodeRef: String, $change: Float, $valueDelivery: Float, $payMethodPState: Int, $pickUp: Int, $totalProductsPrice: Float, $idSubArray: IID_SUB_ITEMS){
|
|
102
102
|
registerSalesStore(input: $input, id: $id, idStore: $idStore, pCodeRef: $pCodeRef, change: $change, valueDelivery: $valueDelivery, payMethodPState: $payMethodPState, pickUp: $pickUp, totalProductsPrice: $totalProductsPrice, idSubArray: $idSubArray){
|
|
103
103
|
ShoppingCard {
|
|
104
104
|
ShoppingCard
|
|
@@ -124,4 +124,4 @@ mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $pC
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
`
|
|
127
|
+
`
|
|
@@ -84,19 +84,45 @@ export const useDeleteProductsFood = ({ sendNotification = () => { } } = {}) =>
|
|
|
84
84
|
pId,
|
|
85
85
|
pState
|
|
86
86
|
}
|
|
87
|
-
},
|
|
88
|
-
update (cache) {
|
|
87
|
+
}, update (cache) {
|
|
89
88
|
cache.modify({
|
|
90
89
|
fields: {
|
|
91
90
|
productFoodsAll (dataOld = []) {
|
|
92
|
-
|
|
91
|
+
if (Array.isArray(dataOld) && dataOld?.length) {
|
|
92
|
+
const product = dataOld?.find((product) => {
|
|
93
|
+
return product.pId === pId
|
|
94
|
+
})
|
|
95
|
+
if (product) {
|
|
96
|
+
const newProductList = dataOld?.filter((product) => {
|
|
97
|
+
return product?.pId !== pId
|
|
98
|
+
})
|
|
99
|
+
return newProductList
|
|
100
|
+
}
|
|
101
|
+
return dataOld
|
|
102
|
+
} else {
|
|
103
|
+
return []
|
|
104
|
+
}
|
|
93
105
|
}
|
|
94
106
|
}
|
|
95
107
|
})
|
|
96
108
|
cache.modify({
|
|
97
109
|
fields: {
|
|
98
110
|
getCatProductsWithProduct (dataOld = []) {
|
|
99
|
-
|
|
111
|
+
if (Array.isArray(dataOld?.catProductsWithProduct) && dataOld?.catProductsWithProduct?.length) {
|
|
112
|
+
const newListCatProducts = dataOld?.catProductsWithProduct?.map((categories) => {
|
|
113
|
+
return {
|
|
114
|
+
...categories,
|
|
115
|
+
productFoodsAll: categories?.productFoodsAll?.length ? categories?.productFoodsAll?.filter((product) => {
|
|
116
|
+
return product?.pId !== pId
|
|
117
|
+
}) : []
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
return {
|
|
121
|
+
catProductsWithProduct: newListCatProducts,
|
|
122
|
+
totalCount: newListCatProducts?.length,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return dataOld
|
|
100
126
|
}
|
|
101
127
|
}
|
|
102
128
|
})
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function convertToIntegerOrFloat(numberString) {
|
|
2
|
+
if (!numberString) return 0;
|
|
3
|
+
|
|
4
|
+
// Convierte a número (entero o flotante)
|
|
5
|
+
const numericValue = parseFloat(numberString);
|
|
6
|
+
|
|
7
|
+
return isNaN(numericValue) ? 0 : numericValue; // Maneja valores no numéricos como 0
|
|
8
|
+
}
|
|
9
|
+
|
|
@@ -26,6 +26,9 @@ import {
|
|
|
26
26
|
} from './queries'
|
|
27
27
|
import { updateExistingOrders } from '../useUpdateExistingOrders'
|
|
28
28
|
import { useGetSale } from './useGetSale'
|
|
29
|
+
import { convertToIntegerOrFloat } from './helpers'
|
|
30
|
+
import { useCatWithProduct } from './../useCatWithProduct/index';
|
|
31
|
+
import { useCheckboxState } from '../useCheckbox';
|
|
29
32
|
export * from './useGetAllSales'
|
|
30
33
|
export { GET_ALL_COUNT_SALES } from './queries'
|
|
31
34
|
|
|
@@ -64,7 +67,14 @@ export const useSales = ({
|
|
|
64
67
|
const keyToSaveData = process.env.LOCAL_SALES_STORE
|
|
65
68
|
const saveDataState = JSON.parse(Cookies.get(keyToSaveData) || '[]')
|
|
66
69
|
const [search, setSearch] = useState('')
|
|
67
|
-
const [
|
|
70
|
+
const [datCat] = useCatWithProduct({})
|
|
71
|
+
const {
|
|
72
|
+
checkedItems,
|
|
73
|
+
disabledItems,
|
|
74
|
+
setCheckedItems,
|
|
75
|
+
handleChangeCheck
|
|
76
|
+
} = useCheckboxState(datCat, [], [])
|
|
77
|
+
const arr = checkedItems ? Array.from(checkedItems) : []
|
|
68
78
|
const [totalProductPrice, setTotalProductPrice] = useState(0)
|
|
69
79
|
const [showMore, setShowMore] = useState(100)
|
|
70
80
|
const [inputValue, setInputValue] = useState('')
|
|
@@ -72,7 +82,11 @@ export const useSales = ({
|
|
|
72
82
|
const [_, setFilteredList] = useState([])
|
|
73
83
|
const [delivery, setDelivery] = useState(false)
|
|
74
84
|
const [print, setPrint] = useState(false)
|
|
75
|
-
const [values, setValues] = useState({
|
|
85
|
+
const [values, setValues] = useState({
|
|
86
|
+
comment: '',
|
|
87
|
+
change: '',
|
|
88
|
+
valueDelivery: ''
|
|
89
|
+
})
|
|
76
90
|
const [dataStore] = useStore()
|
|
77
91
|
const { createdAt } = dataStore || {}
|
|
78
92
|
const [code, setCode] = useState(null)
|
|
@@ -104,7 +118,6 @@ export const useSales = ({
|
|
|
104
118
|
setOpenCurrentSale(data?.registerSalesStore?.Response.success)
|
|
105
119
|
},
|
|
106
120
|
onError: (error) => {
|
|
107
|
-
console.log(error)
|
|
108
121
|
sendNotification({
|
|
109
122
|
backgroundColor: 'error',
|
|
110
123
|
title: error || 'Lo sentimo',
|
|
@@ -261,7 +274,11 @@ export const useSales = ({
|
|
|
261
274
|
return handleChangeNumber(state, action)
|
|
262
275
|
}
|
|
263
276
|
case 'REMOVE_ALL_PRODUCTS':
|
|
264
|
-
setValues({
|
|
277
|
+
setValues({
|
|
278
|
+
comment: '',
|
|
279
|
+
change: '',
|
|
280
|
+
valueDelivery: ''
|
|
281
|
+
})
|
|
265
282
|
return {
|
|
266
283
|
...state,
|
|
267
284
|
PRODUCT: [],
|
|
@@ -362,7 +379,7 @@ export const useSales = ({
|
|
|
362
379
|
const newData = dataOptional.map((el) =>
|
|
363
380
|
el.code === codeCategory ? updatedItem : el
|
|
364
381
|
)
|
|
365
|
-
setDataOptional((
|
|
382
|
+
setDataOptional(() => [...newData])
|
|
366
383
|
}
|
|
367
384
|
}
|
|
368
385
|
|
|
@@ -418,22 +435,24 @@ export const useSales = ({
|
|
|
418
435
|
return sendNotification({
|
|
419
436
|
title: 'Error',
|
|
420
437
|
backgroundColor: 'error',
|
|
421
|
-
description: '
|
|
438
|
+
description: 'Ha ocurrido un error'
|
|
422
439
|
})
|
|
423
440
|
}
|
|
424
441
|
const filteredDataOptional = dataOptional
|
|
425
442
|
.map((obj) => {
|
|
426
|
-
const filteredSubOptions = obj
|
|
427
|
-
(subObj) => subObj
|
|
443
|
+
const filteredSubOptions = obj?.ExtProductFoodsSubOptionalAll?.filter(
|
|
444
|
+
(subObj) => subObj?.check === true
|
|
428
445
|
)
|
|
429
446
|
// Excluya todo el objeto padre si filteredSubOptions está vacío
|
|
430
|
-
if (filteredSubOptions
|
|
447
|
+
if (filteredSubOptions?.length === 0) {
|
|
431
448
|
return null
|
|
432
449
|
}
|
|
433
450
|
return { ...obj, ExtProductFoodsSubOptionalAll: filteredSubOptions }
|
|
434
451
|
})
|
|
435
452
|
.filter((obj) => obj !== null) // Elimine todos los objetos nulos del arreglo
|
|
436
|
-
|
|
453
|
+
const filteredDataExtra = dataExtra?.filter((p) => p?.quantity !== undefined && p?.quantity !== 0);
|
|
454
|
+
|
|
455
|
+
console.log(filteredDataExtra)
|
|
437
456
|
dispatch({
|
|
438
457
|
type: 'PUT_EXTRA_PRODUCTS_AND_OPTIONAL_PRODUCT',
|
|
439
458
|
payload: product.PRODUCT.pId,
|
|
@@ -449,25 +468,31 @@ export const useSales = ({
|
|
|
449
468
|
}
|
|
450
469
|
}
|
|
451
470
|
|
|
452
|
-
function handleIncrementExtra
|
|
453
|
-
const { pId } = product?.PRODUCT || {}
|
|
454
|
-
const exPid = Adicionales.exPid || null
|
|
471
|
+
function handleIncrementExtra({ Adicionales, index }) {
|
|
472
|
+
const { pId } = product?.PRODUCT || {};
|
|
473
|
+
const exPid = Adicionales.exPid || null;
|
|
474
|
+
|
|
455
475
|
if (exPid && pId) {
|
|
456
476
|
const newExtra = dataExtra.map((producto) => {
|
|
457
477
|
if (exPid === producto.exPid) {
|
|
458
|
-
const initialQuantity = producto?.quantity ? producto?.quantity : 0
|
|
478
|
+
const initialQuantity = producto?.quantity ? producto?.quantity : 0;
|
|
479
|
+
const newQuantity = initialQuantity + 1;
|
|
480
|
+
const newExtraPrice = producto.extraPrice * newQuantity;
|
|
481
|
+
|
|
459
482
|
return {
|
|
460
483
|
...producto,
|
|
461
|
-
quantity:
|
|
462
|
-
newExtraPrice:
|
|
463
|
-
}
|
|
484
|
+
quantity: newQuantity,
|
|
485
|
+
newExtraPrice: newExtraPrice,
|
|
486
|
+
};
|
|
464
487
|
}
|
|
465
|
-
return producto
|
|
466
|
-
})
|
|
467
|
-
|
|
488
|
+
return producto;
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
setDataExtra(newExtra);
|
|
468
492
|
}
|
|
469
493
|
}
|
|
470
494
|
|
|
495
|
+
|
|
471
496
|
function handleDecrementExtra ({ Adicionales, index }) {
|
|
472
497
|
const { pId } = product?.PRODUCT || {}
|
|
473
498
|
const exPid = Adicionales.exPid || null
|
|
@@ -478,18 +503,28 @@ export const useSales = ({
|
|
|
478
503
|
return
|
|
479
504
|
}
|
|
480
505
|
|
|
481
|
-
if (pId && exPid) {
|
|
506
|
+
if (pId && exPid && extraIndex !== -1) {
|
|
482
507
|
const newExtra = dataExtra.map((producto, i) => {
|
|
483
508
|
if (exPid === producto.exPid) {
|
|
484
|
-
|
|
509
|
+
// Desestructura la cantidad y el precio extra del producto o establece valores predeterminados
|
|
510
|
+
const { quantity = 0, extraPrice = 0 } = producto
|
|
511
|
+
|
|
512
|
+
// Calcula la nueva cantidad, evitando que sea negativa
|
|
513
|
+
const newQuantity = Math.max(quantity - 1, 0)
|
|
514
|
+
|
|
515
|
+
// Calcula el nuevo precio extra
|
|
516
|
+
const newExtraPrice = newQuantity === 0 ? extraPrice : extraPrice * newQuantity
|
|
517
|
+
|
|
485
518
|
return {
|
|
486
519
|
...producto,
|
|
487
|
-
quantity:
|
|
488
|
-
newExtraPrice
|
|
520
|
+
quantity: newQuantity,
|
|
521
|
+
newExtraPrice
|
|
489
522
|
}
|
|
490
523
|
}
|
|
491
524
|
return producto
|
|
492
525
|
})
|
|
526
|
+
|
|
527
|
+
// Actualiza el estado de dataExtra con el nuevo array
|
|
493
528
|
setDataExtra(newExtra)
|
|
494
529
|
}
|
|
495
530
|
}
|
|
@@ -506,10 +541,17 @@ export const useSales = ({
|
|
|
506
541
|
* @returns {Object} Nuevo estado del carrito con el producto agregado.
|
|
507
542
|
*/
|
|
508
543
|
function addToCartFunc (state, action) {
|
|
509
|
-
const {
|
|
544
|
+
const {
|
|
545
|
+
pId,
|
|
546
|
+
pName,
|
|
547
|
+
getOneTags,
|
|
548
|
+
ProDescription,
|
|
549
|
+
ProImage,
|
|
550
|
+
ProPrice
|
|
551
|
+
} = action.payload
|
|
510
552
|
|
|
511
|
-
const productExist = state
|
|
512
|
-
const OurProduct = productsFood
|
|
553
|
+
const productExist = state?.PRODUCT.find((item) => item.pId === pId)
|
|
554
|
+
const OurProduct = productsFood?.find((item) => item.pId === pId)
|
|
513
555
|
const isFree = productExist?.free
|
|
514
556
|
|
|
515
557
|
const updatedProduct = {
|
|
@@ -532,7 +574,6 @@ export const useSales = ({
|
|
|
532
574
|
PRODUCT: [...state.PRODUCT, updatedProduct]
|
|
533
575
|
}
|
|
534
576
|
}
|
|
535
|
-
|
|
536
577
|
return {
|
|
537
578
|
...state,
|
|
538
579
|
counter: state.counter + 1,
|
|
@@ -545,7 +586,7 @@ export const useSales = ({
|
|
|
545
586
|
getOneTags: OurProduct.genderTags,
|
|
546
587
|
unitPrice: OurProduct?.ProPrice,
|
|
547
588
|
ProPrice: isFree ? 0 : (productExist.ProQuantity + 1) * OurProduct?.ProPrice,
|
|
548
|
-
ProQuantity: productExist.ProQuantity + 1,
|
|
589
|
+
ProQuantity: productExist.ProQuantity + +1,
|
|
549
590
|
free: !!isFree
|
|
550
591
|
}
|
|
551
592
|
}
|
|
@@ -555,7 +596,7 @@ export const useSales = ({
|
|
|
555
596
|
}
|
|
556
597
|
|
|
557
598
|
function removeFunc (state, action) {
|
|
558
|
-
const productExist = state
|
|
599
|
+
const productExist = state?.PRODUCT.find((items) => {
|
|
559
600
|
return items.pId === action.payload.pId
|
|
560
601
|
})
|
|
561
602
|
const OurProduct = productsFood.find((items) => {
|
|
@@ -645,6 +686,7 @@ export const useSales = ({
|
|
|
645
686
|
const sortedProduct = useMemo(() => {
|
|
646
687
|
return getSortedProduct(data.PRODUCT, data.sortBy)
|
|
647
688
|
}, [data.PRODUCT, data.sortBy, getSortedProduct])
|
|
689
|
+
|
|
648
690
|
const finalFilter = PriceRangeFunc(sortedProduct, data.priceRange)
|
|
649
691
|
|
|
650
692
|
const handleList = (text) => {
|
|
@@ -739,6 +781,7 @@ export const useSales = ({
|
|
|
739
781
|
price: totalProductPrice || 0,
|
|
740
782
|
discount: 0
|
|
741
783
|
})
|
|
784
|
+
|
|
742
785
|
function applyDiscount (percentage) {
|
|
743
786
|
const validateCondition =
|
|
744
787
|
isNaN(percentage) || percentage < 0 || percentage > 100
|
|
@@ -770,17 +813,19 @@ export const useSales = ({
|
|
|
770
813
|
setLoadingSale(true)
|
|
771
814
|
const code = RandomCode(10)
|
|
772
815
|
setCode(code)
|
|
816
|
+
const changeValue = values.change ? convertToIntegerOrFloat(values.change) : null;
|
|
817
|
+
|
|
773
818
|
return registerSalesStore({
|
|
774
819
|
variables: {
|
|
775
820
|
input: finalArrayProduct || [],
|
|
776
821
|
id: values?.cliId,
|
|
777
822
|
pCodeRef: code,
|
|
778
|
-
change:
|
|
779
|
-
valueDelivery:
|
|
823
|
+
change: changeValue,
|
|
824
|
+
valueDelivery: convertToIntegerOrFloat(values.valueDelivery),
|
|
780
825
|
payMethodPState: data.payMethodPState,
|
|
781
826
|
pickUp: 1,
|
|
782
827
|
discount: discount.discount || 0,
|
|
783
|
-
totalProductsPrice: totalProductsPrice || 0
|
|
828
|
+
totalProductsPrice: convertToIntegerOrFloat(totalProductsPrice) || 0
|
|
784
829
|
}
|
|
785
830
|
})
|
|
786
831
|
.then((responseRegisterR) => {
|
|
@@ -954,7 +999,6 @@ export const useSales = ({
|
|
|
954
999
|
}
|
|
955
1000
|
}
|
|
956
1001
|
const handleCleanFilter = () => {
|
|
957
|
-
setArrayCategory([])
|
|
958
1002
|
setValues({})
|
|
959
1003
|
setValuesDates({ fromDate: yearMonthDay, toDate: '' })
|
|
960
1004
|
}
|
|
@@ -992,9 +1036,13 @@ export const useSales = ({
|
|
|
992
1036
|
dataExtra: dataExtra || [],
|
|
993
1037
|
fetchMore,
|
|
994
1038
|
discount,
|
|
1039
|
+
checkedItems,
|
|
1040
|
+
datCat,
|
|
1041
|
+
disabledItems,
|
|
1042
|
+
setCheckedItems,
|
|
1043
|
+
handleChangeCheck,
|
|
995
1044
|
handleUpdateAllExtra,
|
|
996
1045
|
dispatch,
|
|
997
|
-
setArrayCategory,
|
|
998
1046
|
handleComment,
|
|
999
1047
|
setModalItem,
|
|
1000
1048
|
handleChangeFilter,
|
|
@@ -4,7 +4,7 @@ import { GET_ONE_SALE } from './queries'
|
|
|
4
4
|
export const useGetSale = () => {
|
|
5
5
|
const [getOnePedidoStore, { loading, data, called, error }] = useLazyQuery(GET_ONE_SALE)
|
|
6
6
|
return {
|
|
7
|
-
data: data?.getOnePedidoStore,
|
|
7
|
+
data: data?.getOnePedidoStore,
|
|
8
8
|
loading,
|
|
9
9
|
error,
|
|
10
10
|
called,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { useQuery, useMutation } from '@apollo/client'
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
GET_ONE_SCHEDULE_STORE,
|
|
4
|
+
GET_SCHEDULE_STORE,
|
|
5
|
+
CREATE_STORE_CALENDAR,
|
|
6
|
+
SET_STATUS_ALL_SCHEDULE_STORE
|
|
7
|
+
} from './queries'
|
|
4
8
|
|
|
5
9
|
export const useSchedule = ({ day = null, idStore = '' }) => {
|
|
6
10
|
const {
|
|
@@ -12,6 +16,41 @@ export const useSchedule = ({ day = null, idStore = '' }) => {
|
|
|
12
16
|
return [data?.getOneStoreSchedules, { loading, error }]
|
|
13
17
|
}
|
|
14
18
|
|
|
19
|
+
export const useSetScheduleOpenAll = () => {
|
|
20
|
+
const [setStoreSchedule, { loading, error }] = useMutation(SET_STATUS_ALL_SCHEDULE_STORE, {
|
|
21
|
+
onError: (e) => {
|
|
22
|
+
console.error(e);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const handleSetStoreSchedule = (scheduleOpenAll) => {
|
|
27
|
+
setStoreSchedule({
|
|
28
|
+
variables: {
|
|
29
|
+
scheduleOpenAll: scheduleOpenAll
|
|
30
|
+
}, update: (cache, { data }) => {
|
|
31
|
+
const success = data?.setScheduleOpenAll?.success
|
|
32
|
+
if (success) {
|
|
33
|
+
cache.modify({
|
|
34
|
+
fields: {
|
|
35
|
+
getStore (_, { readField }) {
|
|
36
|
+
const store = readField('getStore')
|
|
37
|
+
const updatedCart = {
|
|
38
|
+
...store,
|
|
39
|
+
scheduleOpenAll: scheduleOpenAll
|
|
40
|
+
}
|
|
41
|
+
return updatedCart
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return [handleSetStoreSchedule, { loading, error }];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
|
|
15
54
|
export const useSchedules = ({ schDay = 1, idStore = '' }) => {
|
|
16
55
|
const {
|
|
17
56
|
data,
|
|
@@ -32,3 +32,12 @@ export const GET_ONE_SCHEDULE_STORE = gql`
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
`
|
|
35
|
+
|
|
36
|
+
export const SET_STATUS_ALL_SCHEDULE_STORE = gql`
|
|
37
|
+
mutation setScheduleOpenAll($scheduleOpenAll: Boolean!) {
|
|
38
|
+
setScheduleOpenAll(scheduleOpenAll: $scheduleOpenAll) {
|
|
39
|
+
success
|
|
40
|
+
message
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`
|
|
@@ -4,6 +4,7 @@ import { GET_ONE_STORE, GET_ONE_STORE_BY_ID } from './queries' // Reemplaza con
|
|
|
4
4
|
import { errorHandler } from '../../config/client'
|
|
5
5
|
import { useLogout } from '../useLogout'
|
|
6
6
|
export const useStore = ({ isClient = false, idStore = '' } = {}) => {
|
|
7
|
+
|
|
7
8
|
const client = useApolloClient();
|
|
8
9
|
const [onClickLogout, { loading: load }] = useLogout();
|
|
9
10
|
|
|
@@ -17,8 +18,9 @@ export const useStore = ({ isClient = false, idStore = '' } = {}) => {
|
|
|
17
18
|
|
|
18
19
|
useEffect(() => {
|
|
19
20
|
if (cachedData) {
|
|
21
|
+
const array = store ? Object.keys(store) : []
|
|
20
22
|
// Comprobar si los datos de la caché ya están establecidos en el estado
|
|
21
|
-
if (!store ||
|
|
23
|
+
if (!store || Array.isArray(array) && array?.length === 0) {
|
|
22
24
|
setStore(cachedData.getStore);
|
|
23
25
|
}
|
|
24
26
|
}
|
|
@@ -40,7 +42,7 @@ export const useStore = ({ isClient = false, idStore = '' } = {}) => {
|
|
|
40
42
|
error: errorStoreClient
|
|
41
43
|
}];
|
|
42
44
|
} else {
|
|
43
|
-
const {
|
|
45
|
+
const { loading: loadingServer, error: errorServer } = useQuery(GET_ONE_STORE, {
|
|
44
46
|
skip: isClient && !idStore,
|
|
45
47
|
variables: {
|
|
46
48
|
idStore
|
|
@@ -63,16 +65,6 @@ export const useStore = ({ isClient = false, idStore = '' } = {}) => {
|
|
|
63
65
|
}
|
|
64
66
|
});
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
if (!loadingServer && !errorServer && !cachedData) {
|
|
69
|
-
client.writeQuery({
|
|
70
|
-
query: GET_ONE_STORE,
|
|
71
|
-
data: { getStore: store }
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}, [loadingServer, errorServer, cachedData, client, store]);
|
|
75
|
-
|
|
76
|
-
return [store, { loading: load || loadingServer, error }];
|
|
68
|
+
return [store, { loading: load || loadingServer || loading, error }];
|
|
77
69
|
}
|
|
78
70
|
};
|
|
@@ -15,6 +15,7 @@ query getStore($id: ID, $idStore: ID){
|
|
|
15
15
|
getStore(id: $id, idStore: $idStore){
|
|
16
16
|
cId
|
|
17
17
|
id
|
|
18
|
+
scheduleOpenAll
|
|
18
19
|
dId
|
|
19
20
|
idStore
|
|
20
21
|
ctId
|
|
@@ -100,7 +101,7 @@ query getOneStore($StoreName: String, $idStore: ID){
|
|
|
100
101
|
dId
|
|
101
102
|
ctId
|
|
102
103
|
catStore
|
|
103
|
-
neighborhoodStore
|
|
104
|
+
neighborhoodStore
|
|
104
105
|
Viaprincipal
|
|
105
106
|
storeOwner
|
|
106
107
|
storeName
|