npm-pkg-hook 1.0.1 → 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 (65) hide show
  1. package/.env +1 -0
  2. package/.eslintrc.js +132 -0
  3. package/.github/pull_request_template.md +18 -0
  4. package/.github/workflows/pepeline.yaml +30 -0
  5. package/.vscode/extensions.json +6 -0
  6. package/.vscode/settings.json +12 -0
  7. package/next.config.js +4 -4
  8. package/package.json +17 -7
  9. package/script.txt +7 -0
  10. package/src/hooks/index.js +39 -8
  11. package/src/hooks/updateExtProductFoodsOptional/index.js +38 -0
  12. package/src/hooks/useAcumulateDate/index.js +14 -14
  13. package/src/hooks/useAnimationText/index.jsx +7 -6
  14. package/src/hooks/useBanner/index.js +19 -0
  15. package/src/hooks/useCatWithProduct/index.js +42 -0
  16. package/src/hooks/useCatWithProduct/queries.js +172 -0
  17. package/src/hooks/useCategoryInStore/index.js +94 -0
  18. package/src/hooks/{useGetCategorieStore → useCategoryInStore}/queries.js +0 -0
  19. package/src/hooks/useChartData/index.js +168 -0
  20. package/src/hooks/useCheckbox/index.js +114 -0
  21. package/src/hooks/useClients/index.js +13 -0
  22. package/src/hooks/useClients/queries.js +118 -0
  23. package/src/hooks/useConnection/index.js +23 -0
  24. package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +165 -0
  25. package/src/hooks/useCreateProduct/index.js +268 -0
  26. package/src/hooks/useDessert/index.js +141 -0
  27. package/src/hooks/useDrag/index.js +14 -9
  28. package/src/hooks/useFetchMoreInteractions/index.jsx +6 -3
  29. package/src/hooks/useFormTools/index.js +16 -3
  30. package/src/hooks/useFormatDate/index.js +34 -0
  31. package/src/hooks/useImageOptimization/index.js +28 -0
  32. package/src/hooks/useImageWeight/index.js +52 -0
  33. package/src/hooks/useImagesStore/index.js +171 -0
  34. package/src/hooks/useImagesStore/queries.js +216 -0
  35. package/src/hooks/useIntersection/index.js +54 -1
  36. package/src/hooks/useLazyScript/index.js +72 -0
  37. package/src/hooks/useLocationNavigate/index.js +1 -1
  38. package/src/hooks/useMobile/index.js +38 -0
  39. package/src/hooks/useMutateHeight/index.js +37 -0
  40. package/src/hooks/useProductsFood/index.js +190 -0
  41. package/src/hooks/useProductsFood/queriesStore.js +781 -0
  42. package/src/hooks/useProductsFood/usetagsProducts.js +57 -0
  43. package/src/hooks/useReport/index.js +35 -0
  44. package/src/hooks/useReport/queries.js +122 -0
  45. package/src/hooks/useRestaurant/queries.js +11 -1
  46. package/src/hooks/useSales/index.js +589 -0
  47. package/src/hooks/useSales/queries.js +291 -0
  48. package/src/hooks/useSales/useGetSale.js +12 -0
  49. package/src/hooks/useSales/useTotalSales.js +17 -0
  50. package/src/hooks/useSaveAvailableProduct/helpers/index.js +30 -0
  51. package/src/hooks/useSaveAvailableProduct/index.js +26 -0
  52. package/src/hooks/useSaveAvailableProduct/queries.js +10 -0
  53. package/src/hooks/useSchedule/index.jsx +23 -0
  54. package/src/hooks/useStore/index.js +18 -0
  55. package/src/hooks/useStore/queries.js +136 -0
  56. package/src/hooks/useStoreCalendar/index.js +7 -0
  57. package/src/hooks/useUpdateCart/index.js +5 -4
  58. package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +37 -0
  59. package/src/hooks/useUser/index.js +6 -2
  60. package/src/hooks/useUser/queries.js +69 -0
  61. package/src/index.jsx +2 -1
  62. package/src/mock/dessert/index.js +16 -0
  63. package/src/mock/index.js +2 -0
  64. package/src/utils/index.js +80 -1
  65. package/src/hooks/useGetCategorieStore/index.js +0 -21
@@ -0,0 +1,171 @@
1
+ import { useMutation } from '@apollo/client';
2
+ import {
3
+ useRef,
4
+ useState
5
+ } from 'react';
6
+ import {
7
+ CREATE_BANNER_STORE,
8
+ CREATE_LOGO,
9
+ DELETE_ONE_BANNER_STORE,
10
+ DELETE_ONE_LOGO_STORE,
11
+ GET_ONE_BANNER_STORE
12
+ } from '../useProductsFood/queriesStore';
13
+ import { GET_ONE_STORE } from '../useStore/queries';
14
+
15
+ export const useImageStore = (idStore) => {
16
+ // STATES
17
+ const fileInputRef = useRef(null)
18
+ const [{ altLogo, srcLogo }, setPreviewImgLogo] = useState({})
19
+ const initialState = { alt: '/images/DEFAULTBANNER.png', src: '/images/DEFAULTBANNER.png' }
20
+ const [{ alt, src }, setPreviewImg] = useState(initialState)
21
+ const fileInputRefLogo = useRef(null)
22
+ // HOOKS
23
+ const [registerBanner] = useMutation(CREATE_BANNER_STORE, {
24
+ onCompleted: (data) => { return console.log({ message: data?.registerBanner?.message }) },
25
+ context: { clientName: 'admin-server' }
26
+ })
27
+ const [setALogoStore] = useMutation(CREATE_LOGO, {
28
+ onCompleted: (data) => { return console.log({ message: data?.setALogoStore?.message }) },
29
+ context: { clientName: 'admin-server' }
30
+ })
31
+ const [DeleteOneBanner] = useMutation(DELETE_ONE_BANNER_STORE, {
32
+ onCompleted: (data) => { return console.log({ message: data?.DeleteOneBanner?.message }) },
33
+ context: { clientName: 'admin-server' }
34
+ })
35
+ const [deleteALogoStore] = useMutation(DELETE_ONE_LOGO_STORE, {
36
+ onCompleted: (data) => {
37
+ console.log({
38
+ message: data.deleteALogoStore.message
39
+ })
40
+ setPreviewImgLogo(initialState)
41
+ },
42
+ context: { clientName: 'admin-server' },
43
+ update(cache) {
44
+ cache.modify({
45
+ fields: {
46
+ getStore(dataOld = []) {
47
+ return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld })
48
+ }
49
+ }
50
+ })
51
+ }
52
+ })
53
+ // HANDLESS
54
+ const handleDeleteLogo = () => {
55
+ return deleteALogoStore({
56
+ variables: {
57
+ Image: ImageName || null
58
+ }
59
+ })
60
+ }
61
+
62
+ const handleUpdateBanner = event => {
63
+ try {
64
+ const { files } = event.target
65
+ setPreviewImg(
66
+ files.length
67
+ ? {
68
+ src: URL.createObjectURL(files[0]),
69
+ alt: files[0].name
70
+ }
71
+ : initialState
72
+ )
73
+ registerBanner({
74
+ variables: {
75
+ input: {
76
+ bnImage: files[0],
77
+ idStore: idStore
78
+ }
79
+ }, update(cache) {
80
+ cache.modify({
81
+ fields: {
82
+ getOneBanners(dataOld = []) {
83
+ return cache.writeQuery({ query: GET_ONE_BANNER_STORE, data: dataOld })
84
+ }
85
+ }
86
+ })
87
+ }
88
+ }).catch(() => {
89
+ console.log({ message: 'No pudimos cargar la imagen', duration: 7000 })
90
+ setPreviewImg(initialState)
91
+ })
92
+
93
+ } catch {
94
+ setPreviewImg(initialState)
95
+ console.log({ message: 'No pudimos cargar la imagen', duration: 7000 })
96
+ }
97
+ }
98
+ const handleInputChangeLogo = event => {
99
+ const { files } = event.target
100
+ setPreviewImgLogo(
101
+ files.length
102
+ ? {
103
+ srcLogo: URL.createObjectURL(files[0]),
104
+ altLogo: files[0].name
105
+ }
106
+ : initialState
107
+ )
108
+ setALogoStore({
109
+ variables: {
110
+ logo: files[0],
111
+ idStore: idStore
112
+ }, update(cache) {
113
+ cache.modify({
114
+ fields: {
115
+ getStore(dataOld = []) {
116
+ return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld })
117
+ }
118
+ }
119
+ })
120
+ }
121
+ }).catch(() => {
122
+ console.log({ message: 'No pudimos cargar el banner', duration: 7000 })
123
+ setPreviewImgLogo(initialState)
124
+ })
125
+ }
126
+ const HandleDeleteBanner = async () => {
127
+ setPreviewImg(initialState)
128
+ DeleteOneBanner({
129
+ variables: {
130
+ bnState: bnState,
131
+ bnImageFileName: bnImageFileName,
132
+ idStore,
133
+ bnId
134
+ }, update(cache) {
135
+ cache.modify({
136
+ fields: {
137
+ getOneBanners(dataOld = []) {
138
+ return cache.writeQuery({ query: GET_ONE_BANNER_STORE, data: dataOld })
139
+ }
140
+ }
141
+ })
142
+ }
143
+ }).then(() => {
144
+ setPreviewImg(initialState)
145
+ })
146
+ }
147
+ const onTargetClickLogo = e => {
148
+ e.preventDefault()
149
+ fileInputRefLogo.current.click()
150
+ }
151
+ const onTargetClick = e => {
152
+ e.preventDefault()
153
+ fileInputRef.current.click()
154
+ }
155
+ return {
156
+ fileInputRefLogo,
157
+ src,
158
+ alt,
159
+ initialState,
160
+ srcLogo,
161
+ altLogo,
162
+ fileInputRef,
163
+ handleDeleteLogo,
164
+ onTargetClick,
165
+ onTargetClickLogo,
166
+ HandleDeleteBanner,
167
+ handleInputChangeLogo,
168
+ handleUpdateBanner
169
+ }
170
+ }
171
+
@@ -0,0 +1,216 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const CREATE_SCHEDULE_STORE = gql`
4
+ mutation setStoreSchedule($input: IsStoreSchedule!){
5
+ setStoreSchedule(input: $input){
6
+ success
7
+ message
8
+ }
9
+ }
10
+ `
11
+ export const GET_SCHEDULE_STORE = gql`
12
+ query getStoreSchedules($schDay: Int, $idStore: ID) {
13
+ getStoreSchedules(schDay: $schDay, idStore: $idStore){
14
+ schId
15
+ idStore
16
+ schDay
17
+ schHoSta
18
+ schHoEnd
19
+ schState
20
+ }
21
+ }
22
+ `
23
+ export const GET_ONE_SCHEDULE_STORE = gql`
24
+ query getOneStoreSchedules($schDay: Int, $idStore: ID) {
25
+ getOneStoreSchedules(schDay: $schDay, idStore: $idStore){
26
+ schId
27
+ schDay
28
+ schHoSta
29
+ schHoEnd
30
+ schState
31
+ }
32
+ }
33
+ `
34
+ export const GET_CAT_OF_PRODUCTS = gql`
35
+ query getAllCatOfProducts($idStore: ID) {
36
+ getAllCatOfProducts(idStore: $idStore) {
37
+ id
38
+ cpId
39
+ catName
40
+ catDescription
41
+ schState
42
+
43
+ }
44
+ }
45
+ `
46
+ export const REGISTER_CAT_OF_PRODUCTS = gql`
47
+ mutation updatedProducts($input: InputCatProducts){
48
+ updatedProducts(input: $input){
49
+ success
50
+ message
51
+ }
52
+ }
53
+ `
54
+ export const REGISTER_CONTRACT_STORE = gql`
55
+ mutation createOneContract($input: InputContractType) {
56
+ createOneContract(input: $input) {
57
+ success
58
+ message
59
+ }
60
+ }
61
+ `
62
+ export const GET_ALL_EMPLOYEE_STORE = gql`
63
+ query employees ($umId: ID, $cId: ID, $aId: ID){
64
+ employees(umId: $umId, cId: $cId, aId: $aId) {
65
+ eId
66
+ idStore
67
+ id
68
+ idEmployee
69
+ eSalary
70
+ typeContract
71
+ uEmail
72
+ termContract
73
+ eDatAdm
74
+ eState
75
+ }
76
+ }
77
+ `
78
+ export const GET_ALL_PRODUCT_STORE = gql`
79
+ query productFoodsAll($search: String, $min: Int, $max: Int, $gender: [String], $pState: Int, $desc: [String], $categories: [ID], $fromDate: DateTime, $toDate: DateTime ) {
80
+ productFoodsAll(search: $search, min: $min, max: $max, gender: $gender, desc: $desc, pState: $pState categories: $categories, toDate: $toDate, fromDate: $fromDate) {
81
+ pId
82
+ sizeId #Talla
83
+ colorId #Color
84
+ cId #Country
85
+ dId #Department
86
+ ctId #Cuidad
87
+ fId #Características
88
+ pName
89
+ ProPrice
90
+ ProDescuento
91
+ free
92
+ ProUniDisponibles
93
+ ProDescription
94
+ ProProtegido
95
+ ProAssurance
96
+ ValueDelivery
97
+ ProStar
98
+ sTateLogistic
99
+ ProImage
100
+ ProWidth
101
+ ProHeight
102
+ ProLength
103
+ ProWeight
104
+ ProQuantity
105
+ ProOutstanding
106
+ pDatCre
107
+ pDatMod
108
+ ProDelivery
109
+ ProVoltaje
110
+ pState
111
+ feat {
112
+ fId
113
+ thpId
114
+ hpqrQuestion
115
+ }
116
+ area {
117
+ aId
118
+ aName
119
+ }
120
+
121
+ }
122
+ }
123
+
124
+ `
125
+ export const GET_ALL_RATING_START_STORE = gql`
126
+ query getAllRatingStar($idStore: ID){
127
+ getAllRatingStar(idStore: $idStore){
128
+ rSId
129
+ rScore
130
+ idStore
131
+ createAt
132
+ }
133
+ }
134
+ `
135
+ export const GET_ALL_VISITOR_STORE = gql`
136
+ query getAllVisitorStore($idStore: ID, $search: String, $min: Int, $max: Int, $fromDate: DateTime, $toDate: DateTime) {
137
+ getAllVisitorStore(idStore: $idStore, search: $search, min: $min, max: $max, fromDate: $fromDate, toDate: $toDate) {
138
+ visitStoreId
139
+ id
140
+ idStore
141
+ createAt
142
+ updateAt
143
+ }
144
+ }
145
+ `
146
+ export const GET_MIN_PEDIDO = gql`
147
+ query getMinPrice($idStore: ID){
148
+ getMinPrice(idStore: $idStore)
149
+ }
150
+ `
151
+
152
+ export const GET_All_RATING_STORE = gql`
153
+ query getAllRating($idStore: ID){
154
+ getAllRating(idStore: $idStore){
155
+ idStore
156
+ rId
157
+ id
158
+ rAppearance
159
+ rTasty
160
+ rGoodTemperature
161
+ rGoodCondition
162
+ rState
163
+ createAt
164
+ updateAt
165
+ }
166
+ }
167
+ `
168
+ export const CREATE_LOGO = gql`
169
+ mutation setALogoStore($logo: Upload, $idStore: ID) {
170
+ setALogoStore(logo: $logo, idStore: $idStore) {
171
+ success
172
+ message
173
+ }
174
+ }
175
+ `
176
+ export const CREATE_BANNER_STORE = gql`
177
+ mutation registerBanner($input: IBanner) {
178
+ registerBanner(input: $input) {
179
+ success
180
+ message
181
+
182
+ }
183
+ }
184
+ `
185
+ export const DELETE_ONE_LOGO_STORE = gql`
186
+ mutation deleteALogoStore($idStore: ID, $Image: String) {
187
+ deleteALogoStore(idStore: $idStore, Image: $Image) {
188
+ message
189
+ success
190
+ }
191
+
192
+ }
193
+ `
194
+ export const GET_ONE_BANNER_STORE = gql`
195
+ query getOneBanners($idStore: ID, $id: ID) {
196
+ getOneBanners(idStore: $idStore, id: $id) {
197
+ bnId
198
+ id
199
+ path
200
+ bnImageFileName
201
+ idStore
202
+ bnState
203
+ createAt
204
+ updateAt
205
+ }
206
+ }
207
+ `
208
+ export const DELETE_ONE_BANNER_STORE = gql`
209
+ mutation DeleteOneBanner($bnState: Int, $idStore: ID, $bnId: ID, $bnImage: String, $bnImageFileName: String) {
210
+ DeleteOneBanner(bnState: $bnState, idStore: $idStore, bnId: $bnId, bnImage: $bnImage, bnImageFileName: $bnImageFileName ) {
211
+ success
212
+ message
213
+
214
+ }
215
+ }
216
+ `
@@ -28,4 +28,57 @@ export const useOnScreen = (threshold = 0.6) => {
28
28
  )
29
29
 
30
30
  return [setRef, isVisible]
31
- }
31
+ }
32
+
33
+ const defaultObserverOptions = {
34
+ root: null,
35
+ threshold: 0.1,
36
+ rootMargin: "0px"
37
+ };
38
+
39
+ export const useIntersectionObserver = ({
40
+ active = true,
41
+ disconnect,
42
+ el,
43
+ options = defaultObserverOptions,
44
+ onEnter = () => {},
45
+ out = () => {}
46
+ }) => {
47
+ const [onScreen, setOnScreen] = useState()
48
+ useEffect(() => {
49
+ let observer
50
+ const refEl = el.current
51
+ if (IntersectionObserver && active && refEl) {
52
+ observer = new IntersectionObserver((entries) => {
53
+ entries.forEach((entry) => {
54
+ if (disconnect) {
55
+ if (entry.isIntersecting) {
56
+ onEnter()
57
+ setOnScreen(true)
58
+ } else {
59
+ out()
60
+ setOnScreen(false)
61
+ }
62
+ }
63
+ if (!disconnect) {
64
+ onEnter()
65
+ setOnScreen(true)
66
+ }
67
+ })
68
+ }, options)
69
+ observer.observe(refEl)
70
+ }
71
+ return () => {
72
+ if (disconnect) {
73
+ // eslint-disable-next-line no-void
74
+ observer === null || observer === void 0 ? void 0 : observer.disconnect(refEl)
75
+ }
76
+ if (!disconnect) {
77
+ if (el && observer) observer.unobserve(refEl)
78
+ }
79
+ }
80
+ }, [el, onEnter, active, options])
81
+ return {
82
+ onScreen
83
+ }
84
+ }
@@ -0,0 +1,72 @@
1
+ import React from 'react';
2
+
3
+ export const useLazyScript = (src, delay = null) => {
4
+ const [status, setStatus] = React.useState(src ? 'loading' : 'idle');
5
+
6
+ React.useEffect(() => {
7
+ if (!src) {
8
+ setStatus('idle');
9
+ return 'idle';
10
+ }
11
+
12
+ let script = document.querySelector(`script[src='${src}']`);
13
+ let timeout = null;
14
+
15
+ if (!script) {
16
+ if (delay) {
17
+ timeout = setTimeout(() => {
18
+ injectScript();
19
+ // Add event listener after the script is added
20
+ script.addEventListener('load', setStateStatus);
21
+ script.addEventListener('error', setStateStatus);
22
+ }, delay);
23
+ } else {
24
+ injectScript();
25
+ }
26
+ } else {
27
+ setStatus(script.getAttribute('data-status'));
28
+ }
29
+
30
+ const setStateStatus = (event) => {
31
+ setStatus(event.type === 'load' ? 'ready' : 'error');
32
+ };
33
+
34
+ //code to inject script
35
+ function injectScript() {
36
+ script = document.createElement('script');
37
+ script.src = src;
38
+ script.async = true;
39
+ script.setAttribute('data-status', 'loading');
40
+ document.body.appendChild(script);
41
+
42
+ const setDataStatus = (event) => {
43
+ script.setAttribute(
44
+ 'data-status',
45
+ event.type === 'load' ? 'ready' : 'error'
46
+ );
47
+ };
48
+
49
+ script.addEventListener('load', setDataStatus);
50
+ script.addEventListener('error', setDataStatus);
51
+ }
52
+
53
+ if (script) {
54
+ //script will be be undefined available when its delayed hence check it before adding listener
55
+ script.addEventListener('load', setStateStatus);
56
+ script.addEventListener('error', setStateStatus);
57
+ }
58
+
59
+ return () => {
60
+ if (script) {
61
+ script.removeEventListener('load', setStateStatus);
62
+ script.removeEventListener('error', setStateStatus);
63
+ }
64
+ if (timeout) {
65
+ clearTimeout(timeout);
66
+ }
67
+ };
68
+ }, [src]);
69
+
70
+ return status;
71
+ };
72
+
@@ -1,4 +1,4 @@
1
- import { useState, useEffect } from 'react'
1
+ import { useEffect, useState } from 'react'
2
2
 
3
3
  const defaultSettings = {
4
4
  enableHighAccuracy: false,
@@ -0,0 +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
+ };
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