npm-pkg-hook 1.8.5 → 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 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.5"
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
+ }
@@ -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'
@@ -15,14 +15,28 @@ import { getCatProductsWithProduct } from './helpers/manageCacheDataCatProduct'
15
15
  export * from './helpers'
16
16
 
17
17
  export const useCreateProduct = ({
18
- setAlertBox = () => { },
19
18
  router,
20
- sendNotification = () => { }
19
+ setAlertBox = (args) => { return args },
20
+ sendNotification = (args) => { return args }
21
21
  }) => {
22
22
  const [errors, setErrors] = useState({
23
- names: ''
23
+ names: false,
24
+ ProPrice: false,
25
+ ProDescuento: false,
26
+ ProDescription: false,
27
+ ProWeight: false,
28
+ ProHeight: false,
29
+ ValueDelivery: false
30
+ })
31
+ const [values, setValues] = useState({
32
+ ProPrice: 0,
33
+ ProDescuento: 0,
34
+ ProDescription: '',
35
+ ProWeight: '',
36
+ ProHeight: '',
37
+ ValueDelivery: 0,
38
+ carProId: ''
24
39
  })
25
- const [values, setValues] = useState({})
26
40
  const [names, setName] = useLocalStorage('namefood', '')
27
41
  const [showMore, setShowMore] = useState(50)
28
42
  const [search, setSearch] = useState('')
@@ -49,7 +63,9 @@ export const useCreateProduct = ({
49
63
  // HANDLESS
50
64
  const [check, setCheck] = useState({
51
65
  availability: true,
52
- noAvailability: false
66
+ noAvailability: false,
67
+ desc: false,
68
+ freeShipping: false
53
69
  })
54
70
 
55
71
  const handleCheck = (e) => {
@@ -79,7 +95,11 @@ export const useCreateProduct = ({
79
95
  setSearchFilter({ ...filter })
80
96
  }
81
97
  const onClickClear = () => {
82
- setSearchFilter({})
98
+ setSearchFilter({
99
+ gender: [],
100
+ desc: [],
101
+ speciality: []
102
+ })
83
103
  }
84
104
  const handleChangeClick = e => {
85
105
  const {
@@ -96,7 +116,7 @@ export const useCreateProduct = ({
96
116
  handleCheck(e)
97
117
  setValues({
98
118
  ...values,
99
- ValueDelivery: ''
119
+ ValueDelivery: 0
100
120
  })
101
121
  }
102
122
 
@@ -112,7 +132,6 @@ export const useCreateProduct = ({
112
132
  const file = event.target.files[0]
113
133
  setImage(file)
114
134
  const base64 = await convertBase64(file)
115
- // eslint-disable-next-line
116
135
  // const [size, { unit }] = await getFileSizeByUnit(file, "B");
117
136
  setImageBase64(base64)
118
137
  setPreviewImg(
@@ -125,7 +144,9 @@ export const useCreateProduct = ({
125
144
  )
126
145
  }
127
146
  const onTargetClick = () => {
128
- fileInputRef.current.click()
147
+ if (fileInputRef.current) {
148
+ fileInputRef.current.click()
149
+ }
129
150
  }
130
151
  // eslint-disable-next-line no-unused-vars
131
152
  const { img } = useEditImageProduct({ sendNotification, initialState })
@@ -139,23 +160,27 @@ export const useCreateProduct = ({
139
160
  ProHeight,
140
161
  ValueDelivery,
141
162
  carProId
142
- } = values
143
- const formatPrice = ProPrice ? parseFloat(ProPrice?.replace(/\./g, '')) : 0
144
- if (!carProId && !names) return setErrors({ ...errors, carProId: true })
145
-
146
- if (!ProPrice?.length > 0) {
147
- return setErrors({ ...errors, ProPrice: true })
163
+ } = values ?? {
164
+ ProPrice: 0,
165
+ ProDescuento: 0,
166
+ ProDescription: '',
167
+ ProWeight: '',
168
+ ProHeight: 0,
169
+ ValueDelivery: 0,
170
+ carProId: ''
148
171
  }
149
- const ProImage = `https:${process.env.URL_ADMIN_SERVER}static/platos/${image?.name}`
172
+ const formatPrice = ProPrice ?? 0
173
+ if (!carProId && !names) return setErrors({ ...errors, carProId: true })
174
+ const ProImage = `https:${process.env.URL_ADMIN_SERVER}/static/platos/${image?.name}`
150
175
  const pCode = RandomCode(9)
151
176
  try {
152
- updateProductFoods({
177
+ const res = await updateProductFoods({
153
178
  variables: {
154
179
  input: {
155
180
  idStore: dataStore?.getStore?.idStore || '',
156
181
  ProPrice: check?.desc ? 0 : formatPrice,
157
- ProDescuento: check?.desc ? 0 : parseInt(ProDescuento),
158
- ValueDelivery: check?.desc ? 0 : parseFloat(ValueDelivery),
182
+ ProDescuento: check?.desc ? 0 : ProDescuento,
183
+ ValueDelivery: check?.desc ? 0 : ValueDelivery,
159
184
  ProDescription,
160
185
  pName: names,
161
186
  pCode,
@@ -176,63 +201,44 @@ export const useCreateProduct = ({
176
201
  productFoodsAll (dataOld = []) {
177
202
  return cache.writeQuery({ query: GET_ALL_FOOD_PRODUCTS, data: dataOld })
178
203
  },
179
- getCatProductsWithProduct (dataOld = {}) {
204
+ getCatProductsWithProduct () {
180
205
  const updatedData = getCatProductsWithProduct(data, carProId)
181
206
  return updatedData
182
207
  }
183
208
  }
184
209
  })
185
210
  }
186
- }).then((res) => {
187
- const { updateProductFoods } = res?.data || {}
188
- const { pId } = updateProductFoods || {}
189
- setPid(pId ?? null)
190
- router.push(
191
- {
192
- query: {
193
- ...router.query,
194
- food: pId
195
- }
196
- },
197
- undefined,
198
- { shallow: true }
199
- )
200
- sendNotification({
201
- backgroundColor: 'success',
202
- title: 'Success',
203
- description: `El producto ${names} subido con éxito`
204
- })
205
- const objTag = {
206
- aName: tags.tag,
207
- nameTag: tags.tag,
208
- pId
209
- }
210
- if (tags?.tag) handleRegisterTags(objTag)
211
- setValues({})
212
- }).catch(err => {
213
- return sendNotification({
214
- backgroundColor: 'error',
215
- title: `${err}`,
216
- description: 'Error inesperado'
211
+ }).finally(() => {
212
+ setValues({
213
+ ProPrice: 0,
214
+ ProDescuento: 0,
215
+ ProDescription: '',
216
+ ProWeight: '',
217
+ ProHeight: '',
218
+ ValueDelivery: 0,
219
+ carProId: ''
217
220
  })
218
221
  })
219
222
  if (image !== null) {
220
- setImageProducts({
221
- variables: {
222
- input: {
223
- file: image,
224
- pCode
223
+ try {
224
+ await setImageProducts({
225
+ variables: {
226
+ input: {
227
+ file: image,
228
+ pCode
229
+ }
225
230
  }
226
- }
227
- }).then(() => {
228
- }).catch(() => {
231
+ })
232
+ } catch {
229
233
  sendNotification({
230
234
  backgroundColor: 'error',
231
235
  title: `Ocurrió un error en la imagen en el producto ${names}`,
232
236
  description: 'error'
233
237
  })
234
- })
238
+ }
235
239
  }
240
+ setPid(res?.data?.updateProductFoods?.data?.pId ?? null)
241
+ return res
236
242
  } catch (error) {
237
243
  setAlertBox({ message: 'Ha ocurrido un error', duration: 7000 })
238
244
  }
@@ -48,7 +48,7 @@ export const useDessert = ({
48
48
  // If list or list.cards is missing, assume the list is not complete
49
49
  const verifiEmpyRequireCard = list?.cards?.length
50
50
  if (list && list?.cards) {
51
- return verifiEmpyRequireCard === list.numberLimit
51
+ return Number(verifiEmpyRequireCard) === Number(list.numberLimit)
52
52
  }
53
53
 
54
54
  // If list or list.cards is missing, assume the list is not complete
@@ -324,8 +324,22 @@ export const UPDATE_IMAGE_PRODUCT_FOOD = gql`
324
324
  }
325
325
  `
326
326
  export const UPDATE_PRODUCT_FOOD = gql`
327
- mutation updateProductFoods($input: InputProductFood) {
327
+ mutation updateProductFoods($input: InputProductFood) {
328
328
  updateProductFoods(input: $input) {
329
+ success
330
+ message
331
+ errors {
332
+ path
333
+ message
334
+ type
335
+ context {
336
+ limit
337
+ value
338
+ label
339
+ key
340
+ }
341
+ }
342
+ data {
329
343
  pId
330
344
  sizeId #Talla
331
345
  colorId #Color
@@ -355,6 +369,7 @@ export const UPDATE_PRODUCT_FOOD = gql`
355
369
  ProDelivery
356
370
  ProVoltaje
357
371
  }
372
+ }
358
373
  }
359
374
  `
360
375
  // UPDATE EXTRAS
@@ -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
+ }
@@ -208,3 +208,5 @@ export const paymentMethodCards = [
208
208
  icon: 'IconMasterCard'
209
209
  }
210
210
  ]
211
+
212
+ export const CATEGORY_EMPTY = 'NINGUNO'