npm-pkg-hook 1.0.7 → 1.0.9
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 +24 -0
- package/src/config/client/index.js +1 -0
- package/src/hooks/index.js +5 -0
- package/src/hooks/useCatWithProduct/queries.js +5 -5
- package/src/hooks/useCategoryInStore/index.js +1 -0
- package/src/hooks/useClients/index.js +63 -13
- package/src/hooks/useClients/queries.js +10 -1
- package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +9 -2
- package/src/hooks/useCreateProduct/index.js +28 -13
- package/src/hooks/useEmployee/index.js +13 -0
- package/src/hooks/useEmployee/queries.js +17 -0
- package/src/hooks/useFetchMoreInteractions/index.jsx +2 -1
- package/src/hooks/useFormTools/index.js +22 -8
- package/src/hooks/useImagesStore/index.js +16 -5
- package/src/hooks/useImagesStore/queries.js +213 -173
- package/src/hooks/useLazyScript/index.js +3 -3
- package/src/hooks/useLogout/index.js +41 -0
- package/src/hooks/useOrders/index.js +81 -0
- package/src/hooks/useOrders/queries.js +328 -0
- package/src/hooks/useProductsFood/index.js +3 -3
- package/src/hooks/useProductsFood/queriesStore.js +632 -526
- package/src/hooks/useProductsFood/usetagsProducts.js +22 -10
- package/src/hooks/useReport/queries.js +2 -1
- package/src/hooks/useSales/index.js +101 -52
- package/src/hooks/useSetSession/index.js +21 -0
- package/src/hooks/useStore/index.js +42 -13
- package/src/hooks/useStoreContacts/index.js +47 -0
- package/src/hooks/useStoreContacts/queries.js +48 -0
- package/src/hooks/useUser/index.js +6 -1
- package/src/hooks/useUser/queries.js +18 -0
- package/src/utils/index.js +46 -9
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { useMutation } from "@apollo/client"
|
|
2
2
|
import { useState } from "react"
|
|
3
|
-
import { RandomCode } from "../../utils"
|
|
4
3
|
import { REGISTER_TAGS_PRODUCT } from "./queriesStore"
|
|
5
4
|
|
|
6
5
|
export const useTagsProducts = () => {
|
|
7
6
|
const [registerTag] = useMutation(REGISTER_TAGS_PRODUCT)
|
|
8
7
|
const data = [
|
|
9
8
|
{
|
|
10
|
-
id:
|
|
11
|
-
tag: 'Bebida
|
|
9
|
+
id: 1,
|
|
10
|
+
tag: 'Bebida fría'
|
|
12
11
|
},
|
|
13
12
|
{
|
|
14
|
-
id:
|
|
13
|
+
id: 2,
|
|
15
14
|
tag: 'Bebida caliente'
|
|
16
15
|
},
|
|
17
16
|
{
|
|
18
|
-
id:
|
|
17
|
+
id: 3,
|
|
19
18
|
tag: 'Bebida alcohólica'
|
|
20
19
|
},
|
|
21
20
|
{
|
|
22
|
-
id:
|
|
21
|
+
id: 4,
|
|
23
22
|
tag: 'Bebida sin alcohol'
|
|
24
23
|
}
|
|
25
24
|
]
|
|
@@ -27,14 +26,27 @@ export const useTagsProducts = () => {
|
|
|
27
26
|
id: '',
|
|
28
27
|
tag: ''
|
|
29
28
|
})
|
|
29
|
+
|
|
30
30
|
const handleAddTag = (id, tag) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
if (tags.id === id) {
|
|
32
|
+
return setTags({
|
|
33
|
+
id: '',
|
|
34
|
+
tag: ''
|
|
34
35
|
})
|
|
36
|
+
}
|
|
37
|
+
return setTags({
|
|
38
|
+
id,
|
|
39
|
+
tag
|
|
40
|
+
})
|
|
35
41
|
}
|
|
36
42
|
const handleRegister = tag => {
|
|
37
|
-
const {
|
|
43
|
+
const {
|
|
44
|
+
pId,
|
|
45
|
+
idUser,
|
|
46
|
+
idStore,
|
|
47
|
+
nameTag
|
|
48
|
+
} = tag || {}
|
|
49
|
+
|
|
38
50
|
registerTag({
|
|
39
51
|
variables: {
|
|
40
52
|
input: {
|
|
@@ -4,7 +4,8 @@ export const GET_ALL_SALES = gql`
|
|
|
4
4
|
query getAllSalesStore($idStore: ID,$search: String, $min: Int, $max: Int $fromDate: DateTime, $toDate: DateTime ) {
|
|
5
5
|
getAllSalesStore(idStore: $idStore, search: $search, min: $min, max: $max, toDate: $toDate, fromDate: $fromDate) {
|
|
6
6
|
totalProductsPrice
|
|
7
|
-
|
|
7
|
+
channel
|
|
8
|
+
pDatCre
|
|
8
9
|
pCodeRef
|
|
9
10
|
}
|
|
10
11
|
}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
useApolloClient,
|
|
3
|
+
useLazyQuery,
|
|
4
|
+
useMutation
|
|
5
|
+
} from "@apollo/client";
|
|
6
|
+
import {
|
|
7
|
+
useCallback,
|
|
8
|
+
useEffect,
|
|
9
|
+
useReducer,
|
|
10
|
+
useMemo,
|
|
11
|
+
useState
|
|
12
|
+
} from "react";
|
|
3
13
|
import { Cookies } from "../../cookies";
|
|
4
|
-
import { RandomCode, getCurrentDomain
|
|
14
|
+
import { RandomCode, getCurrentDomain } from "../../utils";
|
|
5
15
|
import { useFormatDate } from "../useFormatDate";
|
|
6
16
|
import { useProductsFood } from "../useProductsFood";
|
|
7
17
|
import {
|
|
@@ -62,9 +72,9 @@ export const useSales = ({
|
|
|
62
72
|
const [print, setPrint] = useState(false);
|
|
63
73
|
const [values, setValues] = useState({});
|
|
64
74
|
const [dataStore] = useStore();
|
|
75
|
+
const { createdAt } = dataStore || {};
|
|
65
76
|
const [code, setCode] = useState(null);
|
|
66
77
|
const [openCurrentSale, setOpenCurrentSale] = useState(null);
|
|
67
|
-
const { createdAt } = dataStore || {};
|
|
68
78
|
const [oneProductToComment, setOneProductToComment] = useState({});
|
|
69
79
|
const [sumExtraProducts, setSumExtraProducts] = useState(0);
|
|
70
80
|
const { yearMonthDay } = useFormatDate({ date: createdAt });
|
|
@@ -83,12 +93,21 @@ export const useSales = ({
|
|
|
83
93
|
const error = data?.registerSalesStore?.Response.success
|
|
84
94
|
? "Éxito"
|
|
85
95
|
: "Error";
|
|
86
|
-
sendNotification({
|
|
96
|
+
sendNotification({
|
|
97
|
+
backgroundColor: error ? 'success' : 'error',
|
|
98
|
+
title: error,
|
|
99
|
+
description: message
|
|
100
|
+
});
|
|
87
101
|
setAlertBox({ message: message, type: "success" });
|
|
88
102
|
setOpenCurrentSale(data?.registerSalesStore?.Response.success);
|
|
89
103
|
},
|
|
90
104
|
onError: (error) => {
|
|
91
|
-
|
|
105
|
+
console.log(error)
|
|
106
|
+
sendNotification({
|
|
107
|
+
backgroundColor: 'error',
|
|
108
|
+
title: error || 'Lo sentimo',
|
|
109
|
+
description: 'ha ocurrido un error'
|
|
110
|
+
});
|
|
92
111
|
},
|
|
93
112
|
}
|
|
94
113
|
);
|
|
@@ -143,7 +162,7 @@ export const useSales = ({
|
|
|
143
162
|
return sendNotification({
|
|
144
163
|
title: "Error",
|
|
145
164
|
description: "Esta es la descr",
|
|
146
|
-
backgroundColor: "
|
|
165
|
+
backgroundColor: "error",
|
|
147
166
|
});
|
|
148
167
|
}
|
|
149
168
|
setPrint(!print);
|
|
@@ -244,6 +263,7 @@ export const useSales = ({
|
|
|
244
263
|
return {
|
|
245
264
|
...state,
|
|
246
265
|
PRODUCT: [],
|
|
266
|
+
sortBy: null,
|
|
247
267
|
counter: 0,
|
|
248
268
|
};
|
|
249
269
|
|
|
@@ -394,6 +414,7 @@ export const useSales = ({
|
|
|
394
414
|
if (!product?.PRODUCT?.pId) {
|
|
395
415
|
return sendNotification({
|
|
396
416
|
title: "Error",
|
|
417
|
+
backgroundColor: 'error',
|
|
397
418
|
description: "No se puede actualizar el producto sin pId",
|
|
398
419
|
});
|
|
399
420
|
}
|
|
@@ -419,6 +440,7 @@ export const useSales = ({
|
|
|
419
440
|
} catch (_error) {
|
|
420
441
|
return sendNotification({
|
|
421
442
|
title: "Error",
|
|
443
|
+
backgroundColor: 'error',
|
|
422
444
|
description: "No se puedo actualizar el producto",
|
|
423
445
|
});
|
|
424
446
|
}
|
|
@@ -467,48 +489,67 @@ export const useSales = ({
|
|
|
467
489
|
setDataExtra(newExtra);
|
|
468
490
|
}
|
|
469
491
|
}
|
|
470
|
-
|
|
492
|
+
/**
|
|
493
|
+
* Agrega un producto al carrito de compras.
|
|
494
|
+
* @param {Object} state - Estado actual del carrito.
|
|
495
|
+
* @param {Object} action - Acción que contiene los datos del producto a agregar.
|
|
496
|
+
* @param {string} action.payload.pId - ID del producto.
|
|
497
|
+
* @param {string} action.payload.pName - Nombre del producto.
|
|
498
|
+
* @param {string[]} action.payload.getOneTags - Etiquetas del producto.
|
|
499
|
+
* @param {string} action.payload.ProDescription - Descripción del producto.
|
|
500
|
+
* @param {string} action.payload.ProImage - URL de la imagen del producto.
|
|
501
|
+
* @param {number} action.payload.ProPrice - Precio del producto.
|
|
502
|
+
* @returns {Object} Nuevo estado del carrito con el producto agregado.
|
|
503
|
+
*/
|
|
471
504
|
function addToCartFunc(state, action) {
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
const OurProduct = productsFood.find((
|
|
476
|
-
return items.pId === action.payload.pId;
|
|
477
|
-
});
|
|
505
|
+
const { pId, pName, getOneTags, ProDescription, ProImage, ProPrice } = action.payload;
|
|
506
|
+
|
|
507
|
+
const productExist = state.PRODUCT.find((item) => item.pId === pId);
|
|
508
|
+
const OurProduct = productsFood.find((item) => item.pId === pId);
|
|
478
509
|
const isFree = productExist?.free;
|
|
510
|
+
|
|
511
|
+
const updatedProduct = {
|
|
512
|
+
pId,
|
|
513
|
+
pName,
|
|
514
|
+
getOneTags,
|
|
515
|
+
unitPrice: OurProduct?.ProPrice,
|
|
516
|
+
ProDescription,
|
|
517
|
+
ProImage,
|
|
518
|
+
ProPrice,
|
|
519
|
+
ProQuantity: 1,
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
if (!productExist) {
|
|
523
|
+
return {
|
|
524
|
+
...state,
|
|
525
|
+
counter: state.counter + 1,
|
|
526
|
+
totalAmount: state.totalAmount + ProPrice,
|
|
527
|
+
startAnimateUp: "start-animate-up",
|
|
528
|
+
PRODUCT: [...state.PRODUCT, updatedProduct],
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
|
|
479
532
|
return {
|
|
480
533
|
...state,
|
|
481
534
|
counter: state.counter + 1,
|
|
482
|
-
totalAmount: state.totalAmount +
|
|
535
|
+
totalAmount: state.totalAmount + ProPrice,
|
|
483
536
|
startAnimateUp: "start-animate-up",
|
|
484
|
-
PRODUCT:
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
: state.PRODUCT.map((items) => {
|
|
498
|
-
return items.pId === action.payload.pId
|
|
499
|
-
? {
|
|
500
|
-
...items,
|
|
501
|
-
unitPrice: OurProduct?.ProPrice,
|
|
502
|
-
ProPrice: isFree
|
|
503
|
-
? 0
|
|
504
|
-
: (productExist.ProQuantity + 1) * OurProduct?.ProPrice,
|
|
505
|
-
ProQuantity: productExist.ProQuantity + 1,
|
|
506
|
-
free: isFree ? true : false,
|
|
507
|
-
}
|
|
508
|
-
: items;
|
|
509
|
-
}),
|
|
537
|
+
PRODUCT: state.PRODUCT.map((item) => {
|
|
538
|
+
if (item.pId === pId) {
|
|
539
|
+
return {
|
|
540
|
+
...item,
|
|
541
|
+
getOneTags: OurProduct.genderTags,
|
|
542
|
+
unitPrice: OurProduct?.ProPrice,
|
|
543
|
+
ProPrice: isFree ? 0 : (productExist.ProQuantity + 1) * OurProduct?.ProPrice,
|
|
544
|
+
ProQuantity: productExist.ProQuantity + 1,
|
|
545
|
+
free: isFree ? true : false,
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
return item;
|
|
549
|
+
}),
|
|
510
550
|
};
|
|
511
551
|
}
|
|
552
|
+
|
|
512
553
|
function removeFunc(state, action) {
|
|
513
554
|
const productExist = state.PRODUCT.find((items) => {
|
|
514
555
|
return items.pId === action.payload.pId;
|
|
@@ -574,19 +615,20 @@ export const useSales = ({
|
|
|
574
615
|
};
|
|
575
616
|
}
|
|
576
617
|
|
|
577
|
-
const getSortedProduct = (
|
|
578
|
-
if (
|
|
579
|
-
return
|
|
618
|
+
const getSortedProduct = useCallback((data, sort) => {
|
|
619
|
+
if (sort && sort === "PRICE_HIGH_TO_LOW") {
|
|
620
|
+
return data.sort((a, b) => {
|
|
580
621
|
return b["ProPrice"] - a["ProPrice"];
|
|
581
622
|
});
|
|
582
623
|
}
|
|
583
|
-
if (
|
|
584
|
-
return
|
|
624
|
+
if (sort && sort === "PRICE_LOW_TO_HIGH") {
|
|
625
|
+
return data.sort((a, b) => {
|
|
585
626
|
return a["ProPrice"] - b["ProPrice"];
|
|
586
627
|
});
|
|
587
628
|
}
|
|
588
|
-
return
|
|
589
|
-
}
|
|
629
|
+
return data;
|
|
630
|
+
}, [])
|
|
631
|
+
|
|
590
632
|
const PriceRangeFunc = (products, price) => {
|
|
591
633
|
return (
|
|
592
634
|
products?.length > 0 &&
|
|
@@ -596,7 +638,9 @@ export const useSales = ({
|
|
|
596
638
|
);
|
|
597
639
|
};
|
|
598
640
|
|
|
599
|
-
const sortedProduct =
|
|
641
|
+
const sortedProduct = useMemo(() => {
|
|
642
|
+
return getSortedProduct(data.PRODUCT, data.sortBy);
|
|
643
|
+
}, [data.PRODUCT, data.sortBy, getSortedProduct])
|
|
600
644
|
const finalFilter = PriceRangeFunc(sortedProduct, data.priceRange);
|
|
601
645
|
|
|
602
646
|
const handleList = (text) => {
|
|
@@ -698,6 +742,7 @@ export const useSales = ({
|
|
|
698
742
|
if (validateCondition) {
|
|
699
743
|
return sendNotification({
|
|
700
744
|
title: "Error",
|
|
745
|
+
backgroundColor: 'error',
|
|
701
746
|
description: "el descuento debe ser un número entre 0 y 100%",
|
|
702
747
|
});
|
|
703
748
|
}
|
|
@@ -714,6 +759,7 @@ export const useSales = ({
|
|
|
714
759
|
if (!values?.cliId)
|
|
715
760
|
return sendNotification({
|
|
716
761
|
title: "Error",
|
|
762
|
+
backgroundColor: 'error',
|
|
717
763
|
description: "Elije primero un cliente",
|
|
718
764
|
});
|
|
719
765
|
setLoadingSale(true);
|
|
@@ -875,7 +921,11 @@ export const useSales = ({
|
|
|
875
921
|
setLoadingExtraProduct(false);
|
|
876
922
|
} catch (error) {
|
|
877
923
|
setLoadingExtraProduct(false);
|
|
878
|
-
sendNotification({
|
|
924
|
+
sendNotification({
|
|
925
|
+
title: 'error',
|
|
926
|
+
backgroundColor: 'error',
|
|
927
|
+
description: error || "Lo sentimos, ocurrió un error",
|
|
928
|
+
});
|
|
879
929
|
}
|
|
880
930
|
};
|
|
881
931
|
const handleCleanFilter = () => {
|
|
@@ -885,8 +935,7 @@ export const useSales = ({
|
|
|
885
935
|
};
|
|
886
936
|
const disabledModalItems = dataOptional?.length > 0 || dataExtra?.length > 0;
|
|
887
937
|
return {
|
|
888
|
-
|
|
889
|
-
loading: false,
|
|
938
|
+
loading: loading || loadingSale,
|
|
890
939
|
loadingExtraProduct,
|
|
891
940
|
disabledModalItems: !disabledModalItems,
|
|
892
941
|
loadingRegisterSale,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Cookies } from "../../cookies"
|
|
2
|
+
|
|
3
|
+
export const useSetSession = () => {
|
|
4
|
+
const bookOptionsCookie = {
|
|
5
|
+
RESTAURANT: 'restaurant'
|
|
6
|
+
}
|
|
7
|
+
const handleSession = async (props) => {
|
|
8
|
+
try {
|
|
9
|
+
const { cookie } = props
|
|
10
|
+
for (const element of cookie) {
|
|
11
|
+
const { name, value } = element
|
|
12
|
+
if (value) {
|
|
13
|
+
await Cookies.set(bookOptionsCookie[name], value)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
} catch (error) {
|
|
17
|
+
throw new Error(error)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return [handleSession]
|
|
21
|
+
}
|
|
@@ -1,18 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { useRouter } from 'next/router';
|
|
3
|
+
import { useApolloClient, useQuery } from '@apollo/client';
|
|
4
|
+
import { GET_ONE_STORE } from './queries'; // Reemplaza con la importación correcta de tu consulta
|
|
5
|
+
import { errorHandler } from '../../config/client'
|
|
6
|
+
import { useLogout } from '../useLogout'
|
|
4
7
|
|
|
5
8
|
export const useStore = () => {
|
|
6
|
-
const [store, setStore] = useState({})
|
|
9
|
+
const [store, setStore] = useState({});
|
|
10
|
+
const client = useApolloClient();
|
|
11
|
+
const [onClickLogout, { loading: load, error: err }] = useLogout()
|
|
12
|
+
// Intentar leer los datos de la caché
|
|
13
|
+
const cachedData = client.readQuery({ query: GET_ONE_STORE });
|
|
14
|
+
|
|
15
|
+
if (cachedData) {
|
|
16
|
+
// Comprobar si los datos de la caché ya están establecidos en el estado
|
|
17
|
+
if (!store || Object.keys(store).length === 0) {
|
|
18
|
+
setStore(cachedData.getStore);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
7
22
|
const { loading, error } = useQuery(GET_ONE_STORE, {
|
|
8
|
-
fetchPolicy: 'cache-
|
|
9
|
-
onCompleted: (
|
|
10
|
-
const { getStore } =
|
|
11
|
-
setStore(getStore)
|
|
23
|
+
fetchPolicy: 'cache-first',
|
|
24
|
+
onCompleted: (data) => {
|
|
25
|
+
const { getStore } = data || {};
|
|
26
|
+
setStore(getStore);
|
|
12
27
|
},
|
|
13
28
|
onError: (err) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
29
|
+
if (err.networkError && err.networkError.result) {
|
|
30
|
+
const response = errorHandler(err.networkError.result);
|
|
31
|
+
if (response) {
|
|
32
|
+
onClickLogout()
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Actualizar manualmente la caché después de cada petición exitosa
|
|
39
|
+
if (!loading && !error && !cachedData) {
|
|
40
|
+
client.writeQuery({
|
|
41
|
+
query: GET_ONE_STORE,
|
|
42
|
+
data: { getStore: store },
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return [store, { loading, error }];
|
|
47
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useQuery, useMutation, useLazyQuery } from '@apollo/client'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import {
|
|
4
|
+
GET_ALL_CONTACTS,
|
|
5
|
+
EDIT_ONE_CONTACT,
|
|
6
|
+
CREATE_CONTACTS,
|
|
7
|
+
GET_ONE_CONTACT
|
|
8
|
+
} from './queries'
|
|
9
|
+
|
|
10
|
+
export const useGetStoreContacts = ({
|
|
11
|
+
sendNotification = () => { return },
|
|
12
|
+
max,
|
|
13
|
+
search = ''
|
|
14
|
+
} = {}) => {
|
|
15
|
+
const [clientes, setUseStoreContacts] = useState([])
|
|
16
|
+
const { loading, error, fetchMore, called } = useQuery(GET_ALL_CONTACTS, {
|
|
17
|
+
variables: {
|
|
18
|
+
"max": max,
|
|
19
|
+
"search": search
|
|
20
|
+
},
|
|
21
|
+
onCompleted: (data) => {
|
|
22
|
+
setUseStoreContacts(data)
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
return [clientes?.getAllContacts || [], { loading: called ? false : loading, error, fetchMore }]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const useDeleteUseStoreContacts = ({ sendNotification = () => { return } } = {}) => {
|
|
29
|
+
const [getOneContacts, { data, error, loading }] = useLazyQuery(GET_ONE_CONTACT)
|
|
30
|
+
return [getOneContacts, data?.getOneContacts ?? {}, { loading, error }]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const useGetOneUseStoreContacts = ({ sendNotification = () => { return } } = {}) => {
|
|
34
|
+
const [getOneContacts, { data, error, loading }] = useLazyQuery(GET_ONE_CONTACT)
|
|
35
|
+
return [getOneContacts, { data: data?.getOneContacts, loading, error }]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const useEditOneUseStoreContacts = ({ sendNotification = () => { return } } = {}) => {
|
|
39
|
+
const [editOneContacts, { data, error, loading }] = useMutation(EDIT_ONE_CONTACT)
|
|
40
|
+
return [editOneContacts, { data: data?.editOneContacts, loading, error }]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const useCreateContacts = ({ sendNotification = () => { return } } = {}) => {
|
|
44
|
+
const [createUseStoreContacts, { loading, error }] = useMutation(CREATE_CONTACTS)
|
|
45
|
+
|
|
46
|
+
return [createUseStoreContacts, { loading, error }]
|
|
47
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const CREATE_CONTACTS = gql`
|
|
4
|
+
mutation createContacts ($input: IContacts) {
|
|
5
|
+
createContacts(input: $input) {
|
|
6
|
+
success
|
|
7
|
+
message
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`
|
|
11
|
+
export const GET_ALL_CONTACTS = gql`
|
|
12
|
+
query getAllContacts($idStore: ID, $cId: ID, $dId: ID, $ctId: ID, $search: String, $min: Int, $pState: Int, $max: Int) {
|
|
13
|
+
getAllContacts(idStore: $idStore, cId: $cId, dId: $dId, ctId: $ctId, search: $search, min: $min, pState: $pState, max: $max) {
|
|
14
|
+
contactId
|
|
15
|
+
cntState
|
|
16
|
+
cntComments
|
|
17
|
+
cntNumberPhone
|
|
18
|
+
cntName
|
|
19
|
+
createAt
|
|
20
|
+
updateAt
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`
|
|
24
|
+
|
|
25
|
+
export const GET_ONE_CONTACT = gql`
|
|
26
|
+
query getOneContacts($contactId: String) {
|
|
27
|
+
getOneContacts(contactId: $contactId) {
|
|
28
|
+
contactId
|
|
29
|
+
id
|
|
30
|
+
idStore
|
|
31
|
+
cntName
|
|
32
|
+
cntComments
|
|
33
|
+
cntNumberPhone
|
|
34
|
+
cntState
|
|
35
|
+
createAt
|
|
36
|
+
updateAt
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
`
|
|
40
|
+
|
|
41
|
+
export const EDIT_ONE_CONTACT = gql`
|
|
42
|
+
mutation editOneContacts($input: IContacts) {
|
|
43
|
+
editOneContacts(input: $input) {
|
|
44
|
+
success
|
|
45
|
+
message
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { useQuery } from '@apollo/client'
|
|
2
|
-
import { GET_USER } from './queries'
|
|
2
|
+
import { GET_USER, SET_USER_PROFILE } from './queries'
|
|
3
3
|
|
|
4
4
|
export const useUser = () => {
|
|
5
5
|
const { data, loading, error } = useQuery(GET_USER)
|
|
6
6
|
return [data?.getUser, { loading, error }]
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const useSetUserProfile = () => {
|
|
10
|
+
const [setUserProfile, { loading, error }] = useMutation(SET_USER_PROFILE)
|
|
11
|
+
return [setUserProfile, { loading, error }]
|
|
7
12
|
}
|
|
@@ -66,4 +66,22 @@ mutation updateAvatar($file: Upload){
|
|
|
66
66
|
urlAvatar
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
+
`
|
|
70
|
+
|
|
71
|
+
export const SET_USER_PROFILE = gql`
|
|
72
|
+
mutation setUserProfile($data: IUserProfile!) {
|
|
73
|
+
setUserProfile(input: $data){
|
|
74
|
+
upId
|
|
75
|
+
id
|
|
76
|
+
upPhone
|
|
77
|
+
upDateBir
|
|
78
|
+
upImage
|
|
79
|
+
upBloodG
|
|
80
|
+
cId
|
|
81
|
+
ctId
|
|
82
|
+
dId
|
|
83
|
+
upAddress
|
|
84
|
+
upZipCode
|
|
85
|
+
}
|
|
86
|
+
}
|
|
69
87
|
`
|
package/src/utils/index.js
CHANGED
|
@@ -4,23 +4,39 @@
|
|
|
4
4
|
* @param {array} elements elementos del formulario
|
|
5
5
|
* @return {array} devuelve un array de booleanos con el nombre identificador para cada estado en react.
|
|
6
6
|
*/
|
|
7
|
+
const validTypes = {
|
|
8
|
+
text: true,
|
|
9
|
+
password: true,
|
|
10
|
+
email: true,
|
|
11
|
+
number: true,
|
|
12
|
+
hidden: true,
|
|
13
|
+
textarea: true
|
|
14
|
+
};
|
|
15
|
+
|
|
7
16
|
export const validationSubmitHooks = elements => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
let errorForm = {};
|
|
18
|
+
|
|
19
|
+
for (const element of elements) {
|
|
20
|
+
if (element.name) {
|
|
21
|
+
const elementType = element.type || element.tagName.toLowerCase();
|
|
22
|
+
if (validTypes[elementType]) {
|
|
23
|
+
if (element.dataset.required === 'true') {
|
|
24
|
+
if (!element.value) {
|
|
25
|
+
errorForm = { ...errorForm, [element.name]: true };
|
|
15
26
|
} else {
|
|
16
|
-
errorForm = { ...errorForm, [element.name]: false }
|
|
27
|
+
errorForm = { ...errorForm, [element.name]: false };
|
|
17
28
|
}
|
|
29
|
+
} else {
|
|
30
|
+
errorForm = { ...errorForm, [element.name]: false };
|
|
18
31
|
}
|
|
19
32
|
}
|
|
20
33
|
}
|
|
21
|
-
return errorForm
|
|
22
34
|
}
|
|
23
35
|
|
|
36
|
+
return errorForm;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
|
|
24
40
|
export const getCurrentDomain = () => {
|
|
25
41
|
return typeof window !== 'undefined' && window.location.hostname.split('.').slice(-2).join('.')
|
|
26
42
|
}
|
|
@@ -57,7 +73,28 @@ export const initializer = (initialValue = initialState) => { return JSON.parse(
|
|
|
57
73
|
export const numberFormat = value => { return value ? (parseInt(value) ? new Intl.NumberFormat('de-DE').format(parseFloat(`${value}`.replace(/\./g, ''))) : value) : (value) }
|
|
58
74
|
|
|
59
75
|
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* @param {Object} data objeto a filtrar
|
|
79
|
+
* @param {Array} filters array a comparar o claves del objeto a excluir
|
|
80
|
+
* @param {boolean} dataFilter booleano para devolver los datos filtrados o no
|
|
81
|
+
* @return {Object} devuelve un objeto con los datos filtrados
|
|
82
|
+
*/
|
|
83
|
+
export const filterKeyObject = (data, filters, dataFilter) => {
|
|
84
|
+
let values = {}, valuesFilter = {}
|
|
85
|
+
for (const elem in data) {
|
|
86
|
+
let coincidence = false
|
|
87
|
+
for (let i = 0; i < filters.length; i++) {
|
|
88
|
+
if (elem === filters[i]) coincidence = true
|
|
89
|
+
else valuesFilter = filters[i]
|
|
90
|
+
}
|
|
60
91
|
|
|
92
|
+
if (!coincidence) values = { ...values, [elem]: data[elem] }
|
|
93
|
+
else valuesFilter = { ...valuesFilter, [elem]: data[elem] }
|
|
94
|
+
}
|
|
95
|
+
if (!dataFilter) return values
|
|
96
|
+
if (dataFilter) return { values, valuesFilter }
|
|
97
|
+
}
|
|
61
98
|
export const MONTHS = [
|
|
62
99
|
'January',
|
|
63
100
|
'February',
|