npm-pkg-hook 1.1.0 → 1.1.2

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 (69) hide show
  1. package/.eslintrc.js +132 -132
  2. package/next.config.js +0 -1
  3. package/package.json +46 -43
  4. package/src/config/client/errors.js +2 -1
  5. package/src/hooks/getSession/index.js +18 -0
  6. package/src/hooks/index.js +27 -7
  7. package/src/hooks/useAnimationFrame/index.js +45 -0
  8. package/src/hooks/useAnimationText/index.jsx +11 -13
  9. package/src/hooks/useCatWithProduct/index.js +37 -4
  10. package/src/hooks/useCatWithProduct/queries.js +0 -16
  11. package/src/hooks/useCategoriesProduct/index.js +12 -0
  12. package/src/hooks/useCategoriesProduct/queries.js +16 -0
  13. package/src/hooks/useChartData/index.js +182 -154
  14. package/src/hooks/useCheckbox/index.js +5 -1
  15. package/src/hooks/useClients/index.js +17 -8
  16. package/src/hooks/useCreateProduct/index.js +95 -65
  17. package/src/hooks/useDeleteSubProductOptional/index.js +30 -0
  18. package/src/hooks/useDeleteSubProductOptional/queries.js +10 -0
  19. package/src/hooks/useDessert/helpers/index.js +51 -0
  20. package/src/hooks/useDessert/index.js +319 -121
  21. package/src/hooks/useDevices/index.js +36 -0
  22. package/src/hooks/useDevices/queries.js +19 -0
  23. package/src/hooks/useDrag/index.js +1 -1
  24. package/src/hooks/useDropzone/index.js +79 -0
  25. package/src/hooks/useDynamicAuth/index.js +13 -0
  26. package/src/hooks/useDynamicAuth/queries.js +24 -0
  27. package/src/hooks/useEmployee/index.js +11 -8
  28. package/src/hooks/useFingerprintjs/index.js +176 -0
  29. package/src/hooks/useFormTools/index.js +1 -1
  30. package/src/hooks/useFullScreenMode/index.js +8 -9
  31. package/src/hooks/useGenerateNumberArray/index.js +17 -0
  32. package/src/hooks/useImagesStore/index.js +176 -143
  33. package/src/hooks/useImagesStore/queries.js +1 -28
  34. package/src/hooks/useKeypress/index.js +7 -1
  35. package/src/hooks/useLocalSorage/index.js +1 -1
  36. package/src/hooks/useLogout/index.js +22 -25
  37. package/src/hooks/useManageQueryParams/index.js +37 -0
  38. package/src/hooks/useProductsFood/queriesStore.js +3 -16
  39. package/src/hooks/useProductsFood/usetagsProducts.js +30 -5
  40. package/src/hooks/useProviders/index.js +3 -0
  41. package/src/hooks/useProviders/queries.js +31 -0
  42. package/src/hooks/useProviders/useProvidersCreateStore/index.js +13 -0
  43. package/src/hooks/useProviders/useProvidersDataStore/index.js +24 -0
  44. package/src/hooks/useProvidersStore/index.js +24 -0
  45. package/src/hooks/useProvidersStore/queries.js +31 -0
  46. package/src/hooks/useRatingData/index.js +53 -0
  47. package/src/hooks/useRatingData/queries.js +18 -0
  48. package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -0
  49. package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -0
  50. package/src/hooks/useReport/index.js +16 -7
  51. package/src/hooks/useReport/queries.js +47 -32
  52. package/src/hooks/useSales/index.js +53 -22
  53. package/src/hooks/useSales/queries.js +48 -38
  54. package/src/hooks/useSales/useGetAllSales/index.js +25 -0
  55. package/src/hooks/useSales/useGetSale.js +16 -2
  56. package/src/hooks/useSchedule/index.js +36 -0
  57. package/src/hooks/useSchedule/queries.js +35 -0
  58. package/src/hooks/useScheduleData/index.js +171 -0
  59. package/src/hooks/useScroll/index.js +57 -0
  60. package/src/hooks/useScrollRotate/index.js +14 -0
  61. package/src/hooks/useStatusOpenStore/helpers/index.js +102 -0
  62. package/src/hooks/useStatusOpenStore/index.js +173 -0
  63. package/src/hooks/useUpdateExistingOrders/index.js +8 -8
  64. package/src/hooks/useUser/index.js +7 -2
  65. package/src/hooks/useUser/queries.js +40 -0
  66. package/src/index.jsx +3 -1
  67. package/.vscode/extensions.json +0 -6
  68. package/.vscode/settings.json +0 -8
  69. package/src/hooks/useSchedule/index.jsx +0 -23
@@ -0,0 +1,16 @@
1
+ import { gql } from "@apollo/client";
2
+
3
+ export const GET_ULTIMATE_CATEGORY_PRODUCTS = gql`
4
+ query catProductsAll($search: String, $min: Int, $max: Int, $gender: [String], $desc: [String], $categories: [ID], ) {
5
+ catProductsAll(search: $search, min: $min, max: $max, gender: $gender, desc: $desc, categories: $categories,) {
6
+ carProId
7
+ idStore
8
+ pName
9
+ ProDescription
10
+ ProImage
11
+ pState
12
+ pDatCre
13
+ pDatMod
14
+ }
15
+ }
16
+ `
@@ -3,167 +3,195 @@ import { useState } from 'react';
3
3
  import { SPANISH_MONTHS } from "../../utils/index";
4
4
  import { GET_ALL_SALES } from "../useReport/queries";
5
5
 
6
- export const useChartData = ({ year }) => {
7
- // Construcción del nuevo array:
8
- const { data, loading } = useQuery(GET_ALL_SALES)
9
- const [chartType, setChartType] = useState('bar')
10
- const [chartTypeYear, setChartTypeYear] = useState(new Date().getFullYear())
11
- const [asFilter, setFilter] = useState(false)
12
- const [newResult, setNewResult] = useState([])
13
- let result = []
14
- data?.getAllSalesStore?.length > 0 && data?.getAllSalesStore.reduce(function (res, value) {
15
- // Creamos la posición del array para cada mes
16
- let mes = new Date(value.pDatCre).getMonth()
17
- let Year = new Date(value.pDatCre).getFullYear()
18
- if (!res[mes]) {
19
- res[mes] = { Mes: mes, Year }
20
- // Inicializamos a 0 el valor de cada key
21
- Object.keys(value).forEach((key) => {
22
- if (key != 'pDatCre') {
23
- res[mes][key] = 0
24
- }
25
- })
6
+ // Función para calcular el total de ventas por mes
7
+ const calculateSalesByMonth = (salesData) => {
8
+ try {
9
+ const result = Array.from({ length: 12 }, (_, mes) => ({
10
+ Mes: mes,
11
+ Year: new Date().getFullYear(),
12
+ totalProductsPrice: 0,
13
+ }));
14
+
15
+ salesData?.forEach((value) => {
16
+ const mes = new Date(value.pDatCre).getMonth();
17
+ result[mes].totalProductsPrice += value.totalProductsPrice;
18
+ });
19
+
20
+ return result;
21
+ } catch (error) {
22
+ return []
23
+ }
24
+ };
26
25
 
27
- result.push(res[mes])
28
- }
29
- // Sumamos el valor de cada clave dentro de un bucle
30
- Object.keys(value).forEach(function (key) {
31
- if (key != 'pDatCre') {
32
- res[mes]['totalProductsPrice'] += value['totalProductsPrice']
33
- }
34
- })
35
- return res
36
- }, {})
26
+ // Función para llenar los meses faltantes
27
+ const fillMissingMonths = (data) => {
28
+ try {
29
+ const allMonths = Array.from({ length: 12 }, (_, i) => i);
30
+ const missingMonths = allMonths.filter(month => !data.some(data => data.Mes === month));
31
+ return data.concat(
32
+ missingMonths.map(element => ({
33
+ Mes: element,
34
+ totalProductsPrice: 0,
35
+ Year: '',
36
+ }))
37
+ ).sort((a, b) => a.Mes - b.Mes);
38
+ } catch (error) {
39
+ return []
40
+ }
41
+ };
37
42
 
38
- let allMonths = Array.from({ length: 12 }, (_, i) => { return i })
39
- let missingMonths = allMonths.filter(month => { return !result.some(data => { return data.Mes === month }) })
43
+ // Función para obtener los datos del gráfico
44
+ const getChartData = (asFilter, newResult, result, chartType) => ({
45
+ labels: asFilter
46
+ ? newResult.map(data => SPANISH_MONTHS[data.Mes])
47
+ : result.map(data => SPANISH_MONTHS[data.Mes]),
48
+ datasets: [
49
+ {
50
+ label: `Ventas por meses del año ${asFilter ? chartTypeYear : ''}`,
51
+ data: asFilter
52
+ ? newResult.map(data => data.totalProductsPrice)
53
+ : result.map(data => data.totalProductsPrice),
54
+ backgroundColor: [
55
+ 'rgba(255, 99, 132, 0.2)',
56
+ 'rgba(54, 162, 235, 0.2)',
57
+ 'rgba(255, 206, 86, 0.2)',
58
+ 'rgba(75, 192, 192, 0.2)',
59
+ 'rgba(153, 102, 255, 0.2)',
60
+ 'rgba(255, 159, 64, 0.2)'
61
+ ],
62
+ borderColor: chartType === 'bar'
63
+ ? [
64
+ 'rgba(255, 99, 132, 1)',
65
+ 'rgba(54, 162, 235, 1)',
66
+ 'rgba(255, 206, 86, 1)',
67
+ 'rgba(75, 192, 192, 1)',
68
+ 'rgba(153, 102, 255, 1)',
69
+ 'rgba(255, 159, 64, 1)'
70
+ ]
71
+ : 'rgb(255 0 0)',
72
+ tension: 0.6,
73
+ fill: false,
74
+ borderWidth: 1,
75
+ barPercentage: 1,
76
+ barThickness: 50,
77
+ minBarLength: 3
78
+ }
79
+ ]
80
+ });
40
81
 
41
- for (const element of missingMonths) {
42
- result.push({
43
- 'Mes': element,
44
- 'totalProductsPrice': 0,
45
- 'Year': ''
46
- })
82
+ // Función para agrupar los datos por año
83
+ const groupSalesByYear = (salesData = []) => {
84
+ const groupedData = {};
85
+ try {
86
+ salesData?.forEach((item) => {
87
+ const year = new Date(item.pDatCre).getFullYear();
88
+ if (!groupedData[year]) {
89
+ groupedData[year] = [];
90
+ }
91
+ groupedData[year].push(item);
92
+ });
93
+ return groupedData;
94
+ } catch (error) {
95
+ return groupedData
47
96
  }
97
+ };
98
+
99
+ // Función para obtener años únicos
100
+ const getUniqueYears = (salesData = []) => {
101
+ try {
102
+ const years = [];
103
+ salesData?.forEach((item) => {
104
+ const y = new Date(item.pDatCre).getFullYear();
105
+ if (!years.includes(y)) {
106
+ years.push(y);
107
+ }
108
+ });
109
+ return years.sort((a, b) => b - a);
110
+ } catch (error) {
111
+ return []
112
+ }
113
+ };
114
+
115
+ export const useChartData = ({ year }) => {
116
+ const { data, loading } = useQuery(GET_ALL_SALES);
117
+ const [chartType, setChartType] = useState('Line');
118
+ const [chartTypeYear, setChartTypeYear] = useState(new Date().getFullYear());
119
+ const [asFilter, setFilter] = useState(false);
120
+ const [newResult, setNewResult] = useState([]);
121
+
122
+ const result = calculateSalesByMonth(data?.getAllSalesStore);
123
+
124
+ const filledResult = fillMissingMonths(result);
48
125
 
49
- result.sort((a, b) => { return a.Mes - b.Mes })
126
+ const dataChart = getChartData(asFilter, newResult, filledResult, chartType);
50
127
 
51
- const labelTitle = `Ventas por meses del año ${asFilter ? chartTypeYear : ''}`
52
- // Resultado:
53
- const dataChart = {
54
- labels: asFilter ? newResult.map(data => {
55
- return SPANISH_MONTHS[data.Mes]
56
- }) : result.map(data => {
57
- return SPANISH_MONTHS[data.Mes]
58
- }),
59
- datasets: [
60
- {
61
- label: labelTitle,
62
- data: asFilter ? newResult.map(data => { return data.totalProductsPrice }) : result.map(data => { return data.totalProductsPrice }),
63
- backgroundColor: [
64
- 'rgba(255, 99, 132, 0.2)',
65
- 'rgba(54, 162, 235, 0.2)',
66
- 'rgba(255, 206, 86, 0.2)',
67
- 'rgba(75, 192, 192, 0.2)',
68
- 'rgba(153, 102, 255, 0.2)',
69
- 'rgba(255, 159, 64, 0.2)'
70
- ],
71
- borderColor: chartType === 'bar' ? [
72
- 'rgba(255, 99, 132, 1)',
73
- 'rgba(54, 162, 235, 1)',
74
- 'rgba(255, 206, 86, 1)',
75
- 'rgba(75, 192, 192, 1)',
76
- 'rgba(153, 102, 255, 1)',
77
- 'rgba(255, 159, 64, 1)'
78
- ] : 'rgb(255 0 0)',
79
- tension: 0.6,
80
- fill: false,
81
- borderWidth: 1,
82
- barPercentage: 1,
83
- barThickness: 50,
84
- minBarLength: 3,
85
- }
86
- ]
128
+ const groupedData = groupSalesByYear(data?.getAllSalesStore);
129
+ const years = getUniqueYears(data?.getAllSalesStore);
130
+
131
+ const handleChangeYear = (value) => {
132
+ setFilter(true);
133
+ const currentYear = parseInt(value);
134
+ setChartTypeYear(currentYear || '');
135
+
136
+ if (filledResult?.length > 0) {
137
+ const filterToYear = filledResult.filter((elem) => elem?.Year === currentYear);
138
+ const missingNewMonths = allMonths.filter(month => !filterToYear.some(data => data.Mes === month));
139
+
140
+ const newFilteredResult = filterToYear.concat(
141
+ missingNewMonths.map(element => ({
142
+ Mes: element,
143
+ totalProductsPrice: 0,
144
+ Year: '',
145
+ }))
146
+ ).sort((a, b) => a.Mes - b.Mes);
147
+
148
+ setNewResult(newFilteredResult);
149
+ return newFilteredResult;
87
150
  }
88
- const options = {
89
- interaction: {
90
- mode: 'index',
91
- intersect: false,
92
- },
93
- scales: {
94
- x: {
95
- stacked: true
96
- },
97
- y: {
98
- stacked: true
99
- }
151
+ };
152
+
153
+ const cleanFilter = () => {
154
+ setFilter(false);
155
+ setChartTypeYear(new Date().getFullYear());
156
+ };
157
+
158
+ const sortYear = () => years.sort((a, b) => b - a);
159
+ const labelTitle = `Ventas por meses del año ${asFilter ? chartTypeYear : ''}`
160
+ const organiceYears = sortYear();
161
+ const options = {
162
+ interaction: {
163
+ mode: 'index',
164
+ intersect: false,
165
+ },
166
+ scales: {
167
+ x: {
168
+ stacked: true
100
169
  },
101
- plugins: {
102
- title: {
103
- display: true,
104
- text: labelTitle
105
- },
106
- }
107
- }
108
- const groupedData = {}
109
-
110
- data && data.getAllSalesStore.forEach((item) => {
111
- const year = new Date(item.pDatCre).getFullYear()
112
- if (!groupedData[year]) {
113
- groupedData[year] = []
114
- }
115
- groupedData[year].push(item)
116
- })
117
- const years = []
118
- data && data.getAllSalesStore.forEach((item) => {
119
- const y = new Date(item.pDatCre).getFullYear()
120
- if (!years.includes(y)) {
121
- years.push(y)
170
+ y: {
171
+ stacked: true
122
172
  }
123
- })
124
- const handleChangeYear = (value) => {
125
- setFilter(true)
126
- const currentYear = parseInt(value)
127
- setChartTypeYear(currentYear || '')
128
- if (result?.length > 0) {
129
- const filterToYear = result.filter((elem) => {
130
- return elem?.Year == currentYear
131
- })
132
- let missingNewMonths = allMonths.filter(month => { return !filterToYear.some(data => { return data.Mes === month }) })
133
- for (const element of missingNewMonths) {
134
- filterToYear.push({
135
- 'Mes': element,
136
- 'totalProductsPrice': 0,
137
- 'Year': ''
138
- })
139
- }
140
- filterToYear.sort((a, b) => { return a.Mes - b.Mes })
141
- setNewResult(filterToYear)
142
- return filterToYear
143
- }
144
- }
145
- const cleanFilter = () => {
146
- setFilter(false)
147
- setChartTypeYear(new Date().getFullYear())
148
- }
149
- const sortYear = () => {
150
- return years.sort((a, b) => { return b - a });
151
- }
152
-
153
- const organiceYears = sortYear()
154
- return {
155
- handleChangeYear,
156
- setFilter,
157
- cleanFilter,
158
- setChartType,
159
- years: organiceYears,
160
- asFilter,
161
- chartTypeYear,
162
- options,
163
- chartType,
164
- labelTitle,
165
- result,
166
- dataChart,
167
- loading
173
+ },
174
+ plugins: {
175
+ title: {
176
+ display: true,
177
+ text: labelTitle
178
+ },
168
179
  }
169
- }
180
+ }
181
+ return {
182
+ handleChangeYear,
183
+ setFilter,
184
+ cleanFilter,
185
+ setChartType,
186
+ years: organiceYears,
187
+ asFilter,
188
+ chartTypeYear,
189
+ options,
190
+ chartType,
191
+ labelTitle,
192
+ result: filledResult,
193
+ dataChart,
194
+ loading,
195
+ };
196
+ };
197
+
@@ -15,7 +15,7 @@ import { useCallback, useState } from 'react'
15
15
  * - clearAll (callback)
16
16
  */
17
17
 
18
- export const useCheckboxState = (elem, selectedIds = [], disabledIds = []) => {
18
+ export const useCheckboxState = (elem, selectedIds = [], disabledIds = [], calBack = () => { return }) => {
19
19
  const numTotalItems = elem?.length
20
20
  const [checkedItems, setCheckedItems] = useState(new Set(selectedIds))
21
21
  const [disabledItems, setDisabledItems] = useState(new Set(disabledIds))
@@ -23,14 +23,17 @@ export const useCheckboxState = (elem, selectedIds = [], disabledIds = []) => {
23
23
  const handleChangeCheck = useCallback((event, id) => {
24
24
  const target = event.target
25
25
  setCheckedItems(prevState => {
26
+
26
27
  const newState = new Set(prevState)
27
28
  if (target.checked) {
28
29
  newState.add(id)
29
30
  } else {
30
31
  newState.delete(id)
31
32
  }
33
+ calBack([...newState])
32
34
  return newState
33
35
  })
36
+ // eslint-disable-next-line
34
37
  }, [])
35
38
 
36
39
  const setAll = useCallback(
@@ -106,6 +109,7 @@ export const useCheckboxState = (elem, selectedIds = [], disabledIds = []) => {
106
109
  disabledItems,
107
110
  handleChangeCheck,
108
111
  toggleAll,
112
+ setCheckedItems,
109
113
  selectAll,
110
114
  clearAll,
111
115
  enableCheckboxes,
@@ -1,5 +1,4 @@
1
1
  import { useQuery, useMutation, useLazyQuery } from '@apollo/client'
2
- import { useState } from 'react'
3
2
  import {
4
3
  CREATE_CLIENTS,
5
4
  DELETE_ONE_CLIENTS,
@@ -11,15 +10,25 @@ import {
11
10
  export const useGetClients = ({
12
11
  max,
13
12
  search,
13
+ fromDate, // Agrega las variables fromDate y toDate
14
+ toDate,
14
15
  sendNotification = () => { return }
15
16
  } = {}) => {
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
- }
17
+ const {
18
+ loading,
19
+ error,
20
+ called,
21
+ data
22
+ } = useQuery(GET_ALL_CLIENTS, {
23
+ variables: {
24
+ search: search,
25
+ fromDate: fromDate, // Usa las variables aquí
26
+ toDate: toDate
27
+ }
28
+ });
29
+
30
+ return [data?.getAllClients || [], { loading: called ? false : loading, error }];
31
+ };
23
32
 
24
33
  export const useDeleteClients = ({ sendNotification = () => { return } } = {}) => {
25
34
  const [deleteClient, { loading, error }] = useMutation(DELETE_ONE_CLIENTS)
@@ -1,7 +1,7 @@
1
1
  import { useMutation } from '@apollo/client'
2
2
  import { useRef, useState } from 'react'
3
3
  import { convertBase64, RandomCode } from '../../utils'
4
- import useLocalStorage from '../useLocalSorage'
4
+ import { useLocalStorage } from '../useLocalSorage'
5
5
  import {
6
6
  GET_ALL_FOOD_PRODUCTS,
7
7
  UPDATE_IMAGE_PRODUCT_FOOD,
@@ -10,11 +10,14 @@ import {
10
10
  import { useStore } from '../useStore'
11
11
  import { useTagsProducts } from './../useProductsFood/usetagsProducts'
12
12
  import { useEditImageProduct } from './helpers/useEditImageProduct'
13
+ import { errorHandler } from '../../config/client'
14
+ import { useLogout } from '../useLogout'
13
15
 
14
16
  export const useCreateProduct = ({
15
- setAlertBox = () => { },
16
17
  router,
17
- sendNotification = () => { }
18
+ sendNotification = () => { },
19
+ handleCloseCreateProduct = () => { },
20
+ setAlertBox = () => { }
18
21
  }) => {
19
22
  const [errors, setErrors] = useState({
20
23
  names: ''
@@ -51,7 +54,7 @@ export const useCreateProduct = ({
51
54
 
52
55
  const handleCheck = (e) => {
53
56
  const { name, checked } = e.target
54
- return setCheck((prev) =>({ ...prev, [name]: checked }))
57
+ return setCheck((prev) => ({ ...prev, [name]: checked }))
55
58
  }
56
59
 
57
60
  const handleUpdateBanner = event => {
@@ -120,14 +123,15 @@ export const useCreateProduct = ({
120
123
  alt: files[0].name
121
124
  }
122
125
  : initialState
123
- )
126
+ )
124
127
  }
125
128
  const onTargetClick = () => {
126
129
  fileInputRef.current.click()
127
130
  }
128
131
  const { img } = useEditImageProduct({ sendNotification, initialState })
129
- console.log(values)
130
- const handleRegister = async () => {
132
+ const [onClickLogout] = useLogout()
133
+
134
+ const handleRegister = async ({ callBack = () => { return} } = {}) => {
131
135
  const {
132
136
  ProPrice,
133
137
  ProDescuento,
@@ -146,67 +150,93 @@ export const useCreateProduct = ({
146
150
  const pCode = RandomCode(9)
147
151
  const formatPrice = ProPrice ? parseFloat(ProPrice.replace(/\./g, '')) : 0
148
152
  try {
149
- updateProductFoods({
150
- variables: {
151
- input: {
152
- idStore: dataStore?.getStore?.idStore || '',
153
- ProPrice: check?.desc ? 0 : formatPrice,
154
- ProDescuento: check?.desc ? 0 : parseInt(ProDescuento),
155
- ValueDelivery: check?.desc ? 0 : parseFloat(ValueDelivery),
156
- ProDescription,
157
- pName: names,
158
- pCode,
159
- carProId,
160
- pState: 1,
161
- sTateLogistic: 1,
162
- ProStar: 0,
163
- ProImage,
164
- ProHeight: parseFloat(ProHeight),
165
- ProWeight,
166
- ProOutstanding: check?.desc ? 1 : 0,
167
- ProDelivery: check?.desc ? 1 : 0
168
- }
169
- },
170
- update (cache) {
171
- cache.modify({
172
- fields: {
173
- productFoodsAll (dataOld = []) {
174
- return cache.writeQuery({ query: GET_ALL_FOOD_PRODUCTS, data: dataOld })
153
+ if (names.trim() !== '') {
154
+ updateProductFoods({
155
+ variables: {
156
+ input: {
157
+ idStore: dataStore?.getStore?.idStore || '',
158
+ ProPrice: check?.desc ? 0 : formatPrice,
159
+ ProDescuento: check?.desc ? 0 : parseInt(ProDescuento),
160
+ ValueDelivery: check?.desc ? 0 : parseFloat(ValueDelivery),
161
+ ProDescription,
162
+ pName: names,
163
+ pCode,
164
+ carProId,
165
+ pState: 1,
166
+ sTateLogistic: 1,
167
+ ProStar: 0,
168
+ ProImage,
169
+ ProHeight: parseFloat(ProHeight),
170
+ ProWeight,
171
+ ProOutstanding: check?.desc ? 1 : 0,
172
+ ProDelivery: check?.desc ? 1 : 0
173
+ }
174
+ }, update(cache) {
175
+ cache.modify({
176
+ fields: {
177
+ productFoodsAll(dataOld = []) {
178
+ return cache.writeQuery({ query: GET_ALL_FOOD_PRODUCTS, data: dataOld })
179
+ }
175
180
  }
181
+ })
182
+ }
183
+ }).then((res) => {
184
+
185
+ const { updateProductFoods } = res?.data || {}
186
+ const { pId } = updateProductFoods || {}
187
+
188
+ if (res?.errors?.length > 0) {
189
+ const errors = {
190
+ errors: res?.errors
176
191
  }
177
- })
178
- }
179
- }).then((res) => {
180
- const { updateProductFoods } = res?.data || {}
181
- const { pId } = updateProductFoods || {}
182
- setPid(pId ?? null)
183
- router.push(
184
- {
185
- query: {
186
- ...router.query,
187
- food: pId
192
+ const responseError = errorHandler(errors);
193
+ if (responseError) {
194
+ handleCloseCreateProduct()
195
+ return onClickLogout()
196
+ }
197
+ } else {
198
+ router.push(
199
+ {
200
+ query: {
201
+ ...router.query,
202
+ food: pId
203
+ }
204
+ },
205
+ undefined,
206
+ { shallow: true }
207
+ )
208
+ if (pId){
209
+ setPid(pId ?? null)
210
+ sendNotification({
211
+ backgroundColor: 'success',
212
+ title: 'Success',
213
+ description: `El producto ${names} subido con éxito`
214
+ })
215
+ callBack()
216
+ }
217
+ const objTag = {
218
+ aName: tags?.tag,
219
+ nameTag: tags?.tag,
220
+ pId
188
221
  }
189
- },
190
- undefined,
191
- { shallow: true }
192
- )
193
- sendNotification({
194
- backgroundColor: 'success',
195
- title: 'Success',
196
- description: `El producto ${names} subido con éxito`
222
+ handleRegisterTags(objTag)
223
+ setValues({})
224
+ }
225
+ }).catch(err => {
226
+ return sendNotification({
227
+ backgroundColor: 'error',
228
+ title: 'Error inesperado',
229
+ description: `${err}`
230
+ })
197
231
  })
198
- const objTag = {
199
- aName: tags.tag,
200
- nameTag: tags.tag,
201
- pId
202
- }
203
- handleRegisterTags(objTag)
204
- // setValues({})
205
- }).catch(err => { return sendNotification({
206
- backgroundColor: 'error',
207
- title: `${err}`,
208
- description: 'Error inesperado'
209
- }) })
232
+
233
+ } else {
234
+ return sendNotification({
235
+ backgroundColor: 'warning',
236
+ title: 'Alerta',
237
+ description: 'El nombre del producto no debe estar vacio'
238
+ })
239
+ }
210
240
  if (image !== null) {
211
241
  setImageProducts({
212
242
  variables: {
@@ -219,7 +249,7 @@ export const useCreateProduct = ({
219
249
  }).catch((error) => {
220
250
  sendNotification({
221
251
  backgroundColor: 'error',
222
- title: `Ocurrió un error en la imagen en el producto ${names}`,
252
+ title: `Ocurrió un error en la imagen en el producto ${names}`,
223
253
  description: 'error'
224
254
  })
225
255
  })