npm-pkg-hook 1.8.6 → 1.8.7
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 +4 -2
- package/src/hooks/generateTemplate/index.js +62 -0
- package/src/hooks/index.js +3 -0
- package/src/hooks/useUpdateMultipleProducts/index.js +54 -0
- package/src/hooks/useUpdateMultipleProducts/queries.js +51 -0
- package/src/hooks/useUploadProducts/index.js +43 -0
- package/src/utils/index.js +2 -0
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"dependencies": {
|
|
4
4
|
"@apollo/client": "3.6.9",
|
|
5
5
|
"@typescript-eslint/parser": "^5.37.0",
|
|
6
|
+
"file-saver": "2.0.5",
|
|
6
7
|
"js-cookie": "3.0.1",
|
|
7
8
|
"lodash": "^4.17.21",
|
|
8
9
|
"md5": "2.3.0",
|
|
@@ -10,7 +11,8 @@
|
|
|
10
11
|
"react": "18.1.0",
|
|
11
12
|
"react-dom": "18.1.0",
|
|
12
13
|
"react-query": "^3.39.2",
|
|
13
|
-
"react-responsive": "^10.0.0"
|
|
14
|
+
"react-responsive": "^10.0.0",
|
|
15
|
+
"xlsx": "0.18.5"
|
|
14
16
|
},
|
|
15
17
|
"description": "description-pkg-hook",
|
|
16
18
|
"devDependencies": {
|
|
@@ -45,5 +47,5 @@
|
|
|
45
47
|
"rm": "rm -rf node_modules package-lock.json && npm i",
|
|
46
48
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
47
49
|
},
|
|
48
|
-
"version": "1.8.
|
|
50
|
+
"version": "1.8.7"
|
|
49
51
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as Excel from 'xlsx'
|
|
2
|
+
import { saveAs } from 'file-saver'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Class to generate Excel reports.
|
|
6
|
+
*/
|
|
7
|
+
export class GenerateReport {
|
|
8
|
+
/**
|
|
9
|
+
* Generates an Excel report from given data and type.
|
|
10
|
+
* @param {Array<object>} data - The data to be included in the Excel report.
|
|
11
|
+
* @param {number} type - The type of report to generate.
|
|
12
|
+
* @throws Will throw an error if data is not an array or type is not a valid number.
|
|
13
|
+
*/
|
|
14
|
+
GenExcelReport (data, type) {
|
|
15
|
+
if (!Array.isArray(data)) {
|
|
16
|
+
throw new Error('Data must be an array of objects.')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (typeof type !== 'number') {
|
|
20
|
+
throw new Error('Type must be a valid number.')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const ws = Excel.utils.json_to_sheet(data)
|
|
24
|
+
|
|
25
|
+
// Apply bold font to the header row
|
|
26
|
+
const range = Excel.utils.decode_range(ws['!ref'])
|
|
27
|
+
for (let C = range.s.c; C <= range.e.c; ++C) {
|
|
28
|
+
const cell = ws[Excel.utils.encode_cell({ r: 0, c: C })]
|
|
29
|
+
if (cell) {
|
|
30
|
+
cell.s = {
|
|
31
|
+
font: {
|
|
32
|
+
bold: true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const wb = Excel.utils.book_new()
|
|
39
|
+
Excel.utils.book_append_sheet(wb, ws, 'Hoja1')
|
|
40
|
+
const excelBuffer = Excel.write(wb, { bookType: 'xlsx', type: 'array' })
|
|
41
|
+
const blob = new Blob([excelBuffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
|
|
42
|
+
const fileName = this.GenExcelReportFileName(type)
|
|
43
|
+
if (fileName != null) {
|
|
44
|
+
saveAs(blob, String(fileName))
|
|
45
|
+
} else {
|
|
46
|
+
throw new Error('Invalid report type provided.')
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Generates the file name for the Excel report based on the type.
|
|
52
|
+
* @param {number} type - The type of report.
|
|
53
|
+
* @returns {string | null} The file name for the report, or null if type is invalid.
|
|
54
|
+
*/
|
|
55
|
+
GenExcelReportFileName (type) {
|
|
56
|
+
const fileNames = {
|
|
57
|
+
1: 'report.xlsx'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return fileNames[type] ? fileNames[type] : null
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/hooks/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from './useManageQueryParams'
|
|
|
8
8
|
export * from './useDeliveryTime'
|
|
9
9
|
export * from './useModules'
|
|
10
10
|
export * from './getTotalHours'
|
|
11
|
+
export * from './useUpdateMultipleProducts'
|
|
11
12
|
export * from './useTokenCards'
|
|
12
13
|
export * from './useSubscriptionValidation'
|
|
13
14
|
export * from './convertToMilitaryTime'
|
|
@@ -15,8 +16,10 @@ export * from './statusOpenStores'
|
|
|
15
16
|
export * from './completeSchedules'
|
|
16
17
|
export * from './useLogout/helpers/BroadcastChannel'
|
|
17
18
|
export * from './getCardType'
|
|
19
|
+
export * from './useUploadProducts'
|
|
18
20
|
export * from './newMessageSubscription'
|
|
19
21
|
export * from './useGetCookies'
|
|
22
|
+
export * from './generateTemplate'
|
|
20
23
|
export * from './isTokenExpired'
|
|
21
24
|
export * from './useCreateDeliveryTime'
|
|
22
25
|
export * from './addTenMinutes'
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useMutation } from '@apollo/client'
|
|
2
|
+
import { UPDATE_MULTIPLE_PRODUCTS } from './queries'
|
|
3
|
+
import { CATEGORY_EMPTY, RandomCode } from '../../utils/index'
|
|
4
|
+
import { useCategoriesProduct } from '../useCategoriesProduct'
|
|
5
|
+
|
|
6
|
+
export const useUpdateMultipleProducts = ({
|
|
7
|
+
sendNotification = () => { }
|
|
8
|
+
}) => {
|
|
9
|
+
const [updateMultipleProducts, { data, loading, error }] = useMutation(UPDATE_MULTIPLE_PRODUCTS)
|
|
10
|
+
const [dataCategoriesProducts] = useCategoriesProduct()
|
|
11
|
+
const findEmptyCategory = dataCategoriesProducts?.find(category => category.pName === CATEGORY_EMPTY)
|
|
12
|
+
const updateProducts = async (products) => {
|
|
13
|
+
const newProducts = products.map(product => {
|
|
14
|
+
const code = RandomCode(9)
|
|
15
|
+
return {
|
|
16
|
+
idStore: '',
|
|
17
|
+
ProPrice: product.PRECIO_AL_PUBLICO,
|
|
18
|
+
ProDescuento: 0,
|
|
19
|
+
ValueDelivery: 0,
|
|
20
|
+
ProDescription: product.DESCRIPCION,
|
|
21
|
+
pName: product.NOMBRE,
|
|
22
|
+
pCode: code,
|
|
23
|
+
carProId: findEmptyCategory?.carProId ?? null,
|
|
24
|
+
pState: 1,
|
|
25
|
+
sTateLogistic: 1,
|
|
26
|
+
ProStar: 0,
|
|
27
|
+
ProImage: 'https:http://localhost:8080',
|
|
28
|
+
ProHeight: null,
|
|
29
|
+
ProWeight: '',
|
|
30
|
+
ProOutstanding: 0,
|
|
31
|
+
ProDelivery: 0
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
try {
|
|
36
|
+
const response = await updateMultipleProducts({ variables: { input: newProducts } })
|
|
37
|
+
return response.data.updateMultipleProducts
|
|
38
|
+
} catch (e) {
|
|
39
|
+
sendNotification({
|
|
40
|
+
backgroundColor: 'error',
|
|
41
|
+
description: 'Ocurrió un error al actualizar los productos',
|
|
42
|
+
title: 'Error'
|
|
43
|
+
})
|
|
44
|
+
return []
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
updateProducts,
|
|
50
|
+
data,
|
|
51
|
+
loading,
|
|
52
|
+
error
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const UPDATE_MULTIPLE_PRODUCTS = gql`
|
|
4
|
+
mutation updateMultipleProducts($input: [InputProductFood]) {
|
|
5
|
+
updateMultipleProducts(input: $input) {
|
|
6
|
+
success
|
|
7
|
+
message
|
|
8
|
+
errors {
|
|
9
|
+
path
|
|
10
|
+
message
|
|
11
|
+
type
|
|
12
|
+
context {
|
|
13
|
+
limit
|
|
14
|
+
value
|
|
15
|
+
label
|
|
16
|
+
key
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
data {
|
|
20
|
+
pId
|
|
21
|
+
sizeId
|
|
22
|
+
colorId
|
|
23
|
+
cId
|
|
24
|
+
dId
|
|
25
|
+
ctId
|
|
26
|
+
fId
|
|
27
|
+
pName
|
|
28
|
+
pCode
|
|
29
|
+
ProPrice
|
|
30
|
+
carProId
|
|
31
|
+
ProDescuento
|
|
32
|
+
ProUniDisponibles
|
|
33
|
+
ValueDelivery
|
|
34
|
+
ProDescription
|
|
35
|
+
ProProtegido
|
|
36
|
+
ProAssurance
|
|
37
|
+
ProStar
|
|
38
|
+
pState
|
|
39
|
+
ProImage
|
|
40
|
+
ProWidth
|
|
41
|
+
ProHeight
|
|
42
|
+
ProLength
|
|
43
|
+
ProWeight
|
|
44
|
+
ProQuantity
|
|
45
|
+
ProOutstanding
|
|
46
|
+
ProDelivery
|
|
47
|
+
ProVoltaje
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import * as XLSX from 'xlsx'
|
|
3
|
+
|
|
4
|
+
export const useUploadProducts = () => {
|
|
5
|
+
const [data, setData] = useState([])
|
|
6
|
+
|
|
7
|
+
const [active, setActive] = useState(0)
|
|
8
|
+
const [overActive, setOverActive] = useState(0)
|
|
9
|
+
|
|
10
|
+
const handleOverActive = (index) => {
|
|
11
|
+
setOverActive(index)
|
|
12
|
+
}
|
|
13
|
+
const readExcelFile = (file) => {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const reader = new FileReader()
|
|
16
|
+
reader.onload = (e) => {
|
|
17
|
+
const data = new Uint8Array(e.target.result)
|
|
18
|
+
const workbook = XLSX.read(data, { type: 'array' })
|
|
19
|
+
const sheetName = workbook.SheetNames[0]
|
|
20
|
+
const worksheet = workbook.Sheets[sheetName]
|
|
21
|
+
const json = XLSX.utils.sheet_to_json(worksheet)
|
|
22
|
+
resolve(json)
|
|
23
|
+
}
|
|
24
|
+
reader.onerror = (error) => reject(error)
|
|
25
|
+
reader.readAsArrayBuffer(file)
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const onChangeFiles = async (files) => {
|
|
30
|
+
const filePromises = Array.from(files).map(file => readExcelFile(file))
|
|
31
|
+
const data = await Promise.all(filePromises)
|
|
32
|
+
setData(data.flat())
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
active,
|
|
37
|
+
data,
|
|
38
|
+
overActive,
|
|
39
|
+
handleOverActive,
|
|
40
|
+
onChangeFiles,
|
|
41
|
+
setActive
|
|
42
|
+
}
|
|
43
|
+
}
|