npm-pkg-hook 1.0.4 → 1.0.6

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.
@@ -4,9 +4,5 @@
4
4
  "deepmerge",
5
5
  "Eliminado",
6
6
  "Pedido"
7
- ],
8
- "editor.codeActionsOnSave": {
9
- "source.fixAll.eslint": true,
10
- "source.organizeImports": true
11
- }
7
+ ]
12
8
  }
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "publishConfig": {
8
8
  "registry": "https://registry.npmjs.org/"
9
9
  },
10
- "version": "1.0.4",
10
+ "version": "1.0.6",
11
11
  "description": "description-pkg-hook",
12
12
  "main": "/src/index.jsx",
13
13
  "scripts": {
@@ -15,6 +15,7 @@ export * from './useDrag'
15
15
  export * from './useEvent'
16
16
  export * from './useFetchJson'
17
17
  export * from './useFormatDate'
18
+ export * from './useFormatNumberPhone'
18
19
  export * from './useFormTools/index'
19
20
  export * from './useHover'
20
21
  export * from './useImageOptimization'
@@ -29,6 +30,7 @@ export * from './useMobile'
29
30
  export * from './useMutateHeight'
30
31
  export * from './useProductsFood'
31
32
  export * from './useProductsFood/usetagsProducts'
33
+ export * from './useReactToPrint'
32
34
  export * from './useReport'
33
35
  export * from './useRestaurant'
34
36
  export * from './useSales'
@@ -12,7 +12,7 @@ export const useBanner = () => {
12
12
  } = useQuery(GET_ONE_BANNER_STORE, {
13
13
  context: { clientName: 'admin-server' },
14
14
  variables: {
15
- idStore: !loaStore && store?.store
15
+ idStore: !loaStore && ''
16
16
  }
17
17
  })
18
18
  return [data?.getOneBanners, { loading, error }]
@@ -50,7 +50,6 @@ export const useChartData = ({ year }) => {
50
50
 
51
51
  const labelTitle = `Ventas por meses del año ${asFilter ? chartTypeYear : ''}`
52
52
  // Resultado:
53
-
54
53
  const dataChart = {
55
54
  labels: asFilter ? newResult.map(data => {
56
55
  return SPANISH_MONTHS[data.Mes]
@@ -124,9 +123,11 @@ export const useChartData = ({ year }) => {
124
123
  })
125
124
  const handleChangeYear = (value) => {
126
125
  setFilter(true)
126
+ const currentYear = parseInt(value)
127
+ setChartTypeYear(currentYear || '')
127
128
  if (result?.length > 0) {
128
129
  const filterToYear = result.filter((elem) => {
129
- return elem?.Year == parseInt(value)
130
+ return elem?.Year == currentYear
130
131
  })
131
132
  let missingNewMonths = allMonths.filter(month => { return !filterToYear.some(data => { return data.Mes === month }) })
132
133
  for (const element of missingNewMonths) {
@@ -11,3 +11,13 @@ export const useGetClients = () => {
11
11
  })
12
12
  return [clientes?.getAllClients || [], { loading, error }]
13
13
  }
14
+
15
+ export const useDeleteClients = () => {
16
+ const [clientes, setClients] = useState([])
17
+ const { loading, error } = useQuery(GET_ALL_CLIENTS, {
18
+ onCompleted: (data) => {
19
+ setClients(data)
20
+ }
21
+ })
22
+ return [clientes?.getAllClients || [], { loading, error }]
23
+ }
@@ -9,7 +9,7 @@ import { validationSubmitHooks } from '../../utils'
9
9
  * @description Hook con herramientas de validación y eventos de cambio
10
10
  * @return {Array} devuelve la función onChange a ejecutar y el estado de error de cada input
11
11
  */
12
- export const useFormTools = () => {
12
+ export const useFormTools = ({ sendNotification = () => { } } = {}) => {
13
13
  const [dataForm, setDataForm] = useState({})
14
14
  const [errorForm, setErrorForm] = useState({})
15
15
  const [errorSubmit, setErrorSubmit] = useState(false)
@@ -33,11 +33,12 @@ export const useFormTools = () => {
33
33
  // Handle submit, al enviar formulario
34
34
  const listErrors = Object.values(errorForm)
35
35
  const errors = listErrors.find((error) => {
36
- return error ===true
36
+ return error === true
37
37
  })
38
38
 
39
39
  const handleSubmit = useCallback(({ event, action, msgSuccess, msgError, actionAfterSuccess }) => {
40
- !!event && event.preventDefault()
40
+ event.preventDefault()
41
+ console.log(event)
41
42
  setCalledSubmit(true)
42
43
  let errSub = false
43
44
 
@@ -55,8 +56,8 @@ export const useFormTools = () => {
55
56
 
56
57
  // Valida los errores desde el evento
57
58
  const errores = validationSubmitHooks(event.target.elements)
59
+ console.log({errores})
58
60
  setErrorForm(errores)
59
- console.log("🚀 ~ file: index.js ~ line 50 ~ handleSubmit ~ errores", errores)
60
61
  for (const x in errores) {
61
62
  if (errores[x]) errSub = true
62
63
  }
@@ -65,11 +66,11 @@ export const useFormTools = () => {
65
66
  if (!errSub && action) {
66
67
  action().then(res => {
67
68
  if (res) {
68
- // setAlertBox({ message: msgSuccess || 'Operación exitosa', color: PColor })
69
+ sendNotification({ message: msgSuccess || 'Operación exitosa', description: 'Operación exitosa', color: PColor })
69
70
  !!actionAfterSuccess && actionAfterSuccess()
70
71
  }
71
72
 
72
- }).catch(e => {return console.log({ message: msgError || e?.message || 'Ha ocurrido un error', color: WColor })})
73
+ }).catch(e => {return sendNotification({ title: msgError || e?.message || 'Ha ocurrido un error', color: WColor })})
73
74
  }
74
75
 
75
76
  setErrorSubmit(errSub)
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Description
3
+ * @param {any} phoneNumber type number or string
4
+ * @returns {any}
5
+ */
6
+ export const formatPhoneNumber = (phoneNumber) => {
7
+ const cleaned = ('' + phoneNumber).replace(/\D/g, '');
8
+ const match = cleaned.match(/^(\d{3})(\d{3})(\d{4})$/);
9
+ if (match) {
10
+ return `(${match[1]}) ${match[2]}-${match[3]}`;
11
+ }
12
+ return phoneNumber;
13
+ }
14
+
15
+ /**
16
+ * Description
17
+ * @param {any} phoneNumber type number or string
18
+ * @returns {any}
19
+ */
20
+ export const validatePhoneNumber = (phoneNumber) => {
21
+ const regex = /^\(\d{3}\) \d{3}-\d{4}$/;
22
+ return regex.test(phoneNumber);
23
+ };
@@ -38,10 +38,13 @@ export const useProductsFood = ({
38
38
  search = null,
39
39
  toDate
40
40
  }) => {
41
- const [productsFood, setProductsFood] = useState([])
41
+ // const [productsFood, setProductsFood] = useState([])
42
42
  const [showMore, setShowMore] = useState(50)
43
43
  const { data, loading, fetchMore, error } = useQuery(GET_ALL_PRODUCT_STORE, {
44
- fetchPolicy: fetchPolicy,
44
+ fetchPolicy: fetchPolicy ?? 'cache-and-network',
45
+ notifyOnNetworkStatusChange: true,
46
+ nextFetchPolicy: 'cache-first',
47
+ refetchWritePolicy: 'merge',
45
48
  variables:
46
49
  {
47
50
  categories: categories || [],
@@ -55,9 +58,8 @@ export const useProductsFood = ({
55
58
  toDate: toDate || null
56
59
  }
57
60
  })
58
- useEffect(() => {
59
- setProductsFood(data?.productFoodsAll || [])
60
- }, [data, productsFood])
61
+
62
+ const productsFood = data?.productFoodsAll
61
63
  return [
62
64
  productsFood, {
63
65
  error,
@@ -365,7 +365,6 @@ query ExtProductFoodsOptionalAll($search: String, $min: Int, $max: Int, $pId: ID
365
365
  pDatCre
366
366
  pDatMod
367
367
  }
368
-
369
368
  }
370
369
  }
371
370
  `