npm-pkg-hook 1.0.1 → 1.0.4
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/.env +1 -0
- package/.eslintrc.js +132 -0
- package/.github/pull_request_template.md +18 -0
- package/.github/workflows/pepeline.yaml +30 -0
- package/.vscode/extensions.json +6 -0
- package/.vscode/settings.json +12 -0
- package/next.config.js +4 -4
- package/package.json +17 -7
- package/script.txt +7 -0
- package/src/hooks/index.js +39 -8
- package/src/hooks/updateExtProductFoodsOptional/index.js +38 -0
- package/src/hooks/useAcumulateDate/index.js +14 -14
- package/src/hooks/useAnimationText/index.jsx +7 -6
- package/src/hooks/useBanner/index.js +19 -0
- package/src/hooks/useCatWithProduct/index.js +42 -0
- package/src/hooks/useCatWithProduct/queries.js +172 -0
- package/src/hooks/useCategoryInStore/index.js +94 -0
- package/src/hooks/{useGetCategorieStore → useCategoryInStore}/queries.js +0 -0
- package/src/hooks/useChartData/index.js +168 -0
- package/src/hooks/useCheckbox/index.js +114 -0
- package/src/hooks/useClients/index.js +13 -0
- package/src/hooks/useClients/queries.js +118 -0
- package/src/hooks/useConnection/index.js +23 -0
- package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +165 -0
- package/src/hooks/useCreateProduct/index.js +268 -0
- package/src/hooks/useDessert/index.js +141 -0
- package/src/hooks/useDrag/index.js +14 -9
- package/src/hooks/useFetchMoreInteractions/index.jsx +6 -3
- package/src/hooks/useFormTools/index.js +16 -3
- package/src/hooks/useFormatDate/index.js +34 -0
- package/src/hooks/useImageOptimization/index.js +28 -0
- package/src/hooks/useImageWeight/index.js +52 -0
- package/src/hooks/useImagesStore/index.js +171 -0
- package/src/hooks/useImagesStore/queries.js +216 -0
- package/src/hooks/useIntersection/index.js +54 -1
- package/src/hooks/useLazyScript/index.js +72 -0
- package/src/hooks/useLocationNavigate/index.js +1 -1
- package/src/hooks/useMobile/index.js +38 -0
- package/src/hooks/useMutateHeight/index.js +37 -0
- package/src/hooks/useProductsFood/index.js +190 -0
- package/src/hooks/useProductsFood/queriesStore.js +781 -0
- package/src/hooks/useProductsFood/usetagsProducts.js +57 -0
- package/src/hooks/useReport/index.js +35 -0
- package/src/hooks/useReport/queries.js +122 -0
- package/src/hooks/useRestaurant/queries.js +11 -1
- package/src/hooks/useSales/index.js +589 -0
- package/src/hooks/useSales/queries.js +291 -0
- package/src/hooks/useSales/useGetSale.js +12 -0
- package/src/hooks/useSales/useTotalSales.js +17 -0
- package/src/hooks/useSaveAvailableProduct/helpers/index.js +30 -0
- package/src/hooks/useSaveAvailableProduct/index.js +26 -0
- package/src/hooks/useSaveAvailableProduct/queries.js +10 -0
- package/src/hooks/useSchedule/index.jsx +23 -0
- package/src/hooks/useStore/index.js +18 -0
- package/src/hooks/useStore/queries.js +136 -0
- package/src/hooks/useStoreCalendar/index.js +7 -0
- package/src/hooks/useUpdateCart/index.js +5 -4
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +37 -0
- package/src/hooks/useUser/index.js +6 -2
- package/src/hooks/useUser/queries.js +69 -0
- package/src/index.jsx +2 -1
- package/src/mock/dessert/index.js +16 -0
- package/src/mock/index.js +2 -0
- package/src/utils/index.js +80 -1
- package/src/hooks/useGetCategorieStore/index.js +0 -21
|
@@ -0,0 +1,589 @@
|
|
|
1
|
+
import { useLazyQuery, useMutation } from '@apollo/client'
|
|
2
|
+
import {
|
|
3
|
+
useCallback,
|
|
4
|
+
useEffect,
|
|
5
|
+
useReducer,
|
|
6
|
+
useState
|
|
7
|
+
} from 'react'
|
|
8
|
+
import { Cookies } from '../../cookies'
|
|
9
|
+
import {
|
|
10
|
+
getCurrentDomain,
|
|
11
|
+
RandomCode,
|
|
12
|
+
updateCacheMod
|
|
13
|
+
} from '../../utils'
|
|
14
|
+
import { useFormatDate } from '../useFormatDate'
|
|
15
|
+
import { useProductsFood } from '../useProductsFood'
|
|
16
|
+
import {
|
|
17
|
+
GET_ALL_EXTRA_PRODUCT,
|
|
18
|
+
GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
|
|
19
|
+
GET_ONE_PRODUCTS_FOOD
|
|
20
|
+
} from '../useProductsFood/queriesStore'
|
|
21
|
+
import { useStore } from '../useStore'
|
|
22
|
+
import {
|
|
23
|
+
CREATE_SHOPPING_CARD_TO_USER_STORE,
|
|
24
|
+
GET_ALL_COUNT_SALES,
|
|
25
|
+
GET_ALL_SALES,
|
|
26
|
+
GET_ALL_SALES_STATISTICS
|
|
27
|
+
} from './queries'
|
|
28
|
+
|
|
29
|
+
const initialState = {
|
|
30
|
+
PRODUCT: [],
|
|
31
|
+
totalPrice: 0,
|
|
32
|
+
sortBy: null,
|
|
33
|
+
itemsInCart: 0,
|
|
34
|
+
animateType: '',
|
|
35
|
+
startAnimateUp: '',
|
|
36
|
+
priceRange: 0,
|
|
37
|
+
counter: 0,
|
|
38
|
+
totalAmount: 0,
|
|
39
|
+
payMethodPState: 0
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const initializer = (initialValue = initialState) => { return JSON.parse(Cookies.get(process.env.LOCAL_SALES_STORE) || JSON.stringify(initialState)) || initialValue }
|
|
43
|
+
|
|
44
|
+
export const useSales = ({
|
|
45
|
+
disabled,
|
|
46
|
+
sendNotification,
|
|
47
|
+
router,
|
|
48
|
+
setAlertBox
|
|
49
|
+
}) => {
|
|
50
|
+
const domain = getCurrentDomain()
|
|
51
|
+
const [modalItem, setModalItem] = useState(false)
|
|
52
|
+
const [openCommentModal, setOpenCommentModal] = useState(false)
|
|
53
|
+
const keyToSaveData = process.env.LOCAL_SALES_STORE
|
|
54
|
+
const saveDataState = JSON.parse(Cookies.get(keyToSaveData) || '[]')
|
|
55
|
+
const [search, setSearch] = useState('')
|
|
56
|
+
const [arr] = useState([])
|
|
57
|
+
const [totalProductPrice, setTotalProductPrice] = useState(0)
|
|
58
|
+
const [showMore, setShowMore] = useState(50)
|
|
59
|
+
const [inputValue, setInputValue] = useState('')
|
|
60
|
+
const [_, setFilteredList] = useState([]);
|
|
61
|
+
const [delivery, setDelivery] = useState(false)
|
|
62
|
+
const [print, setPrint] = useState(false)
|
|
63
|
+
const [values, setValues] = useState({})
|
|
64
|
+
const [dataStore] = useStore()
|
|
65
|
+
const [code, setCode] = useState(null)
|
|
66
|
+
const [openCurrentSale, setOpenCurrentSale] = useState(null)
|
|
67
|
+
const { createdAt } = dataStore || {}
|
|
68
|
+
const {yearMonthDay} = useFormatDate({ date: createdAt })
|
|
69
|
+
const [valuesDates, setValuesDates] = useState(() => { return { fromDate: yearMonthDay, toDate: '' } })
|
|
70
|
+
|
|
71
|
+
const [registerSalesStore, { loading: loadingRegisterSale }] = useMutation(CREATE_SHOPPING_CARD_TO_USER_STORE, {
|
|
72
|
+
onCompleted: (data) => {
|
|
73
|
+
const message = `${data?.registerSalesStore?.Response?.message}`
|
|
74
|
+
const error = data?.registerSalesStore?.Response.success ? 'Éxito' : 'Error'
|
|
75
|
+
sendNotification({ title: error, description: message })
|
|
76
|
+
setAlertBox({ message: message, type: 'success' })
|
|
77
|
+
setOpenCurrentSale(data?.registerSalesStore?.Response.success)
|
|
78
|
+
|
|
79
|
+
},
|
|
80
|
+
onError: (error) => {
|
|
81
|
+
console.log('error', error)
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
const [product, setProduct] = useState({
|
|
85
|
+
PRODUCT: {},
|
|
86
|
+
})
|
|
87
|
+
const [productFoodsOne, { data: dataProduct }] = useLazyQuery(GET_ONE_PRODUCTS_FOOD)
|
|
88
|
+
const [ExtProductFoodsOptionalAll, { data: dataOptional }] = useLazyQuery(GET_EXTRAS_PRODUCT_FOOD_OPTIONAL)
|
|
89
|
+
const [ExtProductFoodsAll, { data: dataExtra }] = useLazyQuery(GET_ALL_EXTRA_PRODUCT)
|
|
90
|
+
|
|
91
|
+
const [productsFood, { loading, fetchMore }] = useProductsFood({
|
|
92
|
+
search: search?.length >= 4 ? search : '',
|
|
93
|
+
gender: [],
|
|
94
|
+
desc: [],
|
|
95
|
+
categories: arr || [],
|
|
96
|
+
toDate: valuesDates?.toDate,
|
|
97
|
+
fromDate: valuesDates?.fromDate,
|
|
98
|
+
max: showMore,
|
|
99
|
+
min: 0
|
|
100
|
+
})
|
|
101
|
+
const max = productsFood?.reduce(function (a, b) {
|
|
102
|
+
return Math.max(a, b?.ProPrice || 0)
|
|
103
|
+
}, 0)
|
|
104
|
+
const initialStateSales = {
|
|
105
|
+
PRODUCT: [],
|
|
106
|
+
totalPrice: 0,
|
|
107
|
+
sortBy: null,
|
|
108
|
+
itemsInCart: 0,
|
|
109
|
+
animateType: '',
|
|
110
|
+
startAnimateUp: '',
|
|
111
|
+
priceRange: max || 0,
|
|
112
|
+
counter: 0,
|
|
113
|
+
totalAmount: 0,
|
|
114
|
+
payMethodPState: 0
|
|
115
|
+
}
|
|
116
|
+
// HANDLESS
|
|
117
|
+
// FILTER PRODUCT DATA_DB
|
|
118
|
+
const handlePrint = ({ callback }) => {
|
|
119
|
+
if (disabled) {
|
|
120
|
+
return sendNotification({
|
|
121
|
+
title: 'Error',
|
|
122
|
+
description: 'Esta es la descr',
|
|
123
|
+
backgroundColor: 'red'
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
setPrint(!print)
|
|
127
|
+
}
|
|
128
|
+
const handleChangeFilter = (e) => { return setSearch(e.target.value) }
|
|
129
|
+
const handleChange = e => { return setValues({ ...values, [e.target.name]: e.target.value }) }
|
|
130
|
+
const onChangeInput = (e) => { return setValuesDates({ ...valuesDates, [e.target.name]: e.target.value }) }
|
|
131
|
+
const handleChangeFilterProduct = (e) => {
|
|
132
|
+
let text = searchedInput(e.target.value)
|
|
133
|
+
if (text === undefined || text === '') {
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
let filteredData = handleList(text)
|
|
137
|
+
setFilteredList(filteredData)
|
|
138
|
+
}
|
|
139
|
+
const [oneProductToComment, setOneProductToComment] = useState({})
|
|
140
|
+
const handleComment = (product) => {
|
|
141
|
+
if (product) {
|
|
142
|
+
setOneProductToComment(product)
|
|
143
|
+
setValues({
|
|
144
|
+
...values,
|
|
145
|
+
comment: product?.comment || ''
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
setOpenCommentModal(!openCommentModal)
|
|
149
|
+
}
|
|
150
|
+
const handleChangeNumber = useCallback((state, action) => {
|
|
151
|
+
const event = action.payload
|
|
152
|
+
const { value, index, id } = event || {}
|
|
153
|
+
const productExist = productsFood?.find((items) => {
|
|
154
|
+
return items.pId === id
|
|
155
|
+
})
|
|
156
|
+
const OneProduct = state?.PRODUCT.find((items) => {
|
|
157
|
+
return items.pId === id
|
|
158
|
+
})
|
|
159
|
+
if (value <= 0) {
|
|
160
|
+
dispatch({ type: 'REMOVE_PRODUCT_TO_CART', payload: OneProduct })
|
|
161
|
+
}
|
|
162
|
+
const finalQuantity = state.PRODUCT['ProQuantity'] = value || 0
|
|
163
|
+
const ARR_PRODUCT = state?.PRODUCT?.map((items, i) => {
|
|
164
|
+
return i === index
|
|
165
|
+
? {
|
|
166
|
+
...items,
|
|
167
|
+
ProQuantity: (finalQuantity),
|
|
168
|
+
ProPrice: value ? (value * productExist?.ProPrice) : productExist?.ProPrice
|
|
169
|
+
}
|
|
170
|
+
: items
|
|
171
|
+
})
|
|
172
|
+
return {
|
|
173
|
+
...state,
|
|
174
|
+
PRODUCT: ARR_PRODUCT,
|
|
175
|
+
counter: state.counter + 1
|
|
176
|
+
}
|
|
177
|
+
}, [productsFood])
|
|
178
|
+
const PRODUCT = (state, action) => {
|
|
179
|
+
const productExist = state.PRODUCT.find((items) => {
|
|
180
|
+
return items.pId === action.id
|
|
181
|
+
})
|
|
182
|
+
const OurProduct = productsFood.find((items) => {
|
|
183
|
+
return items.pId === action.id
|
|
184
|
+
})
|
|
185
|
+
const isFree = productExist?.free
|
|
186
|
+
|
|
187
|
+
switch (action.type) {
|
|
188
|
+
case 'ADD_TO_CART':
|
|
189
|
+
return addToCartFunc(state, action)
|
|
190
|
+
case 'ADD_PRODUCT':
|
|
191
|
+
return {
|
|
192
|
+
...state,
|
|
193
|
+
// eslint-disable-next-line
|
|
194
|
+
PRODUCT: [...state?.PRODUCT, action?.payload],
|
|
195
|
+
}
|
|
196
|
+
case 'REMOVE_PRODUCT':
|
|
197
|
+
return removeFunc(state, action)
|
|
198
|
+
case 'REMOVE_PRODUCT_TO_CART':
|
|
199
|
+
return {
|
|
200
|
+
...state,
|
|
201
|
+
PRODUCT: state?.PRODUCT?.filter((t) => {
|
|
202
|
+
return t.pId !== action?.payload.pId
|
|
203
|
+
}),
|
|
204
|
+
counter: state.counter - action.payload.ProQuantity
|
|
205
|
+
}
|
|
206
|
+
case 'ON_CHANGE': {
|
|
207
|
+
return handleChangeNumber(state, action)
|
|
208
|
+
}
|
|
209
|
+
case 'REMOVE_ALL_PRODUCTS':
|
|
210
|
+
return {
|
|
211
|
+
...state,
|
|
212
|
+
PRODUCT: [],
|
|
213
|
+
counter: 0
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
case 'TOGGLE_FREE_PRODUCT':
|
|
217
|
+
return toggleFreeProducts(state, action)
|
|
218
|
+
case 'INCREMENT':
|
|
219
|
+
return {
|
|
220
|
+
...state,
|
|
221
|
+
counter: state.counter + 1,
|
|
222
|
+
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
223
|
+
return items.pId === action.id
|
|
224
|
+
? {
|
|
225
|
+
...items,
|
|
226
|
+
ProQuantity: items.ProQuantity + 1,
|
|
227
|
+
ProPrice: isFree ? 0 : (productExist.ProQuantity + 1) * OurProduct?.ProPrice
|
|
228
|
+
}
|
|
229
|
+
: items
|
|
230
|
+
})
|
|
231
|
+
}
|
|
232
|
+
case 'PUT_COMMENT': return commentProducts(state, action)
|
|
233
|
+
case 'PRICE_RANGE':
|
|
234
|
+
return {
|
|
235
|
+
...state,
|
|
236
|
+
priceRange: action.payload
|
|
237
|
+
}
|
|
238
|
+
case 'SORT':
|
|
239
|
+
return { ...state, sortBy: action.payload }
|
|
240
|
+
case 'DECREMENT':
|
|
241
|
+
return {
|
|
242
|
+
...state
|
|
243
|
+
// counter: state.counter - 1,
|
|
244
|
+
// PRODUCT: state?.PRODUCT?.map((items) => {
|
|
245
|
+
// return items.pId === action.id ? {
|
|
246
|
+
// ...items,
|
|
247
|
+
// ProQuantity: items.ProQuantity - 1,
|
|
248
|
+
// // ProPrice: ((productExist.ProQuantity + 1) * OurProduct?.ProPrice),
|
|
249
|
+
// } : items
|
|
250
|
+
// })
|
|
251
|
+
}
|
|
252
|
+
case 'PAYMENT_METHOD_TRANSACTION':
|
|
253
|
+
return {
|
|
254
|
+
...state,
|
|
255
|
+
payMethodPState: 1
|
|
256
|
+
}
|
|
257
|
+
case 'PAYMENT_METHOD_MONEY':
|
|
258
|
+
return {
|
|
259
|
+
...state,
|
|
260
|
+
payMethodPState: 0
|
|
261
|
+
}
|
|
262
|
+
default:
|
|
263
|
+
return state
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const [data, dispatch] = useReducer(PRODUCT, initialStateSales, initializer)
|
|
267
|
+
const handleRemoveValue = useCallback(({name, value, pId}) => {
|
|
268
|
+
setValues({
|
|
269
|
+
...values,
|
|
270
|
+
[name]: value ?? ''
|
|
271
|
+
})
|
|
272
|
+
return dispatch({
|
|
273
|
+
type: 'PUT_COMMENT',
|
|
274
|
+
payload: pId,
|
|
275
|
+
value: ''
|
|
276
|
+
})
|
|
277
|
+
}, [])
|
|
278
|
+
useEffect(() => {
|
|
279
|
+
Cookies.set(keyToSaveData, JSON.stringify(data), { domain, path: '/' })
|
|
280
|
+
}, [data, domain])
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
function addToCartFunc(state, action) {
|
|
284
|
+
const productExist = state.PRODUCT.find((items) => {
|
|
285
|
+
return items.pId === action.payload.pId
|
|
286
|
+
})
|
|
287
|
+
const OurProduct = productsFood.find((items) => {
|
|
288
|
+
return items.pId === action.payload.pId
|
|
289
|
+
})
|
|
290
|
+
const isFree = productExist?.free
|
|
291
|
+
return {
|
|
292
|
+
...state,
|
|
293
|
+
counter: state.counter + 1,
|
|
294
|
+
totalAmount: state.totalAmount + action.payload.ProPrice,
|
|
295
|
+
startAnimateUp: 'start-animate-up',
|
|
296
|
+
PRODUCT: !productExist
|
|
297
|
+
? [
|
|
298
|
+
...state.PRODUCT,
|
|
299
|
+
{
|
|
300
|
+
pId: action.payload.pId,
|
|
301
|
+
pName: action.payload.pName,
|
|
302
|
+
ProDescription: action.payload.ProDescription,
|
|
303
|
+
ProImage: action.payload.ProImage,
|
|
304
|
+
ProPrice: action.payload.ProPrice,
|
|
305
|
+
ProQuantity: 1
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
: state.PRODUCT.map((items) => {
|
|
309
|
+
return items.pId === action.payload.pId
|
|
310
|
+
? {
|
|
311
|
+
...items,
|
|
312
|
+
ProPrice: isFree ? 0 : (productExist.ProQuantity + 1) * OurProduct?.ProPrice,
|
|
313
|
+
ProQuantity: productExist.ProQuantity + 1,
|
|
314
|
+
free: isFree ? true : false
|
|
315
|
+
}
|
|
316
|
+
: items
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function removeFunc(state, action) {
|
|
321
|
+
const productExist = state.PRODUCT.find((items) => {
|
|
322
|
+
return items.pId === action.payload.pId
|
|
323
|
+
})
|
|
324
|
+
const OurProduct = productsFood.find((items) => {
|
|
325
|
+
return items.pId === action.payload.pId
|
|
326
|
+
})
|
|
327
|
+
return {
|
|
328
|
+
...state,
|
|
329
|
+
counter: state.counter - 1,
|
|
330
|
+
totalAmount: state.totalAmount - action.payload.ProPrice,
|
|
331
|
+
PRODUCT: action.payload.ProQuantity > 1
|
|
332
|
+
? state.PRODUCT.map((items) => {
|
|
333
|
+
return items.pId === action.payload.pId
|
|
334
|
+
? {
|
|
335
|
+
...items,
|
|
336
|
+
pId: action.payload.pId,
|
|
337
|
+
ProQuantity: items.ProQuantity - 1,
|
|
338
|
+
ProPrice: (productExist.ProPrice - OurProduct?.ProPrice)
|
|
339
|
+
}
|
|
340
|
+
: items
|
|
341
|
+
})
|
|
342
|
+
: state.PRODUCT.filter((items) => {
|
|
343
|
+
return items.pId !== action.payload.pId
|
|
344
|
+
})
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
// TOGGLE_FREE_PRODUCT
|
|
348
|
+
function toggleFreeProducts(state, action) {
|
|
349
|
+
const productExist = productsFood.find((items) => {
|
|
350
|
+
return items.pId === action.payload.pId
|
|
351
|
+
})
|
|
352
|
+
return {
|
|
353
|
+
...state,
|
|
354
|
+
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
355
|
+
return items.pId === action.payload.pId
|
|
356
|
+
? {
|
|
357
|
+
...items,
|
|
358
|
+
free: !items.free,
|
|
359
|
+
ProPrice: items.ProPrice
|
|
360
|
+
? 0
|
|
361
|
+
: items.ProQuantity * productExist?.ProPrice
|
|
362
|
+
}
|
|
363
|
+
: items
|
|
364
|
+
})
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// COMMENT_FREE_PRODUCT
|
|
369
|
+
function commentProducts(state, action, deleteValue) {
|
|
370
|
+
return {
|
|
371
|
+
...state,
|
|
372
|
+
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
373
|
+
return items.pId === action.payload
|
|
374
|
+
? {
|
|
375
|
+
...items,
|
|
376
|
+
comment: deleteValue ? '' : values.comment,
|
|
377
|
+
}
|
|
378
|
+
: items
|
|
379
|
+
})
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
const getSortedProduct = (sortData, sortBy) => {
|
|
384
|
+
if (sortBy && sortBy === 'PRICE_HIGH_TO_LOW') {
|
|
385
|
+
return (
|
|
386
|
+
sortData ??
|
|
387
|
+
sortData.sort((a, b) => {
|
|
388
|
+
return b['ProPrice'] - a['ProPrice']
|
|
389
|
+
})
|
|
390
|
+
)
|
|
391
|
+
}
|
|
392
|
+
if (sortBy && sortBy === 'PRICE_LOW_TO_HIGH') {
|
|
393
|
+
return (
|
|
394
|
+
sortData ??
|
|
395
|
+
sortData.sort((a, b) => {
|
|
396
|
+
return a['ProPrice'] - b['ProPrice']
|
|
397
|
+
})
|
|
398
|
+
)
|
|
399
|
+
}
|
|
400
|
+
return sortData
|
|
401
|
+
}
|
|
402
|
+
const PriceRangeFunc = (products, price) => {
|
|
403
|
+
return (
|
|
404
|
+
products?.length > 0 &&
|
|
405
|
+
products?.filter((items) => {
|
|
406
|
+
return items?.ProPrice >= price
|
|
407
|
+
})
|
|
408
|
+
)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const sortedProduct = getSortedProduct(data.PRODUCT, data.sortBy)
|
|
412
|
+
const finalFilter = PriceRangeFunc(sortedProduct, data.priceRange)
|
|
413
|
+
|
|
414
|
+
const handleList = (text) => {
|
|
415
|
+
let inputText = text.toLowerCase()
|
|
416
|
+
let dataList = []
|
|
417
|
+
dataList = finalFilter.filter((item) => {
|
|
418
|
+
return item.pName.toLowerCase().includes(inputText)
|
|
419
|
+
})
|
|
420
|
+
return dataList
|
|
421
|
+
}
|
|
422
|
+
const searchedInput = (words) => {
|
|
423
|
+
setInputValue(words)
|
|
424
|
+
let n = words.split(' ')
|
|
425
|
+
if (n.length !== 0) {
|
|
426
|
+
if (n[n.length - 1] === '') {
|
|
427
|
+
n.pop()
|
|
428
|
+
}
|
|
429
|
+
return n[n.length - 1]
|
|
430
|
+
}
|
|
431
|
+
return ''
|
|
432
|
+
}
|
|
433
|
+
const newArrayProducts =
|
|
434
|
+
data?.PRODUCT?.length > 0 &&
|
|
435
|
+
data?.PRODUCT?.map((product) => {
|
|
436
|
+
return {
|
|
437
|
+
pId: product?.pId,
|
|
438
|
+
id: values?.cliId,
|
|
439
|
+
cantProducts: parseInt(product?.ProQuantity ? product?.ProQuantity : 0),
|
|
440
|
+
comments: product?.comment ?? ''
|
|
441
|
+
}
|
|
442
|
+
})
|
|
443
|
+
const handleSubmit = () => {
|
|
444
|
+
const code = RandomCode(10)
|
|
445
|
+
setCode(code)
|
|
446
|
+
return registerSalesStore({
|
|
447
|
+
variables: {
|
|
448
|
+
input: newArrayProducts || [],
|
|
449
|
+
id: values?.cliId,
|
|
450
|
+
pCodeRef: code,
|
|
451
|
+
change: values.change,
|
|
452
|
+
valueDelivery: parseInt(values.valueDelivery),
|
|
453
|
+
payMethodPState: data.payMethodPState,
|
|
454
|
+
pickUp: 1,
|
|
455
|
+
totalProductsPrice: totalProductPrice || 0
|
|
456
|
+
},
|
|
457
|
+
update: (cache, { data: {
|
|
458
|
+
getAllSalesStoreStatistic,
|
|
459
|
+
getTodaySales,
|
|
460
|
+
getAllSalesStore
|
|
461
|
+
} }) => {
|
|
462
|
+
updateCacheMod(
|
|
463
|
+
{
|
|
464
|
+
cache,
|
|
465
|
+
query: GET_ALL_SALES,
|
|
466
|
+
nameFun: 'getAllSalesStore',
|
|
467
|
+
dataNew: getAllSalesStore,
|
|
468
|
+
})
|
|
469
|
+
updateCacheMod(
|
|
470
|
+
{
|
|
471
|
+
cache,
|
|
472
|
+
query: GET_ALL_COUNT_SALES,
|
|
473
|
+
nameFun: 'getTodaySales',
|
|
474
|
+
dataNew: getTodaySales,
|
|
475
|
+
})
|
|
476
|
+
return updateCacheMod(
|
|
477
|
+
{
|
|
478
|
+
cache,
|
|
479
|
+
query: GET_ALL_SALES_STATISTICS,
|
|
480
|
+
nameFun: 'getAllSalesStoreStatistic',
|
|
481
|
+
dataNew: getAllSalesStoreStatistic,
|
|
482
|
+
type: 2
|
|
483
|
+
}
|
|
484
|
+
)
|
|
485
|
+
}
|
|
486
|
+
})
|
|
487
|
+
.then((responseRegisterR) => {
|
|
488
|
+
if (responseRegisterR) {
|
|
489
|
+
const { data } = responseRegisterR || {}
|
|
490
|
+
const { registerSalesStore } = data || {}
|
|
491
|
+
const { Response } = registerSalesStore || {}
|
|
492
|
+
console.log(Response)
|
|
493
|
+
if (Response && Response.success === true) {
|
|
494
|
+
// dispatch({ type: 'REMOVE_ALL_PRODUCTS' })
|
|
495
|
+
router.push(
|
|
496
|
+
{
|
|
497
|
+
query: {
|
|
498
|
+
...router.query,
|
|
499
|
+
saleId: code
|
|
500
|
+
}
|
|
501
|
+
},
|
|
502
|
+
undefined,
|
|
503
|
+
{ shallow: true }
|
|
504
|
+
)
|
|
505
|
+
setValues({})
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
})
|
|
509
|
+
}
|
|
510
|
+
let suma = 0
|
|
511
|
+
let total = 0
|
|
512
|
+
|
|
513
|
+
useEffect(() => {
|
|
514
|
+
data.PRODUCT.forEach((a) => {
|
|
515
|
+
const { ProPrice } = a || {}
|
|
516
|
+
suma += ProPrice
|
|
517
|
+
setTotalProductPrice(Math.abs(suma))
|
|
518
|
+
})
|
|
519
|
+
if (data.PRODUCT.length === 0) {
|
|
520
|
+
setTotalProductPrice(0)
|
|
521
|
+
}
|
|
522
|
+
}, [totalProductPrice, suma, total, data])
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
const handleProduct = (PRODUCT) => {
|
|
526
|
+
const { pId } = PRODUCT || {}
|
|
527
|
+
try {
|
|
528
|
+
productFoodsOne({ variables: { pId } })
|
|
529
|
+
ExtProductFoodsOptionalAll({ variables: { pId } })
|
|
530
|
+
ExtProductFoodsAll({ variables: { pId } })
|
|
531
|
+
setProduct(() => {
|
|
532
|
+
return {
|
|
533
|
+
PRODUCT,
|
|
534
|
+
}})
|
|
535
|
+
} catch (error) {
|
|
536
|
+
console.log({ message: 'Lo sentimos, ocurrió un error' })
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
return {
|
|
541
|
+
loading,
|
|
542
|
+
loadingRegisterSale,
|
|
543
|
+
openCurrentSale,
|
|
544
|
+
fetchMore,
|
|
545
|
+
code,
|
|
546
|
+
totalProductPrice,
|
|
547
|
+
saveDataState,
|
|
548
|
+
product,
|
|
549
|
+
data,
|
|
550
|
+
openCommentModal,
|
|
551
|
+
inputValue,
|
|
552
|
+
newArrayProducts,
|
|
553
|
+
delivery,
|
|
554
|
+
valuesDates,
|
|
555
|
+
print,
|
|
556
|
+
finalFilter,
|
|
557
|
+
showMore,
|
|
558
|
+
max,
|
|
559
|
+
values,
|
|
560
|
+
initialStateSales,
|
|
561
|
+
productsFood,
|
|
562
|
+
modalItem,
|
|
563
|
+
oneProductToComment: oneProductToComment ?? null,
|
|
564
|
+
dataProduct: dataProduct?.productFoodsOne || {},
|
|
565
|
+
dataOptional: dataOptional?.ExtProductFoodsOptionalAll || [],
|
|
566
|
+
dataExtra: dataExtra?.ExtProductFoodsAll || [],
|
|
567
|
+
|
|
568
|
+
dispatch,
|
|
569
|
+
handleComment,
|
|
570
|
+
setModalItem,
|
|
571
|
+
handleChangeFilter,
|
|
572
|
+
handleProduct,
|
|
573
|
+
handleChange,
|
|
574
|
+
setOpenCurrentSale,
|
|
575
|
+
onChangeInput,
|
|
576
|
+
handleRemoveValue,
|
|
577
|
+
setDelivery,
|
|
578
|
+
setValues,
|
|
579
|
+
setShowMore,
|
|
580
|
+
PriceRangeFunc,
|
|
581
|
+
handleSubmit,
|
|
582
|
+
handleChangeFilterProduct,
|
|
583
|
+
setTotalProductPrice,
|
|
584
|
+
setInputValue,
|
|
585
|
+
getSortedProduct,
|
|
586
|
+
setPrint: handlePrint,
|
|
587
|
+
PRODUCT
|
|
588
|
+
}
|
|
589
|
+
}
|