npm-pkg-hook 1.10.0 → 1.10.1
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/package.json
CHANGED
|
@@ -59,8 +59,8 @@ export const initializer = (initialValue = initialState) => {
|
|
|
59
59
|
export const useSales = ({
|
|
60
60
|
disabled = false,
|
|
61
61
|
router,
|
|
62
|
-
sendNotification = (
|
|
63
|
-
setAlertBox = (
|
|
62
|
+
sendNotification = (args) => { return args },
|
|
63
|
+
setAlertBox = (args) => { return args }
|
|
64
64
|
}) => {
|
|
65
65
|
const domain = getCurrentDomain()
|
|
66
66
|
const [loadingSale, setLoadingSale] = useState(false)
|
|
@@ -195,11 +195,11 @@ export const useSales = ({
|
|
|
195
195
|
// HANDLESS
|
|
196
196
|
// FILTER PRODUCT DATA_DB
|
|
197
197
|
// @ts-ignore
|
|
198
|
-
const handlePrint = (
|
|
198
|
+
const handlePrint = () => {
|
|
199
199
|
if (disabled) {
|
|
200
200
|
return sendNotification({
|
|
201
201
|
title: 'Error',
|
|
202
|
-
description: 'Esta es la
|
|
202
|
+
description: 'Esta es la descripción',
|
|
203
203
|
backgroundColor: 'error'
|
|
204
204
|
})
|
|
205
205
|
}
|
|
@@ -219,6 +219,25 @@ export const useSales = ({
|
|
|
219
219
|
const onChangeInput = (e) => {
|
|
220
220
|
return setValuesDates({ ...valuesDates, [e.target.name]: e.target.value })
|
|
221
221
|
}
|
|
222
|
+
const handleToggleEditingStatus = (state, action) => {
|
|
223
|
+
const { PRODUCT } = state ?? {
|
|
224
|
+
PRODUCT: []
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
...state,
|
|
228
|
+
PRODUCT: PRODUCT.map((item) => {
|
|
229
|
+
if (item.pId === action.payload.pId) {
|
|
230
|
+
return {
|
|
231
|
+
...item,
|
|
232
|
+
editing: !item.editing,
|
|
233
|
+
oldQuantity: item.ProQuantity
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return item
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
222
241
|
const handleChangeFilterProduct = (e) => {
|
|
223
242
|
const text = searchedInput(e.target.value)
|
|
224
243
|
if (text === undefined || text === '') {
|
|
@@ -232,11 +251,94 @@ export const useSales = ({
|
|
|
232
251
|
setOneProductToComment(product)
|
|
233
252
|
setValues({
|
|
234
253
|
...values,
|
|
235
|
-
comment: product?.comment
|
|
254
|
+
comment: product?.comment ?? ''
|
|
236
255
|
})
|
|
237
256
|
}
|
|
238
257
|
setOpenCommentModal(!openCommentModal)
|
|
239
258
|
}
|
|
259
|
+
const handleSuccessUpdateQuantity = (state, payload) => {
|
|
260
|
+
const { pId } = payload.payload || {
|
|
261
|
+
pId: null
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
...state,
|
|
265
|
+
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
266
|
+
return items.pId === pId
|
|
267
|
+
? {
|
|
268
|
+
...items,
|
|
269
|
+
editing: false,
|
|
270
|
+
oldQuantity: items.ProQuantity
|
|
271
|
+
}
|
|
272
|
+
: items
|
|
273
|
+
})
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Cancels the update of a product's quantity, resetting it to the previous value.
|
|
279
|
+
* @param {Object} state - The current state.
|
|
280
|
+
* @param {Object} payload - The payload containing the product ID.
|
|
281
|
+
* @returns {Object} - The new state with the updated product quantity and editing status.
|
|
282
|
+
*/
|
|
283
|
+
const handleCancelUpdateQuantity = (state, payload) => {
|
|
284
|
+
// Validación de `state`
|
|
285
|
+
if (!state || typeof state !== 'object') {
|
|
286
|
+
sendNotification({
|
|
287
|
+
title: 'Error',
|
|
288
|
+
backgroundColor: 'error',
|
|
289
|
+
description: 'Ha ocurrido un error al actualizar la cantidad del producto.'
|
|
290
|
+
})
|
|
291
|
+
return state // Retorna el estado sin cambios si es inválido.
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Validación de `PRODUCT`
|
|
295
|
+
if (!Array.isArray(state.PRODUCT)) {
|
|
296
|
+
sendNotification({
|
|
297
|
+
title: 'Error',
|
|
298
|
+
backgroundColor: 'error',
|
|
299
|
+
description: 'Ha ocurrido un error al actualizar la cantidad del producto.'
|
|
300
|
+
})
|
|
301
|
+
return state // Retorna el estado sin cambios si `PRODUCT` no es un array.
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Validación de `payload`
|
|
305
|
+
const { pId } = payload.payload || {}
|
|
306
|
+
if (!pId) {
|
|
307
|
+
sendNotification({
|
|
308
|
+
title: 'Error',
|
|
309
|
+
backgroundColor: 'error',
|
|
310
|
+
description: 'Ha ocurrido un error al actualizar la cantidad del producto.'
|
|
311
|
+
})
|
|
312
|
+
return state // Retorna el estado sin cambios si falta `pId`.
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return {
|
|
316
|
+
...state,
|
|
317
|
+
PRODUCT: state.PRODUCT.map((item) => {
|
|
318
|
+
// Validación de propiedades en cada item
|
|
319
|
+
if (item.pId === pId) {
|
|
320
|
+
if (typeof item.oldQuantity !== 'number' || typeof item.unitPrice !== 'number') {
|
|
321
|
+
sendNotification({
|
|
322
|
+
title: 'Error',
|
|
323
|
+
backgroundColor: 'error',
|
|
324
|
+
description: 'Ha ocurrido un error al actualizar la cantidad del producto.'
|
|
325
|
+
})
|
|
326
|
+
return item // Retorna el item sin cambios si las propiedades son inválidas.
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return {
|
|
330
|
+
...item,
|
|
331
|
+
editing: false,
|
|
332
|
+
ProQuantity: item.oldQuantity,
|
|
333
|
+
ProPrice: item.oldQuantity * item.unitPrice
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
return item
|
|
338
|
+
})
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
240
342
|
const handleChangeNumber = useCallback(
|
|
241
343
|
(state, action) => {
|
|
242
344
|
const event = action.payload
|
|
@@ -302,6 +404,12 @@ export const useSales = ({
|
|
|
302
404
|
case 'ON_CHANGE': {
|
|
303
405
|
return handleChangeNumber(state, action)
|
|
304
406
|
}
|
|
407
|
+
case 'UPDATE_SUCCESS_QUANTITY_EDITING_PRODUCT': {
|
|
408
|
+
return handleSuccessUpdateQuantity(state, action)
|
|
409
|
+
}
|
|
410
|
+
case 'CANCEL_UPDATE_QUANTITY_EDITING_PRODUCT': {
|
|
411
|
+
return handleCancelUpdateQuantity(state, action)
|
|
412
|
+
}
|
|
305
413
|
case 'REMOVE_ALL_PRODUCTS':
|
|
306
414
|
// @ts-ignore
|
|
307
415
|
setValues({
|
|
@@ -319,6 +427,9 @@ export const useSales = ({
|
|
|
319
427
|
|
|
320
428
|
case 'TOGGLE_FREE_PRODUCT':
|
|
321
429
|
return toggleFreeProducts(state, action)
|
|
430
|
+
case 'TOGGLE_EDITING_PRODUCT': {
|
|
431
|
+
return handleToggleEditingStatus(state, action)
|
|
432
|
+
}
|
|
322
433
|
case 'INCREMENT':
|
|
323
434
|
return {
|
|
324
435
|
...state,
|
|
@@ -365,6 +476,8 @@ export const useSales = ({
|
|
|
365
476
|
}
|
|
366
477
|
}
|
|
367
478
|
const [data, dispatch] = useReducer(PRODUCT, initialStateSales, initializer)
|
|
479
|
+
console.log({ data })
|
|
480
|
+
|
|
368
481
|
const handleRemoveValue = useCallback(({ name, value, pId }) => {
|
|
369
482
|
setValues({
|
|
370
483
|
...values,
|
|
@@ -611,6 +724,7 @@ export const useSales = ({
|
|
|
611
724
|
const updatedProduct = {
|
|
612
725
|
pId,
|
|
613
726
|
pName,
|
|
727
|
+
editing: false,
|
|
614
728
|
getOneTags,
|
|
615
729
|
unitPrice: OurProduct?.ProPrice,
|
|
616
730
|
ProDescription,
|
|
@@ -639,6 +753,8 @@ export const useSales = ({
|
|
|
639
753
|
...item,
|
|
640
754
|
getOneTags: OurProduct?.genderTags,
|
|
641
755
|
unitPrice: OurProduct?.ProPrice,
|
|
756
|
+
editing: false,
|
|
757
|
+
oldQuantity: productExist.ProQuantity + +1,
|
|
642
758
|
ProPrice: isFree ? 0 : (productExist.ProQuantity + 1) * OurProduct?.ProPrice,
|
|
643
759
|
ProQuantity: productExist.ProQuantity + +1,
|
|
644
760
|
free: !!isFree
|
|
@@ -741,41 +857,40 @@ export const useSales = ({
|
|
|
741
857
|
}
|
|
742
858
|
return ''
|
|
743
859
|
}
|
|
744
|
-
const arrayProduct =
|
|
745
|
-
data?.PRODUCT?.
|
|
746
|
-
|
|
747
|
-
const filteredDataExtra =
|
|
860
|
+
const arrayProduct = data?.PRODUCT?.length > 0
|
|
861
|
+
? data?.PRODUCT?.map((product) => {
|
|
862
|
+
const filteredDataExtra =
|
|
748
863
|
product?.dataExtra?.map(({ __typename, ...rest }) => rest) ?? []
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
)
|
|
758
|
-
return {
|
|
759
|
-
...rest,
|
|
760
|
-
ExtProductFoodsSubOptionalAll: adjustedSubOptionalAll
|
|
864
|
+
const dataOptional = product?.dataOptional?.map(
|
|
865
|
+
({ __typename, ...product }) => {
|
|
866
|
+
const { ExtProductFoodsSubOptionalAll, ...rest } = product
|
|
867
|
+
const adjustedSubOptionalAll = ExtProductFoodsSubOptionalAll?.map(
|
|
868
|
+
(subOption) => {
|
|
869
|
+
const { __typename, ...subOptionRest } = subOption
|
|
870
|
+
return subOptionRest
|
|
761
871
|
}
|
|
872
|
+
)
|
|
873
|
+
return {
|
|
874
|
+
...rest,
|
|
875
|
+
ExtProductFoodsSubOptionalAll: adjustedSubOptionalAll
|
|
762
876
|
}
|
|
763
|
-
)
|
|
764
|
-
const refCodePid = RandomCode(20)
|
|
765
|
-
return {
|
|
766
|
-
pId: product?.pId,
|
|
767
|
-
refCodePid,
|
|
768
|
-
id: values?.cliId,
|
|
769
|
-
cantProducts: parseInt(
|
|
770
|
-
product?.ProQuantity ? product?.ProQuantity : 0
|
|
771
|
-
),
|
|
772
|
-
comments: product?.comment ?? '',
|
|
773
|
-
dataOptional: dataOptional ?? [],
|
|
774
|
-
dataExtra: filteredDataExtra || [],
|
|
775
|
-
ProPrice: product.ProPrice
|
|
776
877
|
}
|
|
777
|
-
|
|
778
|
-
|
|
878
|
+
)
|
|
879
|
+
const refCodePid = RandomCode(20)
|
|
880
|
+
return {
|
|
881
|
+
pId: product?.pId,
|
|
882
|
+
refCodePid,
|
|
883
|
+
id: values?.cliId,
|
|
884
|
+
cantProducts: parseInt(
|
|
885
|
+
product?.ProQuantity ? product?.ProQuantity : 0
|
|
886
|
+
),
|
|
887
|
+
comments: product?.comment ?? '',
|
|
888
|
+
dataOptional: dataOptional ?? [],
|
|
889
|
+
dataExtra: filteredDataExtra || [],
|
|
890
|
+
ProPrice: product.ProPrice
|
|
891
|
+
}
|
|
892
|
+
})
|
|
893
|
+
: []
|
|
779
894
|
const finalArrayProduct = arrayProduct.map((item) => {
|
|
780
895
|
const totalExtra = item.dataExtra.reduce(
|
|
781
896
|
(accumulator, extra) => accumulator + extra.newExtraPrice,
|
|
@@ -14,7 +14,6 @@ export const useUpdateMultipleProducts = ({
|
|
|
14
14
|
const [dataCategoriesProducts] = useCategoriesProduct()
|
|
15
15
|
const findEmptyCategory = dataCategoriesProducts?.find(category => category.pName === CATEGORY_EMPTY)
|
|
16
16
|
const updateProducts = async (products) => {
|
|
17
|
-
console.log("🚀 ~ updateProducts ~ products:", products)
|
|
18
17
|
const newProducts = products.map(product => {
|
|
19
18
|
return {
|
|
20
19
|
idStore: '',
|
|
@@ -239,7 +239,6 @@ export const useUploadProducts = ({
|
|
|
239
239
|
|
|
240
240
|
// Crear una nueva copia de los datos actualizando solo el producto específico
|
|
241
241
|
return prevData.map((product, index) => {
|
|
242
|
-
console.log(index === productIndex)
|
|
243
242
|
return index === productIndex
|
|
244
243
|
? {
|
|
245
244
|
...product,
|