npm-pkg-hook 1.1.8 → 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/.github/pull_request_template.md +17 -17
- package/.github/workflows/pepeline.yaml +29 -29
- package/package.json +1 -1
- package/script.txt +6 -6
- package/src/hooks/getSession/index.js +1 -1
- package/src/hooks/useAsideCart/index.js +0 -1
- package/src/hooks/useCart/useCart/index.js +5 -6
- package/src/hooks/useCatWithProduct/queries.js +1 -1
- package/src/hooks/useCatWithProductClient/index.js +24 -16
- package/src/hooks/useGetMinPrice/index.js +6 -2
- package/src/hooks/useLocationNavigate/index.js +54 -54
- package/src/hooks/useLogout/index.js +1 -1
- package/src/hooks/useProductsFood/index.js +3 -2
- package/src/hooks/useStore/index.js +53 -51
- package/src/hooks/useUser/queries.js +2 -2
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
## What problem is this solving?
|
|
2
|
-
|
|
3
|
-
- [x] this is an example if you finish your work
|
|
4
|
-
|
|
5
|
-
## How should this be manually tested?
|
|
6
|
-
|
|
7
|
-
### Screenshots or example usage
|
|
8
|
-
|
|
9
|
-
## Types of changes
|
|
10
|
-
|
|
11
|
-
* [ ] Bug fix (a non-breaking change which fixes an issue)
|
|
12
|
-
* [ ] New feature (a non-breaking change which adds functionality)
|
|
13
|
-
* [ ] Breaking change (fix or feature that would cause existing functionality to change)
|
|
14
|
-
* [ ] Requires change to documentation, which has been updated accordingly.
|
|
15
|
-
|
|
16
|
-
## PR's related
|
|
17
|
-
|
|
1
|
+
## What problem is this solving?
|
|
2
|
+
|
|
3
|
+
- [x] this is an example if you finish your work
|
|
4
|
+
|
|
5
|
+
## How should this be manually tested?
|
|
6
|
+
|
|
7
|
+
### Screenshots or example usage
|
|
8
|
+
|
|
9
|
+
## Types of changes
|
|
10
|
+
|
|
11
|
+
* [ ] Bug fix (a non-breaking change which fixes an issue)
|
|
12
|
+
* [ ] New feature (a non-breaking change which adds functionality)
|
|
13
|
+
* [ ] Breaking change (fix or feature that would cause existing functionality to change)
|
|
14
|
+
* [ ] Requires change to documentation, which has been updated accordingly.
|
|
15
|
+
|
|
16
|
+
## PR's related
|
|
17
|
+
|
|
18
18
|
- [x] Add the relation between pull request
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
name: Publish package to GitHub Packages
|
|
2
|
-
on:
|
|
3
|
-
push:
|
|
4
|
-
branches: [main]
|
|
5
|
-
pull_request:
|
|
6
|
-
branches: [develop]
|
|
7
|
-
types: [opened, synchronize]
|
|
8
|
-
release:
|
|
9
|
-
types: [created]
|
|
10
|
-
jobs:
|
|
11
|
-
build:
|
|
12
|
-
runs-on: ubuntu-latest
|
|
13
|
-
permissions:
|
|
14
|
-
contents: read
|
|
15
|
-
packages: write
|
|
16
|
-
steps:
|
|
17
|
-
- uses: actions/checkout@v3
|
|
18
|
-
# Setup .npmrc file to publish to GitHub Packages
|
|
19
|
-
- uses: actions/setup-node@v3
|
|
20
|
-
with:
|
|
21
|
-
node-version: '16.x'
|
|
22
|
-
registry-url: 'https://npm.pkg.github.com'
|
|
23
|
-
# Defaults to the user or organization that owns the workflow file
|
|
24
|
-
- run: npm install
|
|
25
|
-
- uses: JS-DevTools/npm-publish@v1
|
|
26
|
-
with:
|
|
27
|
-
token: ${{ secrets.NPM_TOKEN }}
|
|
28
|
-
# - run: npm publish
|
|
29
|
-
# env:
|
|
1
|
+
name: Publish package to GitHub Packages
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
branches: [develop]
|
|
7
|
+
types: [opened, synchronize]
|
|
8
|
+
release:
|
|
9
|
+
types: [created]
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
packages: write
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v3
|
|
18
|
+
# Setup .npmrc file to publish to GitHub Packages
|
|
19
|
+
- uses: actions/setup-node@v3
|
|
20
|
+
with:
|
|
21
|
+
node-version: '16.x'
|
|
22
|
+
registry-url: 'https://npm.pkg.github.com'
|
|
23
|
+
# Defaults to the user or organization that owns the workflow file
|
|
24
|
+
- run: npm install
|
|
25
|
+
- uses: JS-DevTools/npm-publish@v1
|
|
26
|
+
with:
|
|
27
|
+
token: ${{ secrets.NPM_TOKEN }}
|
|
28
|
+
# - run: npm publish
|
|
29
|
+
# env:
|
|
30
30
|
# NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/package.json
CHANGED
package/script.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// (function (params) {
|
|
2
|
-
// var ct = document.createElement('link');
|
|
3
|
-
// ct.rel = 'stylesheet';
|
|
4
|
-
// ct.href = 'https://csswizardry.com/ct/ct.css';
|
|
5
|
-
// ct.classList.add('ct');
|
|
6
|
-
// document.head.appendChild(ct)
|
|
1
|
+
// (function (params) {
|
|
2
|
+
// var ct = document.createElement('link');
|
|
3
|
+
// ct.rel = 'stylesheet';
|
|
4
|
+
// ct.href = 'https://csswizardry.com/ct/ct.css';
|
|
5
|
+
// ct.classList.add('ct');
|
|
6
|
+
// document.head.appendChild(ct)
|
|
7
7
|
// }());
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const getSession = async () => {
|
|
2
2
|
try {
|
|
3
|
-
const res = await fetch(`${process.env.URL_BASE}api/auth/getAuth`,
|
|
3
|
+
const res = await fetch(`${process.env.URL_BASE}/api/auth/getAuth`,
|
|
4
4
|
{ method: 'GET', headers: { 'Content-Type': 'application/json' } })
|
|
5
5
|
const data = await res.json()
|
|
6
6
|
const { ok, ok: { user }, isSession } = data || {}
|
|
@@ -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
|
|
|
@@ -316,17 +316,16 @@ export const useCart = ({
|
|
|
316
316
|
if (!idStore) {
|
|
317
317
|
return
|
|
318
318
|
}
|
|
319
|
-
|
|
319
|
+
const isExistItemInShoppingCart = dataShoppingCard?.find((item) => {
|
|
320
|
+
return item?.productFood && item?.productFood?.pId === food.pId
|
|
321
|
+
}) ?? null
|
|
322
|
+
if (!isExistItemInShoppingCart) handleMenu(1)
|
|
320
323
|
const filteredDataOptional = filterDataOptional(dataOptional)
|
|
321
324
|
|
|
322
325
|
const dataExtraFiltered = filterExtra(dataExtra)
|
|
323
326
|
|
|
324
327
|
const refCodePid = RandomCode(20)
|
|
325
|
-
const isExistItemInShoppingCart = dataShoppingCard?.find((item) => {
|
|
326
|
-
return item?.productFood && item?.productFood?.pId === food.pId
|
|
327
|
-
}) ?? null
|
|
328
328
|
|
|
329
|
-
console.log(isExistItemInShoppingCart)
|
|
330
329
|
const idShoppingCart = isExistItemInShoppingCart?.ShoppingCard
|
|
331
330
|
try {
|
|
332
331
|
const idStore = food?.getStore?.idStore
|
|
@@ -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 [
|
|
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
|
}
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
const defaultSettings = {
|
|
4
|
-
enableHighAccuracy: false,
|
|
5
|
-
timeout: Infinity,
|
|
6
|
-
maximumAge: 0
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const usePosition = (watch = false, settings = defaultSettings) => {
|
|
10
|
-
const [position, setPosition] = useState({})
|
|
11
|
-
const [error, setError] = useState(null)
|
|
12
|
-
|
|
13
|
-
const onChange = ({ coords, timestamp }) => {
|
|
14
|
-
setPosition({
|
|
15
|
-
latitude: coords.latitude,
|
|
16
|
-
longitude: coords.longitude,
|
|
17
|
-
accuracy: coords.accuracy,
|
|
18
|
-
speed: coords.speed,
|
|
19
|
-
timestamp
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const onError = () => {
|
|
24
|
-
setError(error?.message)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
if (!navigator || !navigator.geolocation) {
|
|
29
|
-
setError('Geolocation is not supported')
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let watcher = null
|
|
34
|
-
if (watch) {
|
|
35
|
-
watcher = navigator.geolocation.watchPosition(
|
|
36
|
-
onChange,
|
|
37
|
-
onError,
|
|
38
|
-
settings
|
|
39
|
-
)
|
|
40
|
-
} else {
|
|
41
|
-
navigator.geolocation.getCurrentPosition(onChange, onError, settings)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return () => { return watcher && navigator.geolocation.clearWatch(watcher) }
|
|
45
|
-
}, [
|
|
46
|
-
settings,
|
|
47
|
-
settings.enableHighAccuracy,
|
|
48
|
-
settings.timeout,
|
|
49
|
-
settings.maximumAge,
|
|
50
|
-
watch
|
|
51
|
-
])
|
|
52
|
-
|
|
53
|
-
return { ...position, error }
|
|
54
|
-
}
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
const defaultSettings = {
|
|
4
|
+
enableHighAccuracy: false,
|
|
5
|
+
timeout: Infinity,
|
|
6
|
+
maximumAge: 0
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const usePosition = (watch = false, settings = defaultSettings) => {
|
|
10
|
+
const [position, setPosition] = useState({})
|
|
11
|
+
const [error, setError] = useState(null)
|
|
12
|
+
|
|
13
|
+
const onChange = ({ coords, timestamp }) => {
|
|
14
|
+
setPosition({
|
|
15
|
+
latitude: coords.latitude,
|
|
16
|
+
longitude: coords.longitude,
|
|
17
|
+
accuracy: coords.accuracy,
|
|
18
|
+
speed: coords.speed,
|
|
19
|
+
timestamp
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const onError = () => {
|
|
24
|
+
setError(error?.message)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!navigator || !navigator.geolocation) {
|
|
29
|
+
setError('Geolocation is not supported')
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let watcher = null
|
|
34
|
+
if (watch) {
|
|
35
|
+
watcher = navigator.geolocation.watchPosition(
|
|
36
|
+
onChange,
|
|
37
|
+
onError,
|
|
38
|
+
settings
|
|
39
|
+
)
|
|
40
|
+
} else {
|
|
41
|
+
navigator.geolocation.getCurrentPosition(onChange, onError, settings)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return () => { return watcher && navigator.geolocation.clearWatch(watcher) }
|
|
45
|
+
}, [
|
|
46
|
+
settings,
|
|
47
|
+
settings.enableHighAccuracy,
|
|
48
|
+
settings.timeout,
|
|
49
|
+
settings.maximumAge,
|
|
50
|
+
watch
|
|
51
|
+
])
|
|
52
|
+
|
|
53
|
+
return { ...position, error }
|
|
54
|
+
}
|
|
@@ -12,7 +12,7 @@ export const useLogout = ({ setAlertBox = () => { } } = {}) => {
|
|
|
12
12
|
const onClickLogout = async () => {
|
|
13
13
|
setLoading(true)
|
|
14
14
|
await window
|
|
15
|
-
.fetch(`${process.env.URL_BASE}api/auth/logout/`, {})
|
|
15
|
+
.fetch(`${process.env.URL_BASE}/api/auth/logout/`, {})
|
|
16
16
|
.then(res => {
|
|
17
17
|
if (res) {
|
|
18
18
|
localStorage.removeItem('session')
|
|
@@ -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
|
|
9
|
-
|
|
10
|
-
variables: {
|
|
11
|
-
idStore
|
|
12
|
-
}
|
|
13
|
-
})
|
|
7
|
+
const client = useApolloClient();
|
|
8
|
+
const [onClickLogout, { loading: load }] = useLogout();
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const [
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
`
|