npm-pkg-hook 1.0.6 → 1.0.8

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 (33) 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 +4 -0
  5. package/src/hooks/useCatWithProduct/index.js +2 -0
  6. package/src/hooks/useCatWithProduct/queries.js +8 -7
  7. package/src/hooks/useCategoryInStore/index.js +1 -0
  8. package/src/hooks/useClients/index.js +63 -13
  9. package/src/hooks/useClients/queries.js +10 -1
  10. package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +9 -2
  11. package/src/hooks/useCreateProduct/index.js +19 -6
  12. package/src/hooks/useEmployee/index.js +13 -0
  13. package/src/hooks/useEmployee/queries.js +17 -0
  14. package/src/hooks/useFormTools/index.js +22 -8
  15. package/src/hooks/useFormatDate/index.js +1 -1
  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/useProductsFood/index.js +3 -3
  20. package/src/hooks/useProductsFood/queriesStore.js +632 -526
  21. package/src/hooks/useProductsFood/usetagsProducts.js +22 -10
  22. package/src/hooks/useReport/queries.js +2 -1
  23. package/src/hooks/useSales/index.js +256 -155
  24. package/src/hooks/useSales/queries.js +348 -198
  25. package/src/hooks/useSales/useGetSale.js +9 -8
  26. package/src/hooks/useSales/useTotalSales.js +10 -3
  27. package/src/hooks/useSetSession/index.js +21 -0
  28. package/src/hooks/useStore/index.js +42 -13
  29. package/src/hooks/useStoreContacts/index.js +47 -0
  30. package/src/hooks/useStoreContacts/queries.js +48 -0
  31. package/src/hooks/useUser/index.js +6 -1
  32. package/src/hooks/useUser/queries.js +18 -0
  33. 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.6",
10
+ "version": "1.0.8",
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,6 +5,8 @@ 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'
10
12
  export * from './useConnection'
@@ -26,12 +28,14 @@ export * from './useKeypress'
26
28
  export * from './useLazyScript'
27
29
  export * from './useLocalSorage'
28
30
  export * from './useLocationNavigate'
31
+ export * from './useSetSession'
29
32
  export * from './useMobile'
30
33
  export * from './useMutateHeight'
31
34
  export * from './useProductsFood'
32
35
  export * from './useProductsFood/usetagsProducts'
33
36
  export * from './useReactToPrint'
34
37
  export * from './useReport'
38
+ export * from './useStoreContacts'
35
39
  export * from './useRestaurant'
36
40
  export * from './useSales'
37
41
  export * from './useSales/useGetSale'
@@ -5,6 +5,7 @@ export const useCatWithProduct = ({
5
5
  max = 1,
6
6
  min = 0,
7
7
  search = null,
8
+ productName = null,
8
9
  searchFilter= {}
9
10
  }) => {
10
11
  const {
@@ -22,6 +23,7 @@ export const useCatWithProduct = ({
22
23
  variables:
23
24
  {
24
25
  search,
26
+ productName,
25
27
  gender: gender,
26
28
  min,
27
29
  max: 400,
@@ -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){
@@ -117,8 +117,8 @@ query ExtProductFoodsAll($search: String, $min: Int, $max: Int, $pId: ID) {
117
117
  }
118
118
  `
119
119
  export const GET_ALL_CATEGORIES_WITH_PRODUCT = gql`
120
- query getCatProductsWithProduct($search: String, $min: Int, $max: Int, $gender: [String], $desc: [String], $categories: [ID], ) {
121
- getCatProductsWithProduct(search: $search, min: $min, max: $max, gender: $gender, desc: $desc, categories: $categories,) {
120
+ query getCatProductsWithProduct($search: String, $productName: String, $min: Int, $max: Int, $gender: [String], $desc: [String], $categories: [ID], ) {
121
+ getCatProductsWithProduct(search: $search, min: $min, productName:$productName, max: $max, gender: $gender, desc: $desc, categories: $categories,) {
122
122
  totalCount,
123
123
  catProductsWithProduct {
124
124
  carProId
@@ -136,6 +136,7 @@ query getCatProductsWithProduct($search: String, $min: Int, $max: Int, $gender:
136
136
  productFoodsAll {
137
137
  pId
138
138
  sizeId
139
+
139
140
  colorId
140
141
  carProId
141
142
  cId
@@ -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
@@ -189,14 +189,23 @@ export const useCreateProduct = ({
189
189
  undefined,
190
190
  { shallow: true }
191
191
  )
192
- sendNotification({ title: 'Success', description: `El producto ${names} subido con éxito` })
192
+ sendNotification({
193
+ backgroundColor: 'success',
194
+ title: 'Success',
195
+ description: `El producto ${names} subido con éxito`
196
+ })
193
197
  const objTag = {
194
198
  aName: tags.tag,
199
+ nameTag: tags.tag,
195
200
  pId
196
201
  }
197
202
  handleRegisterTags(objTag)
198
203
  // setValues({})
199
- }).catch(err => { return sendNotification({ title: `${err}`, description: 'Error inesperado' }) })
204
+ }).catch(err => { return sendNotification({
205
+ backgroundColor: 'error',
206
+ title: `${err}`,
207
+ description: 'Error inesperado'
208
+ }) })
200
209
  if (image !== null) {
201
210
  setImageProducts({
202
211
  variables: {
@@ -207,7 +216,11 @@ export const useCreateProduct = ({
207
216
  }
208
217
  }).then((response) => {
209
218
  }).catch((error) => {
210
- sendNotification({ title: `Ocurrió un error en la imagen en el producto ${names}`, description: 'error' })
219
+ sendNotification({
220
+ backgroundColor: 'error',
221
+ title: `Ocurrió un error en la imagen en el producto ${names}`,
222
+ description: 'error'
223
+ })
211
224
  })
212
225
  }
213
226
  } catch (error) {
@@ -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
+ `
@@ -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(() => {
@@ -1,7 +1,7 @@
1
1
  export const useFormatDate = ({
2
2
  date,
3
3
  local = 'ES'
4
- }) => {
4
+ } = {}) => {
5
5
  const dateToFormat = new Date(date ?? Date.now())
6
6
  const fullDate = dateToFormat.toLocaleDateString(local, { year: 'numeric', month: '2-digit', day: '2-digit' })
7
7
  const day = fullDate.split('/')[0]