npm-pkg-hook 1.0.7 → 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.
@@ -1,25 +1,24 @@
1
1
  import { useMutation } from "@apollo/client"
2
2
  import { useState } from "react"
3
- import { RandomCode } from "../../utils"
4
3
  import { REGISTER_TAGS_PRODUCT } from "./queriesStore"
5
4
 
6
5
  export const useTagsProducts = () => {
7
6
  const [registerTag] = useMutation(REGISTER_TAGS_PRODUCT)
8
7
  const data = [
9
8
  {
10
- id: RandomCode(5),
11
- tag: 'Bebida fria'
9
+ id: 1,
10
+ tag: 'Bebida fría'
12
11
  },
13
12
  {
14
- id: RandomCode(5),
13
+ id: 2,
15
14
  tag: 'Bebida caliente'
16
15
  },
17
16
  {
18
- id: RandomCode(5),
17
+ id: 3,
19
18
  tag: 'Bebida alcohólica'
20
19
  },
21
20
  {
22
- id: RandomCode(5),
21
+ id: 4,
23
22
  tag: 'Bebida sin alcohol'
24
23
  }
25
24
  ]
@@ -27,14 +26,27 @@ export const useTagsProducts = () => {
27
26
  id: '',
28
27
  tag: ''
29
28
  })
29
+
30
30
  const handleAddTag = (id, tag) => {
31
- setTags({
32
- id,
33
- tag
31
+ if (tags.id === id) {
32
+ return setTags({
33
+ id: '',
34
+ tag: ''
34
35
  })
36
+ }
37
+ return setTags({
38
+ id,
39
+ tag
40
+ })
35
41
  }
36
42
  const handleRegister = tag => {
37
- const { pId, idUser, idStore, nameTag } = tag || {}
43
+ const {
44
+ pId,
45
+ idUser,
46
+ idStore,
47
+ nameTag
48
+ } = tag || {}
49
+
38
50
  registerTag({
39
51
  variables: {
40
52
  input: {
@@ -4,7 +4,8 @@ export const GET_ALL_SALES = gql`
4
4
  query getAllSalesStore($idStore: ID,$search: String, $min: Int, $max: Int $fromDate: DateTime, $toDate: DateTime ) {
5
5
  getAllSalesStore(idStore: $idStore, search: $search, min: $min, max: $max, toDate: $toDate, fromDate: $fromDate) {
6
6
  totalProductsPrice
7
- pDatCre,
7
+ channel
8
+ pDatCre
8
9
  pCodeRef
9
10
  }
10
11
  }
@@ -1,7 +1,17 @@
1
- import { useApolloClient, useLazyQuery, useMutation } from "@apollo/client";
2
- import { useCallback, useEffect, useReducer, useState } from "react";
1
+ import {
2
+ useApolloClient,
3
+ useLazyQuery,
4
+ useMutation
5
+ } from "@apollo/client";
6
+ import {
7
+ useCallback,
8
+ useEffect,
9
+ useReducer,
10
+ useMemo,
11
+ useState
12
+ } from "react";
3
13
  import { Cookies } from "../../cookies";
4
- import { RandomCode, getCurrentDomain, updateCacheMod } from "../../utils";
14
+ import { RandomCode, getCurrentDomain } from "../../utils";
5
15
  import { useFormatDate } from "../useFormatDate";
6
16
  import { useProductsFood } from "../useProductsFood";
7
17
  import {
@@ -83,12 +93,21 @@ export const useSales = ({
83
93
  const error = data?.registerSalesStore?.Response.success
84
94
  ? "Éxito"
85
95
  : "Error";
86
- sendNotification({ title: error, description: message });
96
+ sendNotification({
97
+ backgroundColor: error ? 'success' : 'error',
98
+ title: error,
99
+ description: message
100
+ });
87
101
  setAlertBox({ message: message, type: "success" });
88
102
  setOpenCurrentSale(data?.registerSalesStore?.Response.success);
89
103
  },
90
104
  onError: (error) => {
91
- sendNotification({ title: error || 'Lo sentimo', description: 'ha ocurrido un error' });
105
+ console.log(error)
106
+ sendNotification({
107
+ backgroundColor: 'error',
108
+ title: error || 'Lo sentimo',
109
+ description: 'ha ocurrido un error'
110
+ });
92
111
  },
93
112
  }
94
113
  );
@@ -143,7 +162,7 @@ export const useSales = ({
143
162
  return sendNotification({
144
163
  title: "Error",
145
164
  description: "Esta es la descr",
146
- backgroundColor: "red",
165
+ backgroundColor: "error",
147
166
  });
148
167
  }
149
168
  setPrint(!print);
@@ -244,6 +263,7 @@ export const useSales = ({
244
263
  return {
245
264
  ...state,
246
265
  PRODUCT: [],
266
+ sortBy: null,
247
267
  counter: 0,
248
268
  };
249
269
 
@@ -394,6 +414,7 @@ export const useSales = ({
394
414
  if (!product?.PRODUCT?.pId) {
395
415
  return sendNotification({
396
416
  title: "Error",
417
+ backgroundColor: 'error',
397
418
  description: "No se puede actualizar el producto sin pId",
398
419
  });
399
420
  }
@@ -419,6 +440,7 @@ export const useSales = ({
419
440
  } catch (_error) {
420
441
  return sendNotification({
421
442
  title: "Error",
443
+ backgroundColor: 'error',
422
444
  description: "No se puedo actualizar el producto",
423
445
  });
424
446
  }
@@ -574,19 +596,20 @@ export const useSales = ({
574
596
  };
575
597
  }
576
598
 
577
- const getSortedProduct = (sortData, sortBy) => {
578
- if (sortBy && sortBy === "PRICE_HIGH_TO_LOW") {
579
- return sortData.sort((a, b) => {
599
+ const getSortedProduct = useCallback((data, sort) => {
600
+ if (sort && sort === "PRICE_HIGH_TO_LOW") {
601
+ return data.sort((a, b) => {
580
602
  return b["ProPrice"] - a["ProPrice"];
581
603
  });
582
604
  }
583
- if (sortBy && sortBy === "PRICE_LOW_TO_HIGH") {
584
- return sortData.sort((a, b) => {
605
+ if (sort && sort === "PRICE_LOW_TO_HIGH") {
606
+ return data.sort((a, b) => {
585
607
  return a["ProPrice"] - b["ProPrice"];
586
608
  });
587
609
  }
588
- return sortData;
589
- };
610
+ return data;
611
+ }, [])
612
+
590
613
  const PriceRangeFunc = (products, price) => {
591
614
  return (
592
615
  products?.length > 0 &&
@@ -596,7 +619,9 @@ export const useSales = ({
596
619
  );
597
620
  };
598
621
 
599
- const sortedProduct = getSortedProduct(data.PRODUCT, data.sortBy);
622
+ const sortedProduct = useMemo(() => {
623
+ return getSortedProduct(data.PRODUCT, data.sortBy);
624
+ }, [data.PRODUCT, data.sortBy, getSortedProduct])
600
625
  const finalFilter = PriceRangeFunc(sortedProduct, data.priceRange);
601
626
 
602
627
  const handleList = (text) => {
@@ -698,6 +723,7 @@ export const useSales = ({
698
723
  if (validateCondition) {
699
724
  return sendNotification({
700
725
  title: "Error",
726
+ backgroundColor: 'error',
701
727
  description: "el descuento debe ser un número entre 0 y 100%",
702
728
  });
703
729
  }
@@ -714,6 +740,7 @@ export const useSales = ({
714
740
  if (!values?.cliId)
715
741
  return sendNotification({
716
742
  title: "Error",
743
+ backgroundColor: 'error',
717
744
  description: "Elije primero un cliente",
718
745
  });
719
746
  setLoadingSale(true);
@@ -875,7 +902,11 @@ export const useSales = ({
875
902
  setLoadingExtraProduct(false);
876
903
  } catch (error) {
877
904
  setLoadingExtraProduct(false);
878
- sendNotification({ description: error || "Lo sentimos, ocurrió un error" });
905
+ sendNotification({
906
+ title: 'error',
907
+ backgroundColor: 'error',
908
+ description: error || "Lo sentimos, ocurrió un error",
909
+ });
879
910
  }
880
911
  };
881
912
  const handleCleanFilter = () => {
@@ -885,8 +916,7 @@ export const useSales = ({
885
916
  };
886
917
  const disabledModalItems = dataOptional?.length > 0 || dataExtra?.length > 0;
887
918
  return {
888
- // loading: loading || loadingSale,
889
- loading: false,
919
+ loading: loading || loadingSale,
890
920
  loadingExtraProduct,
891
921
  disabledModalItems: !disabledModalItems,
892
922
  loadingRegisterSale,
@@ -0,0 +1,21 @@
1
+ import { Cookies } from "../../cookies"
2
+
3
+ export const useSetSession = () => {
4
+ const bookOptionsCookie = {
5
+ RESTAURANT: 'restaurant'
6
+ }
7
+ const handleSession = async (props) => {
8
+ try {
9
+ const { cookie } = props
10
+ for (const element of cookie) {
11
+ const { name, value } = element
12
+ if (value) {
13
+ await Cookies.set(bookOptionsCookie[name], value)
14
+ }
15
+ }
16
+ } catch (error) {
17
+ throw new Error(error)
18
+ }
19
+ }
20
+ return [handleSession]
21
+ }
@@ -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',