npm-pkg-hook 1.1.0 → 1.1.3

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 (72) 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 +2 -169
  14. package/src/hooks/useChartData/useChartData/index.js +197 -0
  15. package/src/hooks/useChartData/useChartDataAllOrders/index.js +89 -0
  16. package/src/hooks/useCheckbox/index.js +5 -1
  17. package/src/hooks/useClients/index.js +17 -8
  18. package/src/hooks/useCreateProduct/index.js +95 -65
  19. package/src/hooks/useDeleteSubProductOptional/index.js +30 -0
  20. package/src/hooks/useDeleteSubProductOptional/queries.js +10 -0
  21. package/src/hooks/useDessert/helpers/index.js +51 -0
  22. package/src/hooks/useDessert/index.js +319 -121
  23. package/src/hooks/useDevices/index.js +36 -0
  24. package/src/hooks/useDevices/queries.js +19 -0
  25. package/src/hooks/useDrag/index.js +1 -1
  26. package/src/hooks/useDropzone/index.js +79 -0
  27. package/src/hooks/useDynamicAuth/index.js +13 -0
  28. package/src/hooks/useDynamicAuth/queries.js +24 -0
  29. package/src/hooks/useEmployee/index.js +11 -8
  30. package/src/hooks/useFingerprintjs/index.js +176 -0
  31. package/src/hooks/useFormTools/index.js +1 -1
  32. package/src/hooks/useFullScreenMode/index.js +8 -9
  33. package/src/hooks/useGenerateNumberArray/index.js +17 -0
  34. package/src/hooks/useImagesStore/index.js +176 -143
  35. package/src/hooks/useImagesStore/queries.js +1 -28
  36. package/src/hooks/useKeypress/index.js +7 -1
  37. package/src/hooks/useLocalSorage/index.js +1 -1
  38. package/src/hooks/useLogout/index.js +22 -25
  39. package/src/hooks/useManageQueryParams/index.js +37 -0
  40. package/src/hooks/useProductsFood/queriesStore.js +3 -16
  41. package/src/hooks/useProductsFood/usetagsProducts.js +30 -5
  42. package/src/hooks/useProviders/index.js +3 -0
  43. package/src/hooks/useProviders/queries.js +31 -0
  44. package/src/hooks/useProviders/useProvidersCreateStore/index.js +13 -0
  45. package/src/hooks/useProviders/useProvidersDataStore/index.js +24 -0
  46. package/src/hooks/useProvidersStore/index.js +24 -0
  47. package/src/hooks/useProvidersStore/queries.js +31 -0
  48. package/src/hooks/useRatingData/index.js +53 -0
  49. package/src/hooks/useRatingData/queries.js +18 -0
  50. package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -0
  51. package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -0
  52. package/src/hooks/useReport/index.js +16 -7
  53. package/src/hooks/useReport/queries.js +47 -32
  54. package/src/hooks/useSales/index.js +53 -22
  55. package/src/hooks/useSales/queries.js +48 -38
  56. package/src/hooks/useSales/useGetAllSales/index.js +25 -0
  57. package/src/hooks/useSales/useGetSale.js +16 -2
  58. package/src/hooks/useSchedule/index.js +36 -0
  59. package/src/hooks/useSchedule/queries.js +35 -0
  60. package/src/hooks/useScheduleData/index.js +171 -0
  61. package/src/hooks/useScroll/index.js +57 -0
  62. package/src/hooks/useScrollRotate/index.js +14 -0
  63. package/src/hooks/useStatusOpenStore/helpers/index.js +102 -0
  64. package/src/hooks/useStatusOpenStore/index.js +173 -0
  65. package/src/hooks/useStoreContacts/index.js +5 -1
  66. package/src/hooks/useUpdateExistingOrders/index.js +8 -8
  67. package/src/hooks/useUser/index.js +7 -2
  68. package/src/hooks/useUser/queries.js +40 -0
  69. package/src/index.jsx +3 -1
  70. package/.vscode/extensions.json +0 -6
  71. package/.vscode/settings.json +0 -8
  72. package/src/hooks/useSchedule/index.jsx +0 -23
@@ -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
  })
@@ -0,0 +1,30 @@
1
+ import { useMutation } from '@apollo/client'
2
+ import { DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS } from './queries'
3
+ import { updateCacheMod } from '../../utils'
4
+ import { GET_EXTRAS_PRODUCT_FOOD_OPTIONAL } from '../useRemoveExtraProductFoodsOptional/queries'
5
+
6
+ export const useDeleteSubProductOptional = ({ setAlertBox = () => { return } } = {}) => {
7
+ const [DeleteExtFoodSubsOptional, {
8
+ loading,
9
+ error,
10
+ called
11
+ }] = useMutation(DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS)
12
+
13
+ const handleRemoveSubProductOptional = ({ state, opSubExPid }) => {
14
+ console.log(state, opSubExPid )
15
+ DeleteExtFoodSubsOptional({
16
+ variables: {
17
+ state: state,
18
+ opSubExPid: opSubExPid
19
+ }, update: (cache, { data: { ExtProductFoodsOptionalAll } }) => {
20
+ return updateCacheMod({
21
+ cache,
22
+ query: GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
23
+ nameFun: 'ExtProductFoodsOptionalAll',
24
+ dataNew: ExtProductFoodsOptionalAll
25
+ })
26
+ }
27
+ }).then(res => { return setAlertBox({ message: res?.message?.DeleteExtFoodSubsOptional?.message }) })
28
+ }
29
+ return [DeleteExtFoodSubsOptional, handleRemoveSubProductOptional, { loading, error, called }]
30
+ }
@@ -0,0 +1,10 @@
1
+ import { gql } from "@apollo/client";
2
+
3
+ export const DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS = gql`
4
+ mutation DeleteExtFoodSubsOptional($opSubExPid: ID, $state: Int, $isCustomSubOpExPid: Boolean){
5
+ DeleteExtFoodSubsOptional(opSubExPid: $opSubExPid, state: $state, isCustomSubOpExPid: $isCustomSubOpExPid){
6
+ success,
7
+ message
8
+ }
9
+ }
10
+ `
@@ -0,0 +1,51 @@
1
+ import { MockData } from '../../../mock'
2
+
3
+ /**
4
+ * Transforms an array of objects into a specific data format suitable for desserts.
5
+ *
6
+ * @param {Array<Object>} dataArray - The array of objects to transform.
7
+ * @return {Object} The transformed data containing lists and listIds.
8
+ * @throws {Error} If dataArray is not an array or if the objects lack required properties.
9
+ */
10
+ export const transformDataToDessert = (dataArray) => {
11
+ try {
12
+ if (!dataArray) {
13
+ return MockData
14
+ }
15
+ if (!Array.isArray(dataArray)) {
16
+ throw new Error('dataArray must be an array.');
17
+ }
18
+
19
+ const transformedData = {
20
+ lists: {},
21
+ listIds: []
22
+ };
23
+
24
+ dataArray.forEach((item) => {
25
+ const listId = item.code;
26
+ transformedData.listIds.push(listId);
27
+ transformedData.lists[listId] = {
28
+ id: listId,
29
+ title: item?.OptionalProName,
30
+ numberLimit: item?.numbersOptionalOnly,
31
+ required: item?.required,
32
+ value: '',
33
+ cards: item?.ExtProductFoodsSubOptionalAll?.length > 0 ? item?.ExtProductFoodsSubOptionalAll?.map(subOptional => {
34
+ return {
35
+ id: subOptional?.exCode,
36
+ title: subOptional?.OptionalSubProName,
37
+ required: subOptional?.state,
38
+ value: ''
39
+ }
40
+ }) : []
41
+ };
42
+ })
43
+
44
+ return transformedData;
45
+ } catch (error) {
46
+ console.error(error.message)
47
+ return MockData
48
+ }
49
+
50
+ };
51
+