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
@@ -1,18 +1,47 @@
1
- import { useQuery } from '@apollo/client'
2
- import { useState } from 'react'
3
- import { GET_ONE_STORE } from './queries'
1
+ import { useState } from 'react';
2
+ import { useRouter } from 'next/router';
3
+ import { useApolloClient, useQuery } from '@apollo/client';
4
+ import { GET_ONE_STORE } from './queries'; // Reemplaza con la importación correcta de tu consulta
5
+ import { errorHandler } from '../../config/client'
6
+ import { useLogout } from '../useLogout'
4
7
 
5
8
  export const useStore = () => {
6
- const [store, setStore] = useState({})
9
+ const [store, setStore] = useState({});
10
+ const client = useApolloClient();
11
+ const [onClickLogout, { loading: load, error: err }] = useLogout()
12
+ // Intentar leer los datos de la caché
13
+ const cachedData = client.readQuery({ query: GET_ONE_STORE });
14
+
15
+ if (cachedData) {
16
+ // Comprobar si los datos de la caché ya están establecidos en el estado
17
+ if (!store || Object.keys(store).length === 0) {
18
+ setStore(cachedData.getStore);
19
+ }
20
+ }
21
+
7
22
  const { loading, error } = useQuery(GET_ONE_STORE, {
8
- fetchPolicy: 'cache-and-network',
9
- onCompleted: (res) => {
10
- const { getStore } = res || {}
11
- setStore(getStore)
23
+ fetchPolicy: 'cache-first',
24
+ onCompleted: (data) => {
25
+ const { getStore } = data || {};
26
+ setStore(getStore);
12
27
  },
13
28
  onError: (err) => {
14
- console.log(err)
15
- }
16
- })
17
- return [store, { loading, error }]
18
- }
29
+ if (err.networkError && err.networkError.result) {
30
+ const response = errorHandler(err.networkError.result);
31
+ if (response) {
32
+ onClickLogout()
33
+ }
34
+ }
35
+ },
36
+ });
37
+
38
+ // Actualizar manualmente la caché después de cada petición exitosa
39
+ if (!loading && !error && !cachedData) {
40
+ client.writeQuery({
41
+ query: GET_ONE_STORE,
42
+ data: { getStore: store },
43
+ });
44
+ }
45
+
46
+ return [store, { loading, error }];
47
+ };
@@ -0,0 +1,47 @@
1
+ import { useQuery, useMutation, useLazyQuery } from '@apollo/client'
2
+ import { useState } from 'react'
3
+ import {
4
+ GET_ALL_CONTACTS,
5
+ EDIT_ONE_CONTACT,
6
+ CREATE_CONTACTS,
7
+ GET_ONE_CONTACT
8
+ } from './queries'
9
+
10
+ export const useGetStoreContacts = ({
11
+ sendNotification = () => { return },
12
+ max,
13
+ search = ''
14
+ } = {}) => {
15
+ const [clientes, setUseStoreContacts] = useState([])
16
+ const { loading, error, fetchMore, called } = useQuery(GET_ALL_CONTACTS, {
17
+ variables: {
18
+ "max": max,
19
+ "search": search
20
+ },
21
+ onCompleted: (data) => {
22
+ setUseStoreContacts(data)
23
+ }
24
+ })
25
+ return [clientes?.getAllContacts || [], { loading: called ? false : loading, error, fetchMore }]
26
+ }
27
+
28
+ export const useDeleteUseStoreContacts = ({ sendNotification = () => { return } } = {}) => {
29
+ const [getOneContacts, { data, error, loading }] = useLazyQuery(GET_ONE_CONTACT)
30
+ return [getOneContacts, data?.getOneContacts ?? {}, { loading, error }]
31
+ }
32
+
33
+ export const useGetOneUseStoreContacts = ({ sendNotification = () => { return } } = {}) => {
34
+ const [getOneContacts, { data, error, loading }] = useLazyQuery(GET_ONE_CONTACT)
35
+ return [getOneContacts, { data: data?.getOneContacts, loading, error }]
36
+ }
37
+
38
+ export const useEditOneUseStoreContacts = ({ sendNotification = () => { return } } = {}) => {
39
+ const [editOneContacts, { data, error, loading }] = useMutation(EDIT_ONE_CONTACT)
40
+ return [editOneContacts, { data: data?.editOneContacts, loading, error }]
41
+ }
42
+
43
+ export const useCreateContacts = ({ sendNotification = () => { return } } = {}) => {
44
+ const [createUseStoreContacts, { loading, error }] = useMutation(CREATE_CONTACTS)
45
+
46
+ return [createUseStoreContacts, { loading, error }]
47
+ }
@@ -0,0 +1,48 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const CREATE_CONTACTS = gql`
4
+ mutation createContacts ($input: IContacts) {
5
+ createContacts(input: $input) {
6
+ success
7
+ message
8
+ }
9
+ }
10
+ `
11
+ export const GET_ALL_CONTACTS = gql`
12
+ query getAllContacts($idStore: ID, $cId: ID, $dId: ID, $ctId: ID, $search: String, $min: Int, $pState: Int, $max: Int) {
13
+ getAllContacts(idStore: $idStore, cId: $cId, dId: $dId, ctId: $ctId, search: $search, min: $min, pState: $pState, max: $max) {
14
+ contactId
15
+ cntState
16
+ cntComments
17
+ cntNumberPhone
18
+ cntName
19
+ createAt
20
+ updateAt
21
+ }
22
+ }
23
+ `
24
+
25
+ export const GET_ONE_CONTACT = gql`
26
+ query getOneContacts($contactId: String) {
27
+ getOneContacts(contactId: $contactId) {
28
+ contactId
29
+ id
30
+ idStore
31
+ cntName
32
+ cntComments
33
+ cntNumberPhone
34
+ cntState
35
+ createAt
36
+ updateAt
37
+ }
38
+ }
39
+ `
40
+
41
+ export const EDIT_ONE_CONTACT = gql`
42
+ mutation editOneContacts($input: IContacts) {
43
+ editOneContacts(input: $input) {
44
+ success
45
+ message
46
+ }
47
+ }
48
+ `
@@ -1,7 +1,12 @@
1
1
  import { useQuery } from '@apollo/client'
2
- import { GET_USER } from './queries'
2
+ import { GET_USER, SET_USER_PROFILE } from './queries'
3
3
 
4
4
  export const useUser = () => {
5
5
  const { data, loading, error } = useQuery(GET_USER)
6
6
  return [data?.getUser, { loading, error }]
7
+ }
8
+
9
+ export const useSetUserProfile = () => {
10
+ const [setUserProfile, { loading, error }] = useMutation(SET_USER_PROFILE)
11
+ return [setUserProfile, { loading, error }]
7
12
  }
@@ -66,4 +66,22 @@ mutation updateAvatar($file: Upload){
66
66
  urlAvatar
67
67
  }
68
68
  }
69
+ `
70
+
71
+ export const SET_USER_PROFILE = gql`
72
+ mutation setUserProfile($data: IUserProfile!) {
73
+ setUserProfile(input: $data){
74
+ upId
75
+ id
76
+ upPhone
77
+ upDateBir
78
+ upImage
79
+ upBloodG
80
+ cId
81
+ ctId
82
+ dId
83
+ upAddress
84
+ upZipCode
85
+ }
86
+ }
69
87
  `
@@ -4,23 +4,39 @@
4
4
  * @param {array} elements elementos del formulario
5
5
  * @return {array} devuelve un array de booleanos con el nombre identificador para cada estado en react.
6
6
  */
7
+ const validTypes = {
8
+ text: true,
9
+ password: true,
10
+ email: true,
11
+ number: true,
12
+ hidden: true,
13
+ textarea: true
14
+ };
15
+
7
16
  export const validationSubmitHooks = elements => {
8
- let errorForm = {}
9
- for (const element of elements) {
10
- if (element.name) {
11
- if (element.type === 'text' || element.type === 'password' || element.type === 'email' || element.type === 'number' || element.type === 'hidden') {
12
- if (element.dataset.required === 'true') {
13
- if (!element.value) errorForm = { ...errorForm, [element.name]: !element.value }
14
- else errorForm = { ...errorForm, [element.name]: !element.value }
17
+ let errorForm = {};
18
+
19
+ for (const element of elements) {
20
+ if (element.name) {
21
+ const elementType = element.type || element.tagName.toLowerCase();
22
+ if (validTypes[elementType]) {
23
+ if (element.dataset.required === 'true') {
24
+ if (!element.value) {
25
+ errorForm = { ...errorForm, [element.name]: true };
15
26
  } else {
16
- errorForm = { ...errorForm, [element.name]: false }
27
+ errorForm = { ...errorForm, [element.name]: false };
17
28
  }
29
+ } else {
30
+ errorForm = { ...errorForm, [element.name]: false };
18
31
  }
19
32
  }
20
33
  }
21
- return errorForm
22
34
  }
23
35
 
36
+ return errorForm;
37
+ };
38
+
39
+
24
40
  export const getCurrentDomain = () => {
25
41
  return typeof window !== 'undefined' && window.location.hostname.split('.').slice(-2).join('.')
26
42
  }
@@ -57,7 +73,28 @@ export const initializer = (initialValue = initialState) => { return JSON.parse(
57
73
  export const numberFormat = value => { return value ? (parseInt(value) ? new Intl.NumberFormat('de-DE').format(parseFloat(`${value}`.replace(/\./g, ''))) : value) : (value) }
58
74
 
59
75
 
76
+ /**
77
+ *
78
+ * @param {Object} data objeto a filtrar
79
+ * @param {Array} filters array a comparar o claves del objeto a excluir
80
+ * @param {boolean} dataFilter booleano para devolver los datos filtrados o no
81
+ * @return {Object} devuelve un objeto con los datos filtrados
82
+ */
83
+ export const filterKeyObject = (data, filters, dataFilter) => {
84
+ let values = {}, valuesFilter = {}
85
+ for (const elem in data) {
86
+ let coincidence = false
87
+ for (let i = 0; i < filters.length; i++) {
88
+ if (elem === filters[i]) coincidence = true
89
+ else valuesFilter = filters[i]
90
+ }
60
91
 
92
+ if (!coincidence) values = { ...values, [elem]: data[elem] }
93
+ else valuesFilter = { ...valuesFilter, [elem]: data[elem] }
94
+ }
95
+ if (!dataFilter) return values
96
+ if (dataFilter) return { values, valuesFilter }
97
+ }
61
98
  export const MONTHS = [
62
99
  'January',
63
100
  'February',