npm-pkg-hook 1.1.2 → 1.1.4

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.
Files changed (42) hide show
  1. package/.eslintrc.js +132 -132
  2. package/.vscode/extensions.json +6 -0
  3. package/.vscode/settings.json +8 -0
  4. package/next.config.js +1 -0
  5. package/package.json +43 -46
  6. package/src/config/client/errors.js +1 -2
  7. package/src/hooks/index.js +20 -25
  8. package/src/hooks/useAnimationText/index.jsx +13 -11
  9. package/src/hooks/useCatWithProduct/index.js +4 -37
  10. package/src/hooks/useCatWithProduct/queries.js +16 -0
  11. package/src/hooks/useChartData/index.js +156 -182
  12. package/src/hooks/useChartData/useChartData/index.js +197 -0
  13. package/src/hooks/useChartData/useChartDataAllOrders/index.js +94 -0
  14. package/src/hooks/useCheckbox/index.js +2 -5
  15. package/src/hooks/useClients/index.js +8 -17
  16. package/src/hooks/useCreateProduct/index.js +64 -94
  17. package/src/hooks/useDrag/index.js +1 -0
  18. package/src/hooks/useEmployee/index.js +8 -11
  19. package/src/hooks/useFormTools/index.js +1 -1
  20. package/src/hooks/useFullScreenMode/index.js +8 -8
  21. package/src/hooks/useGoogleLogin/index.js +161 -0
  22. package/src/hooks/useGoogleLogin/loadScript.js +15 -0
  23. package/src/hooks/useGoogleLogin/removeScript.js +7 -0
  24. package/src/hooks/useHover/index.js +1 -1
  25. package/src/hooks/useImagesStore/index.js +144 -176
  26. package/src/hooks/useImagesStore/queries.js +28 -1
  27. package/src/hooks/useKeypress/index.js +1 -7
  28. package/src/hooks/useLogout/index.js +27 -22
  29. package/src/hooks/useManageQueryParams/index.js +1 -1
  30. package/src/hooks/useProductsFood/queriesStore.js +16 -3
  31. package/src/hooks/useReport/index.js +30 -26
  32. package/src/hooks/useReport/queries.js +32 -47
  33. package/src/hooks/useSales/index.js +21 -52
  34. package/src/hooks/useSales/queries.js +38 -48
  35. package/src/hooks/useSales/useGetSale.js +2 -16
  36. package/src/hooks/useSchedule/index.jsx +23 -0
  37. package/src/hooks/useUpdateExistingOrders/index.js +8 -8
  38. package/src/hooks/useUser/index.js +2 -2
  39. package/src/hooks/useUser/queries.js +40 -40
  40. package/src/hooks/useWindowSize/index.js +1 -1
  41. package/src/index.jsx +1 -2
  42. package/src/security/index.js +0 -0
@@ -1,4 +1,5 @@
1
1
  import { useQuery, useMutation, useLazyQuery } from '@apollo/client'
2
+ import { useState } from 'react'
2
3
  import {
3
4
  CREATE_CLIENTS,
4
5
  DELETE_ONE_CLIENTS,
@@ -10,25 +11,15 @@ import {
10
11
  export const useGetClients = ({
11
12
  max,
12
13
  search,
13
- fromDate, // Agrega las variables fromDate y toDate
14
- toDate,
15
14
  sendNotification = () => { return }
16
15
  } = {}) => {
17
- const {
18
- loading,
19
- error,
20
- called,
21
- data
22
- } = useQuery(GET_ALL_CLIENTS, {
23
- variables: {
24
- search: search,
25
- fromDate: fromDate, // Usa las variables aquí
26
- toDate: toDate
27
- }
28
- });
29
-
30
- return [data?.getAllClients || [], { loading: called ? false : loading, error }];
31
- };
16
+ const { loading, error, called, data } = useQuery(GET_ALL_CLIENTS, {
17
+ variables: {
18
+ search: search
19
+ }
20
+ })
21
+ return [data?.getAllClients || [], { loading: called ? false : loading, error }]
22
+ }
32
23
 
33
24
  export const useDeleteClients = ({ sendNotification = () => { return } } = {}) => {
34
25
  const [deleteClient, { loading, error }] = useMutation(DELETE_ONE_CLIENTS)
@@ -10,14 +10,11 @@ import {
10
10
  import { useStore } from '../useStore'
11
11
  import { useTagsProducts } from './../useProductsFood/usetagsProducts'
12
12
  import { useEditImageProduct } from './helpers/useEditImageProduct'
13
- import { errorHandler } from '../../config/client'
14
- import { useLogout } from '../useLogout'
15
13
 
16
14
  export const useCreateProduct = ({
15
+ setAlertBox = () => { },
17
16
  router,
18
- sendNotification = () => { },
19
- handleCloseCreateProduct = () => { },
20
- setAlertBox = () => { }
17
+ sendNotification = () => { }
21
18
  }) => {
22
19
  const [errors, setErrors] = useState({
23
20
  names: ''
@@ -54,7 +51,7 @@ export const useCreateProduct = ({
54
51
 
55
52
  const handleCheck = (e) => {
56
53
  const { name, checked } = e.target
57
- return setCheck((prev) => ({ ...prev, [name]: checked }))
54
+ return setCheck((prev) =>({ ...prev, [name]: checked }))
58
55
  }
59
56
 
60
57
  const handleUpdateBanner = event => {
@@ -123,15 +120,14 @@ export const useCreateProduct = ({
123
120
  alt: files[0].name
124
121
  }
125
122
  : initialState
126
- )
123
+ )
127
124
  }
128
125
  const onTargetClick = () => {
129
126
  fileInputRef.current.click()
130
127
  }
131
128
  const { img } = useEditImageProduct({ sendNotification, initialState })
132
- const [onClickLogout] = useLogout()
133
-
134
- const handleRegister = async ({ callBack = () => { return} } = {}) => {
129
+ console.log(values)
130
+ const handleRegister = async () => {
135
131
  const {
136
132
  ProPrice,
137
133
  ProDescuento,
@@ -150,93 +146,67 @@ export const useCreateProduct = ({
150
146
  const pCode = RandomCode(9)
151
147
  const formatPrice = ProPrice ? parseFloat(ProPrice.replace(/\./g, '')) : 0
152
148
  try {
153
- if (names.trim() !== '') {
154
- updateProductFoods({
155
- variables: {
156
- input: {
157
- idStore: dataStore?.getStore?.idStore || '',
158
- ProPrice: check?.desc ? 0 : formatPrice,
159
- ProDescuento: check?.desc ? 0 : parseInt(ProDescuento),
160
- ValueDelivery: check?.desc ? 0 : parseFloat(ValueDelivery),
161
- ProDescription,
162
- pName: names,
163
- pCode,
164
- carProId,
165
- pState: 1,
166
- sTateLogistic: 1,
167
- ProStar: 0,
168
- ProImage,
169
- ProHeight: parseFloat(ProHeight),
170
- ProWeight,
171
- ProOutstanding: check?.desc ? 1 : 0,
172
- ProDelivery: check?.desc ? 1 : 0
173
- }
174
- }, update(cache) {
175
- cache.modify({
176
- fields: {
177
- productFoodsAll(dataOld = []) {
178
- return cache.writeQuery({ query: GET_ALL_FOOD_PRODUCTS, data: dataOld })
179
- }
180
- }
181
- })
149
+ updateProductFoods({
150
+ variables: {
151
+ input: {
152
+ idStore: dataStore?.getStore?.idStore || '',
153
+ ProPrice: check?.desc ? 0 : formatPrice,
154
+ ProDescuento: check?.desc ? 0 : parseInt(ProDescuento),
155
+ ValueDelivery: check?.desc ? 0 : parseFloat(ValueDelivery),
156
+ ProDescription,
157
+ pName: names,
158
+ pCode,
159
+ carProId,
160
+ pState: 1,
161
+ sTateLogistic: 1,
162
+ ProStar: 0,
163
+ ProImage,
164
+ ProHeight: parseFloat(ProHeight),
165
+ ProWeight,
166
+ ProOutstanding: check?.desc ? 1 : 0,
167
+ ProDelivery: check?.desc ? 1 : 0
182
168
  }
183
- }).then((res) => {
184
-
185
- const { updateProductFoods } = res?.data || {}
186
- const { pId } = updateProductFoods || {}
187
-
188
- if (res?.errors?.length > 0) {
189
- const errors = {
190
- errors: res?.errors
191
- }
192
- const responseError = errorHandler(errors);
193
- if (responseError) {
194
- handleCloseCreateProduct()
195
- return onClickLogout()
196
- }
197
- } else {
198
- router.push(
199
- {
200
- query: {
201
- ...router.query,
202
- food: pId
203
- }
204
- },
205
- undefined,
206
- { shallow: true }
207
- )
208
- if (pId){
209
- setPid(pId ?? null)
210
- sendNotification({
211
- backgroundColor: 'success',
212
- title: 'Success',
213
- description: `El producto ${names} subido con éxito`
214
- })
215
- callBack()
216
- }
217
- const objTag = {
218
- aName: tags?.tag,
219
- nameTag: tags?.tag,
220
- pId
169
+ },
170
+ update (cache) {
171
+ cache.modify({
172
+ fields: {
173
+ productFoodsAll (dataOld = []) {
174
+ return cache.writeQuery({ query: GET_ALL_FOOD_PRODUCTS, data: dataOld })
175
+ }
221
176
  }
222
- handleRegisterTags(objTag)
223
- setValues({})
224
- }
225
- }).catch(err => {
226
- return sendNotification({
227
- backgroundColor: 'error',
228
- title: 'Error inesperado',
229
- description: `${err}`
230
177
  })
178
+ }
179
+ }).then((res) => {
180
+ const { updateProductFoods } = res?.data || {}
181
+ const { pId } = updateProductFoods || {}
182
+ setPid(pId ?? null)
183
+ router.push(
184
+ {
185
+ query: {
186
+ ...router.query,
187
+ food: pId
188
+ }
189
+ },
190
+ undefined,
191
+ { shallow: true }
192
+ )
193
+ sendNotification({
194
+ backgroundColor: 'success',
195
+ title: 'Success',
196
+ description: `El producto ${names} subido con éxito`
231
197
  })
232
-
233
- } else {
234
- return sendNotification({
235
- backgroundColor: 'warning',
236
- title: 'Alerta',
237
- description: 'El nombre del producto no debe estar vacio'
238
- })
239
- }
198
+ const objTag = {
199
+ aName: tags.tag,
200
+ nameTag: tags.tag,
201
+ pId
202
+ }
203
+ handleRegisterTags(objTag)
204
+ // setValues({})
205
+ }).catch(err => { return sendNotification({
206
+ backgroundColor: 'error',
207
+ title: `${err}`,
208
+ description: 'Error inesperado'
209
+ }) })
240
210
  if (image !== null) {
241
211
  setImageProducts({
242
212
  variables: {
@@ -249,7 +219,7 @@ export const useCreateProduct = ({
249
219
  }).catch((error) => {
250
220
  sendNotification({
251
221
  backgroundColor: 'error',
252
- title: `Ocurrió un error en la imagen en el producto ${names}`,
222
+ title: `Ocurrió un error en la imagen en el producto ${names}`,
253
223
  description: 'error'
254
224
  })
255
225
  })
@@ -2,6 +2,7 @@ import { useEffect, useState } from 'react'
2
2
 
3
3
  export function useDrag2 (ref) {
4
4
  useEffect(() => {
5
+ if (!ref || !ref?.current) return null
5
6
  const target = ref?.current
6
7
  if (!target) return
7
8
  const previousOffset = { x: 0, y: 0 }
@@ -1,16 +1,13 @@
1
1
  import { useQuery } from '@apollo/client'
2
+ import { useEffect, useState } from 'react'
2
3
  import { GET_EMPLOYEES } from './queries'
3
4
 
4
5
  export const useEmployee = () => {
5
- const { data, loading, error, fetchMore } = useQuery(GET_EMPLOYEES, {
6
- onError: (error) => {
7
- console.error(error)
8
- }
9
- })
10
- const employees = data?.employees || []
11
- return [employees, {
12
- loading,
13
- error,
14
- fetchMore
15
- }]
6
+ const [clientes, setClients] = useState([])
7
+ const [more, setMore] = useState(100)
8
+ const { data, loading, error, fetchMore } = useQuery(GET_EMPLOYEES)
9
+ useEffect(() => {
10
+ setClients(data)
11
+ }, [clientes, data])
12
+ return [clientes?.employees, { loading, error, fetchMore, setMore, more }]
16
13
  }
@@ -75,7 +75,7 @@ export const useFormTools = ({ sendNotification = () => { } } = {}) => {
75
75
 
76
76
  // Ejecuta la accion si es válido
77
77
  if (!errSub && action) {
78
- action()?.then(res => {
78
+ action().then(res => {
79
79
  if (res) {
80
80
  sendNotification({
81
81
  message: msgSuccess || 'Operación exitosa',
@@ -1,10 +1,7 @@
1
- import React, {
2
- useState,
3
- useRef,
4
- useEffect
5
- } from 'react'
1
+ import React, { useState, useRef, useEffect } from 'react'
2
+ import styled from 'styled-components'
6
3
 
7
- export const useFullScreenMode = () => {
4
+ export const useFullscreenMode = () => {
8
5
  const [isFullscreen, setFullscreen] = useState(false)
9
6
  const elementRef = useRef()
10
7
 
@@ -59,7 +56,10 @@ export const useFullScreenMode = () => {
59
56
  }
60
57
 
61
58
  const ToggleIcon = (
62
- <button onDoubleClick={() => {return (!isFullscreen ? goFullscreen() : exitFullScreen())}}>{!isFullscreen ? 'FullScreen' : 'Normal'}</button>
59
+ <Button onDoubleClick={() => {return (!isFullscreen ? goFullscreen() : exitFullScreen())}}>{!isFullscreen ? 'FullScreen' : 'Normal'}</Button>
63
60
  )
64
61
  return [elementRef, ToggleIcon] //Icon, ref
65
- }
62
+ }
63
+ const Button = styled.button`
64
+
65
+ `
@@ -0,0 +1,161 @@
1
+ import { useState, useEffect } from 'react'
2
+ import loadScript from './loadScript'
3
+ import removeScript from './removeScript'
4
+
5
+ export const useGoogleLogin = ({
6
+ onSuccess = () => {},
7
+ onAutoLoadFinished = () => {},
8
+ onFailure = () => {},
9
+ onRequest = () => {},
10
+ onScriptLoadFailure,
11
+ clientId,
12
+ cookiePolicy,
13
+ loginHint,
14
+ hostedDomain,
15
+ autoLoad,
16
+ isSignedIn,
17
+ fetchBasicProfile,
18
+ redirectUri,
19
+ discoveryDocs,
20
+ uxMode,
21
+ scope,
22
+ accessType,
23
+ responseType,
24
+ jsSrc = 'https://apis.google.com/js/api.js',
25
+ prompt
26
+ }) => {
27
+ const [loaded, setLoaded] = useState(false)
28
+
29
+ function handleSigninSuccess(res) {
30
+ /*
31
+ offer renamed response keys to names that match use
32
+ */
33
+ const basicProfile = res.getBasicProfile()
34
+ const authResponse = res.getAuthResponse(true)
35
+ res.googleId = basicProfile.getId()
36
+ res.tokenObj = authResponse
37
+ res.tokenId = authResponse.id_token
38
+ res.accessToken = authResponse.access_token
39
+ res.profileObj = {
40
+ googleId: basicProfile.getId(),
41
+ imageUrl: basicProfile.getImageUrl(),
42
+ email: basicProfile.getEmail(),
43
+ name: basicProfile.getName(),
44
+ givenName: basicProfile.getGivenName(),
45
+ familyName: basicProfile.getFamilyName()
46
+ }
47
+ onSuccess(res)
48
+ }
49
+
50
+ function signIn(e) {
51
+ if (e) {
52
+ e.preventDefault() // to prevent submit if used within form
53
+ }
54
+ if (loaded) {
55
+ const GoogleAuth = window.gapi.auth2.getAuthInstance()
56
+ const options = {
57
+ prompt
58
+ }
59
+ onRequest()
60
+ if (responseType === 'code') {
61
+ GoogleAuth.grantOfflineAccess(options).then(
62
+ res => onSuccess(res),
63
+ err => onFailure(err)
64
+ )
65
+ } else {
66
+ GoogleAuth.signIn(options).then(
67
+ res => handleSigninSuccess(res),
68
+ err => onFailure(err)
69
+ )
70
+ }
71
+ }
72
+ }
73
+
74
+ useEffect(() => {
75
+ let unmounted = false
76
+ const onLoadFailure = onScriptLoadFailure || onFailure
77
+ loadScript(
78
+ document,
79
+ 'script',
80
+ 'google-login',
81
+ jsSrc,
82
+ () => {
83
+ const params = {
84
+ client_id: clientId,
85
+ cookie_policy: cookiePolicy,
86
+ login_hint: loginHint,
87
+ hosted_domain: hostedDomain,
88
+ fetch_basic_profile: fetchBasicProfile,
89
+ discoveryDocs,
90
+ ux_mode: uxMode,
91
+ redirect_uri: redirectUri,
92
+ scope,
93
+ access_type: accessType
94
+ }
95
+
96
+ if (responseType === 'code') {
97
+ params.access_type = 'offline'
98
+ }
99
+
100
+ window.gapi.load('auth2', () => {
101
+ const GoogleAuth = window.gapi.auth2.getAuthInstance()
102
+ if (!GoogleAuth) {
103
+ window.gapi.auth2.init(params).then(
104
+ res => {
105
+ if (!unmounted) {
106
+ setLoaded(true)
107
+ const signedIn = isSignedIn && res.isSignedIn.get()
108
+ onAutoLoadFinished(signedIn)
109
+ if (signedIn) {
110
+ handleSigninSuccess(res.currentUser.get())
111
+ }
112
+ }
113
+ },
114
+ err => {
115
+ setLoaded(true)
116
+ onAutoLoadFinished(false)
117
+ onLoadFailure(err)
118
+ }
119
+ )
120
+ } else {
121
+ GoogleAuth.then(
122
+ () => {
123
+ if (unmounted) {
124
+ return
125
+ }
126
+ if (isSignedIn && GoogleAuth.isSignedIn.get()) {
127
+ setLoaded(true)
128
+ onAutoLoadFinished(true)
129
+ handleSigninSuccess(GoogleAuth.currentUser.get())
130
+ } else {
131
+ setLoaded(true)
132
+ onAutoLoadFinished(false)
133
+ }
134
+ },
135
+ err => {
136
+ onFailure(err)
137
+ }
138
+ )
139
+ }
140
+ })
141
+ },
142
+ err => {
143
+ onLoadFailure(err)
144
+ }
145
+ )
146
+
147
+ return () => {
148
+ unmounted = true
149
+ removeScript(document, 'google-login')
150
+ }
151
+ }, [])
152
+
153
+ useEffect(() => {
154
+ if (autoLoad) {
155
+ signIn()
156
+ }
157
+ }, [loaded])
158
+
159
+ return { signIn, loaded }
160
+ }
161
+
@@ -0,0 +1,15 @@
1
+ export default (d, s, id, jsSrc, cb, onError) => {
2
+ const element = d.getElementsByTagName(s)[0]
3
+ const fjs = element
4
+ let js = element
5
+ js = d.createElement(s)
6
+ js.id = id
7
+ js.src = jsSrc
8
+ if (fjs && fjs.parentNode) {
9
+ fjs.parentNode.insertBefore(js, fjs)
10
+ } else {
11
+ d.head.appendChild(js)
12
+ }
13
+ js.onerror = onError
14
+ js.onload = cb
15
+ }
@@ -0,0 +1,7 @@
1
+ export default (d, id) => {
2
+ const element = d.getElementById(id)
3
+
4
+ if (element) {
5
+ element.parentNode.removeChild(element)
6
+ }
7
+ }
@@ -1,6 +1,6 @@
1
1
  import { useRef, useState, useEffect } from 'react'
2
2
 
3
- export default function useHover() {
3
+ export function useHover() {
4
4
  const [value, setValue] = useState(false)
5
5
 
6
6
  const ref = useRef(null)