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.
- package/.vscode/settings.json +1 -5
- package/package.json +1 -1
- package/src/hooks/index.js +2 -0
- package/src/hooks/useBanner/index.js +1 -1
- package/src/hooks/useChartData/index.js +3 -2
- package/src/hooks/useClients/index.js +10 -0
- package/src/hooks/useFormTools/index.js +7 -6
- package/src/hooks/useFormatNumberPhone/index.js +23 -0
- package/src/hooks/useProductsFood/index.js +7 -5
- package/src/hooks/useProductsFood/queriesStore.js +0 -1
- package/src/hooks/useReactToPrint/index.js +1201 -0
- package/src/hooks/useSales/helpers/index.js +0 -0
- package/src/hooks/useSales/index.js +627 -337
- package/src/hooks/useSales/queries.js +2 -0
package/.vscode/settings.json
CHANGED
package/package.json
CHANGED
package/src/hooks/index.js
CHANGED
|
@@ -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 &&
|
|
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 ==
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
}, [data, productsFood])
|
|
61
|
+
|
|
62
|
+
const productsFood = data?.productFoodsAll
|
|
61
63
|
return [
|
|
62
64
|
productsFood, {
|
|
63
65
|
error,
|