npm-pkg-hook 1.0.9 → 1.1.0

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/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "publishConfig": {
8
8
  "registry": "https://registry.npmjs.org/"
9
9
  },
10
- "version": "1.0.9",
10
+ "version": "1.1.0",
11
11
  "description": "description-pkg-hook",
12
12
  "main": "/src/index.jsx",
13
13
  "scripts": {
@@ -10,6 +10,7 @@ export * from './useEmployee'
10
10
  export * from './useCheckbox'
11
11
  export * from './useClients'
12
12
  export * from './useOrders'
13
+ export * from './useUpdateExistingOrders'
13
14
  export * from './useConnection'
14
15
  export * from './useCreateProduct'
15
16
  export * from './useCreateProduct/helpers/useEditImageProduct'
@@ -142,7 +142,7 @@ export const useCreateProduct = ({
142
142
  if (!ProPrice?.length > 0) {
143
143
  return setErrors({ ...errors, ProPrice: true })
144
144
  }
145
- const ProImage = `${process.env.URL_ADMIN_SERVER}static/platos/${image?.name}`
145
+ const ProImage = `https:${process.env.URL_ADMIN_SERVER}static/platos/${image?.name}`
146
146
  const pCode = RandomCode(9)
147
147
  const formatPrice = ProPrice ? parseFloat(ProPrice.replace(/\./g, '')) : 0
148
148
  try {
@@ -5,12 +5,14 @@ import {
5
5
  } from '@apollo/client'
6
6
  import { useState } from 'react'
7
7
  import {
8
+ GET_ALL_CATEGORIES_WITH_PRODUCT,
8
9
  GET_ALL_EXTRA_PRODUCT,
9
10
  GET_ALL_PRODUCT_STORE,
10
11
  GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
11
12
  GET_ONE_PRODUCTS_FOOD,
12
13
  UPDATE_PRODUCT_FOOD
13
14
  } from './queriesStore'
15
+ export * from './useEditProduct'
14
16
 
15
17
  /**
16
18
  * Description
@@ -71,8 +73,8 @@ export const useProductsFood = ({
71
73
  ]
72
74
  }
73
75
 
74
- export const useDeleteProductsFood = () => {
75
- const [updateProductFoods] = useMutation(UPDATE_PRODUCT_FOOD)
76
+ export const useDeleteProductsFood = ({ sendNotification = () => { return } } = {}) => {
77
+ const [updateProductFoods, { data, loading, error }] = useMutation(UPDATE_PRODUCT_FOOD)
76
78
 
77
79
  const handleDelete = product => {
78
80
  const { pId, pState } = product || {}
@@ -98,10 +100,23 @@ export const useDeleteProductsFood = () => {
98
100
  }
99
101
  })
100
102
  }
101
- }).catch(err => { return console.log({ message: `${err}`, duration: 7000 }) })
103
+ }).then(() => {
104
+ return sendNotification({
105
+ title: 'Success',
106
+ description: 'El producto se ha eliminado correctamente',
107
+ backgroundColor: 'success'
108
+ })
109
+ }).catch((e) => {
110
+ console.log(e)
111
+ return sendNotification({
112
+ title: 'Error',
113
+ description: 'Ocurrió un error',
114
+ backgroundColor: 'error'
115
+ })
116
+ })
102
117
  }
103
118
  return {
104
- handleDelete
119
+ handleDelete, data, loading, error
105
120
  }
106
121
  }
107
122
 
@@ -0,0 +1,10 @@
1
+ import { useMutation } from '@apollo/client'
2
+ import React from 'react'
3
+ import { EDIT_PRODUCT } from './queriesStore'
4
+
5
+ export const useEditProduct = () => {
6
+ const [editProductFoods, { loading, error }] = useMutation(EDIT_PRODUCT)
7
+
8
+ return [editProductFoods, { loading: loading, error: error }]
9
+ }
10
+
@@ -1,5 +1,4 @@
1
- import { useState } from 'react';
2
- import { useRouter } from 'next/router';
1
+ import { useState, useEffect } from 'react';
3
2
  import { useApolloClient, useQuery } from '@apollo/client';
4
3
  import { GET_ONE_STORE } from './queries'; // Reemplaza con la importación correcta de tu consulta
5
4
  import { errorHandler } from '../../config/client'
@@ -8,16 +7,19 @@ import { useLogout } from '../useLogout'
8
7
  export const useStore = () => {
9
8
  const [store, setStore] = useState({});
10
9
  const client = useApolloClient();
11
- const [onClickLogout, { loading: load, error: err }] = useLogout()
10
+ const [onClickLogout, { loading: load, error: err }] = useLogout();
11
+
12
12
  // Intentar leer los datos de la caché
13
13
  const cachedData = client.readQuery({ query: GET_ONE_STORE });
14
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);
15
+ useEffect(() => {
16
+ if (cachedData) {
17
+ // Comprobar si los datos de la caché ya están establecidos en el estado
18
+ if (!store || Object.keys(store).length === 0) {
19
+ setStore(cachedData.getStore);
20
+ }
19
21
  }
20
- }
22
+ }, [cachedData, store]);
21
23
 
22
24
  const { loading, error } = useQuery(GET_ONE_STORE, {
23
25
  fetchPolicy: 'cache-first',
@@ -29,19 +31,31 @@ export const useStore = () => {
29
31
  if (err.networkError && err.networkError.result) {
30
32
  const response = errorHandler(err.networkError.result);
31
33
  if (response) {
32
- onClickLogout()
34
+ onClickLogout();
33
35
  }
34
36
  }
35
37
  },
36
38
  });
37
39
 
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 },
40
+ // Ejecutar la consulta y almacenarla en la caché
41
+ useEffect(() => {
42
+ client.query({ query: GET_ONE_STORE }).then(() => {
43
+ // Leer la consulta desde la caché
44
+ const cacheData = client.readQuery({ query: GET_ONE_STORE });
45
+ setStore(cacheData?.getStore)
43
46
  });
44
- }
47
+ }, [client]);
45
48
 
46
- return [store, { loading, error }];
49
+ // Actualizar manualmente la caché después de cada petición exitosa
50
+ useEffect(() => {
51
+ if (!loading && !error && !cachedData) {
52
+ client.writeQuery({
53
+ query: GET_ONE_STORE,
54
+ data: { getStore: store },
55
+ });
56
+ }
57
+ }, [loading, error, cachedData, client, store]);
58
+
59
+ return [store, { loading: load || loading, error }];
47
60
  };
61
+
@@ -0,0 +1,91 @@
1
+ export const isValidCodeRef = (codeRef) => {
2
+ return typeof codeRef === "string" && codeRef.trim() !== "";
3
+ };
4
+
5
+ export const isValidState = (state) => {
6
+ const validStates = [0, 1, 2, 3, 4, 5];
7
+ return validStates.includes(state);
8
+ };
9
+
10
+ export const updateExistingOrders = (
11
+ existingOrders,
12
+ pCodeRef,
13
+ pSState,
14
+ objectToAdd
15
+ ) => {
16
+ if (typeof existingOrders !== "object" || existingOrders === null) {
17
+ // existingOrders no es un objeto válido
18
+ return existingOrders;
19
+ }
20
+ if (typeof pCodeRef !== "string" || typeof pSState !== "number") {
21
+ // Los tipos de datos de pCodeRef y pSState no son los esperados
22
+ return existingOrders;
23
+ }
24
+ if (!isValidCodeRef(pCodeRef) || !isValidState(pSState)) {
25
+ // Valores de entrada no válidos, devuelve existingOrders sin cambios
26
+ return existingOrders;
27
+ }
28
+
29
+ const updatedExistingOrders = { ...existingOrders }; // Copiar el objeto existente
30
+
31
+ const statusKeys = {
32
+ 1: "ACEPTA",
33
+ 2: "PROCESSING",
34
+ 3: "READY",
35
+ 4: "CONCLUDES",
36
+ 5: "RECHAZADOS",
37
+ };
38
+ const targetArray = statusKeys[pSState];
39
+
40
+ if (!targetArray || !(targetArray in existingOrders)) {
41
+ // El valor de pSState no está mapeado a ninguna propiedad existente en existingOrders
42
+ return existingOrders;
43
+ }
44
+
45
+ Object.keys(updatedExistingOrders).forEach((key) => {
46
+ if (Array.isArray(updatedExistingOrders[key])) {
47
+ const oneSale = updatedExistingOrders[key].find((order) => {
48
+ return order.pCodeRef === pCodeRef;
49
+ });
50
+
51
+ updatedExistingOrders[key] = updatedExistingOrders[key].filter(
52
+ (order) => {
53
+ return order.pCodeRef !== pCodeRef;
54
+ }
55
+ );
56
+
57
+ if (oneSale !== undefined && oneSale !== null) {
58
+ const updatedOneSale = { ...oneSale, pSState };
59
+
60
+ if (!Array.isArray(updatedExistingOrders[targetArray])) {
61
+ updatedExistingOrders[targetArray] = [];
62
+ }
63
+
64
+ updatedExistingOrders[targetArray] = [
65
+ updatedOneSale,
66
+ ...updatedExistingOrders[targetArray],
67
+ ];
68
+ }
69
+ }
70
+ });
71
+
72
+ if (objectToAdd && objectToAdd.pCodeRef === pCodeRef) {
73
+ if (!Array.isArray(updatedExistingOrders[targetArray])) {
74
+ updatedExistingOrders[targetArray] = [];
75
+ }
76
+
77
+ updatedExistingOrders[targetArray] = [
78
+ objectToAdd,
79
+ ...updatedExistingOrders[targetArray],
80
+ ];
81
+ }
82
+
83
+ // Asegurar que todas las propiedades estén presentes
84
+ Object.keys(statusKeys).forEach((statusKey) => {
85
+ if (!(statusKeys[statusKey] in updatedExistingOrders)) {
86
+ updatedExistingOrders[statusKeys[statusKey]] = [];
87
+ }
88
+ });
89
+
90
+ return updatedExistingOrders;
91
+ };