npm-pkg-hook 1.9.9 → 1.10.0
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
|
@@ -14,6 +14,7 @@ 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)
|
|
17
18
|
const newProducts = products.map(product => {
|
|
18
19
|
return {
|
|
19
20
|
idStore: '',
|
|
@@ -28,6 +29,8 @@ export const useUpdateMultipleProducts = ({
|
|
|
28
29
|
sTateLogistic: 1,
|
|
29
30
|
ProStar: 0,
|
|
30
31
|
ProImage: null,
|
|
32
|
+
vat: product['IMPUESTO (%)'],
|
|
33
|
+
ProBarCode: product.CODIGO_DE_BARRAS,
|
|
31
34
|
ProHeight: null,
|
|
32
35
|
ProWeight: '',
|
|
33
36
|
ProOutstanding: 0,
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export const validateProductDataExcel = (product, productIndex) => {
|
|
2
|
+
const expectedHeaders = [
|
|
3
|
+
{
|
|
4
|
+
name: 'NOMBRE',
|
|
5
|
+
required: true,
|
|
6
|
+
type: 'string'
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
name: 'PRECIO_AL_PUBLICO',
|
|
10
|
+
required: false,
|
|
11
|
+
type: 'number'
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: 'VALOR_DE_COMPRA',
|
|
15
|
+
required: false,
|
|
16
|
+
type: 'number'
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'CANTIDAD',
|
|
20
|
+
required: true,
|
|
21
|
+
type: 'number'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'DESCRIPCION',
|
|
25
|
+
required: true,
|
|
26
|
+
type: 'string'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'DESCUENTO',
|
|
30
|
+
required: false,
|
|
31
|
+
type: 'number'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'CATEGORIA',
|
|
35
|
+
required: false,
|
|
36
|
+
type: 'string'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'CODIGO_DE_BARRAS',
|
|
40
|
+
required: false,
|
|
41
|
+
type: 'string'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'IMPUESTO (%)',
|
|
45
|
+
required: false,
|
|
46
|
+
type: 'number'
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
const errors = []
|
|
51
|
+
|
|
52
|
+
// Validar encabezados requeridos
|
|
53
|
+
expectedHeaders.forEach(({ name, required, type }) => {
|
|
54
|
+
if (required && !(name in product)) {
|
|
55
|
+
errors.push(`Producto ${productIndex + 1}: Faltan la columna requerida: ${name}.`)
|
|
56
|
+
} else if (product[name] !== undefined) {
|
|
57
|
+
const isValidType = typeof product[name] === type || (type === 'number' && typeof product[name] === 'number' && !isNaN(product[name]))
|
|
58
|
+
if (!isValidType) {
|
|
59
|
+
errors.push(`Producto ${productIndex + 1}: El campo ${name} debe ser de tipo ${type}.`)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
return errors // Retorna todos los errores encontrados
|
|
65
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useState } from 'react'
|
|
2
2
|
import * as XLSX from 'xlsx'
|
|
3
3
|
import { RandomCode } from '../../utils'
|
|
4
|
+
import { validateProductDataExcel } from './helpers/validateProductDataExcel'
|
|
4
5
|
|
|
5
6
|
const STEPS = {
|
|
6
7
|
UPLOAD_FILE: 0,
|
|
@@ -41,19 +42,37 @@ export const useUploadProducts = ({
|
|
|
41
42
|
const filePromises = Array.from(files).map(file => readExcelFile(file))
|
|
42
43
|
const newData = await Promise.all(filePromises)
|
|
43
44
|
|
|
44
|
-
const newProducts = newData.flat().map((product) => {
|
|
45
|
+
const newProducts = newData.flat().map((product, index) => {
|
|
45
46
|
const PRECIO_AL_PUBLICO = isNaN(product.PRECIO_AL_PUBLICO) ? 0.00 : product.PRECIO_AL_PUBLICO
|
|
46
47
|
const VALOR_DE_COMPRA = isNaN(product.VALOR_DE_COMPRA) ? 0.00 : product.VALOR_DE_COMPRA
|
|
48
|
+
const validationErrors = validateProductDataExcel(product, index)
|
|
49
|
+
|
|
47
50
|
const code = RandomCode(9)
|
|
48
51
|
return {
|
|
49
52
|
...product,
|
|
50
53
|
CANTIDAD: isNaN(product.CANTIDAD) ? 1 : product.CANTIDAD,
|
|
51
54
|
ORIGINAL_CANTIDAD: isNaN(product.CANTIDAD) ? 1 : product.CANTIDAD,
|
|
52
55
|
free: false,
|
|
56
|
+
product: product?.DESCRIPCION,
|
|
53
57
|
pCode: code,
|
|
54
58
|
editing: false,
|
|
55
59
|
PRECIO_AL_PUBLICO,
|
|
56
|
-
VALOR_DE_COMPRA
|
|
60
|
+
VALOR_DE_COMPRA,
|
|
61
|
+
errors: validationErrors.length > 0 ? validationErrors : null
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
// Notificación de errores
|
|
66
|
+
newProducts.forEach(product => {
|
|
67
|
+
if (product.errors) {
|
|
68
|
+
// Enviar una notificación por cada error encontrado
|
|
69
|
+
product.errors.forEach(error => {
|
|
70
|
+
sendNotification({
|
|
71
|
+
description: error,
|
|
72
|
+
title: 'Error',
|
|
73
|
+
backgroundColor: 'error'
|
|
74
|
+
})
|
|
75
|
+
})
|
|
57
76
|
}
|
|
58
77
|
})
|
|
59
78
|
|
|
@@ -80,7 +99,7 @@ export const useUploadProducts = ({
|
|
|
80
99
|
})
|
|
81
100
|
} catch (error) {
|
|
82
101
|
sendNotification({
|
|
83
|
-
description: 'Un
|
|
102
|
+
description: 'Un error ha ocurrido mientras se cargaba el archivo de productos.',
|
|
84
103
|
title: 'Error',
|
|
85
104
|
backgroundColor: 'error'
|
|
86
105
|
})
|
|
@@ -188,21 +207,33 @@ export const useUploadProducts = ({
|
|
|
188
207
|
setData((prevData) => {
|
|
189
208
|
// Validar que el índice es un número válido
|
|
190
209
|
if (typeof productIndex !== 'number' || productIndex < 0 || productIndex >= prevData.length) {
|
|
191
|
-
|
|
210
|
+
sendNotification({
|
|
211
|
+
description: `Invalid product index: ${productIndex}`,
|
|
212
|
+
title: 'Error',
|
|
213
|
+
backgroundColor: 'error'
|
|
214
|
+
})
|
|
192
215
|
return prevData // Retorna el estado anterior si el índice es inválido
|
|
193
216
|
}
|
|
194
217
|
|
|
195
218
|
// Validar que el producto existe y tiene la propiedad 'editing'
|
|
196
219
|
const product = prevData[productIndex]
|
|
197
220
|
if (!product || typeof product.editing === 'undefined') {
|
|
198
|
-
|
|
221
|
+
sendNotification({
|
|
222
|
+
description: `Product or "editing" property not found for index: ${productIndex}`,
|
|
223
|
+
title: 'Error',
|
|
224
|
+
backgroundColor: 'error'
|
|
225
|
+
})
|
|
199
226
|
return prevData // Retorna el estado anterior si no se encuentra el producto
|
|
200
227
|
}
|
|
201
228
|
|
|
202
229
|
// Evitar cambios innecesarios si el estado de 'editing' no cambia
|
|
203
230
|
const updatedEditingStatus = !product.editing
|
|
204
231
|
if (product.editing === updatedEditingStatus) {
|
|
205
|
-
|
|
232
|
+
sendNotification({
|
|
233
|
+
description: `Product "editing" status is already: ${updatedEditingStatus}`,
|
|
234
|
+
title: 'Info',
|
|
235
|
+
backgroundColor: 'info'
|
|
236
|
+
})
|
|
206
237
|
return prevData // No actualiza si el estado es el mismo
|
|
207
238
|
}
|
|
208
239
|
|
|
@@ -227,12 +258,13 @@ export const useUploadProducts = ({
|
|
|
227
258
|
* @param {number} productIndex - The index of the product to update.
|
|
228
259
|
*/
|
|
229
260
|
const handleSuccessUpdateQuantity = (productIndex) => {
|
|
261
|
+
const product = data[productIndex]
|
|
230
262
|
setData((prevData) => {
|
|
231
263
|
// Validar que `CANTIDAD` sea un número entero
|
|
232
264
|
const product = prevData[productIndex]
|
|
233
265
|
if (!Number.isInteger(product?.CANTIDAD)) {
|
|
234
266
|
sendNotification({
|
|
235
|
-
description: '
|
|
267
|
+
description: 'La cantidad debe ser un valor entero.',
|
|
236
268
|
title: 'Error',
|
|
237
269
|
backgroundColor: 'error'
|
|
238
270
|
})
|
|
@@ -256,12 +288,13 @@ export const useUploadProducts = ({
|
|
|
256
288
|
|
|
257
289
|
return filteredData
|
|
258
290
|
})
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
291
|
+
if (product.CANTIDAD !== data[productIndex].ORIGINAL_CANTIDAD) {
|
|
292
|
+
sendNotification({
|
|
293
|
+
description: `Cantidad actualizada con éxito para el producto ${product.NOMBRE} #${productIndex}.`,
|
|
294
|
+
title: 'Éxito',
|
|
295
|
+
backgroundColor: 'success'
|
|
296
|
+
})
|
|
297
|
+
}
|
|
265
298
|
}
|
|
266
299
|
|
|
267
300
|
const handleChangeQuantity = (event, productIndex) => {
|