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,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,11 +1,17 @@
1
- import { useLazyQuery, useMutation } from "@apollo/client";
2
- import { useCallback, useEffect, useReducer, useState } from "react";
3
- import { Cookies } from "../../cookies";
4
1
  import {
5
- RandomCode,
6
- getCurrentDomain,
7
- updateCacheMod
8
- } from "../../utils";
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";
13
+ import { Cookies } from "../../cookies";
14
+ import { RandomCode, getCurrentDomain } from "../../utils";
9
15
  import { useFormatDate } from "../useFormatDate";
10
16
  import { useProductsFood } from "../useProductsFood";
11
17
  import {
@@ -17,6 +23,7 @@ import { useStore } from "../useStore";
17
23
  import {
18
24
  CREATE_SHOPPING_CARD_TO_USER_STORE,
19
25
  GET_ALL_COUNT_SALES,
26
+ GET_ALL_PEDIDOS,
20
27
  GET_ALL_SALES,
21
28
  GET_ALL_SALES_STATISTICS,
22
29
  } from "./queries";
@@ -68,10 +75,13 @@ export const useSales = ({
68
75
  const [code, setCode] = useState(null);
69
76
  const [openCurrentSale, setOpenCurrentSale] = useState(null);
70
77
  const { createdAt } = dataStore || {};
78
+ const [oneProductToComment, setOneProductToComment] = useState({});
79
+ const [sumExtraProducts, setSumExtraProducts] = useState(0);
71
80
  const { yearMonthDay } = useFormatDate({ date: createdAt });
72
81
  const [valuesDates, setValuesDates] = useState(() => {
73
82
  return { fromDate: yearMonthDay, toDate: "" };
74
83
  });
84
+ const [loadingExtraProduct, setLoadingExtraProduct] = useState(false);
75
85
  const [dataOptional, setDataOptional] = useState([]);
76
86
  const [dataExtra, setDataExtra] = useState([]);
77
87
 
@@ -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
- console.log("error", 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);
@@ -165,7 +184,6 @@ export const useSales = ({
165
184
  let filteredData = handleList(text);
166
185
  setFilteredList(filteredData);
167
186
  };
168
- const [oneProductToComment, setOneProductToComment] = useState({});
169
187
  const handleComment = (product) => {
170
188
  if (product) {
171
189
  setOneProductToComment(product);
@@ -213,7 +231,7 @@ export const useSales = ({
213
231
  const productExist = state.PRODUCT.find((items) => {
214
232
  return items.pId === action.id;
215
233
  });
216
- const OurProduct = productsFood.find((items) => {
234
+ const OurProduct = productsFood?.find((items) => {
217
235
  return items.pId === action.id;
218
236
  });
219
237
  const isFree = productExist?.free;
@@ -245,6 +263,7 @@ export const useSales = ({
245
263
  return {
246
264
  ...state,
247
265
  PRODUCT: [],
266
+ sortBy: null,
248
267
  counter: 0,
249
268
  };
250
269
 
@@ -363,7 +382,6 @@ export const useSales = ({
363
382
  * Description
364
383
  * @returns {any}
365
384
  * */
366
- const [sumExtraProducts, setSumExtraProducts] = useState(0);
367
385
  useEffect(() => {
368
386
  const arr =
369
387
  dataExtra?.length > 0
@@ -392,26 +410,40 @@ export const useSales = ({
392
410
  }, [dataExtra]);
393
411
 
394
412
  function handleUpdateAllExtra() {
395
- const { pId } = product?.PRODUCT || {};
396
- const filteredDataOptional = dataOptional.map((obj) => {
397
- const filteredSubOptions = obj.ExtProductFoodsSubOptionalAll.filter(
398
- (subObj) => subObj.check === true
399
- );
400
- // Excluya todo el objeto padre si filteredSubOptions está vacío
401
- if (filteredSubOptions.length === 0) {
402
- return null;
403
- }
404
- return { ...obj, ExtProductFoodsSubOptionalAll: filteredSubOptions };
405
- }).filter((obj) => obj !== null); // Elimine todos los objetos nulos del arreglo
406
- const filteredDataExtra = dataExtra.filter((p) => {
407
- return p.quantity !== 0;
408
- });
409
- return dispatch({
410
- type: "PUT_EXTRA_PRODUCTS_AND_OPTIONAL_PRODUCT",
411
- payload: pId,
412
- dataOptional: filteredDataOptional,
413
- dataExtra: filteredDataExtra,
414
- });
413
+ try {
414
+ if (!product?.PRODUCT?.pId) {
415
+ return sendNotification({
416
+ title: "Error",
417
+ backgroundColor: 'error',
418
+ description: "No se puede actualizar el producto sin pId",
419
+ });
420
+ }
421
+ const filteredDataOptional = dataOptional
422
+ .map((obj) => {
423
+ const filteredSubOptions = obj.ExtProductFoodsSubOptionalAll.filter(
424
+ (subObj) => subObj.check === true
425
+ );
426
+ // Excluya todo el objeto padre si filteredSubOptions está vacío
427
+ if (filteredSubOptions.length === 0) {
428
+ return null;
429
+ }
430
+ return { ...obj, ExtProductFoodsSubOptionalAll: filteredSubOptions };
431
+ })
432
+ .filter((obj) => obj !== null); // Elimine todos los objetos nulos del arreglo
433
+ const filteredDataExtra = dataExtra.filter((p) => p.quantity !== 0);
434
+ dispatch({
435
+ type: "PUT_EXTRA_PRODUCTS_AND_OPTIONAL_PRODUCT",
436
+ payload: product.PRODUCT.pId,
437
+ dataOptional: filteredDataOptional,
438
+ dataExtra: filteredDataExtra,
439
+ });
440
+ } catch (_error) {
441
+ return sendNotification({
442
+ title: "Error",
443
+ backgroundColor: 'error',
444
+ description: "No se puedo actualizar el producto",
445
+ });
446
+ }
415
447
  }
416
448
 
417
449
  function handleIncrementExtra({ Adicionales, index }) {
@@ -564,23 +596,20 @@ export const useSales = ({
564
596
  };
565
597
  }
566
598
 
567
- const getSortedProduct = (sortData, sortBy) => {
568
- if (sortBy && sortBy === "PRICE_HIGH_TO_LOW") {
569
- return (
570
- sortData.sort((a, b) => {
571
- return b["ProPrice"] - a["ProPrice"];
572
- })
573
- );
599
+ const getSortedProduct = useCallback((data, sort) => {
600
+ if (sort && sort === "PRICE_HIGH_TO_LOW") {
601
+ return data.sort((a, b) => {
602
+ return b["ProPrice"] - a["ProPrice"];
603
+ });
574
604
  }
575
- if (sortBy && sortBy === "PRICE_LOW_TO_HIGH") {
576
- return (
577
- sortData.sort((a, b) => {
578
- return a["ProPrice"] - b["ProPrice"];
579
- })
580
- );
605
+ if (sort && sort === "PRICE_LOW_TO_HIGH") {
606
+ return data.sort((a, b) => {
607
+ return a["ProPrice"] - b["ProPrice"];
608
+ });
581
609
  }
582
- return sortData;
583
- };
610
+ return data;
611
+ }, [])
612
+
584
613
  const PriceRangeFunc = (products, price) => {
585
614
  return (
586
615
  products?.length > 0 &&
@@ -590,7 +619,9 @@ export const useSales = ({
590
619
  );
591
620
  };
592
621
 
593
- const sortedProduct = getSortedProduct(data.PRODUCT, data.sortBy);
622
+ const sortedProduct = useMemo(() => {
623
+ return getSortedProduct(data.PRODUCT, data.sortBy);
624
+ }, [data.PRODUCT, data.sortBy, getSortedProduct])
594
625
  const finalFilter = PriceRangeFunc(sortedProduct, data.priceRange);
595
626
 
596
627
  const handleList = (text) => {
@@ -612,31 +643,104 @@ export const useSales = ({
612
643
  }
613
644
  return "";
614
645
  };
615
- const newArrayProducts =
616
- data?.PRODUCT?.length > 0 ?
617
- data?.PRODUCT?.map((product) => {
618
- const filteredDataExtra = product?.dataExtra?.map(({__typename, ...rest}) => rest) ?? [];
619
- const dataOptional = product?.dataOptional?.map(({ __typename, ...product}) => {
620
- const {ExtProductFoodsSubOptionalAll, ...rest} = product;
621
- const adjustedSubOptionalAll = ExtProductFoodsSubOptionalAll?.map(subOption => {
622
- const {__typename, ...subOptionRest} = subOption;
623
- return subOptionRest;
624
- });
625
- return {...rest, ExtProductFoodsSubOptionalAll: adjustedSubOptionalAll};
646
+ const arrayProduct =
647
+ data?.PRODUCT?.length > 0
648
+ ? data?.PRODUCT?.map((product) => {
649
+ const filteredDataExtra =
650
+ product?.dataExtra?.map(({ __typename, ...rest }) => rest) ?? [];
651
+ const dataOptional = product?.dataOptional?.map(
652
+ ({ __typename, ...product }) => {
653
+ const { ExtProductFoodsSubOptionalAll, ...rest } = product;
654
+ const adjustedSubOptionalAll = ExtProductFoodsSubOptionalAll?.map(
655
+ (subOption) => {
656
+ const { __typename, ...subOptionRest } = subOption;
657
+ return subOptionRest;
658
+ }
659
+ );
660
+ return {
661
+ ...rest,
662
+ ExtProductFoodsSubOptionalAll: adjustedSubOptionalAll,
663
+ };
664
+ }
665
+ );
666
+ const refCodePid = RandomCode(20)
667
+ return {
668
+ pId: product?.pId,
669
+ refCodePid: refCodePid,
670
+ id: values?.cliId,
671
+ cantProducts: parseInt(
672
+ product?.ProQuantity ? product?.ProQuantity : 0
673
+ ),
674
+ comments: product?.comment ?? "",
675
+ dataOptional: dataOptional ?? [],
676
+ dataExtra: filteredDataExtra || [],
677
+ ProPrice: product.ProPrice,
678
+ };
679
+ })
680
+ : [];
681
+ const finalArrayProduct = arrayProduct.map((item) => {
682
+ const totalExtra = item.dataExtra.reduce(
683
+ (accumulator, extra) => accumulator + extra.newExtraPrice,
684
+ 0
685
+ );
686
+ return { ...item, totalExtra };
687
+ });
688
+
689
+ let totalSale = 0;
690
+ function sumProPriceAndTotalExtra(data) {
691
+ return data.map((item) => {
692
+ const totalExtra = item.dataExtra.reduce((acc, curr) => {
693
+ const newExtraPrice = parseFloat(curr.newExtraPrice);
694
+ if (isNaN(newExtraPrice)) {
695
+ return acc;
696
+ }
697
+ return acc + newExtraPrice;
698
+ }, 0);
699
+ const total = item.ProPrice + totalExtra;
700
+ return { ...item, totalExtra, total };
701
+ });
702
+ }
703
+ useEffect(() => {
704
+ const dataCountTotal = sumProPriceAndTotalExtra(finalArrayProduct);
705
+ dataCountTotal.forEach((a) => {
706
+ const { total } = a || {};
707
+ totalSale += total;
708
+ setTotalProductPrice(Math.abs(totalSale));
709
+ });
710
+ if (data.PRODUCT.length === 0) {
711
+ setTotalProductPrice(0);
712
+ }
713
+ }, [totalProductPrice, totalSale, data, finalArrayProduct]);
714
+
715
+ const [discount, setDiscount] = useState({
716
+ price: totalProductPrice || 0,
717
+ discount: 0,
718
+ });
719
+ function applyDiscount(percentage) {
720
+ const validateCondition =
721
+ isNaN(percentage) || percentage < 0 || percentage > 100;
722
+
723
+ if (validateCondition) {
724
+ return sendNotification({
725
+ title: "Error",
726
+ backgroundColor: 'error',
727
+ description: "el descuento debe ser un número entre 0 y 100%",
626
728
  });
627
- return {
628
- pId: product?.pId,
629
- id: values?.cliId,
630
- cantProducts: parseInt(product?.ProQuantity ? product?.ProQuantity : 0),
631
- comments: product?.comment ?? "",
632
- dataOptional: dataOptional ?? [],
633
- dataExtra: filteredDataExtra || []
634
- };
635
- }) : [];
729
+ }
730
+ const decimal = parseFloat(percentage) / 100;
731
+ const result = decimal * parseFloat(totalProductPrice);
732
+ setDiscount({ price: result, discount: percentage });
733
+
734
+ return { price: result, discount: percentage };
735
+ }
736
+ const totalProductsPrice = totalProductPrice;
737
+ const client = useApolloClient()
738
+
636
739
  const handleSubmit = () => {
637
740
  if (!values?.cliId)
638
741
  return sendNotification({
639
742
  title: "Error",
743
+ backgroundColor: 'error',
640
744
  description: "Elije primero un cliente",
641
745
  });
642
746
  setLoadingSale(true);
@@ -644,38 +748,16 @@ export const useSales = ({
644
748
  setCode(code);
645
749
  return registerSalesStore({
646
750
  variables: {
647
- input: newArrayProducts || [],
751
+ input: finalArrayProduct || [],
648
752
  id: values?.cliId,
649
753
  pCodeRef: code,
650
754
  change: values.change,
651
755
  valueDelivery: parseInt(values.valueDelivery),
652
756
  payMethodPState: data.payMethodPState,
653
757
  pickUp: 1,
654
- totalProductsPrice: totalProductPrice || 0,
655
- },
656
- update: (
657
- cache,
658
- { data: { getAllSalesStoreStatistic, getTodaySales, getAllSalesStore } }
659
- ) => {
660
- updateCacheMod({
661
- cache,
662
- query: GET_ALL_SALES,
663
- nameFun: "getAllSalesStore",
664
- dataNew: getAllSalesStore,
665
- });
666
- updateCacheMod({
667
- cache,
668
- query: GET_ALL_COUNT_SALES,
669
- nameFun: "getTodaySales",
670
- dataNew: getTodaySales,
671
- });
672
- updateCacheMod({
673
- cache,
674
- query: GET_ALL_SALES_STATISTICS,
675
- nameFun: "getAllSalesStoreStatistic",
676
- dataNew: getAllSalesStoreStatistic
677
- });
678
- },
758
+ discount: discount.discount || 0,
759
+ totalProductsPrice: totalProductsPrice || 0,
760
+ }
679
761
  })
680
762
  .then((responseRegisterR) => {
681
763
  if (responseRegisterR) {
@@ -684,6 +766,13 @@ export const useSales = ({
684
766
  const { Response } = registerSalesStore || {};
685
767
  if (Response && Response.success === true) {
686
768
  // dispatch({ type: 'REMOVE_ALL_PRODUCTS' })
769
+ client.query({
770
+ query: GET_ALL_COUNT_SALES,
771
+ fetchPolicy: 'network-only',
772
+ onCompleted: (data) => {
773
+ client.writeQuery({ query: GET_ALL_COUNT_SALES, data: { getTodaySales: data.countSales.todaySales } })
774
+ }
775
+ })
687
776
  router.push(
688
777
  {
689
778
  query: {
@@ -692,7 +781,7 @@ export const useSales = ({
692
781
  },
693
782
  },
694
783
  undefined,
695
- { shallow: true }
784
+ { shallow: true }
696
785
  );
697
786
  // setValues({})
698
787
  }
@@ -710,73 +799,80 @@ export const useSales = ({
710
799
  let suma = 0;
711
800
  let total = 0;
712
801
 
713
- useEffect(() => {
714
- data.PRODUCT.forEach((a) => {
715
- const { ProPrice } = a || {};
716
- suma += ProPrice;
717
- setTotalProductPrice(Math.abs(suma));
718
- });
719
- if (data.PRODUCT.length === 0) {
720
- setTotalProductPrice(0);
721
- }
722
- }, [totalProductPrice, suma, total, data]);
723
- const [loadingExtraProduct, setLoadingExtraProduct] = useState(false);
724
-
725
802
  const handleProduct = async (PRODUCT) => {
726
- setLoadingExtraProduct(true)
803
+ setLoadingExtraProduct(true);
727
804
  const { pId } = PRODUCT || {};
728
805
  try {
729
806
  const originalArray = data.PRODUCT.find((item) => {
730
807
  return item.pId === pId;
731
808
  });
732
809
  // OPTIONAL
733
- productFoodsOne({ variables: { pId } })
734
- const optionalAll = await ExtProductFoodsSubOptionalAll({ variables: { pId } })
735
- const optionalFetch = optionalAll.data.ExtProductFoodsOptionalAll
736
- setDataOptional(optionalFetch || [])
737
- const existOptionalCookies = originalArray?.dataOptional
738
- const filteredDataOptional = existOptionalCookies?.length ? existOptionalCookies?.map((obj) => {
739
- const filteredSubOptions = obj.ExtProductFoodsSubOptionalAll.filter(
740
- (subObj) => subObj.check === true
741
- );
742
- // Excluya todo el objeto padre si filteredSubOptions está vacío
743
- if (filteredSubOptions.length === 0) {
744
- return null;
745
- }
746
- return { ...obj, ExtProductFoodsSubOptionalAll: filteredSubOptions };
747
- }).filter((obj) => obj !== null) : [];
810
+ productFoodsOne({ variables: { pId } });
811
+ const optionalAll = await ExtProductFoodsSubOptionalAll({
812
+ variables: { pId },
813
+ });
814
+ const optionalFetch = optionalAll.data.ExtProductFoodsOptionalAll;
815
+ setDataOptional(optionalFetch || []);
816
+ const existOptionalCookies = originalArray?.dataOptional;
817
+ const filteredDataOptional = existOptionalCookies?.length
818
+ ? existOptionalCookies
819
+ ?.map((obj) => {
820
+ const filteredSubOptions =
821
+ obj.ExtProductFoodsSubOptionalAll.filter(
822
+ (subObj) => subObj.check === true
823
+ );
824
+ // Excluya todo el objeto padre si filteredSubOptions está vacío
825
+ if (filteredSubOptions.length === 0) {
826
+ return null;
827
+ }
828
+ return {
829
+ ...obj,
830
+ ExtProductFoodsSubOptionalAll: filteredSubOptions,
831
+ };
832
+ })
833
+ .filter((obj) => obj !== null)
834
+ : [];
748
835
 
749
- // Actualizar optionalAll.data.ExtProductFoodsSubOptionalAll con los valores actualizados de originalArray2.ExtProductFoodsSubOptionalAll
750
- if (optionalFetch && filteredDataOptional) {
751
- const updateOption = optionalFetch.map((obj) => {
752
- const matchingArray = filteredDataOptional.find((o) => o && o.opExPid === obj.opExPid);
836
+ // Actualizar optionalAll.data.ExtProductFoodsSubOptionalAll con los valores actualizados de originalArray2.ExtProductFoodsSubOptionalAll
837
+ if (optionalFetch && filteredDataOptional) {
838
+ const updateOption = optionalFetch
839
+ .map((obj) => {
840
+ const matchingArray = filteredDataOptional.find(
841
+ (o) => o && o.opExPid === obj.opExPid
842
+ );
753
843
  if (!matchingArray) {
754
844
  return obj;
755
845
  }
756
- const extProductFoodsSubOptionalAll = obj.ExtProductFoodsSubOptionalAll || [];
757
- const updateExtProductFoodsSubOptionalAll = extProductFoodsSubOptionalAll.map((subObj) => {
758
- const newItem = matchingArray.ExtProductFoodsSubOptionalAll.find(
759
- (newItem) => newItem && newItem.opSubExPid === subObj.opSubExPid
760
- );
761
- if (newItem) {
762
- return {
763
- ...subObj,
764
- check: true
765
- };
766
- }
767
- return subObj;
768
- });
846
+ const extProductFoodsSubOptionalAll =
847
+ obj.ExtProductFoodsSubOptionalAll || [];
848
+ const updateExtProductFoodsSubOptionalAll =
849
+ extProductFoodsSubOptionalAll.map((subObj) => {
850
+ const newItem =
851
+ matchingArray.ExtProductFoodsSubOptionalAll.find(
852
+ (newItem) =>
853
+ newItem && newItem.opSubExPid === subObj.opSubExPid
854
+ );
855
+ if (newItem) {
856
+ return {
857
+ ...subObj,
858
+ check: true,
859
+ };
860
+ }
861
+ return subObj;
862
+ });
769
863
  return {
770
864
  ...obj,
771
- ExtProductFoodsSubOptionalAll: updateExtProductFoodsSubOptionalAll
865
+ ExtProductFoodsSubOptionalAll:
866
+ updateExtProductFoodsSubOptionalAll,
772
867
  };
773
- }).filter(obj => obj);
774
- if (existOptionalCookies) {
775
- setDataOptional(updateOption || [])
776
- } else {
777
- setDataOptional(optionalAll.data.ExtProductFoodsOptionalAll || [])
778
- }
868
+ })
869
+ .filter((obj) => obj);
870
+ if (existOptionalCookies) {
871
+ setDataOptional(updateOption || []);
872
+ } else {
873
+ setDataOptional(optionalAll.data.ExtProductFoodsOptionalAll || []);
779
874
  }
875
+ }
780
876
  // NO OPTIONAL
781
877
  const extProduct = await ExtProductFoodsAll({ variables: { pId } });
782
878
  let finalData;
@@ -803,10 +899,14 @@ export const useSales = ({
803
899
  PRODUCT,
804
900
  };
805
901
  });
806
- setLoadingExtraProduct(false)
902
+ setLoadingExtraProduct(false);
807
903
  } catch (error) {
808
- setLoadingExtraProduct(false)
809
- console.log({ message: error || "Lo sentimos, ocurrió un error" });
904
+ setLoadingExtraProduct(false);
905
+ sendNotification({
906
+ title: 'error',
907
+ backgroundColor: 'error',
908
+ description: error || "Lo sentimos, ocurrió un error",
909
+ });
810
910
  }
811
911
  };
812
912
  const handleCleanFilter = () => {
@@ -814,10 +914,9 @@ export const useSales = ({
814
914
  setValues({});
815
915
  setValuesDates({ fromDate: yearMonthDay, toDate: "" });
816
916
  };
817
- const disabledModalItems = dataOptional?.length > 0 || dataExtra?.length > 0
917
+ const disabledModalItems = dataOptional?.length > 0 || dataExtra?.length > 0;
818
918
  return {
819
- // loading: loading || loadingSale,
820
- loading: false,
919
+ loading: loading || loadingSale,
821
920
  loadingExtraProduct,
822
921
  disabledModalItems: !disabledModalItems,
823
922
  loadingRegisterSale,
@@ -830,7 +929,7 @@ export const useSales = ({
830
929
  data,
831
930
  openCommentModal,
832
931
  inputValue,
833
- newArrayProducts,
932
+ arrayProduct,
834
933
  delivery,
835
934
  valuesDates,
836
935
  print,
@@ -848,6 +947,7 @@ export const useSales = ({
848
947
  dataOptional: dataOptional || [],
849
948
  dataExtra: dataExtra || [],
850
949
  fetchMore,
950
+ discount,
851
951
  handleUpdateAllExtra,
852
952
  dispatch,
853
953
  setArrayCategory,
@@ -859,6 +959,7 @@ export const useSales = ({
859
959
  setOpenCurrentSale,
860
960
  onChangeInput,
861
961
  handleRemoveValue,
962
+ applyDiscount,
862
963
  setDelivery,
863
964
  setValues,
864
965
  setShowMore,