npm-pkg-hook 1.2.6 → 1.2.8

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
@@ -43,5 +43,5 @@
43
43
  "rm": "rm -rf node_modules package-lock.json && npm i",
44
44
  "test": "echo \"Error: no test specified\" && exit 1"
45
45
  },
46
- "version": "1.2.6"
46
+ "version": "1.2.8"
47
47
  }
@@ -11,6 +11,7 @@ export * from './useStatusOpenStore'
11
11
  export * from './useScheduleData'
12
12
  export * from './useOrders'
13
13
  export * from './useFingerprintjs'
14
+ export * from './useEditCategory'
14
15
  export * from './useEmployee'
15
16
  export * from './useCheckbox'
16
17
  export * from './useRemoveExtraProductFoodsOptional'
@@ -8,15 +8,17 @@ export const useUpdateExtProductFoodsOptional = () => {
8
8
  const handleUpdateExtProduct = async ({
9
9
  pId,
10
10
  code,
11
+ opExPid,
11
12
  OptionalProName,
12
13
  required,
13
14
  numbersOptionalOnly
14
15
  }) => {
15
- await updateExtProductFoodsOptional({
16
+ return await updateExtProductFoodsOptional({
16
17
  variables: {
17
18
  input: {
18
19
  pId,
19
20
  code,
21
+ opExPid,
20
22
  OptionalProName,
21
23
  required,
22
24
  numbersOptionalOnly
@@ -11,7 +11,6 @@ export const useDeleteSubProductOptional = ({ setAlertBox = () => { } } = {}) =>
11
11
  }] = useMutation(DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS)
12
12
 
13
13
  const handleRemoveSubProductOptional = ({ state, opSubExPid }) => {
14
- console.log(state, opSubExPid)
15
14
  DeleteExtFoodSubsOptional({
16
15
  variables: {
17
16
  state,
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  useState,
3
- useEffect,
4
- useMemo
3
+ useEffect
5
4
  } from 'react'
6
5
  import { MockData } from '../../mock'
7
6
  import { RandomCode, updateCacheMod } from '../../utils'
@@ -11,6 +10,7 @@ import { useRemoveExtraProductFoodsOptional } from '../useRemoveExtraProductFood
11
10
  import { GET_EXTRAS_PRODUCT_FOOD_OPTIONAL } from '../useRemoveExtraProductFoodsOptional/queries'
12
11
  import { transformDataToDessert } from './helpers'
13
12
  import { useDeleteSubProductOptional } from '../useDeleteSubProductOptional'
13
+ import { useEditSubProductOptional } from '../useEditSubProductOptional'
14
14
  export * from './helpers'
15
15
  export const useDessert = ({
16
16
  pId = null,
@@ -18,10 +18,11 @@ export const useDessert = ({
18
18
  sendNotification = () => { }
19
19
  }) => {
20
20
  // Initialize state variables using the useState hook
21
- const [setCheck, setChecker] = useState({}) // State for checkboxes
21
+ const [setCheck, setChecker] = useState({
22
+ exState: false
23
+ }) // State for checkboxes
22
24
  const [valueItems, setValueItems] = useState('') // State for input values
23
25
  const [title, setTitle] = useState('') // State for title input value
24
-
25
26
  // Initialize the data state with the transformedData or MockData
26
27
  const [data, setData] = useState(MockData)
27
28
  const dataListIds = data?.listIds?.filter(x => x !== '01list')
@@ -69,6 +70,7 @@ export const useDessert = ({
69
70
  const { handleUpdateExtProduct } = useUpdateExtProductFoodsOptional()
70
71
  const { DeleteExtProductFoodsOptional } = useRemoveExtraProductFoodsOptional()
71
72
  const [DeleteExtFoodSubsOptional] = useDeleteSubProductOptional()
73
+ const [editExtFoodSubsOptional, { loading: loadingEditSubOptional }] = useEditSubProductOptional()
72
74
 
73
75
  // HANDLESS
74
76
  /**
@@ -156,12 +158,12 @@ export const useDessert = ({
156
158
  isCustomSubOpExPid = false
157
159
  }) => {
158
160
  try {
159
- const forRemove = Boolean(isCustomSubOpExPid && listID && id)
161
+ const forRemove = Boolean(listID && id)
160
162
  if (forRemove) {
161
163
  DeleteExtFoodSubsOptional({
162
164
  variables: {
163
165
  isCustomSubOpExPid,
164
- opSubExPid: listID,
166
+ opSubExPid: id,
165
167
  state: 1
166
168
  }
167
169
  })
@@ -180,7 +182,7 @@ export const useDessert = ({
180
182
  const currentList = data.lists[listID]
181
183
 
182
184
  // Filter out the item with the specified ID from the current list's cards array
183
- const totalCart = currentList.cards.filter((cart) => cart.id !== id)
185
+ const filteredCart = currentList?.cards?.filter((cart) => cart.id !== id)
184
186
 
185
187
  // Update the current list's cards with the filtered array to remove the specified item
186
188
  setData({
@@ -189,7 +191,7 @@ export const useDessert = ({
189
191
  ...data.lists,
190
192
  [listID]: {
191
193
  ...currentList,
192
- cards: totalCart
194
+ cards: filteredCart
193
195
  }
194
196
  }
195
197
  })
@@ -197,6 +199,146 @@ export const useDessert = ({
197
199
  console.error(error)
198
200
  }
199
201
  }
202
+ const [selectedItem, setSelectedItem] = useState({})
203
+
204
+ const editOneItem = ({
205
+ listID = '',
206
+ id = '',
207
+ title = null
208
+ }) => {
209
+ try {
210
+ setSelectedItem(() => {
211
+ return { listID, id }
212
+ })
213
+ const currentList = data.lists[listID];
214
+ const findItem = currentList?.cards?.find(item => item.id === id)
215
+ const checkDifferentText = findItem?.title !== title
216
+ if (title && checkDifferentText) {
217
+ editExtFoodSubsOptional({
218
+ variables: {
219
+ isCustomSubOpExPid: false,
220
+ opSubExPid: id,
221
+ OptionalSubProName: title
222
+ }
223
+ }).then(({ data: response }) => {
224
+ const { editExtFoodSubsOptional } = response || {}
225
+ const { success } = editExtFoodSubsOptional || { success: false }
226
+ if (success) {
227
+ sendNotification({
228
+ description: 'El sub item actualizado con exito',
229
+ title: 'Actualizado',
230
+ backgroundColor: 'success'
231
+ })
232
+ const currentList = data.lists[listID];
233
+ const updatedCards = currentList?.cards?.map((card) => {
234
+ if (card.id === id) {
235
+ return {
236
+ ...card,
237
+ title: title
238
+ };
239
+ }
240
+ return card;
241
+ });
242
+ setData({
243
+ listIds: [...data.listIds],
244
+ lists: {
245
+ ...data.lists,
246
+ [listID]: {
247
+ ...currentList,
248
+ cards: updatedCards
249
+ }
250
+ }
251
+ });
252
+ }
253
+ })
254
+ }
255
+ } catch (error) {
256
+ console.error(error)
257
+ }
258
+ }
259
+ const [selectedExtra, setSelectedExtra] = useState({})
260
+ const [openModalEditExtra, setOpenModalEditExtra] = useState(false)
261
+
262
+ const updateListById = (listId, updatedFields) => {
263
+ setData((prevData) => {
264
+ const updatedLists = {
265
+ ...prevData.lists,
266
+ [listId]: {
267
+ ...prevData.lists[listId],
268
+ ...updatedFields
269
+ }
270
+ };
271
+
272
+ return {
273
+ ...prevData,
274
+ lists: updatedLists
275
+ };
276
+ });
277
+ };
278
+ /**
279
+ * Edit a extra.
280
+ * @async
281
+ * @param {Object} options - Opciones para la edición del extra.
282
+ * @param {string} options.id - ID del extra.
283
+ * @param {number|null} options.numberLimit - Límite de número para el extra.
284
+ * @param {string} options.title - Título del extra.
285
+ * @param {boolean} options.required - Indica si el extra es requerido.
286
+ * @throws {Error} Se lanza un error si no se proporciona un ID válido.
287
+ * @returns {Promise<void>}
288
+ */
289
+ const editOneExtra = async ({
290
+ id = '',
291
+ numberLimit = null,
292
+ title,
293
+ required
294
+ }) => {
295
+ try {
296
+ if (id) {
297
+ const response = await handleUpdateExtProduct({
298
+ opExPid: id,
299
+ code: id,
300
+ OptionalProName: title,
301
+ required: required ? 1 : 0,
302
+ numbersOptionalOnly: numberLimit
303
+ })
304
+ const { data } = response || {}
305
+ if (!data?.updateExtProductFoodsOptional) return sendNotification({
306
+ description: 'Ocurrió un error, intenta de nuevo',
307
+ title: 'Error',
308
+ backgroundColor: 'warning'
309
+ })
310
+ const { success, message } = data?.updateExtProductFoodsOptional || {}
311
+ if (success) {
312
+ setSelectedExtra({})
313
+ setOpenModalEditExtra(false)
314
+ sendNotification({
315
+ description: message,
316
+ title: 'Actualizado',
317
+ backgroundColor: 'success'
318
+ })
319
+ return updateListById(id, {
320
+ title: title,
321
+ numberLimit: numberLimit,
322
+ required: required ? 1 : 0
323
+ });
324
+ }
325
+ }
326
+
327
+ if (!id) return sendNotification({
328
+ description: 'Ocurrió un error, intenta de nuevo',
329
+ title: 'Error',
330
+ backgroundColor: 'warning'
331
+ })
332
+ } catch (error) {
333
+ setSelectedExtra({})
334
+ setOpenModalEditExtra(false)
335
+ sendNotification({
336
+ description: 'Ocurrió un error, intenta de nuevo',
337
+ title: 'Error',
338
+ backgroundColor: 'warning'
339
+ })
340
+ }
341
+ }
200
342
 
201
343
  const addCard = async (title, listId) => {
202
344
  const id = RandomCode(9)
@@ -316,6 +458,7 @@ export const useDessert = ({
316
458
  addCard,
317
459
  data,
318
460
  dataListIds,
461
+ loadingEditSubOptional,
319
462
  isCompleteRequired,
320
463
  handleAdd,
321
464
  handleAddList,
@@ -323,9 +466,16 @@ export const useDessert = ({
323
466
  handleCheck,
324
467
  handleRemoveList,
325
468
  removeOneItem,
469
+ editOneExtra,
470
+ editOneItem,
326
471
  setCheck,
472
+ selectedItem,
327
473
  setData,
328
474
  setTitle,
329
- title
475
+ title,
476
+ selectedExtra,
477
+ openModalEditExtra,
478
+ setSelectedExtra,
479
+ setOpenModalEditExtra,
330
480
  }
331
481
  }
@@ -0,0 +1,41 @@
1
+ import { gql, useMutation } from '@apollo/client';
2
+
3
+ const EDIT_CATEGORY_PRODUCT = gql`
4
+ mutation EditOneCategoryProduct($pName: String!, $ProDescription: String, $carProId: ID!) {
5
+ editOneCategoryProduct(pName: $pName, ProDescription: $ProDescription, carProId: $carProId) {
6
+ success
7
+ message
8
+ }
9
+ }
10
+ `;
11
+
12
+ export const useEditCategoryProduct = ({ sendNotification = () => { return } } = {}) => {
13
+ const [editCategoryProductMutation] = useMutation(EDIT_CATEGORY_PRODUCT);
14
+
15
+ const editCategoryProduct = async (pName, ProDescription, carProId) => {
16
+ try {
17
+ const { data } = await editCategoryProductMutation({
18
+ variables: { pName, ProDescription, carProId }
19
+ });
20
+
21
+ if (data.editOneCategoryProduct.success) {
22
+ return {
23
+ success: true,
24
+ message: 'Categoría de producto editada correctamente'
25
+ };
26
+ } else {
27
+ return {
28
+ success: false,
29
+ message: data.editOneCategoryProduct.message || 'Error al editar la categoría de producto'
30
+ };
31
+ }
32
+ } catch (error) {
33
+ return {
34
+ success: false,
35
+ message: error.message || 'Error al editar la categoría de producto'
36
+ };
37
+ }
38
+ };
39
+
40
+ return { editCategoryProduct }
41
+ };
@@ -0,0 +1,11 @@
1
+ import { EDIT_EXTRA_SUB_OPTIONAL_PRODUCTS } from "./queries"
2
+ import { useMutation } from '@apollo/client'
3
+
4
+ export const useEditSubProductOptional = () => {
5
+ const [editExtFoodSubsOptional, {
6
+ loading,
7
+ error,
8
+ called
9
+ }] = useMutation(EDIT_EXTRA_SUB_OPTIONAL_PRODUCTS)
10
+ return [editExtFoodSubsOptional, { loading, error, called }]
11
+ }
@@ -0,0 +1,10 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const EDIT_EXTRA_SUB_OPTIONAL_PRODUCTS = gql`
4
+ mutation editExtFoodSubsOptional($opSubExPid: ID, $state: Int, $isCustomSubOpExPid: Boolean, $OptionalSubProName: String){
5
+ editExtFoodSubsOptional(opSubExPid: $opSubExPid, state: $state, isCustomSubOpExPid: $isCustomSubOpExPid, OptionalSubProName: $OptionalSubProName){
6
+ success,
7
+ message
8
+ }
9
+ }
10
+ `
@@ -80,10 +80,10 @@ export const useFormTools = ({ sendNotification = () => { } } = {}) => {
80
80
  sendNotification({
81
81
  message: msgSuccess || 'Operación exitosa',
82
82
  description: 'Operación exitosa',
83
- backgroundColor: 'success'
83
+ backgroundColor: 'success'
84
84
  })
85
85
  !!actionAfterSuccess && actionAfterSuccess()
86
- }
86
+ }
87
87
  }).catch(e => { return sendNotification({ title: msgError || e?.message || 'Ha ocurrido un error', backgroundColor: 'error' }) })
88
88
  }
89
89
 
@@ -92,9 +92,9 @@ export const useFormTools = ({ sendNotification = () => { } } = {}) => {
92
92
 
93
93
  useEffect(() => { return setCalledSubmit(false) }, [calledSubmit])
94
94
  useEffect(() => {
95
- return setCalledSubmit(false)
95
+ return setCalledSubmit(false)
96
96
  },
97
97
  [])
98
98
 
99
99
  return [handleChange, handleSubmit, handleForcedData, { dataForm, errorForm, errorSubmit, calledSubmit, setForcedError }]
100
- }
100
+ }
@@ -12,7 +12,7 @@ import {
12
12
  } from '../useProductsFood/queriesStore'
13
13
  import { GET_ONE_STORE } from '../useStore/queries'
14
14
  export { GET_MIN_PEDIDO } from './queries'
15
-
15
+ export * from './queries'
16
16
  export const useImageStore = ({ idStore, sendNotification = () => { } } = {}) => {
17
17
  // STATES
18
18
  const fileInputRef = useRef(null)
@@ -374,13 +374,8 @@ export const UPDATE_EXTRAS_PRODUCT_FOOD = gql`
374
374
  export const UPDATE_EXTRAS_PRODUCT_FOOD_OPTIONAL = gql`
375
375
  mutation updateExtProductFoodsOptional($input: InputExtProductFoodOptional) {
376
376
  updateExtProductFoodsOptional(input: $input) {
377
- pId
378
- opExPid
379
- OptionalProName
380
- code
381
- required
382
- state
383
- numbersOptionalOnly
377
+ success,
378
+ message
384
379
  }
385
380
  }
386
381
  `