npm-pkg-hook 1.0.2 → 1.0.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 (84) hide show
  1. package/.babelrc +13 -13
  2. package/.env +1 -0
  3. package/.eslintrc.js +132 -0
  4. package/.eslintrc.json +107 -107
  5. package/.github/pull_request_template.md +17 -17
  6. package/.github/workflows/pepeline.yaml +29 -29
  7. package/.vscode/extensions.json +6 -0
  8. package/.vscode/settings.json +12 -0
  9. package/README.md +1 -1
  10. package/jsconfig.json +27 -27
  11. package/next.config.js +128 -128
  12. package/package.json +8 -6
  13. package/script.txt +7 -0
  14. package/src/cookies/index.ts +3 -3
  15. package/src/hooks/index.js +46 -19
  16. package/src/hooks/updateExtProductFoodsOptional/index.js +38 -0
  17. package/src/hooks/useAcumulateDate/index.js +16 -16
  18. package/src/hooks/useAnimationText/index.jsx +31 -30
  19. package/src/hooks/useBanner/index.js +19 -0
  20. package/src/hooks/useCatWithProduct/index.js +42 -0
  21. package/src/hooks/useCatWithProduct/queries.js +172 -0
  22. package/src/hooks/useCategoryInStore/index.js +94 -0
  23. package/src/hooks/{useGetCategorieStore → useCategoryInStore}/queries.js +77 -77
  24. package/src/hooks/useCategoryStore/index.js +7 -7
  25. package/src/hooks/useCategoryStore/queries.js +16 -16
  26. package/src/hooks/useChartData/index.js +168 -0
  27. package/src/hooks/useCheckbox/index.js +114 -114
  28. package/src/hooks/useClients/index.js +13 -13
  29. package/src/hooks/useClients/queries.js +117 -117
  30. package/src/hooks/useConnection/index.js +23 -0
  31. package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +165 -0
  32. package/src/hooks/useCreateProduct/index.js +268 -0
  33. package/src/hooks/useDessert/index.js +141 -0
  34. package/src/hooks/useDrag/index.js +62 -57
  35. package/src/hooks/useEvent/index.js +33 -33
  36. package/src/hooks/useFetchJson/index.js +24 -24
  37. package/src/hooks/useFetchMoreInteractions/index.jsx +37 -34
  38. package/src/hooks/useFormTools/index.js +83 -70
  39. package/src/hooks/useFormatDate/index.js +34 -0
  40. package/src/hooks/useFullScreenMode/index.js +65 -65
  41. package/src/hooks/useHover/index.js +28 -28
  42. package/src/hooks/useImageOptimization/index.js +28 -0
  43. package/src/hooks/useImageWeight/index.js +52 -0
  44. package/src/hooks/useImagesStore/index.js +171 -0
  45. package/src/hooks/useImagesStore/queries.js +216 -0
  46. package/src/hooks/useInnerHtml/index.js +37 -37
  47. package/src/hooks/useIntersection/index.js +84 -31
  48. package/src/hooks/useKeypress/index.js +27 -27
  49. package/src/hooks/useLazyScript/index.js +72 -0
  50. package/src/hooks/useLocalSorage/index.js +35 -35
  51. package/src/hooks/useLocationNavigate/index.js +54 -54
  52. package/src/hooks/useMobile/index.js +37 -37
  53. package/src/hooks/useMutateHeight/index.js +37 -0
  54. package/src/hooks/useProductsFood/index.js +190 -0
  55. package/src/hooks/{useGetProductsFood → useProductsFood}/queriesStore.js +780 -765
  56. package/src/hooks/useProductsFood/usetagsProducts.js +57 -0
  57. package/src/hooks/useReport/index.js +35 -0
  58. package/src/hooks/useReport/queries.js +122 -0
  59. package/src/hooks/useRestaurant/index.js +19 -19
  60. package/src/hooks/useRestaurant/queries.js +79 -69
  61. package/src/hooks/useSales/index.js +589 -489
  62. package/src/hooks/useSales/queries.js +290 -229
  63. package/src/hooks/useSales/useGetSale.js +12 -0
  64. package/src/hooks/useSales/useTotalSales.js +17 -0
  65. package/src/hooks/useSaveAvailableProduct/helpers/index.js +30 -0
  66. package/src/hooks/useSaveAvailableProduct/index.js +26 -0
  67. package/src/hooks/useSaveAvailableProduct/queries.js +10 -0
  68. package/src/hooks/useSchedule/index.jsx +23 -0
  69. package/src/hooks/useSetState/index.js +24 -24
  70. package/src/hooks/useStore/index.js +17 -17
  71. package/src/hooks/useStore/queries.js +135 -135
  72. package/src/hooks/useStoreCalendar/index.js +7 -0
  73. package/src/hooks/useTimeAgo/useTimeAgo.js +39 -39
  74. package/src/hooks/useUpdateCart/index.js +124 -124
  75. package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +37 -0
  76. package/src/hooks/useUser/index.js +7 -3
  77. package/src/hooks/useUser/queries.js +69 -0
  78. package/src/hooks/useWindowSize/index.js +37 -37
  79. package/src/index.jsx +2 -1
  80. package/src/mock/dessert/index.js +16 -0
  81. package/src/mock/index.js +2 -0
  82. package/src/utils/index.js +106 -54
  83. package/src/hooks/useGetCategorieStore/index.js +0 -21
  84. package/src/hooks/useGetProductsFood/index.js +0 -46
@@ -1,36 +1,36 @@
1
- import { useState } from 'react'
2
-
3
- export default function useLocalStorage(key, initialValue) {
4
- // const { setAlertBox } = useContext(Context)
5
- // State to store our value
6
- // Pass initial state function to useState so logic is only executed once
7
- const [storedValue, setStoredValue] = useState(() => {
8
- try {
9
- // Get from local storage by key
10
- const item = window.localStorage.getItem(key)
11
- // Parse stored json or if none return initialValue
12
- return item ? JSON.parse(item) : initialValue
13
- } catch (error) {
14
- // If error also return initialValue
15
- return initialValue
16
- }
17
- })
18
-
19
- // Return a wrapped version of useState's setter function that ...
20
- // ... persists the new value to localStorage.
21
- const setValue = value => {
22
- try {
23
- // Allow value to be a function so we have same API as useState
24
- const valueToStore =
25
- value instanceof Function ? value(storedValue) : value
26
- // Save state
27
- setStoredValue(valueToStore)
28
- // Save to local storage
29
- window.localStorage.setItem(key, JSON.stringify(valueToStore))
30
- } catch (error) {
31
- // A more advanced implementation would handle the error case
32
- }
33
- }
34
-
35
- return [storedValue, setValue]
1
+ import { useState } from 'react'
2
+
3
+ export default function useLocalStorage(key, initialValue) {
4
+ // const { setAlertBox } = useContext(Context)
5
+ // State to store our value
6
+ // Pass initial state function to useState so logic is only executed once
7
+ const [storedValue, setStoredValue] = useState(() => {
8
+ try {
9
+ // Get from local storage by key
10
+ const item = window.localStorage.getItem(key)
11
+ // Parse stored json or if none return initialValue
12
+ return item ? JSON.parse(item) : initialValue
13
+ } catch (error) {
14
+ // If error also return initialValue
15
+ return initialValue
16
+ }
17
+ })
18
+
19
+ // Return a wrapped version of useState's setter function that ...
20
+ // ... persists the new value to localStorage.
21
+ const setValue = value => {
22
+ try {
23
+ // Allow value to be a function so we have same API as useState
24
+ const valueToStore =
25
+ value instanceof Function ? value(storedValue) : value
26
+ // Save state
27
+ setStoredValue(valueToStore)
28
+ // Save to local storage
29
+ window.localStorage.setItem(key, JSON.stringify(valueToStore))
30
+ } catch (error) {
31
+ // A more advanced implementation would handle the error case
32
+ }
33
+ }
34
+
35
+ return [storedValue, setValue]
36
36
  }
@@ -1,54 +1,54 @@
1
- import { useState, useEffect } from 'react'
2
-
3
- const defaultSettings = {
4
- enableHighAccuracy: false,
5
- timeout: Infinity,
6
- maximumAge: 0
7
- }
8
-
9
- export const usePosition = (watch = false, settings = defaultSettings) => {
10
- const [position, setPosition] = useState({})
11
- const [error, setError] = useState(null)
12
-
13
- const onChange = ({ coords, timestamp }) => {
14
- setPosition({
15
- latitude: coords.latitude,
16
- longitude: coords.longitude,
17
- accuracy: coords.accuracy,
18
- speed: coords.speed,
19
- timestamp
20
- })
21
- }
22
-
23
- const onError = () => {
24
- setError(error?.message)
25
- }
26
-
27
- useEffect(() => {
28
- if (!navigator || !navigator.geolocation) {
29
- setError('Geolocation is not supported')
30
- return
31
- }
32
-
33
- let watcher = null
34
- if (watch) {
35
- watcher = navigator.geolocation.watchPosition(
36
- onChange,
37
- onError,
38
- settings
39
- )
40
- } else {
41
- navigator.geolocation.getCurrentPosition(onChange, onError, settings)
42
- }
43
-
44
- return () => { return watcher && navigator.geolocation.clearWatch(watcher) }
45
- }, [
46
- settings,
47
- settings.enableHighAccuracy,
48
- settings.timeout,
49
- settings.maximumAge,
50
- watch
51
- ])
52
-
53
- return { ...position, error }
54
- }
1
+ import { useEffect, useState } from 'react'
2
+
3
+ const defaultSettings = {
4
+ enableHighAccuracy: false,
5
+ timeout: Infinity,
6
+ maximumAge: 0
7
+ }
8
+
9
+ export const usePosition = (watch = false, settings = defaultSettings) => {
10
+ const [position, setPosition] = useState({})
11
+ const [error, setError] = useState(null)
12
+
13
+ const onChange = ({ coords, timestamp }) => {
14
+ setPosition({
15
+ latitude: coords.latitude,
16
+ longitude: coords.longitude,
17
+ accuracy: coords.accuracy,
18
+ speed: coords.speed,
19
+ timestamp
20
+ })
21
+ }
22
+
23
+ const onError = () => {
24
+ setError(error?.message)
25
+ }
26
+
27
+ useEffect(() => {
28
+ if (!navigator || !navigator.geolocation) {
29
+ setError('Geolocation is not supported')
30
+ return
31
+ }
32
+
33
+ let watcher = null
34
+ if (watch) {
35
+ watcher = navigator.geolocation.watchPosition(
36
+ onChange,
37
+ onError,
38
+ settings
39
+ )
40
+ } else {
41
+ navigator.geolocation.getCurrentPosition(onChange, onError, settings)
42
+ }
43
+
44
+ return () => { return watcher && navigator.geolocation.clearWatch(watcher) }
45
+ }, [
46
+ settings,
47
+ settings.enableHighAccuracy,
48
+ settings.timeout,
49
+ settings.maximumAge,
50
+ watch
51
+ ])
52
+
53
+ return { ...position, error }
54
+ }
@@ -1,38 +1,38 @@
1
- import { useEffect, useState } from 'react'
2
-
3
- export const useMobile = (props) => {
4
- const { callBack = () => { return null; } } = props || {};
5
- const [innerHeight, setInnerHeight] = useState();
6
- const [innerWidth, setInnerWidth] = useState();
7
- let isMobile = false;
8
- useEffect(() => {
9
- setInnerHeight(window.innerHeight);
10
- setInnerWidth(window.innerWidth);
11
- callBack();
12
- }, []);
13
- useEffect(() => {
14
- const handleResize = () => {
15
- if (!isNaN(window === null || window === void 0 ? void 0 : window.innerHeight) && (window === null || window === void 0 ? void 0 : window.innerHeight) != innerHeight) {
16
- setInnerHeight(window.innerHeight);
17
- }
18
- if (!isNaN(window.innerWidth) && window.innerWidth != innerWidth) {
19
- setInnerWidth(window.innerWidth);
20
- }
21
- callBack();
22
- };
23
- if (typeof window !== 'undefined') {
24
- window.addEventListener('resize', handleResize);
25
- }
26
- return () => {
27
- window.removeEventListener('resize', handleResize);
28
- };
29
- });
30
- if (typeof window !== 'undefined' && /Mobile/i.test((navigator === null || navigator === void 0 ? void 0 : navigator.userAgent) || (navigator === null || navigator === void 0 ? void 0 : navigator.vendor))) {
31
- isMobile = true;
32
- }
33
- return {
34
- isMobile,
35
- innerHeight,
36
- innerWidth
37
- };
1
+ import { useEffect, useState } from 'react';
2
+
3
+ export const useMobile = (props) => {
4
+ const { callBack = () => { return null; } } = props || {};
5
+ const [innerHeight, setInnerHeight] = useState();
6
+ const [innerWidth, setInnerWidth] = useState();
7
+ let isMobile = false;
8
+ useEffect(() => {
9
+ setInnerHeight(window.innerHeight);
10
+ setInnerWidth(window.innerWidth);
11
+ callBack();
12
+ }, []);
13
+ useEffect(() => {
14
+ const handleResize = () => {
15
+ if (!isNaN(window === null || window === void 0 ? void 0 : window.innerHeight) && (window === null || window === void 0 ? void 0 : window.innerHeight) != innerHeight) {
16
+ setInnerHeight(window.innerHeight);
17
+ }
18
+ if (!isNaN(window.innerWidth) && window.innerWidth != innerWidth) {
19
+ setInnerWidth(window.innerWidth);
20
+ }
21
+ callBack();
22
+ };
23
+ if (typeof window !== 'undefined') {
24
+ window.addEventListener('resize', handleResize);
25
+ }
26
+ return () => {
27
+ window.removeEventListener('resize', handleResize);
28
+ };
29
+ });
30
+ if (typeof window !== 'undefined' && /Mobile/i.test((navigator === null || navigator === void 0 ? void 0 : navigator.userAgent) || (navigator === null || navigator === void 0 ? void 0 : navigator.vendor))) {
31
+ isMobile = true;
32
+ }
33
+ return {
34
+ isMobile,
35
+ innerHeight,
36
+ innerWidth
37
+ };
38
38
  };
@@ -0,0 +1,37 @@
1
+ import {
2
+ useEffect,
3
+ useRef,
4
+ useState
5
+ } from 'react';
6
+
7
+
8
+ export const useMutateHeight = ({ isCollapsed = false }) => {
9
+ const [collapsed, setCollapsed] = useState(isCollapsed);
10
+ const childrenContainerRef = useRef(null);
11
+
12
+ useEffect(() => {
13
+ setCollapsed(isCollapsed);
14
+ if (childrenContainerRef.current !== null) {
15
+ const height = isCollapsed
16
+ ? childrenContainerRef.current.scrollHeight
17
+ : 0;
18
+ childrenContainerRef.current.style.height = `${height}px`;
19
+ }
20
+ }, [isCollapsed]);
21
+
22
+ const handleCollapsed = visible => {
23
+ setCollapsed(visible);
24
+ if (childrenContainerRef.current !== null) {
25
+ const height = visible ? childrenContainerRef.current.scrollHeight : 0;
26
+ childrenContainerRef.current.style.height = `${height}px`;
27
+ }
28
+ };
29
+
30
+ return {
31
+ handleCollapsed,
32
+ childrenContainerRef,
33
+ collapsed
34
+ };
35
+ };
36
+
37
+ // https://codesandbox.io/s/dropdown-navigation-9fx6r?file=/src/Navigation/Navigation.js:357-775
@@ -0,0 +1,190 @@
1
+ import {
2
+ useLazyQuery,
3
+ useMutation,
4
+ useQuery
5
+ } from '@apollo/client'
6
+ import { useEffect, useState } from 'react'
7
+ import {
8
+ GET_ALL_EXTRA_PRODUCT,
9
+ GET_ALL_PRODUCT_STORE,
10
+ GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
11
+ GET_ONE_PRODUCTS_FOOD,
12
+ UPDATE_PRODUCT_FOOD
13
+ } from './queriesStore'
14
+
15
+ /**
16
+ * Description
17
+ * @param {any} categories
18
+ * @param {any} desc
19
+ * @param {any} fetchPolicy='network-only'
20
+ * @param {any} fromDate
21
+ * @param {any} gender
22
+ * @param {any} max=50
23
+ * @param {any} min
24
+ * @param {any} pState
25
+ * @param {any} search=null
26
+ * @param {any} toDate
27
+ * @returns {any}
28
+ */
29
+ export const useProductsFood = ({
30
+ categories,
31
+ desc,
32
+ fetchPolicy = 'network-only',
33
+ fromDate,
34
+ gender,
35
+ max = 50,
36
+ min,
37
+ pState,
38
+ search = null,
39
+ toDate
40
+ }) => {
41
+ const [productsFood, setProductsFood] = useState([])
42
+ const [showMore, setShowMore] = useState(50)
43
+ const { data, loading, fetchMore, error } = useQuery(GET_ALL_PRODUCT_STORE, {
44
+ fetchPolicy: fetchPolicy,
45
+ variables:
46
+ {
47
+ categories: categories || [],
48
+ desc: desc || [],
49
+ fromDate: fromDate || null,
50
+ gender: gender || [],
51
+ max: max || null,
52
+ min: min || null,
53
+ pState: pState || 0,
54
+ search: search ?? search,
55
+ toDate: toDate || null
56
+ }
57
+ })
58
+ useEffect(() => {
59
+ setProductsFood(data?.productFoodsAll || [])
60
+ }, [data, productsFood])
61
+ return [
62
+ productsFood, {
63
+ error,
64
+ loading,
65
+ showMore,
66
+ fetchMore,
67
+ setShowMore
68
+ }
69
+ ]
70
+ }
71
+
72
+ export const useDeleteProductsFood = () => {
73
+ const [updateProductFoods] = useMutation(UPDATE_PRODUCT_FOOD)
74
+
75
+ const handleDelete = product => {
76
+ const { pId, pState } = product || {}
77
+ updateProductFoods({
78
+ variables: {
79
+ input: {
80
+ pId,
81
+ pState
82
+ }
83
+ }, update(cache) {
84
+ cache.modify({
85
+ fields: {
86
+ productFoodsAll(dataOld = []) {
87
+ return cache.writeQuery({ query: GET_ALL_PRODUCT_STORE, data: dataOld })
88
+ }
89
+ }
90
+ })
91
+ cache.modify({
92
+ fields: {
93
+ getCatProductsWithProduct(dataOld = []) {
94
+ return cache.writeQuery({ query: GET_ALL_CATEGORIES_WITH_PRODUCT, data: dataOld })
95
+ }
96
+ }
97
+ })
98
+ }
99
+ }).catch(err => { return console.log({ message: `${err}`, duration: 7000 }) })
100
+ }
101
+ return {
102
+ handleDelete
103
+ }
104
+ }
105
+
106
+
107
+ export const useExtProductFoodsAll = () => {
108
+ const [ExtProductFoodsAll,
109
+ {
110
+ data,
111
+ loading,
112
+ error
113
+ }
114
+ ] = useLazyQuery(GET_ALL_EXTRA_PRODUCT)
115
+
116
+ const handleExtProductFoodsAll = (pId) => {
117
+ ExtProductFoodsAll({
118
+ variables: {
119
+ pId
120
+ }
121
+ })
122
+ }
123
+ return [handleExtProductFoodsAll,
124
+ {
125
+ data: data?.ExtProductFoodsAll || [],
126
+ loading,
127
+ error
128
+ }
129
+ ]
130
+ }
131
+ export const useExtProductFoodsOptionalAll = () => {
132
+
133
+ const [ExtProductFoodsOptionalAll,
134
+ {
135
+ data,
136
+ loading,
137
+ error
138
+ }] = useLazyQuery(GET_EXTRAS_PRODUCT_FOOD_OPTIONAL)
139
+
140
+ const handleGetExtProductFood = (pId) => {
141
+ try {
142
+ ExtProductFoodsOptionalAll({
143
+ variables: {
144
+ pId
145
+ }
146
+ })
147
+ } catch (e) {
148
+ console.log(e)
149
+ }
150
+ }
151
+ return [handleGetExtProductFood,
152
+ {
153
+ data: data?.ExtProductFoodsOptionalAll || [],
154
+ loading,
155
+ error,
156
+ }]
157
+ }
158
+
159
+
160
+ export const useGetOneProductsFood = () => {
161
+ const [productFoodsOne,
162
+ {
163
+ data,
164
+ loading,
165
+ error
166
+ }] = useLazyQuery(GET_ONE_PRODUCTS_FOOD)
167
+ const [handleGetExtProductFood, { data: dataOptional }] = useExtProductFoodsOptionalAll()
168
+ const [handleExtProductFoodsAll, { data: dataExtra }] = useExtProductFoodsAll()
169
+ const handleGetOneProduct = (food) => {
170
+ const { pId } = food
171
+ try {
172
+ productFoodsOne({
173
+ variables: {
174
+ pId: pId
175
+ }
176
+ })
177
+ handleGetExtProductFood(pId)
178
+ handleExtProductFoodsAll(pId)
179
+ } catch (e) {
180
+ console.log(e)
181
+ }
182
+ }
183
+ return [handleGetOneProduct, {
184
+ data: data?.productFoodsOne || {},
185
+ dataExtra,
186
+ dataOptional,
187
+ loading,
188
+ error,
189
+ }]
190
+ }