npm-pkg-hook 1.4.4 → 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 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
@@ -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.4.4"
46
+ "version": "1.4.6"
47
47
  }
@@ -6,7 +6,12 @@
6
6
  * @param {string} idStore - The ID of the store
7
7
  * @returns {string} - The generated URL or null if any field is missing
8
8
  */
9
- export const generateStoreURL = ({ city, department, storeName, idStore }) => {
9
+ export const generateStoreURL = ({
10
+ city,
11
+ department,
12
+ storeName,
13
+ idStore
14
+ }) => {
10
15
  try {
11
16
  // Validate all necessary fields
12
17
  if (
@@ -16,7 +21,7 @@ export const generateStoreURL = ({ city, department, storeName, idStore }) => {
16
21
  !storeName ||
17
22
  !idStore
18
23
  ) {
19
- return null // Return null or any default case you'd prefer
24
+ return '/' // Return null or any default case you'd prefer
20
25
  }
21
26
 
22
27
  const cityName = city.cName.toLocaleLowerCase()
@@ -27,6 +32,6 @@ export const generateStoreURL = ({ city, department, storeName, idStore }) => {
27
32
 
28
33
  return `${process.env.MAIN_URL_BASE}/delivery/${cityName}-${departmentName}/${formattedStoreName}/${idStore}`
29
34
  } catch (_) {
30
- return null
35
+ return '/'
31
36
  }
32
37
  }
@@ -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'
@@ -61,7 +61,6 @@ export const useAsideCart = ({
61
61
  setTotalProductPrice(Math.abs(totalPrice))
62
62
  }, [dataShoppingCard])
63
63
 
64
- console.log(dataShoppingCard)
65
64
  const [deleteOneItem] = useMutation(DELETE_ONE_ITEM_SHOPPING_PRODUCT, {
66
65
  onCompleted: data => {
67
66
  setAlertBox({ message: data?.deleteOneItem?.message })
@@ -82,53 +81,45 @@ export const useAsideCart = ({
82
81
  }
83
82
  }
84
83
  /**
85
- * Handle the deletion of a shopping cart item.
86
- * @param {Object} item - The item to be deleted from the shopping cart.
87
- */
84
+ * Handle the deletion of a shopping cart item.
85
+ * @param {Object} item - The item to be deleted from the shopping cart.
86
+ */
88
87
  const handleDeleteItemShopping = async (item) => {
88
+ if (!item) {
89
+ return setAlertBox({
90
+ message: 'Error borrando el producto. Por favor intenta nuevamente.',
91
+ color: 'error'
92
+ })
93
+ }
94
+
89
95
  try {
90
96
  const { cState, ShoppingCard } = item
91
97
  await deleteOneItem({
92
- variables: {
93
- cState,
94
- ShoppingCard
95
- },
96
- update: (cache, { data }) => {
97
- const success = data?.deleteOneItem?.success
98
- if (success && ShoppingCard) {
99
- cache.modify({
100
- fields: {
101
- getAllShoppingCard (existingCart, { readField }) {
102
- if (Array.isArray(existingCart) && existingCart) {
103
- if (existingCart.length === 1) {
104
- setCountItemProduct(0)
105
- }
106
- const updatedCart = {
107
- ...existingCart,
108
- ...existingCart?.filter(product =>
109
- readField('ShoppingCard', product) !== ShoppingCard
110
- )
111
- }
112
- if (typeof updatedCart === 'object' && updatedCart !== null) {
113
- const newLength = Object.keys(updatedCart)
114
- if (updatedCart && newLength) {
115
- setCountItemProduct(Object.keys(updatedCart).length)
116
- }
117
- }
118
- return updatedCart
119
- } else {
120
- return []
121
- }
122
- }
98
+ variables: { cState, ShoppingCard },
99
+ update: (cache) => {
100
+ cache.modify({
101
+ fields: {
102
+ getAllShoppingCard (existingCart, { readField }) {
103
+ if (!Array.isArray(existingCart)) return []
104
+
105
+ const filteredCart = existingCart.filter(product =>
106
+ readField('ShoppingCard', product) !== ShoppingCard
107
+ )
108
+
109
+ // Actualizar el contador de productos
110
+ setCountItemProduct(filteredCart.length)
111
+
112
+ return filteredCart?.length > 0 ? filteredCart : []
123
113
  }
124
- })
125
- }
114
+ }
115
+ })
126
116
  }
127
117
  })
128
118
  } catch (error) {
129
- setAlertBox({ message: 'Error borranto el item. Por favor intenta nuevamente.', color: 'error' })
119
+ setAlertBox({ message: 'Error borrando el producto. Por favor intenta nuevamente.', color: 'error' })
130
120
  }
131
121
  }
122
+
132
123
  /**
133
124
  * Calculate the total price of a product.
134
125
  * @param {number} ProPrice - The price of the product.
@@ -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
+ `
@@ -1,6 +1,6 @@
1
1
  import { useApolloClient } from '@apollo/client'
2
2
  import { useState } from 'react'
3
- import { Cookies } from '../../cookies'
3
+ import { Cookies } from '../../cookies/index'
4
4
  import { signOutAuth } from './helpers'
5
5
  export { signOutAuth } from './helpers'
6
6
 
@@ -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
- if (!logoutResponse.ok) return
18
- await window
19
- .fetch(`${process.env.URL_BASE}/api/auth/logout/`, {})
20
- .then(res => {
21
- if (res) {
22
- Cookies.remove(process.env.SESSION_NAME)
23
- Cookies.remove(process.env.LOCAL_SALES_STORE)
24
- Cookies.remove('restaurant')
25
- Cookies.remove('usuario')
26
- Cookies.remove('session')
27
- client?.clearStore()
28
- setLoading(false)
29
- console.log('Borrado todo')
30
- }
31
- })
32
- signOutAuth({ redirect: true, callbackUrl: '/' })
33
- .catch(() => {
34
- setError(true)
35
- setAlertBox({ message: 'Ocurrió un error al cerrar session' })
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 session' })
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 client = useApolloClient();
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, error: errorServer } = useQuery(GET_ONE_STORE, {
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
+ }
File without changes