npm-pkg-hook 1.4.5 → 1.4.6
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/.eslintrc.js +38 -38
- package/package.json +1 -1
- package/src/hooks/index.js +3 -0
- package/src/hooks/useGetAllLocationUser/index.js +12 -0
- package/src/hooks/useGetAllLocationUser/queries.js +44 -0
- package/src/hooks/useLogout/index.js +26 -21
- package/src/hooks/useQueryLocationsMap/index.js +19 -0
- package/src/hooks/useQueryLocationsMap/queries.js +40 -0
- package/src/hooks/useSaveLocation/index.js +16 -0
- package/src/hooks/useSaveLocation/queries.js +19 -0
- package/src/hooks/useStore/index.js +23 -24
package/.eslintrc.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
settings: {
|
|
3
|
-
react: {
|
|
4
|
-
version: 'detect'
|
|
5
|
-
}
|
|
6
|
-
},
|
|
7
|
-
env: {
|
|
8
|
-
browser: true,
|
|
9
|
-
es2021: true,
|
|
10
|
-
node: true
|
|
11
|
-
},
|
|
12
|
-
extends: [
|
|
13
|
-
'standard',
|
|
14
|
-
'plugin:react/recommended'
|
|
15
|
-
],
|
|
16
|
-
overrides: [
|
|
17
|
-
{
|
|
18
|
-
env: {
|
|
19
|
-
node: true
|
|
20
|
-
},
|
|
21
|
-
files: [
|
|
22
|
-
'.eslintrc.{js,cjs}'
|
|
23
|
-
],
|
|
24
|
-
parserOptions: {
|
|
25
|
-
sourceType: 'script'
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
],
|
|
29
|
-
parserOptions: {
|
|
30
|
-
ecmaVersion: 'latest',
|
|
31
|
-
sourceType: 'module'
|
|
32
|
-
},
|
|
33
|
-
plugins: [
|
|
34
|
-
'react'
|
|
35
|
-
],
|
|
36
|
-
rules: {
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
module.exports = {
|
|
2
|
+
settings: {
|
|
3
|
+
react: {
|
|
4
|
+
version: 'detect'
|
|
5
|
+
}
|
|
6
|
+
},
|
|
7
|
+
env: {
|
|
8
|
+
browser: true,
|
|
9
|
+
es2021: true,
|
|
10
|
+
node: true
|
|
11
|
+
},
|
|
12
|
+
extends: [
|
|
13
|
+
'standard',
|
|
14
|
+
'plugin:react/recommended'
|
|
15
|
+
],
|
|
16
|
+
overrides: [
|
|
17
|
+
{
|
|
18
|
+
env: {
|
|
19
|
+
node: true
|
|
20
|
+
},
|
|
21
|
+
files: [
|
|
22
|
+
'.eslintrc.{js,cjs}'
|
|
23
|
+
],
|
|
24
|
+
parserOptions: {
|
|
25
|
+
sourceType: 'script'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
parserOptions: {
|
|
30
|
+
ecmaVersion: 'latest',
|
|
31
|
+
sourceType: 'module'
|
|
32
|
+
},
|
|
33
|
+
plugins: [
|
|
34
|
+
'react'
|
|
35
|
+
],
|
|
36
|
+
rules: {
|
|
37
|
+
}
|
|
38
|
+
}
|
package/package.json
CHANGED
package/src/hooks/index.js
CHANGED
|
@@ -12,12 +12,15 @@ export * from './useScheduleData'
|
|
|
12
12
|
export * from './useOrders'
|
|
13
13
|
export * from './usePushNotifications'
|
|
14
14
|
export * from './useLocationManager'
|
|
15
|
+
export * from './useQueryLocationsMap'
|
|
16
|
+
export * from './useGetAllLocationUser'
|
|
15
17
|
export * from './useFingerprintjs'
|
|
16
18
|
export * from './useCountries'
|
|
17
19
|
export * from './useDessertWithPrice'
|
|
18
20
|
export * from './generateStoreURL'
|
|
19
21
|
export * from './useCreateStorePendingToRegister'
|
|
20
22
|
export * from './useDepartments'
|
|
23
|
+
export * from './useSaveLocation'
|
|
21
24
|
export * from './useRoads'
|
|
22
25
|
export * from './useCities'
|
|
23
26
|
export * from './useEditCategory'
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useQuery } from '@apollo/client'
|
|
2
|
+
import { GET_ALL_LOCATIONS } from './queries'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* useGetAllLocationUser
|
|
6
|
+
* @returns {any}
|
|
7
|
+
*/
|
|
8
|
+
export const useGetAllLocationUser = () => {
|
|
9
|
+
const { data, loading } = useQuery(GET_ALL_LOCATIONS)
|
|
10
|
+
|
|
11
|
+
return [data, { loading }]
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const GET_ALL_LOCATIONS = gql`
|
|
4
|
+
|
|
5
|
+
query getUserLocations {
|
|
6
|
+
getUserLocations {
|
|
7
|
+
locationId
|
|
8
|
+
# id
|
|
9
|
+
cId
|
|
10
|
+
dId
|
|
11
|
+
ctId
|
|
12
|
+
uLatitud
|
|
13
|
+
uLongitude
|
|
14
|
+
uLocationKnow
|
|
15
|
+
uPiso
|
|
16
|
+
DatCre
|
|
17
|
+
DatMod
|
|
18
|
+
pais {
|
|
19
|
+
cId
|
|
20
|
+
cName
|
|
21
|
+
cCalCod
|
|
22
|
+
cState
|
|
23
|
+
cDatCre
|
|
24
|
+
cDatMod
|
|
25
|
+
}
|
|
26
|
+
city {
|
|
27
|
+
ctId
|
|
28
|
+
dId
|
|
29
|
+
cName
|
|
30
|
+
cState
|
|
31
|
+
cDatCre
|
|
32
|
+
cDatMod
|
|
33
|
+
}
|
|
34
|
+
department {
|
|
35
|
+
dId
|
|
36
|
+
cId
|
|
37
|
+
dName
|
|
38
|
+
dState
|
|
39
|
+
dDatCre
|
|
40
|
+
dDatMod
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`
|
|
@@ -12,33 +12,38 @@ export const useLogout = ({ setAlertBox = () => { } } = {}) => {
|
|
|
12
12
|
const onClickLogout = async () => {
|
|
13
13
|
try {
|
|
14
14
|
setLoading(true)
|
|
15
|
+
|
|
15
16
|
// Logout from the server
|
|
16
17
|
const logoutResponse = await window.fetch(`${process.env.URL_BASE}/api/auth/logout/`, {})
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
|
|
19
|
+
if (!logoutResponse.ok) {
|
|
20
|
+
setLoading(false)
|
|
21
|
+
// Manejar el caso en que la solicitud no es exitosa, por ejemplo, mostrar un mensaje de error
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const response = await logoutResponse.json() // Espera la resolución de la promesa de respuesta y obtén los datos JSON
|
|
26
|
+
const { status } = response || {}
|
|
27
|
+
if (status === 200) {
|
|
28
|
+
Cookies.remove(process.env.SESSION_NAME)
|
|
29
|
+
Cookies.remove(process.env.LOCAL_SALES_STORE)
|
|
30
|
+
Cookies.remove('restaurant')
|
|
31
|
+
Cookies.remove('usuario')
|
|
32
|
+
Cookies.remove('session')
|
|
33
|
+
client?.clearStore()
|
|
34
|
+
setLoading(false)
|
|
35
|
+
console.log('Borrado todo')
|
|
36
|
+
signOutAuth({ redirect: true, callbackUrl: '/' })
|
|
37
|
+
.catch(() => {
|
|
38
|
+
setError(true)
|
|
39
|
+
setAlertBox({ message: 'Ocurrió un error al cerrar session' })
|
|
40
|
+
})
|
|
41
|
+
}
|
|
37
42
|
setLoading(false)
|
|
38
43
|
} catch (error) {
|
|
39
44
|
setLoading(false)
|
|
40
45
|
setError(true)
|
|
41
|
-
setAlertBox({ message: 'Ocurrió un error al cerrar
|
|
46
|
+
setAlertBox({ message: 'Ocurrió un error al cerrar sesión' })
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useLazyQuery } from '@apollo/client'
|
|
2
|
+
import { GET_ONE_COUNTRY, GET_ONE_DEPARTMENT, GET_ONE_CITY } from './queries'
|
|
3
|
+
|
|
4
|
+
const useGetOneCountry = () => {
|
|
5
|
+
const [getOneCountry, { data: dataCountry }] = useLazyQuery(GET_ONE_COUNTRY)
|
|
6
|
+
return { getOneCountry, dataCountry }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const useGetOneDepartment = () => {
|
|
10
|
+
const [getOneDepartment, { data: dataDepartment }] = useLazyQuery(GET_ONE_DEPARTMENT)
|
|
11
|
+
return { getOneDepartment, dataDepartment }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const useGetOneCity = () => {
|
|
15
|
+
const [getOneCities, { data: dataGetOneCity }] = useLazyQuery(GET_ONE_CITY)
|
|
16
|
+
return { getOneCities, dataGetOneCity }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { useGetOneCountry, useGetOneDepartment, useGetOneCity }
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const GET_ONE_COUNTRY = gql`
|
|
4
|
+
query getOneCountry($cId: ID){
|
|
5
|
+
getOneCountry(cId: $cId) {
|
|
6
|
+
cId
|
|
7
|
+
cName
|
|
8
|
+
cName
|
|
9
|
+
cDatCre
|
|
10
|
+
cCalCod
|
|
11
|
+
cState
|
|
12
|
+
cDatMod
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
`
|
|
17
|
+
export const GET_ONE_DEPARTMENT = gql`
|
|
18
|
+
query getOneDepartment($dId: ID){
|
|
19
|
+
getOneDepartment(dId: $dId) {
|
|
20
|
+
dId
|
|
21
|
+
cId
|
|
22
|
+
dName
|
|
23
|
+
dState
|
|
24
|
+
dDatCre
|
|
25
|
+
dDatMod
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`
|
|
29
|
+
export const GET_ONE_CITY = gql`
|
|
30
|
+
query getOneCities($ctId: ID){
|
|
31
|
+
getOneCities(ctId: $ctId) {
|
|
32
|
+
ctId
|
|
33
|
+
dId
|
|
34
|
+
cName
|
|
35
|
+
cState
|
|
36
|
+
cDatCre
|
|
37
|
+
cDatMod
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useMutation } from '@apollo/client'
|
|
2
|
+
import { SAVE_LOCATION_USER } from './queries'
|
|
3
|
+
|
|
4
|
+
export const useSaveLocation = () => {
|
|
5
|
+
const [updateUserLocations, { loading, error, data }] =
|
|
6
|
+
useMutation(SAVE_LOCATION_USER)
|
|
7
|
+
|
|
8
|
+
return [
|
|
9
|
+
updateUserLocations,
|
|
10
|
+
{
|
|
11
|
+
loading,
|
|
12
|
+
error,
|
|
13
|
+
data
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const SAVE_LOCATION_USER = gql`
|
|
4
|
+
mutation updateUserLocations($input: InputUserLocation) {
|
|
5
|
+
updateUserLocations(input: $input) {
|
|
6
|
+
locationId
|
|
7
|
+
id
|
|
8
|
+
cId
|
|
9
|
+
dId
|
|
10
|
+
ctId
|
|
11
|
+
uLatitud
|
|
12
|
+
uLongitude
|
|
13
|
+
uLocationKnow
|
|
14
|
+
uPiso
|
|
15
|
+
DatCre
|
|
16
|
+
DatMod
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`
|
|
@@ -4,27 +4,26 @@ 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
|
-
|
|
8
|
-
const
|
|
9
|
-
const [onClickLogout, { loading: load }] = useLogout();
|
|
7
|
+
const client = useApolloClient()
|
|
8
|
+
const [onClickLogout, { loading: load }] = useLogout()
|
|
10
9
|
|
|
11
10
|
// Variables para almacenar los datos del store
|
|
12
|
-
const [store, setStore] = useState({})
|
|
13
|
-
const [loading, setLoading] = useState(false)
|
|
14
|
-
const [error, setError] = useState(null)
|
|
11
|
+
const [store, setStore] = useState({})
|
|
12
|
+
const [loading, setLoading] = useState(false)
|
|
13
|
+
const [error, setError] = useState(null)
|
|
15
14
|
|
|
16
15
|
// Intentar leer los datos de la caché
|
|
17
|
-
const cachedData = client.readQuery({ query: GET_ONE_STORE })
|
|
16
|
+
const cachedData = client.readQuery({ query: GET_ONE_STORE })
|
|
18
17
|
|
|
19
18
|
useEffect(() => {
|
|
20
19
|
if (cachedData) {
|
|
21
20
|
const array = store ? Object.keys(store) : []
|
|
22
21
|
// Comprobar si los datos de la caché ya están establecidos en el estado
|
|
23
|
-
if (!store || Array.isArray(array) && array?.length === 0) {
|
|
24
|
-
setStore(cachedData.getStore)
|
|
22
|
+
if ((!store || Array.isArray(array)) && array?.length === 0) {
|
|
23
|
+
setStore(cachedData.getStore)
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
|
-
}, [cachedData, store])
|
|
26
|
+
}, [cachedData, store])
|
|
28
27
|
|
|
29
28
|
if (isClient && !!idStore) {
|
|
30
29
|
const { data, refetch, loading: loadingClient, error: errorStoreClient } = useQuery(GET_ONE_STORE_BY_ID, {
|
|
@@ -32,39 +31,39 @@ export const useStore = ({ isClient = false, idStore = '' } = {}) => {
|
|
|
32
31
|
variables: {
|
|
33
32
|
idStore
|
|
34
33
|
}
|
|
35
|
-
})
|
|
34
|
+
})
|
|
36
35
|
|
|
37
|
-
const dataOneStoreClient = !loadingClient ? data?.getOneStore : {}
|
|
36
|
+
const dataOneStoreClient = !loadingClient ? data?.getOneStore : {}
|
|
38
37
|
|
|
39
38
|
return [dataOneStoreClient, {
|
|
40
39
|
refetch,
|
|
41
40
|
loading: loadingClient,
|
|
42
41
|
error: errorStoreClient
|
|
43
|
-
}]
|
|
42
|
+
}]
|
|
44
43
|
} else {
|
|
45
|
-
const { loading: loadingServer
|
|
44
|
+
const { loading: loadingServer } = useQuery(GET_ONE_STORE, {
|
|
46
45
|
skip: isClient && !idStore,
|
|
47
46
|
variables: {
|
|
48
47
|
idStore
|
|
49
48
|
},
|
|
50
49
|
fetchPolicy: 'cache-first',
|
|
51
50
|
onCompleted: (data) => {
|
|
52
|
-
const { getStore } = data || {}
|
|
53
|
-
setStore(getStore)
|
|
54
|
-
setLoading(false)
|
|
51
|
+
const { getStore } = data || {}
|
|
52
|
+
setStore(getStore)
|
|
53
|
+
setLoading(false)
|
|
55
54
|
},
|
|
56
55
|
onError: (err) => {
|
|
57
56
|
if (err.networkError && err.networkError.result) {
|
|
58
|
-
const response = errorHandler(err.networkError.result)
|
|
57
|
+
const response = errorHandler(err.networkError.result)
|
|
59
58
|
if (response) {
|
|
60
|
-
onClickLogout()
|
|
59
|
+
onClickLogout()
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
|
-
setError(err)
|
|
64
|
-
setLoading(false)
|
|
62
|
+
setError(err)
|
|
63
|
+
setLoading(false)
|
|
65
64
|
}
|
|
66
|
-
})
|
|
65
|
+
})
|
|
67
66
|
|
|
68
|
-
return [store, { loading: load || loadingServer || loading, error }]
|
|
67
|
+
return [store, { loading: load || loadingServer || loading, error }]
|
|
69
68
|
}
|
|
70
|
-
}
|
|
69
|
+
}
|