npm-pkg-hook 1.1.5 → 1.1.9
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/.eslintrc.js +19 -113
- package/.eslintrc.json +127 -108
- package/.github/pull_request_template.md +17 -17
- package/.github/workflows/pepeline.yaml +29 -29
- package/next.config.js +2 -5
- package/package.json +27 -24
- package/script.txt +6 -6
- package/src/config/client/errors.js +14 -14
- package/src/config/client/index.js +1 -1
- package/src/hooks/getCategoriesWithProduct/helpers/index.js +7 -0
- package/src/hooks/getCategoriesWithProduct/index.js +62 -0
- package/src/hooks/getSession/index.js +18 -18
- package/src/hooks/index.js +13 -9
- package/src/hooks/useAcumulateDate/index.js +1 -1
- package/src/hooks/useAnimationFrame/index.js +45 -45
- package/src/hooks/useAsideCart/helpers/index.js +22 -0
- package/src/hooks/useAsideCart/index.js +156 -0
- package/src/hooks/useAsideCart/queries.js +10 -0
- package/src/hooks/useBanner/index.js +11 -11
- package/src/hooks/useCart/index.js +2 -0
- package/src/hooks/useCart/queries.js +164 -0
- package/src/hooks/useCart/useCart/helpers/index.js +75 -0
- package/src/hooks/useCart/useCart/index.js +411 -0
- package/src/hooks/useCart/useGetCart/index.js +31 -0
- package/src/hooks/useCatWithProduct/index.js +15 -15
- package/src/hooks/useCatWithProduct/queries.js +1 -1
- package/src/hooks/useCatWithProductClient/index.js +48 -0
- package/src/hooks/useCatWithProductClient/queries.js +55 -0
- package/src/hooks/useCategoriesProduct/index.js +12 -12
- package/src/hooks/useCategoriesProduct/queries.js +16 -16
- package/src/hooks/useCategoryInStore/index.js +39 -36
- package/src/hooks/useCategoryInStore/queries.js +78 -78
- package/src/hooks/useCategoryStore/index.js +2 -2
- package/src/hooks/useChartData/index.js +159 -156
- package/src/hooks/useChartData/useChartData/index.js +199 -197
- package/src/hooks/useChartData/useChartDataAllOrders/index.js +94 -94
- package/src/hooks/useCheckbox/index.js +115 -115
- package/src/hooks/useClients/index.js +12 -14
- package/src/hooks/useClients/queries.js +1 -1
- package/src/hooks/useConnection/index.js +20 -21
- package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +6 -2
- package/src/hooks/useCreateProduct/index.js +22 -19
- package/src/hooks/useDeleteSubProductOptional/index.js +31 -30
- package/src/hooks/useDeleteSubProductOptional/queries.js +10 -10
- package/src/hooks/useDessert/helpers/index.js +51 -51
- package/src/hooks/useDessert/index.js +56 -65
- package/src/hooks/useDevices/index.js +35 -36
- package/src/hooks/useDevices/queries.js +19 -19
- package/src/hooks/useDropzone/index.js +94 -79
- package/src/hooks/useDynamicAuth/index.js +13 -13
- package/src/hooks/useDynamicAuth/queries.js +24 -24
- package/src/hooks/useEmployee/queries.js +1 -1
- package/src/hooks/useEvent/index.js +33 -33
- package/src/hooks/useFavoriteStores/index.js +19 -0
- package/src/hooks/useFavoriteStores/queries.js +47 -0
- package/src/hooks/useFetchJson/index.js +25 -25
- package/src/hooks/useFingerprintjs/index.js +172 -176
- package/src/hooks/useFormTools/index.js +12 -11
- package/src/hooks/useFormatDate/index.js +20 -21
- package/src/hooks/useFormatNumberPhone/index.js +9 -9
- package/src/hooks/useFullScreenMode/index.js +65 -65
- package/src/hooks/useGenerateNumberArray/index.js +17 -17
- package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.js +14 -0
- package/src/hooks/useGetFoodRecomended/index.js +33 -0
- package/src/hooks/useGetFoodRecomended/queries.js +47 -0
- package/src/hooks/useGetMinPrice/index.js +8 -0
- package/src/hooks/useGetMinPrice/queries.js +7 -0
- package/src/hooks/useGetOneStoreRating/index.js +40 -0
- package/src/hooks/useGetOneStoreRating/queries.js +18 -0
- package/src/hooks/useGoogleLogin/index.js +160 -161
- package/src/hooks/useHover/index.js +29 -29
- package/src/hooks/useImageOptimization/index.js +15 -15
- package/src/hooks/useImageWeight/index.js +18 -19
- package/src/hooks/useImagesStore/index.js +139 -140
- package/src/hooks/useImagesStore/queries.js +19 -18
- package/src/hooks/useInnerHtml/index.js +39 -38
- package/src/hooks/useIntersection/index.js +4 -4
- package/src/hooks/useKeypress/index.js +28 -28
- package/src/hooks/useLazyScript/index.js +35 -36
- package/src/hooks/useLocalSorage/index.js +2 -2
- package/src/hooks/useLocationNavigate/index.js +54 -54
- package/src/hooks/useLogout/index.js +24 -24
- package/src/hooks/useManageQueryParams/index.js +36 -37
- package/src/hooks/useMobile/index.js +39 -38
- package/src/hooks/useMutateHeight/index.js +15 -16
- package/src/hooks/useOrderClient/index.js +5 -0
- package/src/hooks/useOrders/index.js +10 -16
- package/src/hooks/useOrders/queries.js +1 -1
- package/src/hooks/useProductsFood/index.js +32 -32
- package/src/hooks/useProductsFood/queriesStore.js +49 -48
- package/src/hooks/useProductsFood/useEditProduct.js +2 -4
- package/src/hooks/useProductsFood/usetagsProducts.js +83 -83
- package/src/hooks/useProviders/index.js +3 -3
- package/src/hooks/useProviders/queries.js +31 -31
- package/src/hooks/useProviders/useProvidersCreateStore/index.js +12 -13
- package/src/hooks/useProviders/useProvidersDataStore/index.js +24 -24
- package/src/hooks/useProvidersStore/index.js +24 -24
- package/src/hooks/useProvidersStore/queries.js +31 -31
- package/src/hooks/useRatingArrayData/index.js +54 -0
- package/src/hooks/{useRatingData → useRatingArrayData}/queries.js +19 -18
- package/src/hooks/useReactToPrint/index.js +1120 -1098
- package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -23
- package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -48
- package/src/hooks/useReport/index.js +9 -9
- package/src/hooks/useReport/queries.js +1 -1
- package/src/hooks/useRestaurant/index.js +19 -19
- package/src/hooks/useRestaurant/queries.js +80 -80
- package/src/hooks/useSales/index.js +476 -451
- package/src/hooks/useSales/queries.js +14 -15
- package/src/hooks/useSales/useGetAllSales/index.js +25 -25
- package/src/hooks/useSales/useTotalSales.js +18 -18
- package/src/hooks/useSaveAvailableProduct/helpers/index.js +29 -29
- package/src/hooks/useSaveAvailableProduct/index.js +16 -16
- package/src/hooks/useSaveAvailableProduct/queries.js +1 -1
- package/src/hooks/useSchedule/index.js +33 -36
- package/src/hooks/useSchedule/index.jsx +22 -22
- package/src/hooks/useSchedule/queries.js +34 -35
- package/src/hooks/useScheduleData/index.js +123 -171
- package/src/hooks/useScroll/index.js +56 -57
- package/src/hooks/useScrollRotate/index.js +16 -14
- package/src/hooks/useSetSession/index.js +16 -16
- package/src/hooks/useSetState/index.js +3 -3
- package/src/hooks/useStatusOpenStore/helpers/index.js +101 -102
- package/src/hooks/useStatusOpenStore/index.js +172 -173
- package/src/hooks/useStatusOrdersClient/helpers/index.js +14 -0
- package/src/hooks/useStatusOrdersClient/index.js +17 -0
- package/src/hooks/useStatusOrdersClient/queries.js +80 -0
- package/src/hooks/useStore/index.js +40 -25
- package/src/hooks/useStore/queries.js +162 -136
- package/src/hooks/useStoreCalendar/index.js +5 -7
- package/src/hooks/useStoreContacts/index.js +16 -16
- package/src/hooks/useStoreContacts/queries.js +1 -1
- package/src/hooks/useTimeAgo/useTimeAgo.js +39 -39
- package/src/hooks/useUpdateCart/index.js +34 -28
- package/src/hooks/useUpdateExistingOrders/index.js +35 -35
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +38 -37
- package/src/hooks/useUser/index.js +1 -1
- package/src/hooks/useUser/queries.js +1 -1
- package/src/hooks/useWindowSize/index.js +38 -38
- package/src/mock/dessert/index.js +16 -16
- package/src/mock/index.js +1 -2
- package/src/utils/index.js +42 -45
- package/src/hooks/useRatingData/index.js +0 -53
- package/src/hooks/useSalesClient/index.js +0 -1
|
@@ -1,105 +1,107 @@
|
|
|
1
1
|
import {
|
|
2
|
-
from,
|
|
3
2
|
useApolloClient,
|
|
4
3
|
useLazyQuery,
|
|
5
4
|
useMutation
|
|
6
|
-
} from
|
|
5
|
+
} from '@apollo/client'
|
|
7
6
|
import {
|
|
8
7
|
useCallback,
|
|
9
8
|
useEffect,
|
|
10
9
|
useReducer,
|
|
11
10
|
useMemo,
|
|
12
11
|
useState
|
|
13
|
-
} from
|
|
14
|
-
import { Cookies } from
|
|
15
|
-
import { RandomCode, getCurrentDomain } from
|
|
16
|
-
import { useFormatDate } from
|
|
17
|
-
import { useProductsFood } from
|
|
12
|
+
} from 'react'
|
|
13
|
+
import { Cookies } from '../../cookies'
|
|
14
|
+
import { RandomCode, getCurrentDomain } from '../../utils'
|
|
15
|
+
import { useFormatDate } from '../useFormatDate'
|
|
16
|
+
import { useProductsFood } from '../useProductsFood'
|
|
18
17
|
import {
|
|
19
18
|
GET_ALL_EXTRA_PRODUCT,
|
|
20
19
|
GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
|
|
21
|
-
GET_ONE_PRODUCTS_FOOD
|
|
22
|
-
} from
|
|
23
|
-
import { useStore } from
|
|
20
|
+
GET_ONE_PRODUCTS_FOOD
|
|
21
|
+
} from '../useProductsFood/queriesStore'
|
|
22
|
+
import { useStore } from '../useStore'
|
|
24
23
|
import {
|
|
25
24
|
CREATE_SHOPPING_CARD_TO_USER_STORE,
|
|
26
25
|
GET_ALL_COUNT_SALES
|
|
27
|
-
} from
|
|
26
|
+
} from './queries'
|
|
27
|
+
import { updateExistingOrders } from '../useUpdateExistingOrders'
|
|
28
|
+
import { useGetSale } from './useGetSale'
|
|
28
29
|
export * from './useGetAllSales'
|
|
29
|
-
export { GET_ALL_COUNT_SALES }
|
|
30
|
+
export { GET_ALL_COUNT_SALES } from './queries'
|
|
30
31
|
|
|
31
32
|
const initialState = {
|
|
32
33
|
PRODUCT: [],
|
|
33
34
|
totalPrice: 0,
|
|
34
35
|
sortBy: null,
|
|
35
36
|
itemsInCart: 0,
|
|
36
|
-
animateType:
|
|
37
|
-
startAnimateUp:
|
|
37
|
+
animateType: '',
|
|
38
|
+
startAnimateUp: '',
|
|
38
39
|
priceRange: 0,
|
|
39
40
|
counter: 0,
|
|
40
41
|
totalAmount: 0,
|
|
41
|
-
payMethodPState: 0
|
|
42
|
-
}
|
|
42
|
+
payMethodPState: 0
|
|
43
|
+
}
|
|
43
44
|
|
|
44
45
|
const initializer = (initialValue = initialState) => {
|
|
45
46
|
return (
|
|
46
47
|
JSON.parse(
|
|
47
48
|
Cookies.get(process.env.LOCAL_SALES_STORE) || JSON.stringify(initialState)
|
|
48
49
|
) || initialValue
|
|
49
|
-
)
|
|
50
|
-
}
|
|
50
|
+
)
|
|
51
|
+
}
|
|
51
52
|
|
|
52
53
|
export const useSales = ({
|
|
53
54
|
disabled,
|
|
54
55
|
sendNotification,
|
|
55
56
|
router,
|
|
56
|
-
setAlertBox
|
|
57
|
+
setAlertBox
|
|
57
58
|
}) => {
|
|
58
|
-
const domain = getCurrentDomain()
|
|
59
|
-
const [loadingSale, setLoadingSale] = useState(false)
|
|
60
|
-
const [errorSale, setErrorSale] = useState(false)
|
|
61
|
-
const [modalItem, setModalItem] = useState(false)
|
|
62
|
-
const [openCommentModal, setOpenCommentModal] = useState(false)
|
|
63
|
-
const keyToSaveData = process.env.LOCAL_SALES_STORE
|
|
64
|
-
const saveDataState = JSON.parse(Cookies.get(keyToSaveData) ||
|
|
65
|
-
const [search, setSearch] = useState(
|
|
66
|
-
const [arr, setArrayCategory] = useState([])
|
|
67
|
-
const [totalProductPrice, setTotalProductPrice] = useState(0)
|
|
68
|
-
const [showMore, setShowMore] = useState(100)
|
|
69
|
-
const [inputValue, setInputValue] = useState(
|
|
70
|
-
|
|
71
|
-
const [
|
|
72
|
-
const [
|
|
73
|
-
const [
|
|
74
|
-
const [
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const [
|
|
78
|
-
const [
|
|
79
|
-
const [
|
|
80
|
-
const
|
|
59
|
+
const domain = getCurrentDomain()
|
|
60
|
+
const [loadingSale, setLoadingSale] = useState(false)
|
|
61
|
+
const [errorSale, setErrorSale] = useState(false)
|
|
62
|
+
const [modalItem, setModalItem] = useState(false)
|
|
63
|
+
const [openCommentModal, setOpenCommentModal] = useState(false)
|
|
64
|
+
const keyToSaveData = process.env.LOCAL_SALES_STORE
|
|
65
|
+
const saveDataState = JSON.parse(Cookies.get(keyToSaveData) || '[]')
|
|
66
|
+
const [search, setSearch] = useState('')
|
|
67
|
+
const [arr, setArrayCategory] = useState([])
|
|
68
|
+
const [totalProductPrice, setTotalProductPrice] = useState(0)
|
|
69
|
+
const [showMore, setShowMore] = useState(100)
|
|
70
|
+
const [inputValue, setInputValue] = useState('')
|
|
71
|
+
// eslint-disable-next-line no-unused-vars
|
|
72
|
+
const [_, setFilteredList] = useState([])
|
|
73
|
+
const [delivery, setDelivery] = useState(false)
|
|
74
|
+
const [print, setPrint] = useState(false)
|
|
75
|
+
const [values, setValues] = useState({})
|
|
76
|
+
const [dataStore] = useStore()
|
|
77
|
+
const { createdAt } = dataStore || {}
|
|
78
|
+
const [code, setCode] = useState(null)
|
|
79
|
+
const [openCurrentSale, setOpenCurrentSale] = useState(null)
|
|
80
|
+
const [oneProductToComment, setOneProductToComment] = useState({})
|
|
81
|
+
const [sumExtraProducts, setSumExtraProducts] = useState(0)
|
|
82
|
+
const { yearMonthDay } = useFormatDate({ date: createdAt })
|
|
81
83
|
const [valuesDates, setValuesDates] = useState(() => {
|
|
82
|
-
return { fromDate: yearMonthDay, toDate:
|
|
83
|
-
})
|
|
84
|
-
const [loadingExtraProduct, setLoadingExtraProduct] = useState(false)
|
|
85
|
-
const [dataOptional, setDataOptional] = useState([])
|
|
86
|
-
const [dataExtra, setDataExtra] = useState([])
|
|
84
|
+
return { fromDate: yearMonthDay, toDate: '' }
|
|
85
|
+
})
|
|
86
|
+
const [loadingExtraProduct, setLoadingExtraProduct] = useState(false)
|
|
87
|
+
const [dataOptional, setDataOptional] = useState([])
|
|
88
|
+
const [dataExtra, setDataExtra] = useState([])
|
|
87
89
|
|
|
88
90
|
const [registerSalesStore, { loading: loadingRegisterSale }] = useMutation(
|
|
89
91
|
CREATE_SHOPPING_CARD_TO_USER_STORE,
|
|
90
92
|
{
|
|
91
93
|
onCompleted: (data) => {
|
|
92
|
-
const message = `${data?.registerSalesStore?.Response?.message}
|
|
94
|
+
const message = `${data?.registerSalesStore?.Response?.message}`
|
|
93
95
|
const error = data?.registerSalesStore?.Response.success
|
|
94
|
-
?
|
|
95
|
-
:
|
|
96
|
+
? 'Éxito'
|
|
97
|
+
: 'Error'
|
|
96
98
|
sendNotification({
|
|
97
99
|
backgroundColor: error ? 'success' : 'error',
|
|
98
100
|
title: error,
|
|
99
101
|
description: message
|
|
100
|
-
})
|
|
101
|
-
setAlertBox({ message
|
|
102
|
-
setOpenCurrentSale(data?.registerSalesStore?.Response.success)
|
|
102
|
+
})
|
|
103
|
+
setAlertBox({ message, type: 'success' })
|
|
104
|
+
setOpenCurrentSale(data?.registerSalesStore?.Response.success)
|
|
103
105
|
},
|
|
104
106
|
onError: (error) => {
|
|
105
107
|
console.log(error)
|
|
@@ -107,107 +109,107 @@ export const useSales = ({
|
|
|
107
109
|
backgroundColor: 'error',
|
|
108
110
|
title: error || 'Lo sentimo',
|
|
109
111
|
description: 'ha ocurrido un error'
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
+
})
|
|
113
|
+
}
|
|
112
114
|
}
|
|
113
|
-
)
|
|
115
|
+
)
|
|
114
116
|
const [product, setProduct] = useState({
|
|
115
|
-
PRODUCT: {}
|
|
116
|
-
})
|
|
117
|
+
PRODUCT: {}
|
|
118
|
+
})
|
|
117
119
|
const [productFoodsOne, { data: dataProduct }] = useLazyQuery(
|
|
118
120
|
GET_ONE_PRODUCTS_FOOD
|
|
119
|
-
)
|
|
121
|
+
)
|
|
120
122
|
const [ExtProductFoodsSubOptionalAll] = useLazyQuery(
|
|
121
123
|
GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
|
|
122
124
|
{
|
|
123
125
|
onError: () => {
|
|
124
|
-
setDataOptional([])
|
|
125
|
-
}
|
|
126
|
+
setDataOptional([])
|
|
127
|
+
}
|
|
126
128
|
}
|
|
127
|
-
)
|
|
129
|
+
)
|
|
128
130
|
const [ExtProductFoodsAll] = useLazyQuery(GET_ALL_EXTRA_PRODUCT, {
|
|
129
131
|
onError: () => {
|
|
130
|
-
setDataExtra([])
|
|
131
|
-
}
|
|
132
|
-
})
|
|
132
|
+
setDataExtra([])
|
|
133
|
+
}
|
|
134
|
+
})
|
|
133
135
|
const [productsFood, { loading, fetchMore }] = useProductsFood({
|
|
134
|
-
search: search?.length >= 4 ? search :
|
|
136
|
+
search: search?.length >= 4 ? search : '',
|
|
135
137
|
gender: [],
|
|
136
138
|
desc: [],
|
|
137
139
|
categories: arr || [],
|
|
138
140
|
toDate: valuesDates?.toDate,
|
|
139
141
|
fromDate: valuesDates?.fromDate,
|
|
140
142
|
max: showMore,
|
|
141
|
-
min: 0
|
|
142
|
-
})
|
|
143
|
+
min: 0
|
|
144
|
+
})
|
|
143
145
|
const max = productsFood?.reduce(function (a, b) {
|
|
144
|
-
return Math.max(a, b?.ProPrice || 0)
|
|
145
|
-
}, 0)
|
|
146
|
+
return Math.max(a, b?.ProPrice || 0)
|
|
147
|
+
}, 0)
|
|
146
148
|
const initialStateSales = {
|
|
147
149
|
PRODUCT: [],
|
|
148
150
|
totalPrice: 0,
|
|
149
151
|
sortBy: null,
|
|
150
152
|
itemsInCart: 0,
|
|
151
|
-
animateType:
|
|
152
|
-
startAnimateUp:
|
|
153
|
+
animateType: '',
|
|
154
|
+
startAnimateUp: '',
|
|
153
155
|
priceRange: max || 0,
|
|
154
156
|
counter: 0,
|
|
155
157
|
totalAmount: 0,
|
|
156
|
-
payMethodPState: 0
|
|
157
|
-
}
|
|
158
|
+
payMethodPState: 0
|
|
159
|
+
}
|
|
158
160
|
// HANDLESS
|
|
159
161
|
// FILTER PRODUCT DATA_DB
|
|
160
162
|
const handlePrint = ({ callback }) => {
|
|
161
163
|
if (disabled) {
|
|
162
164
|
return sendNotification({
|
|
163
|
-
title:
|
|
164
|
-
description:
|
|
165
|
-
backgroundColor:
|
|
166
|
-
})
|
|
165
|
+
title: 'Error',
|
|
166
|
+
description: 'Esta es la descr',
|
|
167
|
+
backgroundColor: 'error'
|
|
168
|
+
})
|
|
167
169
|
}
|
|
168
|
-
setPrint(!print)
|
|
169
|
-
}
|
|
170
|
+
setPrint(!print)
|
|
171
|
+
}
|
|
170
172
|
const handleChangeFilter = (e) => {
|
|
171
|
-
return setSearch(e.target.value)
|
|
172
|
-
}
|
|
173
|
+
return setSearch(e.target.value)
|
|
174
|
+
}
|
|
173
175
|
const handleChange = (e) => {
|
|
174
|
-
return setValues({ ...values, [e.target.name]: e.target.value })
|
|
175
|
-
}
|
|
176
|
+
return setValues({ ...values, [e.target.name]: e.target.value })
|
|
177
|
+
}
|
|
176
178
|
const onChangeInput = (e) => {
|
|
177
|
-
return setValuesDates({ ...valuesDates, [e.target.name]: e.target.value })
|
|
178
|
-
}
|
|
179
|
+
return setValuesDates({ ...valuesDates, [e.target.name]: e.target.value })
|
|
180
|
+
}
|
|
179
181
|
const handleChangeFilterProduct = (e) => {
|
|
180
|
-
|
|
181
|
-
if (text === undefined || text ===
|
|
182
|
-
return
|
|
182
|
+
const text = searchedInput(e.target.value)
|
|
183
|
+
if (text === undefined || text === '') {
|
|
184
|
+
return
|
|
183
185
|
}
|
|
184
|
-
|
|
185
|
-
setFilteredList(filteredData)
|
|
186
|
-
}
|
|
186
|
+
const filteredData = handleList(text)
|
|
187
|
+
setFilteredList(filteredData)
|
|
188
|
+
}
|
|
187
189
|
const handleComment = (product) => {
|
|
188
190
|
if (product) {
|
|
189
|
-
setOneProductToComment(product)
|
|
191
|
+
setOneProductToComment(product)
|
|
190
192
|
setValues({
|
|
191
193
|
...values,
|
|
192
|
-
comment: product?.comment ||
|
|
193
|
-
})
|
|
194
|
+
comment: product?.comment || ''
|
|
195
|
+
})
|
|
194
196
|
}
|
|
195
|
-
setOpenCommentModal(!openCommentModal)
|
|
196
|
-
}
|
|
197
|
+
setOpenCommentModal(!openCommentModal)
|
|
198
|
+
}
|
|
197
199
|
const handleChangeNumber = useCallback(
|
|
198
200
|
(state, action) => {
|
|
199
|
-
const event = action.payload
|
|
200
|
-
const { value, index, id } = event || {}
|
|
201
|
+
const event = action.payload
|
|
202
|
+
const { value, index, id } = event || {}
|
|
201
203
|
const productExist = productsFood?.find((items) => {
|
|
202
|
-
return items.pId === id
|
|
203
|
-
})
|
|
204
|
+
return items.pId === id
|
|
205
|
+
})
|
|
204
206
|
const OneProduct = state?.PRODUCT.find((items) => {
|
|
205
|
-
return items.pId === id
|
|
206
|
-
})
|
|
207
|
+
return items.pId === id
|
|
208
|
+
})
|
|
207
209
|
if (value <= 0) {
|
|
208
|
-
dispatch({ type:
|
|
210
|
+
dispatch({ type: 'REMOVE_PRODUCT_TO_CART', payload: OneProduct })
|
|
209
211
|
}
|
|
210
|
-
const finalQuantity = (state.PRODUCT
|
|
212
|
+
const finalQuantity = (state.PRODUCT.ProQuantity = value || 0)
|
|
211
213
|
const ARR_PRODUCT = state?.PRODUCT?.map((items, i) => {
|
|
212
214
|
return i === index
|
|
213
215
|
? {
|
|
@@ -215,61 +217,61 @@ export const useSales = ({
|
|
|
215
217
|
ProQuantity: finalQuantity,
|
|
216
218
|
ProPrice: value
|
|
217
219
|
? value * productExist?.ProPrice
|
|
218
|
-
: productExist?.ProPrice
|
|
220
|
+
: productExist?.ProPrice
|
|
219
221
|
}
|
|
220
|
-
: items
|
|
221
|
-
})
|
|
222
|
+
: items
|
|
223
|
+
})
|
|
222
224
|
return {
|
|
223
225
|
...state,
|
|
224
226
|
PRODUCT: ARR_PRODUCT,
|
|
225
|
-
counter: state.counter + 1
|
|
226
|
-
}
|
|
227
|
+
counter: state.counter + 1
|
|
228
|
+
}
|
|
227
229
|
},
|
|
228
230
|
[productsFood]
|
|
229
|
-
)
|
|
231
|
+
)
|
|
230
232
|
const PRODUCT = (state, action) => {
|
|
231
233
|
const productExist = state.PRODUCT.find((items) => {
|
|
232
|
-
return items.pId === action.id
|
|
233
|
-
})
|
|
234
|
+
return items.pId === action.id
|
|
235
|
+
})
|
|
234
236
|
const OurProduct = productsFood?.find((items) => {
|
|
235
|
-
return items.pId === action.id
|
|
236
|
-
})
|
|
237
|
-
const isFree = productExist?.free
|
|
237
|
+
return items.pId === action.id
|
|
238
|
+
})
|
|
239
|
+
const isFree = productExist?.free
|
|
238
240
|
|
|
239
241
|
switch (action.type) {
|
|
240
|
-
case
|
|
241
|
-
return addToCartFunc(state, action)
|
|
242
|
-
case
|
|
242
|
+
case 'ADD_TO_CART':
|
|
243
|
+
return addToCartFunc(state, action)
|
|
244
|
+
case 'ADD_PRODUCT':
|
|
243
245
|
return {
|
|
244
246
|
...state,
|
|
245
247
|
// eslint-disable-next-line
|
|
246
248
|
PRODUCT: [...state?.PRODUCT, action?.payload],
|
|
247
|
-
}
|
|
248
|
-
case
|
|
249
|
-
return removeFunc(state, action)
|
|
250
|
-
case
|
|
249
|
+
}
|
|
250
|
+
case 'REMOVE_PRODUCT':
|
|
251
|
+
return removeFunc(state, action)
|
|
252
|
+
case 'REMOVE_PRODUCT_TO_CART':
|
|
251
253
|
return {
|
|
252
254
|
...state,
|
|
253
255
|
PRODUCT: state?.PRODUCT?.filter((t) => {
|
|
254
|
-
return t.pId !== action?.payload.pId
|
|
256
|
+
return t.pId !== action?.payload.pId
|
|
255
257
|
}),
|
|
256
|
-
counter: state.counter - action.payload.ProQuantity
|
|
257
|
-
}
|
|
258
|
-
case
|
|
259
|
-
return handleChangeNumber(state, action)
|
|
258
|
+
counter: state.counter - action.payload.ProQuantity
|
|
259
|
+
}
|
|
260
|
+
case 'ON_CHANGE': {
|
|
261
|
+
return handleChangeNumber(state, action)
|
|
260
262
|
}
|
|
261
|
-
case
|
|
262
|
-
setValues({})
|
|
263
|
+
case 'REMOVE_ALL_PRODUCTS':
|
|
264
|
+
setValues({})
|
|
263
265
|
return {
|
|
264
266
|
...state,
|
|
265
267
|
PRODUCT: [],
|
|
266
268
|
sortBy: null,
|
|
267
|
-
counter: 0
|
|
268
|
-
}
|
|
269
|
+
counter: 0
|
|
270
|
+
}
|
|
269
271
|
|
|
270
|
-
case
|
|
271
|
-
return toggleFreeProducts(state, action)
|
|
272
|
-
case
|
|
272
|
+
case 'TOGGLE_FREE_PRODUCT':
|
|
273
|
+
return toggleFreeProducts(state, action)
|
|
274
|
+
case 'INCREMENT':
|
|
273
275
|
return {
|
|
274
276
|
...state,
|
|
275
277
|
counter: state.counter + 1,
|
|
@@ -280,25 +282,25 @@ export const useSales = ({
|
|
|
280
282
|
ProQuantity: items.ProQuantity + 1,
|
|
281
283
|
ProPrice: isFree
|
|
282
284
|
? 0
|
|
283
|
-
: (productExist.ProQuantity + 1) * OurProduct?.ProPrice
|
|
285
|
+
: (productExist.ProQuantity + 1) * OurProduct?.ProPrice
|
|
284
286
|
}
|
|
285
|
-
: items
|
|
286
|
-
})
|
|
287
|
-
}
|
|
288
|
-
case
|
|
289
|
-
return commentProducts(state, action)
|
|
290
|
-
case
|
|
291
|
-
return handleUpdateAllExtraAndOptional(state, action)
|
|
292
|
-
case
|
|
287
|
+
: items
|
|
288
|
+
})
|
|
289
|
+
}
|
|
290
|
+
case 'PUT_COMMENT':
|
|
291
|
+
return commentProducts(state, action)
|
|
292
|
+
case 'PUT_EXTRA_PRODUCTS_AND_OPTIONAL_PRODUCT':
|
|
293
|
+
return handleUpdateAllExtraAndOptional(state, action)
|
|
294
|
+
case 'PRICE_RANGE':
|
|
293
295
|
return {
|
|
294
296
|
...state,
|
|
295
|
-
priceRange: action.payload
|
|
296
|
-
}
|
|
297
|
-
case
|
|
298
|
-
return { ...state, sortBy: action.payload }
|
|
299
|
-
case
|
|
297
|
+
priceRange: action.payload
|
|
298
|
+
}
|
|
299
|
+
case 'SORT':
|
|
300
|
+
return { ...state, sortBy: action.payload }
|
|
301
|
+
case 'DECREMENT':
|
|
300
302
|
return {
|
|
301
|
-
...state
|
|
303
|
+
...state
|
|
302
304
|
// counter: state.counter - 1,
|
|
303
305
|
// PRODUCT: state?.PRODUCT?.map((items) => {
|
|
304
306
|
// return items.pId === action.id ? {
|
|
@@ -307,43 +309,44 @@ export const useSales = ({
|
|
|
307
309
|
// // ProPrice: ((productExist.ProQuantity + 1) * OurProduct?.ProPrice),
|
|
308
310
|
// } : items
|
|
309
311
|
// })
|
|
310
|
-
}
|
|
311
|
-
case
|
|
312
|
+
}
|
|
313
|
+
case 'PAYMENT_METHOD_TRANSACTION':
|
|
312
314
|
return {
|
|
313
315
|
...state,
|
|
314
|
-
payMethodPState: 1
|
|
315
|
-
}
|
|
316
|
-
case
|
|
316
|
+
payMethodPState: 1
|
|
317
|
+
}
|
|
318
|
+
case 'PAYMENT_METHOD_MONEY':
|
|
317
319
|
return {
|
|
318
320
|
...state,
|
|
319
|
-
payMethodPState: 0
|
|
320
|
-
}
|
|
321
|
+
payMethodPState: 0
|
|
322
|
+
}
|
|
321
323
|
default:
|
|
322
|
-
return state
|
|
324
|
+
return state
|
|
323
325
|
}
|
|
324
|
-
}
|
|
325
|
-
const [data, dispatch] = useReducer(PRODUCT, initialStateSales, initializer)
|
|
326
|
+
}
|
|
327
|
+
const [data, dispatch] = useReducer(PRODUCT, initialStateSales, initializer)
|
|
326
328
|
const handleRemoveValue = useCallback(({ name, value, pId }) => {
|
|
327
329
|
setValues({
|
|
328
330
|
...values,
|
|
329
|
-
[name]: value ??
|
|
330
|
-
})
|
|
331
|
+
[name]: value ?? ''
|
|
332
|
+
})
|
|
331
333
|
return dispatch({
|
|
332
|
-
type:
|
|
334
|
+
type: 'PUT_COMMENT',
|
|
333
335
|
payload: pId,
|
|
334
|
-
value:
|
|
335
|
-
})
|
|
336
|
-
}, [])
|
|
336
|
+
value: ''
|
|
337
|
+
})
|
|
338
|
+
}, [])
|
|
337
339
|
useEffect(() => {
|
|
338
|
-
Cookies.set(keyToSaveData, JSON.stringify(data), { domain, path:
|
|
339
|
-
}, [data, domain])
|
|
340
|
+
Cookies.set(keyToSaveData, JSON.stringify(data), { domain, path: '/' })
|
|
341
|
+
}, [data, domain])
|
|
340
342
|
|
|
341
|
-
const handleAddOptional = ({ exOptional, codeCategory
|
|
342
|
-
|
|
343
|
-
|
|
343
|
+
const handleAddOptional = ({ exOptional = null, codeCategory = null }) => {
|
|
344
|
+
if (!exOptional || !codeCategory) return
|
|
345
|
+
const item = dataOptional.find((item) => item.code === codeCategory)
|
|
346
|
+
if (!item) return
|
|
344
347
|
const idx = item.ExtProductFoodsSubOptionalAll.findIndex(
|
|
345
348
|
(el) => el.opSubExPid === exOptional
|
|
346
|
-
)
|
|
349
|
+
)
|
|
347
350
|
if (item && idx !== -1) {
|
|
348
351
|
const updatedItem = {
|
|
349
352
|
...item,
|
|
@@ -351,19 +354,19 @@ export const useSales = ({
|
|
|
351
354
|
...item.ExtProductFoodsSubOptionalAll.slice(0, idx),
|
|
352
355
|
{
|
|
353
356
|
...item.ExtProductFoodsSubOptionalAll[idx],
|
|
354
|
-
check: !item.ExtProductFoodsSubOptionalAll[idx].check
|
|
357
|
+
check: !item.ExtProductFoodsSubOptionalAll[idx].check
|
|
355
358
|
},
|
|
356
|
-
...item.ExtProductFoodsSubOptionalAll.slice(idx + 1)
|
|
357
|
-
]
|
|
358
|
-
}
|
|
359
|
+
...item.ExtProductFoodsSubOptionalAll.slice(idx + 1)
|
|
360
|
+
]
|
|
361
|
+
}
|
|
359
362
|
const newData = dataOptional.map((el) =>
|
|
360
363
|
el.code === codeCategory ? updatedItem : el
|
|
361
|
-
)
|
|
362
|
-
setDataOptional((prevData) => [...newData])
|
|
364
|
+
)
|
|
365
|
+
setDataOptional((prevData) => [...newData])
|
|
363
366
|
}
|
|
364
|
-
}
|
|
367
|
+
}
|
|
365
368
|
|
|
366
|
-
function handleUpdateAllExtraAndOptional(state, action) {
|
|
369
|
+
function handleUpdateAllExtraAndOptional (state, action) {
|
|
367
370
|
return {
|
|
368
371
|
...state,
|
|
369
372
|
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
@@ -371,11 +374,11 @@ export const useSales = ({
|
|
|
371
374
|
? {
|
|
372
375
|
...items,
|
|
373
376
|
dataOptional: action.dataOptional || [],
|
|
374
|
-
dataExtra: action.dataExtra || []
|
|
377
|
+
dataExtra: action.dataExtra || []
|
|
375
378
|
}
|
|
376
|
-
: items
|
|
377
|
-
})
|
|
378
|
-
}
|
|
379
|
+
: items
|
|
380
|
+
})
|
|
381
|
+
}
|
|
379
382
|
}
|
|
380
383
|
|
|
381
384
|
/**
|
|
@@ -386,110 +389,111 @@ export const useSales = ({
|
|
|
386
389
|
const arr =
|
|
387
390
|
dataExtra?.length > 0
|
|
388
391
|
? dataExtra?.filter((p) => {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
: []
|
|
392
|
-
const val = arr.findIndex((item) => item.quantity !== 0)
|
|
392
|
+
return p.quantity !== 0
|
|
393
|
+
})
|
|
394
|
+
: []
|
|
395
|
+
const val = arr.findIndex((item) => item.quantity !== 0)
|
|
393
396
|
if (val === -1) {
|
|
394
|
-
setSumExtraProducts(0)
|
|
397
|
+
setSumExtraProducts(0)
|
|
395
398
|
}
|
|
396
|
-
function sumNewExtraPrice() {
|
|
397
|
-
let sum = 0
|
|
399
|
+
function sumNewExtraPrice () {
|
|
400
|
+
let sum = 0
|
|
398
401
|
arr.forEach((obj) => {
|
|
399
|
-
sum += obj.newExtraPrice ?? 0
|
|
400
|
-
})
|
|
402
|
+
sum += obj.newExtraPrice ?? 0
|
|
403
|
+
})
|
|
401
404
|
if (arr.length === 0) {
|
|
402
|
-
setSumExtraProducts(0)
|
|
405
|
+
setSumExtraProducts(0)
|
|
403
406
|
}
|
|
404
|
-
setSumExtraProducts(sum)
|
|
405
|
-
return sum
|
|
407
|
+
setSumExtraProducts(sum)
|
|
408
|
+
return sum
|
|
406
409
|
}
|
|
407
410
|
if (arr.length > 0) {
|
|
408
|
-
sumNewExtraPrice()
|
|
411
|
+
sumNewExtraPrice()
|
|
409
412
|
}
|
|
410
|
-
}, [dataExtra])
|
|
413
|
+
}, [dataExtra])
|
|
411
414
|
|
|
412
|
-
function handleUpdateAllExtra() {
|
|
415
|
+
function handleUpdateAllExtra () {
|
|
413
416
|
try {
|
|
414
417
|
if (!product?.PRODUCT?.pId) {
|
|
415
418
|
return sendNotification({
|
|
416
|
-
title:
|
|
419
|
+
title: 'Error',
|
|
417
420
|
backgroundColor: 'error',
|
|
418
|
-
description:
|
|
419
|
-
})
|
|
421
|
+
description: 'No se puede actualizar el producto sin pId'
|
|
422
|
+
})
|
|
420
423
|
}
|
|
421
424
|
const filteredDataOptional = dataOptional
|
|
422
425
|
.map((obj) => {
|
|
423
426
|
const filteredSubOptions = obj.ExtProductFoodsSubOptionalAll.filter(
|
|
424
427
|
(subObj) => subObj.check === true
|
|
425
|
-
)
|
|
428
|
+
)
|
|
426
429
|
// Excluya todo el objeto padre si filteredSubOptions está vacío
|
|
427
430
|
if (filteredSubOptions.length === 0) {
|
|
428
|
-
return null
|
|
431
|
+
return null
|
|
429
432
|
}
|
|
430
|
-
return { ...obj, ExtProductFoodsSubOptionalAll: filteredSubOptions }
|
|
433
|
+
return { ...obj, ExtProductFoodsSubOptionalAll: filteredSubOptions }
|
|
431
434
|
})
|
|
432
|
-
.filter((obj) => obj !== null)
|
|
433
|
-
const filteredDataExtra = dataExtra.filter((p) => p.quantity !== 0)
|
|
435
|
+
.filter((obj) => obj !== null) // Elimine todos los objetos nulos del arreglo
|
|
436
|
+
const filteredDataExtra = dataExtra.filter((p) => p.quantity !== 0)
|
|
434
437
|
dispatch({
|
|
435
|
-
type:
|
|
438
|
+
type: 'PUT_EXTRA_PRODUCTS_AND_OPTIONAL_PRODUCT',
|
|
436
439
|
payload: product.PRODUCT.pId,
|
|
437
440
|
dataOptional: filteredDataOptional,
|
|
438
|
-
dataExtra: filteredDataExtra
|
|
439
|
-
})
|
|
441
|
+
dataExtra: filteredDataExtra
|
|
442
|
+
})
|
|
440
443
|
} catch (_error) {
|
|
441
444
|
return sendNotification({
|
|
442
|
-
title:
|
|
445
|
+
title: 'Error',
|
|
443
446
|
backgroundColor: 'error',
|
|
444
|
-
description:
|
|
445
|
-
})
|
|
447
|
+
description: 'No se puedo actualizar el producto'
|
|
448
|
+
})
|
|
446
449
|
}
|
|
447
450
|
}
|
|
448
451
|
|
|
449
|
-
function handleIncrementExtra({ Adicionales, index }) {
|
|
450
|
-
const { pId } = product?.PRODUCT || {}
|
|
451
|
-
const exPid = Adicionales.exPid || null
|
|
452
|
+
function handleIncrementExtra ({ Adicionales, index }) {
|
|
453
|
+
const { pId } = product?.PRODUCT || {}
|
|
454
|
+
const exPid = Adicionales.exPid || null
|
|
452
455
|
if (exPid && pId) {
|
|
453
456
|
const newExtra = dataExtra.map((producto) => {
|
|
454
457
|
if (exPid === producto.exPid) {
|
|
455
|
-
const initialQuantity = producto?.quantity ? producto?.quantity : 0
|
|
458
|
+
const initialQuantity = producto?.quantity ? producto?.quantity : 0
|
|
456
459
|
return {
|
|
457
460
|
...producto,
|
|
458
461
|
quantity: initialQuantity + 1,
|
|
459
|
-
newExtraPrice: producto.extraPrice * (initialQuantity + 1)
|
|
460
|
-
}
|
|
462
|
+
newExtraPrice: producto.extraPrice * (initialQuantity + 1)
|
|
463
|
+
}
|
|
461
464
|
}
|
|
462
|
-
return producto
|
|
463
|
-
})
|
|
464
|
-
return setDataExtra(newExtra)
|
|
465
|
+
return producto
|
|
466
|
+
})
|
|
467
|
+
return setDataExtra(newExtra)
|
|
465
468
|
}
|
|
466
469
|
}
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
const
|
|
470
|
+
|
|
471
|
+
function handleDecrementExtra ({ Adicionales, index }) {
|
|
472
|
+
const { pId } = product?.PRODUCT || {}
|
|
473
|
+
const exPid = Adicionales.exPid || null
|
|
470
474
|
|
|
471
475
|
// Comprobar que el objeto Adicionales existe en dataExtra
|
|
472
|
-
const extraIndex = dataExtra.findIndex((extra) => extra.exPid === exPid)
|
|
476
|
+
const extraIndex = dataExtra.findIndex((extra) => extra.exPid === exPid)
|
|
473
477
|
if (extraIndex === -1) {
|
|
474
|
-
return
|
|
478
|
+
return
|
|
475
479
|
}
|
|
476
480
|
|
|
477
481
|
if (pId && exPid) {
|
|
478
482
|
const newExtra = dataExtra.map((producto, i) => {
|
|
479
483
|
if (exPid === producto.exPid) {
|
|
480
|
-
const initialQuantity = producto?.quantity
|
|
484
|
+
const initialQuantity = producto?.quantity
|
|
481
485
|
return {
|
|
482
486
|
...producto,
|
|
483
487
|
quantity: initialQuantity - 1,
|
|
484
|
-
newExtraPrice: producto.extraPrice * (initialQuantity - 1)
|
|
485
|
-
}
|
|
488
|
+
newExtraPrice: producto.extraPrice * (initialQuantity - 1)
|
|
489
|
+
}
|
|
486
490
|
}
|
|
487
|
-
return producto
|
|
488
|
-
})
|
|
489
|
-
setDataExtra(newExtra)
|
|
491
|
+
return producto
|
|
492
|
+
})
|
|
493
|
+
setDataExtra(newExtra)
|
|
490
494
|
}
|
|
491
495
|
}
|
|
492
|
-
/**
|
|
496
|
+
/**
|
|
493
497
|
* Agrega un producto al carrito de compras.
|
|
494
498
|
* @param {Object} state - Estado actual del carrito.
|
|
495
499
|
* @param {Object} action - Acción que contiene los datos del producto a agregar.
|
|
@@ -501,12 +505,12 @@ export const useSales = ({
|
|
|
501
505
|
* @param {number} action.payload.ProPrice - Precio del producto.
|
|
502
506
|
* @returns {Object} Nuevo estado del carrito con el producto agregado.
|
|
503
507
|
*/
|
|
504
|
-
function addToCartFunc(state, action) {
|
|
505
|
-
const { pId, pName, getOneTags, ProDescription, ProImage, ProPrice } = action.payload
|
|
508
|
+
function addToCartFunc (state, action) {
|
|
509
|
+
const { pId, pName, getOneTags, ProDescription, ProImage, ProPrice } = action.payload
|
|
506
510
|
|
|
507
|
-
const productExist = state.PRODUCT.find((item) => item.pId === pId)
|
|
508
|
-
const OurProduct = productsFood.find((item) => item.pId === pId)
|
|
509
|
-
const isFree = productExist?.free
|
|
511
|
+
const productExist = state.PRODUCT.find((item) => item.pId === pId)
|
|
512
|
+
const OurProduct = productsFood.find((item) => item.pId === pId)
|
|
513
|
+
const isFree = productExist?.free
|
|
510
514
|
|
|
511
515
|
const updatedProduct = {
|
|
512
516
|
pId,
|
|
@@ -516,24 +520,24 @@ export const useSales = ({
|
|
|
516
520
|
ProDescription,
|
|
517
521
|
ProImage,
|
|
518
522
|
ProPrice,
|
|
519
|
-
ProQuantity: 1
|
|
520
|
-
}
|
|
523
|
+
ProQuantity: 1
|
|
524
|
+
}
|
|
521
525
|
|
|
522
526
|
if (!productExist) {
|
|
523
527
|
return {
|
|
524
528
|
...state,
|
|
525
529
|
counter: state.counter + 1,
|
|
526
530
|
totalAmount: state.totalAmount + ProPrice,
|
|
527
|
-
startAnimateUp:
|
|
528
|
-
PRODUCT: [...state.PRODUCT, updatedProduct]
|
|
529
|
-
}
|
|
531
|
+
startAnimateUp: 'start-animate-up',
|
|
532
|
+
PRODUCT: [...state.PRODUCT, updatedProduct]
|
|
533
|
+
}
|
|
530
534
|
}
|
|
531
|
-
|
|
535
|
+
|
|
532
536
|
return {
|
|
533
537
|
...state,
|
|
534
538
|
counter: state.counter + 1,
|
|
535
539
|
totalAmount: state.totalAmount + ProPrice,
|
|
536
|
-
startAnimateUp:
|
|
540
|
+
startAnimateUp: 'start-animate-up',
|
|
537
541
|
PRODUCT: state.PRODUCT.map((item) => {
|
|
538
542
|
if (item.pId === pId) {
|
|
539
543
|
return {
|
|
@@ -542,21 +546,21 @@ export const useSales = ({
|
|
|
542
546
|
unitPrice: OurProduct?.ProPrice,
|
|
543
547
|
ProPrice: isFree ? 0 : (productExist.ProQuantity + 1) * OurProduct?.ProPrice,
|
|
544
548
|
ProQuantity: productExist.ProQuantity + 1,
|
|
545
|
-
free: isFree
|
|
546
|
-
}
|
|
549
|
+
free: !!isFree
|
|
550
|
+
}
|
|
547
551
|
}
|
|
548
|
-
return item
|
|
549
|
-
})
|
|
550
|
-
}
|
|
552
|
+
return item
|
|
553
|
+
})
|
|
554
|
+
}
|
|
551
555
|
}
|
|
552
|
-
|
|
553
|
-
function removeFunc(state, action) {
|
|
556
|
+
|
|
557
|
+
function removeFunc (state, action) {
|
|
554
558
|
const productExist = state.PRODUCT.find((items) => {
|
|
555
|
-
return items.pId === action.payload.pId
|
|
556
|
-
})
|
|
559
|
+
return items.pId === action.payload.pId
|
|
560
|
+
})
|
|
557
561
|
const OurProduct = productsFood.find((items) => {
|
|
558
|
-
return items.pId === action.payload.pId
|
|
559
|
-
})
|
|
562
|
+
return items.pId === action.payload.pId
|
|
563
|
+
})
|
|
560
564
|
return {
|
|
561
565
|
...state,
|
|
562
566
|
counter: state.counter - 1,
|
|
@@ -564,26 +568,26 @@ export const useSales = ({
|
|
|
564
568
|
PRODUCT:
|
|
565
569
|
action.payload.ProQuantity > 1
|
|
566
570
|
? state.PRODUCT.map((items) => {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
571
|
+
return items.pId === action.payload.pId
|
|
572
|
+
? {
|
|
573
|
+
...items,
|
|
574
|
+
pId: action.payload.pId,
|
|
575
|
+
ProQuantity: items.ProQuantity - 1,
|
|
576
|
+
ProPrice: productExist.ProPrice - OurProduct?.ProPrice
|
|
577
|
+
}
|
|
578
|
+
: items
|
|
579
|
+
})
|
|
576
580
|
: state.PRODUCT.filter((items) => {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
581
|
+
return items.pId !== action.payload.pId
|
|
582
|
+
})
|
|
583
|
+
}
|
|
580
584
|
}
|
|
581
585
|
|
|
582
586
|
// TOGGLE_FREE_PRODUCT
|
|
583
|
-
function toggleFreeProducts(state, action) {
|
|
587
|
+
function toggleFreeProducts (state, action) {
|
|
584
588
|
const productExist = productsFood.find((items) => {
|
|
585
|
-
return items.pId === action.payload.pId
|
|
586
|
-
})
|
|
589
|
+
return items.pId === action.payload.pId
|
|
590
|
+
})
|
|
587
591
|
return {
|
|
588
592
|
...state,
|
|
589
593
|
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
@@ -593,178 +597,179 @@ export const useSales = ({
|
|
|
593
597
|
free: !items.free,
|
|
594
598
|
ProPrice: items.ProPrice
|
|
595
599
|
? 0
|
|
596
|
-
: items.ProQuantity * productExist?.ProPrice
|
|
600
|
+
: items.ProQuantity * productExist?.ProPrice
|
|
597
601
|
}
|
|
598
|
-
: items
|
|
599
|
-
})
|
|
600
|
-
}
|
|
602
|
+
: items
|
|
603
|
+
})
|
|
604
|
+
}
|
|
601
605
|
}
|
|
602
606
|
|
|
603
607
|
// COMMENT_FREE_PRODUCT
|
|
604
|
-
function commentProducts(state, action, deleteValue) {
|
|
608
|
+
function commentProducts (state, action, deleteValue) {
|
|
605
609
|
return {
|
|
606
610
|
...state,
|
|
607
611
|
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
608
612
|
return items.pId === action.payload
|
|
609
613
|
? {
|
|
610
614
|
...items,
|
|
611
|
-
comment: deleteValue ?
|
|
615
|
+
comment: deleteValue ? '' : values.comment
|
|
612
616
|
}
|
|
613
|
-
: items
|
|
614
|
-
})
|
|
615
|
-
}
|
|
617
|
+
: items
|
|
618
|
+
})
|
|
619
|
+
}
|
|
616
620
|
}
|
|
617
621
|
|
|
618
622
|
const getSortedProduct = useCallback((data, sort) => {
|
|
619
|
-
if (sort && sort ===
|
|
623
|
+
if (sort && sort === 'PRICE_HIGH_TO_LOW') {
|
|
620
624
|
return data.sort((a, b) => {
|
|
621
|
-
return b
|
|
622
|
-
})
|
|
625
|
+
return b.ProPrice - a.ProPrice
|
|
626
|
+
})
|
|
623
627
|
}
|
|
624
|
-
if (sort && sort ===
|
|
628
|
+
if (sort && sort === 'PRICE_LOW_TO_HIGH') {
|
|
625
629
|
return data.sort((a, b) => {
|
|
626
|
-
return a
|
|
627
|
-
})
|
|
630
|
+
return a.ProPrice - b.ProPrice
|
|
631
|
+
})
|
|
628
632
|
}
|
|
629
|
-
return data
|
|
633
|
+
return data
|
|
630
634
|
}, [])
|
|
631
635
|
|
|
632
636
|
const PriceRangeFunc = (products, price) => {
|
|
633
637
|
return (
|
|
634
638
|
products?.length > 0 &&
|
|
635
639
|
products?.filter((items) => {
|
|
636
|
-
return items?.ProPrice >= price
|
|
640
|
+
return items?.ProPrice >= price
|
|
637
641
|
})
|
|
638
|
-
)
|
|
639
|
-
}
|
|
642
|
+
)
|
|
643
|
+
}
|
|
640
644
|
|
|
641
645
|
const sortedProduct = useMemo(() => {
|
|
642
|
-
return getSortedProduct(data.PRODUCT, data.sortBy)
|
|
646
|
+
return getSortedProduct(data.PRODUCT, data.sortBy)
|
|
643
647
|
}, [data.PRODUCT, data.sortBy, getSortedProduct])
|
|
644
|
-
const finalFilter = PriceRangeFunc(sortedProduct, data.priceRange)
|
|
648
|
+
const finalFilter = PriceRangeFunc(sortedProduct, data.priceRange)
|
|
645
649
|
|
|
646
650
|
const handleList = (text) => {
|
|
647
|
-
|
|
648
|
-
let dataList = []
|
|
651
|
+
const inputText = text.toLowerCase()
|
|
652
|
+
let dataList = []
|
|
649
653
|
dataList = finalFilter.filter((item) => {
|
|
650
|
-
return item.pName.toLowerCase().includes(inputText)
|
|
651
|
-
})
|
|
652
|
-
return dataList
|
|
653
|
-
}
|
|
654
|
+
return item.pName.toLowerCase().includes(inputText)
|
|
655
|
+
})
|
|
656
|
+
return dataList
|
|
657
|
+
}
|
|
654
658
|
const searchedInput = (words) => {
|
|
655
|
-
setInputValue(words)
|
|
656
|
-
|
|
659
|
+
setInputValue(words)
|
|
660
|
+
const n = words.split(' ')
|
|
657
661
|
if (n.length !== 0) {
|
|
658
|
-
if (n[n.length - 1] ===
|
|
659
|
-
n.pop()
|
|
662
|
+
if (n[n.length - 1] === '') {
|
|
663
|
+
n.pop()
|
|
660
664
|
}
|
|
661
|
-
return n[n.length - 1]
|
|
665
|
+
return n[n.length - 1]
|
|
662
666
|
}
|
|
663
|
-
return
|
|
664
|
-
}
|
|
667
|
+
return ''
|
|
668
|
+
}
|
|
665
669
|
const arrayProduct =
|
|
666
670
|
data?.PRODUCT?.length > 0
|
|
667
671
|
? data?.PRODUCT?.map((product) => {
|
|
668
|
-
|
|
669
|
-
product?.dataExtra?.map(({ __typename, ...rest }) => rest) ?? []
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
};
|
|
672
|
+
const filteredDataExtra =
|
|
673
|
+
product?.dataExtra?.map(({ __typename, ...rest }) => rest) ?? []
|
|
674
|
+
const dataOptional = product?.dataOptional?.map(
|
|
675
|
+
({ __typename, ...product }) => {
|
|
676
|
+
const { ExtProductFoodsSubOptionalAll, ...rest } = product
|
|
677
|
+
const adjustedSubOptionalAll = ExtProductFoodsSubOptionalAll?.map(
|
|
678
|
+
(subOption) => {
|
|
679
|
+
const { __typename, ...subOptionRest } = subOption
|
|
680
|
+
return subOptionRest
|
|
681
|
+
}
|
|
682
|
+
)
|
|
683
|
+
return {
|
|
684
|
+
...rest,
|
|
685
|
+
ExtProductFoodsSubOptionalAll: adjustedSubOptionalAll
|
|
683
686
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
}
|
|
699
|
-
|
|
687
|
+
}
|
|
688
|
+
)
|
|
689
|
+
const refCodePid = RandomCode(20)
|
|
690
|
+
return {
|
|
691
|
+
pId: product?.pId,
|
|
692
|
+
refCodePid,
|
|
693
|
+
id: values?.cliId,
|
|
694
|
+
cantProducts: parseInt(
|
|
695
|
+
product?.ProQuantity ? product?.ProQuantity : 0
|
|
696
|
+
),
|
|
697
|
+
comments: product?.comment ?? '',
|
|
698
|
+
dataOptional: dataOptional ?? [],
|
|
699
|
+
dataExtra: filteredDataExtra || [],
|
|
700
|
+
ProPrice: product.ProPrice
|
|
701
|
+
}
|
|
702
|
+
})
|
|
703
|
+
: []
|
|
700
704
|
const finalArrayProduct = arrayProduct.map((item) => {
|
|
701
705
|
const totalExtra = item.dataExtra.reduce(
|
|
702
706
|
(accumulator, extra) => accumulator + extra.newExtraPrice,
|
|
703
707
|
0
|
|
704
|
-
)
|
|
705
|
-
return { ...item, totalExtra }
|
|
706
|
-
})
|
|
708
|
+
)
|
|
709
|
+
return { ...item, totalExtra }
|
|
710
|
+
})
|
|
707
711
|
|
|
708
|
-
let totalSale = 0
|
|
709
|
-
function sumProPriceAndTotalExtra(data) {
|
|
712
|
+
let totalSale = 0
|
|
713
|
+
function sumProPriceAndTotalExtra (data) {
|
|
710
714
|
return data.map((item) => {
|
|
711
715
|
const totalExtra = item.dataExtra.reduce((acc, curr) => {
|
|
712
|
-
const newExtraPrice = parseFloat(curr.newExtraPrice)
|
|
716
|
+
const newExtraPrice = parseFloat(curr.newExtraPrice)
|
|
713
717
|
if (isNaN(newExtraPrice)) {
|
|
714
|
-
return acc
|
|
718
|
+
return acc
|
|
715
719
|
}
|
|
716
|
-
return acc + newExtraPrice
|
|
717
|
-
}, 0)
|
|
718
|
-
const total = item.ProPrice + totalExtra
|
|
719
|
-
return { ...item, totalExtra, total }
|
|
720
|
-
})
|
|
720
|
+
return acc + newExtraPrice
|
|
721
|
+
}, 0)
|
|
722
|
+
const total = item.ProPrice + totalExtra
|
|
723
|
+
return { ...item, totalExtra, total }
|
|
724
|
+
})
|
|
721
725
|
}
|
|
722
726
|
useEffect(() => {
|
|
723
|
-
const dataCountTotal = sumProPriceAndTotalExtra(finalArrayProduct)
|
|
727
|
+
const dataCountTotal = sumProPriceAndTotalExtra(finalArrayProduct)
|
|
724
728
|
dataCountTotal.forEach((a) => {
|
|
725
|
-
const { total } = a || {}
|
|
726
|
-
totalSale += total
|
|
727
|
-
setTotalProductPrice(Math.abs(totalSale))
|
|
728
|
-
})
|
|
729
|
+
const { total } = a || {}
|
|
730
|
+
totalSale += total
|
|
731
|
+
setTotalProductPrice(Math.abs(totalSale))
|
|
732
|
+
})
|
|
729
733
|
if (data.PRODUCT.length === 0) {
|
|
730
|
-
setTotalProductPrice(0)
|
|
734
|
+
setTotalProductPrice(0)
|
|
731
735
|
}
|
|
732
|
-
}, [totalProductPrice, totalSale, data, finalArrayProduct])
|
|
736
|
+
}, [totalProductPrice, totalSale, data, finalArrayProduct])
|
|
733
737
|
|
|
734
738
|
const [discount, setDiscount] = useState({
|
|
735
739
|
price: totalProductPrice || 0,
|
|
736
|
-
discount: 0
|
|
737
|
-
})
|
|
738
|
-
function applyDiscount(percentage) {
|
|
740
|
+
discount: 0
|
|
741
|
+
})
|
|
742
|
+
function applyDiscount (percentage) {
|
|
739
743
|
const validateCondition =
|
|
740
|
-
isNaN(percentage) || percentage < 0 || percentage > 100
|
|
744
|
+
isNaN(percentage) || percentage < 0 || percentage > 100
|
|
741
745
|
|
|
742
746
|
if (validateCondition) {
|
|
743
747
|
return sendNotification({
|
|
744
|
-
title:
|
|
748
|
+
title: 'Error',
|
|
745
749
|
backgroundColor: 'error',
|
|
746
|
-
description:
|
|
747
|
-
})
|
|
750
|
+
description: 'el descuento debe ser un número entre 0 y 100%'
|
|
751
|
+
})
|
|
748
752
|
}
|
|
749
|
-
const decimal = parseFloat(percentage) / 100
|
|
750
|
-
const result = decimal * parseFloat(totalProductPrice)
|
|
751
|
-
setDiscount({ price: result, discount: percentage })
|
|
753
|
+
const decimal = parseFloat(percentage) / 100
|
|
754
|
+
const result = decimal * parseFloat(totalProductPrice)
|
|
755
|
+
setDiscount({ price: result, discount: percentage })
|
|
752
756
|
|
|
753
|
-
return { price: result, discount: percentage }
|
|
757
|
+
return { price: result, discount: percentage }
|
|
754
758
|
}
|
|
755
|
-
const totalProductsPrice = totalProductPrice
|
|
759
|
+
const totalProductsPrice = totalProductPrice
|
|
756
760
|
const client = useApolloClient()
|
|
757
|
-
|
|
761
|
+
const { getOnePedidoStore } = useGetSale()
|
|
758
762
|
const handleSubmit = () => {
|
|
759
|
-
if (!values?.cliId)
|
|
763
|
+
if (!values?.cliId) {
|
|
760
764
|
return sendNotification({
|
|
761
|
-
title:
|
|
765
|
+
title: 'Error',
|
|
762
766
|
backgroundColor: 'error',
|
|
763
|
-
description:
|
|
764
|
-
})
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
767
|
+
description: 'Elije primero un cliente'
|
|
768
|
+
})
|
|
769
|
+
}
|
|
770
|
+
setLoadingSale(true)
|
|
771
|
+
const code = RandomCode(10)
|
|
772
|
+
setCode(code)
|
|
768
773
|
return registerSalesStore({
|
|
769
774
|
variables: {
|
|
770
775
|
input: finalArrayProduct || [],
|
|
@@ -775,14 +780,14 @@ export const useSales = ({
|
|
|
775
780
|
payMethodPState: data.payMethodPState,
|
|
776
781
|
pickUp: 1,
|
|
777
782
|
discount: discount.discount || 0,
|
|
778
|
-
totalProductsPrice: totalProductsPrice || 0
|
|
783
|
+
totalProductsPrice: totalProductsPrice || 0
|
|
779
784
|
}
|
|
780
785
|
})
|
|
781
786
|
.then((responseRegisterR) => {
|
|
782
787
|
if (responseRegisterR) {
|
|
783
|
-
const { data } = responseRegisterR || {}
|
|
784
|
-
const { registerSalesStore } = data || {}
|
|
785
|
-
const { Response } = registerSalesStore || {}
|
|
788
|
+
const { data } = responseRegisterR || {}
|
|
789
|
+
const { registerSalesStore } = data || {}
|
|
790
|
+
const { Response } = registerSalesStore || {}
|
|
786
791
|
if (Response && Response.success === true) {
|
|
787
792
|
// dispatch({ type: 'REMOVE_ALL_PRODUCTS' })
|
|
788
793
|
client.query({
|
|
@@ -792,65 +797,85 @@ export const useSales = ({
|
|
|
792
797
|
client.writeQuery({ query: GET_ALL_COUNT_SALES, data: { getTodaySales: data.countSales.todaySales } })
|
|
793
798
|
}
|
|
794
799
|
})
|
|
800
|
+
getOnePedidoStore({
|
|
801
|
+
variables: {
|
|
802
|
+
pCodeRef: code || ''
|
|
803
|
+
}
|
|
804
|
+
}).then((responseSale) => {
|
|
805
|
+
if (responseSale?.data?.getOnePedidoStore) {
|
|
806
|
+
const currentSale = responseSale?.data?.getOnePedidoStore || {}
|
|
807
|
+
const inComingCodeRef = currentSale?.pCodeRef || null
|
|
808
|
+
if (!inComingCodeRef) return
|
|
809
|
+
client.cache.modify({
|
|
810
|
+
fields: {
|
|
811
|
+
getAllOrdersFromStore (existingOrders = []) {
|
|
812
|
+
try {
|
|
813
|
+
return updateExistingOrders(existingOrders, inComingCodeRef, 1, currentSale)
|
|
814
|
+
} catch (e) {
|
|
815
|
+
return existingOrders
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
})
|
|
820
|
+
}
|
|
821
|
+
})
|
|
795
822
|
router.push(
|
|
796
823
|
{
|
|
797
824
|
query: {
|
|
798
825
|
...router.query,
|
|
799
|
-
saleId: code
|
|
800
|
-
}
|
|
826
|
+
saleId: code
|
|
827
|
+
}
|
|
801
828
|
},
|
|
802
829
|
undefined,
|
|
803
830
|
{ shallow: true }
|
|
804
|
-
)
|
|
805
|
-
|
|
831
|
+
)
|
|
832
|
+
setValues({})
|
|
806
833
|
}
|
|
807
834
|
}
|
|
808
|
-
setLoadingSale(false)
|
|
835
|
+
setLoadingSale(false)
|
|
809
836
|
})
|
|
810
837
|
.catch(() => {
|
|
811
|
-
setLoadingSale(false)
|
|
812
|
-
setErrorSale(true)
|
|
838
|
+
setLoadingSale(false)
|
|
839
|
+
setErrorSale(true)
|
|
813
840
|
})
|
|
814
841
|
.finally(() => {
|
|
815
|
-
setLoadingSale(false)
|
|
816
|
-
})
|
|
817
|
-
}
|
|
818
|
-
let suma = 0;
|
|
819
|
-
let total = 0;
|
|
842
|
+
setLoadingSale(false)
|
|
843
|
+
})
|
|
844
|
+
}
|
|
820
845
|
|
|
821
846
|
const handleProduct = async (PRODUCT) => {
|
|
822
|
-
setLoadingExtraProduct(true)
|
|
823
|
-
const { pId } = PRODUCT || {}
|
|
847
|
+
setLoadingExtraProduct(true)
|
|
848
|
+
const { pId } = PRODUCT || {}
|
|
824
849
|
try {
|
|
825
850
|
const originalArray = data.PRODUCT.find((item) => {
|
|
826
|
-
return item.pId === pId
|
|
827
|
-
})
|
|
851
|
+
return item.pId === pId
|
|
852
|
+
})
|
|
828
853
|
// OPTIONAL
|
|
829
|
-
productFoodsOne({ variables: { pId } })
|
|
854
|
+
productFoodsOne({ variables: { pId } })
|
|
830
855
|
const optionalAll = await ExtProductFoodsSubOptionalAll({
|
|
831
|
-
variables: { pId }
|
|
832
|
-
})
|
|
833
|
-
const optionalFetch = optionalAll.data.ExtProductFoodsOptionalAll
|
|
834
|
-
setDataOptional(optionalFetch || [])
|
|
835
|
-
const existOptionalCookies = originalArray?.dataOptional
|
|
856
|
+
variables: { pId }
|
|
857
|
+
})
|
|
858
|
+
const optionalFetch = optionalAll.data.ExtProductFoodsOptionalAll
|
|
859
|
+
setDataOptional(optionalFetch || [])
|
|
860
|
+
const existOptionalCookies = originalArray?.dataOptional
|
|
836
861
|
const filteredDataOptional = existOptionalCookies?.length
|
|
837
862
|
? existOptionalCookies
|
|
838
|
-
|
|
839
|
-
|
|
863
|
+
?.map((obj) => {
|
|
864
|
+
const filteredSubOptions =
|
|
840
865
|
obj.ExtProductFoodsSubOptionalAll.filter(
|
|
841
866
|
(subObj) => subObj.check === true
|
|
842
|
-
)
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
: []
|
|
867
|
+
)
|
|
868
|
+
// Excluya todo el objeto padre si filteredSubOptions está vacío
|
|
869
|
+
if (filteredSubOptions.length === 0) {
|
|
870
|
+
return null
|
|
871
|
+
}
|
|
872
|
+
return {
|
|
873
|
+
...obj,
|
|
874
|
+
ExtProductFoodsSubOptionalAll: filteredSubOptions
|
|
875
|
+
}
|
|
876
|
+
})
|
|
877
|
+
.filter((obj) => obj !== null)
|
|
878
|
+
: []
|
|
854
879
|
|
|
855
880
|
// Actualizar optionalAll.data.ExtProductFoodsSubOptionalAll con los valores actualizados de originalArray2.ExtProductFoodsSubOptionalAll
|
|
856
881
|
if (optionalFetch && filteredDataOptional) {
|
|
@@ -858,51 +883,51 @@ export const useSales = ({
|
|
|
858
883
|
.map((obj) => {
|
|
859
884
|
const matchingArray = filteredDataOptional.find(
|
|
860
885
|
(o) => o && o.opExPid === obj.opExPid
|
|
861
|
-
)
|
|
886
|
+
)
|
|
862
887
|
if (!matchingArray) {
|
|
863
|
-
return obj
|
|
888
|
+
return obj
|
|
864
889
|
}
|
|
865
890
|
const extProductFoodsSubOptionalAll =
|
|
866
|
-
obj.ExtProductFoodsSubOptionalAll || []
|
|
891
|
+
obj.ExtProductFoodsSubOptionalAll || []
|
|
867
892
|
const updateExtProductFoodsSubOptionalAll =
|
|
868
893
|
extProductFoodsSubOptionalAll.map((subObj) => {
|
|
869
894
|
const newItem =
|
|
870
895
|
matchingArray.ExtProductFoodsSubOptionalAll.find(
|
|
871
896
|
(newItem) =>
|
|
872
897
|
newItem && newItem.opSubExPid === subObj.opSubExPid
|
|
873
|
-
)
|
|
898
|
+
)
|
|
874
899
|
if (newItem) {
|
|
875
900
|
return {
|
|
876
901
|
...subObj,
|
|
877
|
-
check: true
|
|
878
|
-
}
|
|
902
|
+
check: true
|
|
903
|
+
}
|
|
879
904
|
}
|
|
880
|
-
return subObj
|
|
881
|
-
})
|
|
905
|
+
return subObj
|
|
906
|
+
})
|
|
882
907
|
return {
|
|
883
908
|
...obj,
|
|
884
909
|
ExtProductFoodsSubOptionalAll:
|
|
885
|
-
updateExtProductFoodsSubOptionalAll
|
|
886
|
-
}
|
|
910
|
+
updateExtProductFoodsSubOptionalAll
|
|
911
|
+
}
|
|
887
912
|
})
|
|
888
|
-
.filter((obj) => obj)
|
|
913
|
+
.filter((obj) => obj)
|
|
889
914
|
if (existOptionalCookies) {
|
|
890
|
-
setDataOptional(updateOption || [])
|
|
915
|
+
setDataOptional(updateOption || [])
|
|
891
916
|
} else {
|
|
892
|
-
setDataOptional(optionalAll.data.ExtProductFoodsOptionalAll || [])
|
|
917
|
+
setDataOptional(optionalAll.data.ExtProductFoodsOptionalAll || [])
|
|
893
918
|
}
|
|
894
919
|
}
|
|
895
920
|
// NO OPTIONAL
|
|
896
|
-
const extProduct = await ExtProductFoodsAll({ variables: { pId } })
|
|
897
|
-
let finalData
|
|
921
|
+
const extProduct = await ExtProductFoodsAll({ variables: { pId } })
|
|
922
|
+
let finalData
|
|
898
923
|
if (!originalArray?.dataExtra) {
|
|
899
|
-
finalData = extProduct?.data?.ExtProductFoodsAll
|
|
924
|
+
finalData = extProduct?.data?.ExtProductFoodsAll
|
|
900
925
|
} else {
|
|
901
926
|
const filteredData = originalArray.dataExtra.filter((item) =>
|
|
902
927
|
extProduct?.data?.ExtProductFoodsAll.some(
|
|
903
928
|
(newItem) => newItem.exPid === item.exPid
|
|
904
929
|
)
|
|
905
|
-
)
|
|
930
|
+
)
|
|
906
931
|
finalData = originalArray?.dataExtra?.concat(
|
|
907
932
|
extProduct?.data?.ExtProductFoodsAll?.filter(
|
|
908
933
|
(item) =>
|
|
@@ -910,30 +935,30 @@ export const useSales = ({
|
|
|
910
935
|
(filteredItem) => filteredItem.exPid === item.exPid
|
|
911
936
|
)
|
|
912
937
|
)
|
|
913
|
-
)
|
|
938
|
+
)
|
|
914
939
|
}
|
|
915
|
-
setDataExtra(finalData)
|
|
940
|
+
setDataExtra(finalData)
|
|
916
941
|
setProduct(() => {
|
|
917
942
|
return {
|
|
918
|
-
PRODUCT
|
|
919
|
-
}
|
|
920
|
-
})
|
|
921
|
-
setLoadingExtraProduct(false)
|
|
943
|
+
PRODUCT
|
|
944
|
+
}
|
|
945
|
+
})
|
|
946
|
+
setLoadingExtraProduct(false)
|
|
922
947
|
} catch (error) {
|
|
923
|
-
setLoadingExtraProduct(false)
|
|
948
|
+
setLoadingExtraProduct(false)
|
|
924
949
|
sendNotification({
|
|
925
950
|
title: 'error',
|
|
926
951
|
backgroundColor: 'error',
|
|
927
|
-
description: error ||
|
|
928
|
-
})
|
|
952
|
+
description: error || 'Lo sentimos, ocurrió un error'
|
|
953
|
+
})
|
|
929
954
|
}
|
|
930
|
-
}
|
|
955
|
+
}
|
|
931
956
|
const handleCleanFilter = () => {
|
|
932
|
-
setArrayCategory([])
|
|
933
|
-
setValues({})
|
|
934
|
-
setValuesDates({ fromDate: yearMonthDay, toDate:
|
|
935
|
-
}
|
|
936
|
-
const disabledModalItems = dataOptional?.length > 0 || dataExtra?.length > 0
|
|
957
|
+
setArrayCategory([])
|
|
958
|
+
setValues({})
|
|
959
|
+
setValuesDates({ fromDate: yearMonthDay, toDate: '' })
|
|
960
|
+
}
|
|
961
|
+
const disabledModalItems = dataOptional?.length > 0 || dataExtra?.length > 0
|
|
937
962
|
return {
|
|
938
963
|
loading: loading || loadingSale,
|
|
939
964
|
loadingExtraProduct,
|
|
@@ -994,6 +1019,6 @@ export const useSales = ({
|
|
|
994
1019
|
handleIncrementExtra,
|
|
995
1020
|
setProduct,
|
|
996
1021
|
setPrint: handlePrint,
|
|
997
|
-
PRODUCT
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1022
|
+
PRODUCT
|
|
1023
|
+
}
|
|
1024
|
+
}
|