npm-pkg-hook 1.1.9 → 1.2.0

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 CHANGED
@@ -43,5 +43,5 @@
43
43
  "rm": "rm -rf node_modules package-lock.json && npm i",
44
44
  "test": "echo \"Error: no test specified\" && exit 1"
45
45
  },
46
- "version": "1.1.9"
46
+ "version": "1.2.0"
47
47
  }
@@ -35,7 +35,6 @@ export const useAsideCart = ({
35
35
  const [totalProductPrice, setTotalProductPrice] = useState(0)
36
36
 
37
37
  const [dataShoppingCard, { loading }] = useGetCart({ setCountItemProduct })
38
- console.log({ dataShoppingCard })
39
38
 
40
39
  // Lógica de transformación de los datos
41
40
  const result2 = useMemo(() => {
@@ -149,7 +149,7 @@ export const useCart = ({
149
149
  setDataOptional(updateOption || [])
150
150
  }
151
151
  }
152
-
152
+ if (!pId || pId === '') return
153
153
  const resultExtra = await handleExtProductFoodsAll(pId)
154
154
  const originalArray = resultExtra?.data?.ExtProductFoodsAll
155
155
 
@@ -326,7 +326,6 @@ export const useCart = ({
326
326
 
327
327
  const refCodePid = RandomCode(20)
328
328
 
329
- console.log(isExistItemInShoppingCart)
330
329
  const idShoppingCart = isExistItemInShoppingCart?.ShoppingCard
331
330
  try {
332
331
  const idStore = food?.getStore?.idStore
@@ -170,4 +170,4 @@ query getCatProductsWithProduct($search: String, $productName: String, $min: Int
170
170
  }
171
171
  }
172
172
  }
173
- `
173
+ `
@@ -1,11 +1,12 @@
1
- import { useQuery } from '@apollo/client'
2
- import { GET_ALL_CATEGORIES_WITH_PRODUCT_CLIENTS } from './queries'
1
+ import { useQuery } from '@apollo/client';
2
+ import { GET_ALL_CATEGORIES_WITH_PRODUCT_CLIENTS } from './queries';
3
+ import { useMemo } from 'react';
3
4
 
4
5
  /**
5
6
  * Custom hook to fetch categories with product data.
6
7
  *
7
8
  * @param {string} idStore - The ID of the store.
8
- * @returns {object} - The hook result containing data and fetch function.
9
+ * @returns {object} - The hook result containing filtered data, loading state, and fetch function.
9
10
  */
10
11
  export const useCatWithProductClient = (idStore) => {
11
12
  const { data, loading, error, fetchMore } = useQuery(GET_ALL_CATEGORIES_WITH_PRODUCT_CLIENTS, {
@@ -16,9 +17,9 @@ export const useCatWithProductClient = (idStore) => {
16
17
  search: '',
17
18
  gender: [],
18
19
  desc: [],
19
- categories: []
20
- }
21
- })
20
+ categories: [],
21
+ },
22
+ });
22
23
 
23
24
  const fetchCategories = () => {
24
25
  fetchMore({
@@ -28,21 +29,28 @@ export const useCatWithProductClient = (idStore) => {
28
29
  search: '',
29
30
  gender: [],
30
31
  desc: [],
31
- categories: []
32
+ categories: [],
32
33
  },
33
34
  updateQuery: (prev, { fetchMoreResult }) => {
34
- if (!fetchMoreResult) return prev
35
+ if (!fetchMoreResult) return prev;
35
36
  return {
36
37
  ...prev,
37
- getCatProductsWithProductClient: fetchMoreResult.getCatProductsWithProductClient
38
- }
39
- }
40
- })
41
- }
38
+ getCatProductsWithProductClient: fetchMoreResult.getCatProductsWithProductClient,
39
+ };
40
+ },
41
+ });
42
+ };
43
+
44
+ // Utiliza useMemo para memorizar el resultado filtrado
45
+ const filteredData = useMemo(() => {
46
+ return data?.getCatProductsWithProductClient?.filter(
47
+ (category) => category?.productFoodsAll?.length > 0
48
+ ) || [];
49
+ }, [data]);
42
50
 
43
- return [data?.getCatProductsWithProductClient || [], {
51
+ return [filteredData, {
44
52
  loading,
45
53
  error,
46
- fetchCategories
54
+ fetchCategories,
47
55
  }]
48
- }
56
+ };
@@ -1,8 +1,12 @@
1
1
  import { useQuery } from '@apollo/client'
2
2
  import { GET_MIN_PEDIDO } from './queries'
3
3
 
4
- export const useGetMinPrice = () => {
5
- const { data, loading, error } = useQuery(GET_MIN_PEDIDO)
4
+ export const useGetMinPrice = ({ idStore = '' } = {}) => {
5
+ const { data, loading, error } = useQuery(GET_MIN_PEDIDO, {
6
+ variables: {
7
+ idStore
8
+ }
9
+ })
6
10
 
7
11
  return [data, { loading, error }]
8
12
  }
@@ -84,7 +84,7 @@ export const useDeleteProductsFood = ({ sendNotification = () => { } } = {}) =>
84
84
  pId,
85
85
  pState
86
86
  }
87
- },
87
+ },
88
88
  update (cache) {
89
89
  cache.modify({
90
90
  fields: {
@@ -131,6 +131,7 @@ export const useExtProductFoodsAll = () => {
131
131
  ] = useLazyQuery(GET_ALL_EXTRA_PRODUCT)
132
132
 
133
133
  const handleExtProductFoodsAll = (pId) => {
134
+ if (!pId) return
134
135
  return ExtProductFoodsAll({
135
136
  variables: {
136
137
  pId
@@ -146,7 +147,7 @@ export const useExtProductFoodsAll = () => {
146
147
  ]
147
148
  }
148
149
 
149
- export const useExtProductFoodsOptionalAll = () => {
150
+ export const useExtProductFoodsOptionalAll = () => {
150
151
  const [ExtProductFoodsOptionalAll,
151
152
  {
152
153
  data,
@@ -3,74 +3,76 @@ import { useApolloClient, useQuery } from '@apollo/client'
3
3
  import { GET_ONE_STORE, GET_ONE_STORE_BY_ID } from './queries' // Reemplaza con la importación correcta de tu consulta
4
4
  import { errorHandler } from '../../config/client'
5
5
  import { useLogout } from '../useLogout'
6
-
7
6
  export const useStore = ({ isClient = false, idStore = '' } = {}) => {
8
- const { data, refetch, loading: loadingClient, error: errorStoreClient } = useQuery(GET_ONE_STORE_BY_ID, {
9
- skip: !isClient,
10
- variables: {
11
- idStore
12
- }
13
- })
7
+ const client = useApolloClient();
8
+ const [onClickLogout, { loading: load }] = useLogout();
14
9
 
15
- const [store, setStore] = useState({})
16
- const client = useApolloClient()
17
- const [onClickLogout, { loading: load }] = useLogout()
10
+ // Variables para almacenar los datos del store
11
+ const [store, setStore] = useState({});
12
+ const [loading, setLoading] = useState(false);
13
+ const [error, setError] = useState(null);
18
14
 
19
15
  // Intentar leer los datos de la caché
20
- const cachedData = client.readQuery({ query: GET_ONE_STORE })
16
+ const cachedData = client.readQuery({ query: GET_ONE_STORE });
21
17
 
22
18
  useEffect(() => {
23
19
  if (cachedData) {
24
20
  // Comprobar si los datos de la caché ya están establecidos en el estado
25
21
  if (!store || Object.keys(store).length === 0) {
26
- setStore(cachedData.getStore)
22
+ setStore(cachedData.getStore);
27
23
  }
28
24
  }
29
- }, [cachedData, store])
25
+ }, [cachedData, store]);
30
26
 
31
- const { loading, error } = useQuery(GET_ONE_STORE, {
32
- skip: isClient,
33
- fetchPolicy: 'cache-first',
34
- onCompleted: (data) => {
35
- const { getStore } = data || {}
36
- setStore(getStore)
37
- },
38
- onError: (err) => {
39
- if (err.networkError && err.networkError.result) {
40
- const response = errorHandler(err.networkError.result)
41
- if (response) {
42
- onClickLogout()
43
- }
27
+ if (isClient && !!idStore) {
28
+ const { data, refetch, loading: loadingClient, error: errorStoreClient } = useQuery(GET_ONE_STORE_BY_ID, {
29
+ skip: !isClient,
30
+ variables: {
31
+ idStore
44
32
  }
45
- }
46
- })
33
+ });
47
34
 
48
- // Ejecutar la consulta y almacenarla en la caché
49
- useEffect(() => {
50
- client.query({ query: GET_ONE_STORE }).then(() => {
51
- // Leer la consulta desde la caché
52
- const cacheData = client.readQuery({ query: GET_ONE_STORE })
53
- setStore(cacheData?.getStore)
54
- })
55
- }, [client])
35
+ const dataOneStoreClient = !loadingClient ? data?.getOneStore : {};
56
36
 
57
- // Actualizar manualmente la caché después de cada petición exitosa
58
- useEffect(() => {
59
- if (!loading && !error && !cachedData) {
60
- client.writeQuery({
61
- query: GET_ONE_STORE,
62
- data: { getStore: store }
63
- })
64
- }
65
- }, [loading, error, cachedData, client, store])
66
-
67
- if (isClient) {
68
- const dataOneStoreClient = !loadingClient ? data?.getOneStore : {}
69
37
  return [dataOneStoreClient, {
70
38
  refetch,
71
39
  loading: loadingClient,
72
40
  error: errorStoreClient
73
- }]
41
+ }];
42
+ } else {
43
+ const { data, loading: loadingServer, error: errorServer } = useQuery(GET_ONE_STORE, {
44
+ skip: isClient && !idStore,
45
+ variables: {
46
+ idStore
47
+ },
48
+ fetchPolicy: 'cache-first',
49
+ onCompleted: (data) => {
50
+ const { getStore } = data || {};
51
+ setStore(getStore);
52
+ setLoading(false);
53
+ },
54
+ onError: (err) => {
55
+ if (err.networkError && err.networkError.result) {
56
+ const response = errorHandler(err.networkError.result);
57
+ if (response) {
58
+ onClickLogout();
59
+ }
60
+ }
61
+ setError(err);
62
+ setLoading(false);
63
+ }
64
+ });
65
+
66
+ // Actualizar manualmente la caché después de cada petición exitosa
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 }];
74
77
  }
75
- return [store, { loading: load || loading, error }]
76
- }
78
+ };
@@ -49,7 +49,7 @@ query getOneUserProfile($id: ID) {
49
49
 
50
50
  export const GET_USER = gql`
51
51
  query getUser($id: ID){
52
- getUser(id: $id ){
52
+ getUser(id: $id ){
53
53
  id
54
54
  name
55
55
  username
@@ -124,4 +124,4 @@ export const SET_USER_PROFILE = gql`
124
124
  upZipCode
125
125
  }
126
126
  }
127
- `
127
+ `