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.
Files changed (32) hide show
  1. package/package.json +1 -1
  2. package/src/config/client/errors.js +24 -0
  3. package/src/config/client/index.js +1 -0
  4. package/src/hooks/index.js +5 -0
  5. package/src/hooks/useCatWithProduct/queries.js +5 -5
  6. package/src/hooks/useCategoryInStore/index.js +1 -0
  7. package/src/hooks/useClients/index.js +63 -13
  8. package/src/hooks/useClients/queries.js +10 -1
  9. package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +9 -2
  10. package/src/hooks/useCreateProduct/index.js +28 -13
  11. package/src/hooks/useEmployee/index.js +13 -0
  12. package/src/hooks/useEmployee/queries.js +17 -0
  13. package/src/hooks/useFetchMoreInteractions/index.jsx +2 -1
  14. package/src/hooks/useFormTools/index.js +22 -8
  15. package/src/hooks/useImagesStore/index.js +16 -5
  16. package/src/hooks/useImagesStore/queries.js +213 -173
  17. package/src/hooks/useLazyScript/index.js +3 -3
  18. package/src/hooks/useLogout/index.js +41 -0
  19. package/src/hooks/useOrders/index.js +81 -0
  20. package/src/hooks/useOrders/queries.js +328 -0
  21. package/src/hooks/useProductsFood/index.js +3 -3
  22. package/src/hooks/useProductsFood/queriesStore.js +632 -526
  23. package/src/hooks/useProductsFood/usetagsProducts.js +22 -10
  24. package/src/hooks/useReport/queries.js +2 -1
  25. package/src/hooks/useSales/index.js +101 -52
  26. package/src/hooks/useSetSession/index.js +21 -0
  27. package/src/hooks/useStore/index.js +42 -13
  28. package/src/hooks/useStoreContacts/index.js +47 -0
  29. package/src/hooks/useStoreContacts/queries.js +48 -0
  30. package/src/hooks/useUser/index.js +6 -1
  31. package/src/hooks/useUser/queries.js +18 -0
  32. package/src/utils/index.js +46 -9
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "publishConfig": {
8
8
  "registry": "https://registry.npmjs.org/"
9
9
  },
10
- "version": "1.0.7",
10
+ "version": "1.0.9",
11
11
  "description": "description-pkg-hook",
12
12
  "main": "/src/index.jsx",
13
13
  "scripts": {
@@ -0,0 +1,24 @@
1
+ import { onError } from '@apollo/client/link/error'
2
+
3
+ export const errorHandler = (error) => {
4
+ let logout = null
5
+ if (error) {
6
+ error.errors?.length && error.errors.forEach(err => {
7
+ const { code, message: { message } } = err.extensions
8
+ if (code === 'UNAUTHENTICATED' || code === 'FORBIDDEN') {
9
+ logout = true
10
+ return {
11
+ status: 'FORBIDDEN',
12
+ message
13
+ }
14
+ }
15
+ })
16
+ }
17
+ return logout
18
+ }
19
+
20
+ export const errorLink = onError(({ graphQLErrors, networkError }) => {
21
+ if (graphQLErrors)graphQLErrors.map(({ message, location, path }) => { return console.log(`[GraphQL error]: Message: ${message}, Location: ${location}, Path: ${path}`) })
22
+
23
+ if (networkError) console.log(`[Network error]: ${networkError}`)
24
+ })
@@ -0,0 +1 @@
1
+ export * from './errors';
@@ -5,8 +5,11 @@ export * from './useCategoryInStore'
5
5
  export * from './useCategoryStore'
6
6
  export * from './useCatWithProduct'
7
7
  export * from './useChartData'
8
+ export * from './useLogout'
9
+ export * from './useEmployee'
8
10
  export * from './useCheckbox'
9
11
  export * from './useClients'
12
+ export * from './useOrders'
10
13
  export * from './useConnection'
11
14
  export * from './useCreateProduct'
12
15
  export * from './useCreateProduct/helpers/useEditImageProduct'
@@ -26,12 +29,14 @@ export * from './useKeypress'
26
29
  export * from './useLazyScript'
27
30
  export * from './useLocalSorage'
28
31
  export * from './useLocationNavigate'
32
+ export * from './useSetSession'
29
33
  export * from './useMobile'
30
34
  export * from './useMutateHeight'
31
35
  export * from './useProductsFood'
32
36
  export * from './useProductsFood/usetagsProducts'
33
37
  export * from './useReactToPrint'
34
38
  export * from './useReport'
39
+ export * from './useStoreContacts'
35
40
  export * from './useRestaurant'
36
41
  export * from './useSales'
37
42
  export * from './useSales/useGetSale'
@@ -41,12 +41,12 @@ export const DELETE_ONE_CAT_PRODUCTS = gql`
41
41
  `
42
42
  export const DELETE_ONE_CAT_PRODUCTS_FINAL = gql`
43
43
 
44
- mutation deleteCatFinalOfProducts($idPc: ID){
45
- deleteCatFinalOfProducts(idPc: $idPc){
46
- success
47
- message
44
+ mutation deleteCatFinalOfProducts($idPc: ID, $withProduct: Boolean) {
45
+ deleteCatFinalOfProducts(idPc: $idPc, withProduct: $withProduct) {
46
+ success
47
+ message
48
+ }
48
49
  }
49
- }
50
50
  `
51
51
  export const DELETE_EXTRA_PRODUCTS = gql`
52
52
  mutation deleteextraproductfoods($id: ID, $state: Int){
@@ -3,6 +3,7 @@ import { useState } from 'react';
3
3
  import { DELETE_ONE_CAT_PRODUCTS, GET_ULTIMATE_CATEGORY_PRODUCTS } from '../useProductsFood/queriesStore';
4
4
  import { UPDATE_CAT_IN_PRODUCT } from './../useProductsFood/queriesStore';
5
5
  import { GET_ONE_STORE_IN_CATEGORY } from './queries';
6
+
6
7
  export const useCategoryInStore = ({ catStoreId }) => {
7
8
  // STATES
8
9
  const [categories, setOneCategoryInStore] = useState([])
@@ -1,23 +1,73 @@
1
- import { useQuery } from '@apollo/client'
1
+ import { useQuery, useMutation, useLazyQuery } from '@apollo/client'
2
2
  import { useState } from 'react'
3
- import { GET_ALL_CLIENTS } from './queries'
3
+ import {
4
+ CREATE_CLIENTS,
5
+ DELETE_ONE_CLIENTS,
6
+ GET_ALL_CLIENTS,
7
+ GET_ONE_CLIENT,
8
+ EDIT_ONE_CLIENT
9
+ } from './queries'
4
10
 
5
- export const useGetClients = () => {
6
- const [clientes, setClients] = useState([])
7
- const { loading, error } = useQuery(GET_ALL_CLIENTS, {
8
- onCompleted: (data) => {
9
- setClients(data)
11
+ export const useGetClients = ({
12
+ max,
13
+ search,
14
+ sendNotification = () => { return }
15
+ } = {}) => {
16
+ const { loading, error, called, data } = useQuery(GET_ALL_CLIENTS, {
17
+ variables: {
18
+ search: search
19
+ }
20
+ })
21
+ return [data?.getAllClients || [], { loading: called ? false : loading, error }]
22
+ }
23
+
24
+ export const useDeleteClients = ({ sendNotification = () => { return } } = {}) => {
25
+ const [deleteClient, { loading, error }] = useMutation(DELETE_ONE_CLIENTS)
26
+ return [deleteClient, { loading, error }]
27
+ }
28
+
29
+ export const useCreateClient = ({ sendNotification = () => { return } } = {}) => {
30
+ const [createClients, { loading, error }] = useMutation(CREATE_CLIENTS, {
31
+ onError: (data) => {
32
+ // sendNotification({
33
+ // title: '',
34
+ // description: 'Error',
35
+ // backgroundColor: 'error'
36
+ // })
10
37
  }
11
38
  })
12
- return [clientes?.getAllClients || [], { loading, error }]
39
+
40
+ return [createClients || [], { loading, error }]
13
41
  }
14
42
 
15
- export const useDeleteClients = () => {
16
- const [clientes, setClients] = useState([])
17
- const { loading, error } = useQuery(GET_ALL_CLIENTS, {
43
+ export const useEditClient = ({ sendNotification = () => { return } } = {}) => {
44
+ const [editOneClient, { loading, error, data }] = useMutation(EDIT_ONE_CLIENT, {
18
45
  onCompleted: (data) => {
19
- setClients(data)
46
+ console.log(data)
47
+ if (data?.editOneClient?.success) {
48
+ return sendNotification({
49
+ title: 'Exito',
50
+ description: data?.editOneClient?.message,
51
+ backgroundColor: 'success'
52
+ })
53
+ }
54
+ },
55
+ onError: (data) => {
56
+ if (data?.editOneClient) {
57
+ return sendNotification({
58
+ title: 'Error',
59
+ description: data?.editOneClient?.message,
60
+ backgroundColor: 'error'
61
+ })
62
+ }
20
63
  }
21
64
  })
22
- return [clientes?.getAllClients || [], { loading, error }]
65
+
66
+ return [editOneClient, { loading, error, data }]
67
+ }
68
+
69
+ export const useGetOneClient = ({ sendNotification = () => { return } } = {}) => {
70
+ const [getOneClients, { data, loading, error }] = useLazyQuery(GET_ONE_CLIENT)
71
+
72
+ return [getOneClients || [], { loading, error, data }]
23
73
  }
@@ -65,6 +65,15 @@ query getOneClients($cliId: ID) {
65
65
  }
66
66
  `
67
67
 
68
+ export const EDIT_ONE_CLIENT = gql`
69
+ mutation editOneClient($input: IClients) {
70
+ editOneClient(input: $input) {
71
+ success
72
+ message
73
+ }
74
+ }
75
+ `
76
+
68
77
  export const CREATE_SHOPPING_CARD = gql`
69
78
  mutation registerShoppingCard($input: IShoppingCard, $idSubArray: IID_SUB_ITEMS){
70
79
  registerShoppingCard(input: $input, idSubArray: $idSubArray){
@@ -91,7 +100,7 @@ mutation registerShoppingCard($input: IShoppingCard, $idSubArray: IID_SUB_ITEMS
91
100
  export const CREATE_SHOPPING_CARD_TO_USER_STORE = gql`
92
101
  mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $pCodeRef: String, $change: String, $valueDelivery: Float, $payMethodPState: Int, $pickUp: Int, $totalProductsPrice: Float, $idSubArray: IID_SUB_ITEMS){
93
102
  registerSalesStore(input: $input, id: $id, idStore: $idStore, pCodeRef: $pCodeRef, change: $change, valueDelivery: $valueDelivery, payMethodPState: $payMethodPState, pickUp: $pickUp, totalProductsPrice: $totalProductsPrice, idSubArray: $idSubArray){
94
- ShoppingCard {
103
+ ShoppingCard {
95
104
  ShoppingCard
96
105
  id
97
106
  pId
@@ -80,12 +80,19 @@ export const useEditImageProduct = ({ sendNotification = () => { }, initialState
80
80
  : initialState
81
81
  )
82
82
  // You can use the file object to send it to a server or to download it
83
- sendNotification({ title: 'Exito', description: 'Imagen editada' })
83
+ sendNotification({
84
+ backgroundColor: 'success',
85
+ title: 'Exito',
86
+ description: 'Imagen editada' })
84
87
  setExistImage(true)
85
88
  handleOpenEditImage()
86
89
  })
87
90
  .catch(() => {
88
- sendNotification({ title: 'Error', description: 'Ha ocurrido un error!' })
91
+ sendNotification({
92
+ backgroundColor: 'error',
93
+ title: 'Error',
94
+ description: 'Ha ocurrido un error!'
95
+ })
89
96
  })
90
97
  // You can use the file object to send it to a server or to download it
91
98
  }
@@ -37,10 +37,10 @@ export const useCreateProduct = ({
37
37
 
38
38
  const [dataStore] = useStore()
39
39
  const {
40
- handleRegister: handleRegisterTags,
41
40
  data,
42
- handleAddTag,
43
- tags
41
+ tags,
42
+ handleRegister: handleRegisterTags,
43
+ handleAddTag
44
44
  } = useTagsProducts()
45
45
 
46
46
  // HANDLESS
@@ -51,7 +51,7 @@ export const useCreateProduct = ({
51
51
 
52
52
  const handleCheck = (e) => {
53
53
  const { name, checked } = e.target
54
- return setCheck({ ...check, [name]: checked ? true : false })
54
+ return setCheck((prev) =>({ ...prev, [name]: checked }))
55
55
  }
56
56
 
57
57
  const handleUpdateBanner = event => {
@@ -120,12 +120,13 @@ export const useCreateProduct = ({
120
120
  alt: files[0].name
121
121
  }
122
122
  : initialState
123
- )
123
+ )
124
124
  }
125
125
  const onTargetClick = () => {
126
126
  fileInputRef.current.click()
127
127
  }
128
128
  const { img } = useEditImageProduct({ sendNotification, initialState })
129
+ console.log(values)
129
130
  const handleRegister = async () => {
130
131
  const {
131
132
  ProPrice,
@@ -149,9 +150,9 @@ export const useCreateProduct = ({
149
150
  variables: {
150
151
  input: {
151
152
  idStore: dataStore?.getStore?.idStore || '',
152
- ProPrice: check ? 0 : formatPrice,
153
- ProDescuento: check ? 0 : parseInt(ProDescuento),
154
- ValueDelivery: check ? 0 : parseFloat(ValueDelivery),
153
+ ProPrice: check?.desc ? 0 : formatPrice,
154
+ ProDescuento: check?.desc ? 0 : parseInt(ProDescuento),
155
+ ValueDelivery: check?.desc ? 0 : parseFloat(ValueDelivery),
155
156
  ProDescription,
156
157
  pName: names,
157
158
  pCode,
@@ -162,8 +163,8 @@ export const useCreateProduct = ({
162
163
  ProImage,
163
164
  ProHeight: parseFloat(ProHeight),
164
165
  ProWeight,
165
- ProOutstanding: check ? 1 : 0,
166
- ProDelivery: check ? 1 : 0
166
+ ProOutstanding: check?.desc ? 1 : 0,
167
+ ProDelivery: check?.desc ? 1 : 0
167
168
  }
168
169
  },
169
170
  update (cache) {
@@ -189,14 +190,23 @@ export const useCreateProduct = ({
189
190
  undefined,
190
191
  { shallow: true }
191
192
  )
192
- sendNotification({ title: 'Success', description: `El producto ${names} subido con éxito` })
193
+ sendNotification({
194
+ backgroundColor: 'success',
195
+ title: 'Success',
196
+ description: `El producto ${names} subido con éxito`
197
+ })
193
198
  const objTag = {
194
199
  aName: tags.tag,
200
+ nameTag: tags.tag,
195
201
  pId
196
202
  }
197
203
  handleRegisterTags(objTag)
198
204
  // setValues({})
199
- }).catch(err => { return sendNotification({ title: `${err}`, description: 'Error inesperado' }) })
205
+ }).catch(err => { return sendNotification({
206
+ backgroundColor: 'error',
207
+ title: `${err}`,
208
+ description: 'Error inesperado'
209
+ }) })
200
210
  if (image !== null) {
201
211
  setImageProducts({
202
212
  variables: {
@@ -207,7 +217,11 @@ export const useCreateProduct = ({
207
217
  }
208
218
  }).then((response) => {
209
219
  }).catch((error) => {
210
- sendNotification({ title: `Ocurrió un error en la imagen en el producto ${names}`, description: 'error' })
220
+ sendNotification({
221
+ backgroundColor: 'error',
222
+ title: `Ocurrió un error en la imagen en el producto ${names}`,
223
+ description: 'error'
224
+ })
211
225
  })
212
226
  }
213
227
  } catch (error) {
@@ -262,6 +276,7 @@ export const useCreateProduct = ({
262
276
  setShowMore,
263
277
  onTargetClick,
264
278
  handleAddTag,
279
+ handleCheck,
265
280
  handleCheckFreeShipping,
266
281
  check
267
282
  }
@@ -0,0 +1,13 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { useEffect, useState } from 'react'
3
+ import { GET_EMPLOYEES } from './queries'
4
+
5
+ export const useEmployee = () => {
6
+ const [clientes, setClients] = useState([])
7
+ const [more, setMore] = useState(100)
8
+ const { data, loading, error, fetchMore } = useQuery(GET_EMPLOYEES)
9
+ useEffect(() => {
10
+ setClients(data)
11
+ }, [clientes, data])
12
+ return [clientes?.employees, { loading, error, fetchMore, setMore, more }]
13
+ }
@@ -0,0 +1,17 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const GET_EMPLOYEES = gql`
4
+ query employees {
5
+ employees {
6
+ eId
7
+ idStore
8
+ idEmployee
9
+ eSalary
10
+ typeContract
11
+ tpEmail
12
+ termContract
13
+ eDatAdm
14
+ eState
15
+ }
16
+ }
17
+ `
@@ -1,6 +1,7 @@
1
1
  import React, {
2
2
  useEffect,
3
- useRef, useState
3
+ useRef,
4
+ useState
4
5
  } from 'react'
5
6
 
6
7
  export const useFetchMoreInteractions = ({
@@ -36,9 +36,14 @@ export const useFormTools = ({ sendNotification = () => { } } = {}) => {
36
36
  return error === true
37
37
  })
38
38
 
39
- const handleSubmit = useCallback(({ event, action, msgSuccess, msgError, actionAfterSuccess }) => {
39
+ const handleSubmit = ({
40
+ event,
41
+ msgError = '',
42
+ msgSuccess,
43
+ action = () => { return },
44
+ actionAfterSuccess = () => { return }
45
+ }) => {
40
46
  event.preventDefault()
41
- console.log(event)
42
47
  setCalledSubmit(true)
43
48
  let errSub = false
44
49
 
@@ -46,7 +51,13 @@ export const useFormTools = ({ sendNotification = () => { } } = {}) => {
46
51
  for (const x in errorForm) {
47
52
  if (errorForm[x]) errSub = true
48
53
  }
49
-
54
+ if (errSub) {
55
+ sendNotification({
56
+ title: 'Completa los campos requeridos',
57
+ description: 'Error',
58
+ backgroundColor: 'error'
59
+ })
60
+ }
50
61
  if (errors) {
51
62
  setErrorSubmit(true)
52
63
  return setForcedError({ ...errorForm })
@@ -56,25 +67,28 @@ export const useFormTools = ({ sendNotification = () => { } } = {}) => {
56
67
 
57
68
  // Valida los errores desde el evento
58
69
  const errores = validationSubmitHooks(event.target.elements)
59
- console.log({errores})
60
70
  setErrorForm(errores)
61
71
  for (const x in errores) {
62
72
  if (errores[x]) errSub = true
63
73
  }
74
+ if (errSub) return setErrorSubmit(errSub)
64
75
 
65
- // Ejecuta la petición si es válido
76
+ // Ejecuta la accion si es válido
66
77
  if (!errSub && action) {
67
78
  action().then(res => {
68
79
  if (res) {
69
- sendNotification({ message: msgSuccess || 'Operación exitosa', description: 'Operación exitosa', color: PColor })
80
+ sendNotification({
81
+ message: msgSuccess || 'Operación exitosa',
82
+ description: 'Operación exitosa',
83
+ backgroundColor: 'success' })
70
84
  !!actionAfterSuccess && actionAfterSuccess()
71
85
  }
72
86
 
73
- }).catch(e => {return sendNotification({ title: msgError || e?.message || 'Ha ocurrido un error', color: WColor })})
87
+ }).catch(e => {return sendNotification({ title: msgError || e?.message || 'Ha ocurrido un error', backgroundColor: 'error' })})
74
88
  }
75
89
 
76
90
  setErrorSubmit(errSub)
77
- }, [errorForm, setErrorForm])
91
+ }
78
92
 
79
93
  useEffect(() => {return setCalledSubmit(false)}, [calledSubmit])
80
94
  useEffect(() => {
@@ -12,7 +12,7 @@ import {
12
12
  } from '../useProductsFood/queriesStore';
13
13
  import { GET_ONE_STORE } from '../useStore/queries';
14
14
 
15
- export const useImageStore = (idStore) => {
15
+ export const useImageStore = ({ idStore, sendNotification = () => { return } } = {}) => {
16
16
  // STATES
17
17
  const fileInputRef = useRef(null)
18
18
  const [{ altLogo, srcLogo }, setPreviewImgLogo] = useState({})
@@ -86,13 +86,20 @@ export const useImageStore = (idStore) => {
86
86
  })
87
87
  }
88
88
  }).catch(() => {
89
- console.log({ message: 'No pudimos cargar la imagen', duration: 7000 })
89
+ sendNotification({
90
+ title: 'No pudimos cargar la imagen',
91
+ description: 'Error',
92
+ backgroundColor: 'error'
93
+ })
90
94
  setPreviewImg(initialState)
91
95
  })
92
-
93
96
  } catch {
94
97
  setPreviewImg(initialState)
95
- console.log({ message: 'No pudimos cargar la imagen', duration: 7000 })
98
+ sendNotification({
99
+ title: 'No pudimos cargar la imagen',
100
+ description: 'Error',
101
+ backgroundColor: 'error'
102
+ })
96
103
  }
97
104
  }
98
105
  const handleInputChangeLogo = event => {
@@ -119,7 +126,11 @@ export const useImageStore = (idStore) => {
119
126
  })
120
127
  }
121
128
  }).catch(() => {
122
- console.log({ message: 'No pudimos cargar el banner', duration: 7000 })
129
+ sendNotification({
130
+ title: 'No pudimos cargar la imagen',
131
+ description: 'Error',
132
+ backgroundColor: 'error'
133
+ })
123
134
  setPreviewImgLogo(initialState)
124
135
  })
125
136
  }