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.
- package/.env +1 -0
- package/.eslintrc.js +132 -0
- package/.github/pull_request_template.md +18 -0
- package/.github/workflows/pepeline.yaml +30 -0
- package/.vscode/extensions.json +6 -0
- package/.vscode/settings.json +12 -0
- package/next.config.js +4 -4
- package/package.json +17 -7
- package/script.txt +7 -0
- package/src/hooks/index.js +39 -8
- package/src/hooks/updateExtProductFoodsOptional/index.js +38 -0
- package/src/hooks/useAcumulateDate/index.js +14 -14
- package/src/hooks/useAnimationText/index.jsx +7 -6
- package/src/hooks/useBanner/index.js +19 -0
- package/src/hooks/useCatWithProduct/index.js +42 -0
- package/src/hooks/useCatWithProduct/queries.js +172 -0
- package/src/hooks/useCategoryInStore/index.js +94 -0
- package/src/hooks/{useGetCategorieStore → useCategoryInStore}/queries.js +0 -0
- package/src/hooks/useChartData/index.js +168 -0
- package/src/hooks/useCheckbox/index.js +114 -0
- package/src/hooks/useClients/index.js +13 -0
- package/src/hooks/useClients/queries.js +118 -0
- package/src/hooks/useConnection/index.js +23 -0
- package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +165 -0
- package/src/hooks/useCreateProduct/index.js +268 -0
- package/src/hooks/useDessert/index.js +141 -0
- package/src/hooks/useDrag/index.js +14 -9
- package/src/hooks/useFetchMoreInteractions/index.jsx +6 -3
- package/src/hooks/useFormTools/index.js +16 -3
- package/src/hooks/useFormatDate/index.js +34 -0
- package/src/hooks/useImageOptimization/index.js +28 -0
- package/src/hooks/useImageWeight/index.js +52 -0
- package/src/hooks/useImagesStore/index.js +171 -0
- package/src/hooks/useImagesStore/queries.js +216 -0
- package/src/hooks/useIntersection/index.js +54 -1
- package/src/hooks/useLazyScript/index.js +72 -0
- package/src/hooks/useLocationNavigate/index.js +1 -1
- package/src/hooks/useMobile/index.js +38 -0
- package/src/hooks/useMutateHeight/index.js +37 -0
- package/src/hooks/useProductsFood/index.js +190 -0
- package/src/hooks/useProductsFood/queriesStore.js +781 -0
- package/src/hooks/useProductsFood/usetagsProducts.js +57 -0
- package/src/hooks/useReport/index.js +35 -0
- package/src/hooks/useReport/queries.js +122 -0
- package/src/hooks/useRestaurant/queries.js +11 -1
- package/src/hooks/useSales/index.js +589 -0
- package/src/hooks/useSales/queries.js +291 -0
- package/src/hooks/useSales/useGetSale.js +12 -0
- package/src/hooks/useSales/useTotalSales.js +17 -0
- package/src/hooks/useSaveAvailableProduct/helpers/index.js +30 -0
- package/src/hooks/useSaveAvailableProduct/index.js +26 -0
- package/src/hooks/useSaveAvailableProduct/queries.js +10 -0
- package/src/hooks/useSchedule/index.jsx +23 -0
- package/src/hooks/useStore/index.js +18 -0
- package/src/hooks/useStore/queries.js +136 -0
- package/src/hooks/useStoreCalendar/index.js +7 -0
- package/src/hooks/useUpdateCart/index.js +5 -4
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +37 -0
- package/src/hooks/useUser/index.js +6 -2
- package/src/hooks/useUser/queries.js +69 -0
- package/src/index.jsx +2 -1
- package/src/mock/dessert/index.js +16 -0
- package/src/mock/index.js +2 -0
- package/src/utils/index.js +80 -1
- package/src/hooks/useGetCategorieStore/index.js +0 -21
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useMutation, useQuery } from '@apollo/client';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { DELETE_ONE_CAT_PRODUCTS, GET_ULTIMATE_CATEGORY_PRODUCTS } from '../useProductsFood/queriesStore';
|
|
4
|
+
import { UPDATE_CAT_IN_PRODUCT } from './../useProductsFood/queriesStore';
|
|
5
|
+
import { GET_ONE_STORE_IN_CATEGORY } from './queries';
|
|
6
|
+
export const useCategoryInStore = ({ catStoreId }) => {
|
|
7
|
+
// STATES
|
|
8
|
+
const [categories, setOneCategoryInStore] = useState([])
|
|
9
|
+
const [deleteCatOfProducts] = useMutation(DELETE_ONE_CAT_PRODUCTS, {
|
|
10
|
+
onError: (e) => {
|
|
11
|
+
setAlertBox({
|
|
12
|
+
message: e.graphQLErrors[0].message,
|
|
13
|
+
color: WColor
|
|
14
|
+
})
|
|
15
|
+
},
|
|
16
|
+
update(cache) {
|
|
17
|
+
cache.modify({
|
|
18
|
+
fields: {
|
|
19
|
+
catProductsAll(dataOld = []) {
|
|
20
|
+
return cache.writeQuery({ query: GET_ULTIMATE_CATEGORY_PRODUCTS, data: dataOld })
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
const [updatedCatWithProducts] = useMutation(UPDATE_CAT_IN_PRODUCT, {
|
|
27
|
+
onError: (e) => {
|
|
28
|
+
console.log({
|
|
29
|
+
message: e.graphQLErrors[0].message,
|
|
30
|
+
color: WColor
|
|
31
|
+
})
|
|
32
|
+
},
|
|
33
|
+
update(cache) {
|
|
34
|
+
cache.modify({
|
|
35
|
+
fields: {
|
|
36
|
+
catProductsAll(dataOld = []) {
|
|
37
|
+
return cache.writeQuery({ query: GET_ULTIMATE_CATEGORY_PRODUCTS, data: dataOld })
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
// QUERIES
|
|
44
|
+
const { data } = useQuery(GET_ULTIMATE_CATEGORY_PRODUCTS)
|
|
45
|
+
const {
|
|
46
|
+
loading,
|
|
47
|
+
error
|
|
48
|
+
} = useQuery(GET_ONE_STORE_IN_CATEGORY, {
|
|
49
|
+
variables: {
|
|
50
|
+
catStore: catStoreId
|
|
51
|
+
},
|
|
52
|
+
onError: () => {
|
|
53
|
+
console.log({ message: '', duration: 5000 })
|
|
54
|
+
},
|
|
55
|
+
onCompleted: () => {
|
|
56
|
+
setOneCategoryInStore(data.getOneCatStore)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
// HANDLESS
|
|
60
|
+
const handlerDeleteCategoryInStore = (category) => {
|
|
61
|
+
const { pState, idPc } = category || {}
|
|
62
|
+
if (!idPc || !pState) return
|
|
63
|
+
return deleteCatOfProducts({
|
|
64
|
+
variables: { idPc, pState }, update(cache) {
|
|
65
|
+
cache.modify({
|
|
66
|
+
fields: {
|
|
67
|
+
catProductsAll(dataOld = []) {
|
|
68
|
+
return cache.writeQuery({ query: GET_ULTIMATE_CATEGORY_PRODUCTS, data: dataOld })
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
const handleUpdateCatInProduct = async ({ data }) => {
|
|
76
|
+
await updatedCatWithProducts({
|
|
77
|
+
variables: {
|
|
78
|
+
input: {
|
|
79
|
+
setData: data?.map(x => { return { idProduct: x.pId } }),
|
|
80
|
+
idCat: idCat
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
categories,
|
|
87
|
+
data: data?.catProductsAll || [],
|
|
88
|
+
loading,
|
|
89
|
+
error,
|
|
90
|
+
handlerDeleteCategoryInStore,
|
|
91
|
+
handleUpdateCatInProduct
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
File without changes
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { useQuery } from '@apollo/client';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { SPANISH_MONTHS } from "../../utils/index";
|
|
4
|
+
import { GET_ALL_SALES } from "../useReport/queries";
|
|
5
|
+
|
|
6
|
+
export const useChartData = ({ year }) => {
|
|
7
|
+
// Construcción del nuevo array:
|
|
8
|
+
const { data, loading } = useQuery(GET_ALL_SALES)
|
|
9
|
+
const [chartType, setChartType] = useState('bar')
|
|
10
|
+
const [chartTypeYear, setChartTypeYear] = useState(new Date().getFullYear())
|
|
11
|
+
const [asFilter, setFilter] = useState(false)
|
|
12
|
+
const [newResult, setNewResult] = useState([])
|
|
13
|
+
let result = []
|
|
14
|
+
data?.getAllSalesStore?.length > 0 && data?.getAllSalesStore.reduce(function (res, value) {
|
|
15
|
+
// Creamos la posición del array para cada mes
|
|
16
|
+
let mes = new Date(value.pDatCre).getMonth()
|
|
17
|
+
let Year = new Date(value.pDatCre).getFullYear()
|
|
18
|
+
if (!res[mes]) {
|
|
19
|
+
res[mes] = { Mes: mes, Year }
|
|
20
|
+
// Inicializamos a 0 el valor de cada key
|
|
21
|
+
Object.keys(value).forEach((key) => {
|
|
22
|
+
if (key != 'pDatCre') {
|
|
23
|
+
res[mes][key] = 0
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
result.push(res[mes])
|
|
28
|
+
}
|
|
29
|
+
// Sumamos el valor de cada clave dentro de un bucle
|
|
30
|
+
Object.keys(value).forEach(function (key) {
|
|
31
|
+
if (key != 'pDatCre') {
|
|
32
|
+
res[mes]['totalProductsPrice'] += value['totalProductsPrice']
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
return res
|
|
36
|
+
}, {})
|
|
37
|
+
|
|
38
|
+
let allMonths = Array.from({ length: 12 }, (_, i) => { return i })
|
|
39
|
+
let missingMonths = allMonths.filter(month => { return !result.some(data => { return data.Mes === month }) })
|
|
40
|
+
|
|
41
|
+
for (const element of missingMonths) {
|
|
42
|
+
result.push({
|
|
43
|
+
'Mes': element,
|
|
44
|
+
'totalProductsPrice': 0,
|
|
45
|
+
'Year': ''
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
result.sort((a, b) => { return a.Mes - b.Mes })
|
|
50
|
+
|
|
51
|
+
const labelTitle = `Ventas por meses del año ${asFilter ? chartTypeYear : ''}`
|
|
52
|
+
// Resultado:
|
|
53
|
+
|
|
54
|
+
const dataChart = {
|
|
55
|
+
labels: asFilter ? newResult.map(data => {
|
|
56
|
+
return SPANISH_MONTHS[data.Mes]
|
|
57
|
+
}) : result.map(data => {
|
|
58
|
+
return SPANISH_MONTHS[data.Mes]
|
|
59
|
+
}),
|
|
60
|
+
datasets: [
|
|
61
|
+
{
|
|
62
|
+
label: labelTitle,
|
|
63
|
+
data: asFilter ? newResult.map(data => { return data.totalProductsPrice }) : result.map(data => { return data.totalProductsPrice }),
|
|
64
|
+
backgroundColor: [
|
|
65
|
+
'rgba(255, 99, 132, 0.2)',
|
|
66
|
+
'rgba(54, 162, 235, 0.2)',
|
|
67
|
+
'rgba(255, 206, 86, 0.2)',
|
|
68
|
+
'rgba(75, 192, 192, 0.2)',
|
|
69
|
+
'rgba(153, 102, 255, 0.2)',
|
|
70
|
+
'rgba(255, 159, 64, 0.2)'
|
|
71
|
+
],
|
|
72
|
+
borderColor: chartType === 'bar' ? [
|
|
73
|
+
'rgba(255, 99, 132, 1)',
|
|
74
|
+
'rgba(54, 162, 235, 1)',
|
|
75
|
+
'rgba(255, 206, 86, 1)',
|
|
76
|
+
'rgba(75, 192, 192, 1)',
|
|
77
|
+
'rgba(153, 102, 255, 1)',
|
|
78
|
+
'rgba(255, 159, 64, 1)'
|
|
79
|
+
] : 'rgb(255 0 0)',
|
|
80
|
+
tension: 0.6,
|
|
81
|
+
fill: false,
|
|
82
|
+
borderWidth: 1,
|
|
83
|
+
barPercentage: 1,
|
|
84
|
+
barThickness: 50,
|
|
85
|
+
minBarLength: 3,
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
const options = {
|
|
90
|
+
interaction: {
|
|
91
|
+
mode: 'index',
|
|
92
|
+
intersect: false,
|
|
93
|
+
},
|
|
94
|
+
scales: {
|
|
95
|
+
x: {
|
|
96
|
+
stacked: true
|
|
97
|
+
},
|
|
98
|
+
y: {
|
|
99
|
+
stacked: true
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
plugins: {
|
|
103
|
+
title: {
|
|
104
|
+
display: true,
|
|
105
|
+
text: labelTitle
|
|
106
|
+
},
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const groupedData = {}
|
|
110
|
+
|
|
111
|
+
data && data.getAllSalesStore.forEach((item) => {
|
|
112
|
+
const year = new Date(item.pDatCre).getFullYear()
|
|
113
|
+
if (!groupedData[year]) {
|
|
114
|
+
groupedData[year] = []
|
|
115
|
+
}
|
|
116
|
+
groupedData[year].push(item)
|
|
117
|
+
})
|
|
118
|
+
const years = []
|
|
119
|
+
data && data.getAllSalesStore.forEach((item) => {
|
|
120
|
+
const y = new Date(item.pDatCre).getFullYear()
|
|
121
|
+
if (!years.includes(y)) {
|
|
122
|
+
years.push(y)
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
const handleChangeYear = (value) => {
|
|
126
|
+
setFilter(true)
|
|
127
|
+
if (result?.length > 0) {
|
|
128
|
+
const filterToYear = result.filter((elem) => {
|
|
129
|
+
return elem?.Year == parseInt(value)
|
|
130
|
+
})
|
|
131
|
+
let missingNewMonths = allMonths.filter(month => { return !filterToYear.some(data => { return data.Mes === month }) })
|
|
132
|
+
for (const element of missingNewMonths) {
|
|
133
|
+
filterToYear.push({
|
|
134
|
+
'Mes': element,
|
|
135
|
+
'totalProductsPrice': 0,
|
|
136
|
+
'Year': ''
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
filterToYear.sort((a, b) => { return a.Mes - b.Mes })
|
|
140
|
+
setNewResult(filterToYear)
|
|
141
|
+
return filterToYear
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const cleanFilter = () => {
|
|
145
|
+
setFilter(false)
|
|
146
|
+
setChartTypeYear(new Date().getFullYear())
|
|
147
|
+
}
|
|
148
|
+
const sortYear = () => {
|
|
149
|
+
return years.sort((a, b) => { return b - a });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const organiceYears = sortYear()
|
|
153
|
+
return {
|
|
154
|
+
handleChangeYear,
|
|
155
|
+
setFilter,
|
|
156
|
+
cleanFilter,
|
|
157
|
+
setChartType,
|
|
158
|
+
years: organiceYears,
|
|
159
|
+
asFilter,
|
|
160
|
+
chartTypeYear,
|
|
161
|
+
options,
|
|
162
|
+
chartType,
|
|
163
|
+
labelTitle,
|
|
164
|
+
result,
|
|
165
|
+
dataChart,
|
|
166
|
+
loading
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hook for managing multiple checkbox states
|
|
5
|
+
*
|
|
6
|
+
* @param {Array<String | Number>} elem - list of all elem
|
|
7
|
+
* @param {Array<String | Number>} selectedIds - list of selected elem (optional)
|
|
8
|
+
*
|
|
9
|
+
* @returns {Object}
|
|
10
|
+
* - checkboxStates (state object),
|
|
11
|
+
* - numSelectedItems (number),
|
|
12
|
+
* - handleChangeCheck (callback),
|
|
13
|
+
* - toggleAll (callback),
|
|
14
|
+
* - selectAll (callback),
|
|
15
|
+
* - clearAll (callback)
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export const useCheckboxState = (elem, selectedIds = [], disabledIds = []) => {
|
|
19
|
+
const numTotalItems = elem?.length
|
|
20
|
+
const [checkedItems, setCheckedItems] = useState(new Set(selectedIds))
|
|
21
|
+
const [disabledItems, setDisabledItems] = useState(new Set(disabledIds))
|
|
22
|
+
|
|
23
|
+
const handleChangeCheck = useCallback((event, id) => {
|
|
24
|
+
const target = event.target
|
|
25
|
+
setCheckedItems(prevState => {
|
|
26
|
+
const newState = new Set(prevState)
|
|
27
|
+
if (target.checked) {
|
|
28
|
+
newState.add(id)
|
|
29
|
+
} else {
|
|
30
|
+
newState.delete(id)
|
|
31
|
+
}
|
|
32
|
+
return newState
|
|
33
|
+
})
|
|
34
|
+
}, [])
|
|
35
|
+
|
|
36
|
+
const setAll = useCallback(
|
|
37
|
+
isChecked => {
|
|
38
|
+
setCheckedItems(prevState => {
|
|
39
|
+
const newState = new Set(prevState)
|
|
40
|
+
for (const id of elem) {
|
|
41
|
+
if (disabledItems.has(id)) {
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
if (isChecked) {
|
|
45
|
+
newState.add(id)
|
|
46
|
+
} else {
|
|
47
|
+
newState.delete(id)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return newState
|
|
51
|
+
})
|
|
52
|
+
},
|
|
53
|
+
[elem, disabledItems]
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
const selectAll = useCallback(() => {
|
|
57
|
+
if (checkedItems.size === numTotalItems) {
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
setAll(true)
|
|
61
|
+
}, [checkedItems, numTotalItems, setAll])
|
|
62
|
+
|
|
63
|
+
const clearAll = useCallback(() => {
|
|
64
|
+
if (checkedItems.size === 0) {
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
setAll(false)
|
|
68
|
+
}, [checkedItems, setAll])
|
|
69
|
+
|
|
70
|
+
const toggleAll = useCallback(() => {
|
|
71
|
+
const numDisabledAndChecked = [...disabledItems].reduce((count, id) => {
|
|
72
|
+
if (checkedItems.has(id)) {
|
|
73
|
+
return count + 1
|
|
74
|
+
}
|
|
75
|
+
return count
|
|
76
|
+
}, 0)
|
|
77
|
+
if (checkedItems.size - numDisabledAndChecked === 0) {
|
|
78
|
+
selectAll()
|
|
79
|
+
} else {
|
|
80
|
+
clearAll()
|
|
81
|
+
}
|
|
82
|
+
}, [checkedItems, disabledItems, selectAll, clearAll])
|
|
83
|
+
|
|
84
|
+
const enableCheckboxes = useCallback((...elem) => {
|
|
85
|
+
setDisabledItems(prevState => {
|
|
86
|
+
const newState = new Set(prevState)
|
|
87
|
+
for (const id of elem) {
|
|
88
|
+
newState.delete(id)
|
|
89
|
+
}
|
|
90
|
+
return newState
|
|
91
|
+
})
|
|
92
|
+
}, [])
|
|
93
|
+
|
|
94
|
+
const disableCheckboxes = useCallback((...elem) => {
|
|
95
|
+
setDisabledItems(prevState => {
|
|
96
|
+
const newState = new Set(prevState)
|
|
97
|
+
for (const id of elem) {
|
|
98
|
+
newState.add(id)
|
|
99
|
+
}
|
|
100
|
+
return newState
|
|
101
|
+
})
|
|
102
|
+
}, [])
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
checkedItems,
|
|
106
|
+
disabledItems,
|
|
107
|
+
handleChangeCheck,
|
|
108
|
+
toggleAll,
|
|
109
|
+
selectAll,
|
|
110
|
+
clearAll,
|
|
111
|
+
enableCheckboxes,
|
|
112
|
+
disableCheckboxes
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useQuery } from '@apollo/client'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { GET_ALL_CLIENTS } from './queries'
|
|
4
|
+
|
|
5
|
+
export const useGetClients = () => {
|
|
6
|
+
const [clientes, setClients] = useState([])
|
|
7
|
+
const { loading, error } = useQuery(GET_ALL_CLIENTS, {
|
|
8
|
+
onCompleted: (data) => {
|
|
9
|
+
setClients(data)
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
return [clientes?.getAllClients || [], { loading, error }]
|
|
13
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const CREATE_CLIENTS = gql`
|
|
4
|
+
mutation createClients ($input: IClients) {
|
|
5
|
+
createClients(input: $input) {
|
|
6
|
+
cliId
|
|
7
|
+
idStore
|
|
8
|
+
idUser
|
|
9
|
+
clState
|
|
10
|
+
ClientAddress
|
|
11
|
+
clientNumber
|
|
12
|
+
ccClient
|
|
13
|
+
gender
|
|
14
|
+
clientLastName
|
|
15
|
+
clientName
|
|
16
|
+
createAt
|
|
17
|
+
updateAt
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
`
|
|
21
|
+
export const DELETE_ONE_CLIENTS = gql`
|
|
22
|
+
mutation deleteClient($cliId: ID, $clState: Int!) {
|
|
23
|
+
deleteClient(cliId: $cliId, clState: $clState) {
|
|
24
|
+
success
|
|
25
|
+
message
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`
|
|
29
|
+
export const GET_ALL_CLIENTS = gql`
|
|
30
|
+
query getAllClients($idStore: ID, $cId: ID, $dId: ID, $ctId: ID, $search: String, $min: Int, $max: Int, $fromDate: DateTime, $toDate: DateTime ) {
|
|
31
|
+
getAllClients(idStore: $idStore, cId: $cId, dId: $dId, ctId: $ctId, search: $search, min: $min, max: $max, fromDate: $fromDate, toDate: $toDate) {
|
|
32
|
+
cliId
|
|
33
|
+
idStore
|
|
34
|
+
gender
|
|
35
|
+
# idUser
|
|
36
|
+
clState
|
|
37
|
+
clientNumber
|
|
38
|
+
ccClient
|
|
39
|
+
clientLastName
|
|
40
|
+
clientName
|
|
41
|
+
ClientAddress
|
|
42
|
+
createAt
|
|
43
|
+
updateAt
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`
|
|
48
|
+
export const GET_ONE_CLIENT = gql`
|
|
49
|
+
query getOneClients($cliId: ID) {
|
|
50
|
+
getOneClients(cliId: $cliId) {
|
|
51
|
+
cliId
|
|
52
|
+
idStore
|
|
53
|
+
idUser
|
|
54
|
+
clState
|
|
55
|
+
clientNumber
|
|
56
|
+
ClientAddress
|
|
57
|
+
gender
|
|
58
|
+
ccClient
|
|
59
|
+
clientLastName
|
|
60
|
+
clientName
|
|
61
|
+
createAt
|
|
62
|
+
updateAt
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
`
|
|
67
|
+
|
|
68
|
+
export const CREATE_SHOPPING_CARD = gql`
|
|
69
|
+
mutation registerShoppingCard($input: IShoppingCard, $idSubArray: IID_SUB_ITEMS){
|
|
70
|
+
registerShoppingCard(input: $input, idSubArray: $idSubArray){
|
|
71
|
+
ShoppingCard
|
|
72
|
+
id
|
|
73
|
+
pId
|
|
74
|
+
subProductsId
|
|
75
|
+
ShoppingCardRefCode
|
|
76
|
+
uuid
|
|
77
|
+
discountCardProduct
|
|
78
|
+
idUser
|
|
79
|
+
cName
|
|
80
|
+
idStore
|
|
81
|
+
cState
|
|
82
|
+
cDatCre
|
|
83
|
+
cDatMod
|
|
84
|
+
csDescription
|
|
85
|
+
cantProducts
|
|
86
|
+
comments
|
|
87
|
+
# idSubArray
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
`
|
|
91
|
+
export const CREATE_SHOPPING_CARD_TO_USER_STORE = gql`
|
|
92
|
+
mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $pCodeRef: String, $change: String, $valueDelivery: Float, $payMethodPState: Int, $pickUp: Int, $totalProductsPrice: Float, $idSubArray: IID_SUB_ITEMS){
|
|
93
|
+
registerSalesStore(input: $input, id: $id, idStore: $idStore, pCodeRef: $pCodeRef, change: $change, valueDelivery: $valueDelivery, payMethodPState: $payMethodPState, pickUp: $pickUp, totalProductsPrice: $totalProductsPrice, idSubArray: $idSubArray){
|
|
94
|
+
ShoppingCard {
|
|
95
|
+
ShoppingCard
|
|
96
|
+
id
|
|
97
|
+
pId
|
|
98
|
+
subProductsId
|
|
99
|
+
ShoppingCardRefCode
|
|
100
|
+
uuid
|
|
101
|
+
discountCardProduct
|
|
102
|
+
idUser
|
|
103
|
+
cName
|
|
104
|
+
idStore
|
|
105
|
+
cState
|
|
106
|
+
cDatCre
|
|
107
|
+
cDatMod
|
|
108
|
+
csDescription
|
|
109
|
+
cantProducts
|
|
110
|
+
comments
|
|
111
|
+
}
|
|
112
|
+
Response {
|
|
113
|
+
success
|
|
114
|
+
message
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
`
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const useConnection = ({ setConnectionStatus }) => {
|
|
2
|
+
async function updateConnectionStatus() {
|
|
3
|
+
if (navigator.onLine) {
|
|
4
|
+
setConnectionStatus(navigator.onLine);
|
|
5
|
+
} else {
|
|
6
|
+
setConnectionStatus(navigator.onLine);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Attaching event handler for the load event
|
|
11
|
+
// window.addEventListener('load', updateConnectionStatus);
|
|
12
|
+
|
|
13
|
+
// Attaching event handler for the online event
|
|
14
|
+
window.addEventListener('online', function(e) {
|
|
15
|
+
updateConnectionStatus();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// Attaching event handler for the offline event
|
|
19
|
+
window.addEventListener('offline', function(e) {
|
|
20
|
+
updateConnectionStatus();
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { useRef, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
export const useEditImageProduct = ({ sendNotification = () => { }, initialState }) => {
|
|
4
|
+
const [openEditImage, setopenEditImage] = useState(false)
|
|
5
|
+
const [tags, setTags] = useState([])
|
|
6
|
+
const [errors, setErrors] = useState({})
|
|
7
|
+
const handleOpenEditImage = () => {
|
|
8
|
+
setopenEditImage(!openEditImage)
|
|
9
|
+
}
|
|
10
|
+
// eslint-disable-next-line
|
|
11
|
+
const changeHandler = (name, value) => {
|
|
12
|
+
if (name === 'tags') {
|
|
13
|
+
setTags(value)
|
|
14
|
+
if (value.length > 0 && errors.tags) {
|
|
15
|
+
setErrors(prev => {
|
|
16
|
+
const prevErrors = { ...prev }
|
|
17
|
+
delete prevErrors.tags
|
|
18
|
+
return prevErrors
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const [existImage, setExistImage] = useState(false)
|
|
24
|
+
const [crop, setCrop] = useState({ x: 0, y: 0 })
|
|
25
|
+
const [zoom, setZoom] = useState(0)
|
|
26
|
+
const imageRef = useRef(null)
|
|
27
|
+
const onCropChange = (crop) => {
|
|
28
|
+
setCrop(crop)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const onZoomChange = (zoom) => {
|
|
32
|
+
setZoom(zoom)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const onCropComplete = (crop, pixelCrop) => {
|
|
36
|
+
const canvas = document.createElement('canvas')
|
|
37
|
+
const img = imageRef.current
|
|
38
|
+
|
|
39
|
+
canvas.width = pixelCrop.width
|
|
40
|
+
canvas.height = pixelCrop.height
|
|
41
|
+
|
|
42
|
+
const ctx = canvas.getContext('2d')
|
|
43
|
+
ctx.drawImage(
|
|
44
|
+
img,
|
|
45
|
+
pixelCrop.x,
|
|
46
|
+
pixelCrop.y,
|
|
47
|
+
pixelCrop.width,
|
|
48
|
+
pixelCrop.height,
|
|
49
|
+
0, 0,
|
|
50
|
+
pixelCrop.width,
|
|
51
|
+
pixelCrop.height)
|
|
52
|
+
// ctx.drawImage(
|
|
53
|
+
// img,
|
|
54
|
+
// pixelCrop.x,
|
|
55
|
+
// pixelCrop.y,
|
|
56
|
+
// pixelCrop.width,
|
|
57
|
+
// pixelCrop.height,
|
|
58
|
+
// 0,
|
|
59
|
+
// 0,
|
|
60
|
+
// canvas.width,
|
|
61
|
+
// canvas.height
|
|
62
|
+
// )
|
|
63
|
+
const croppedUrl = canvas.toDataURL()
|
|
64
|
+
// console.log(croppedUrl)
|
|
65
|
+
// You can use the croppedUrl for whatever you want
|
|
66
|
+
// for example, you can set it as the src of an img element
|
|
67
|
+
// or send it to a server
|
|
68
|
+
// Convert the dataURL to a blob
|
|
69
|
+
fetch(croppedUrl)
|
|
70
|
+
.then(response => { return response.blob() })
|
|
71
|
+
.then(blob => {
|
|
72
|
+
// Create a new File
|
|
73
|
+
const file = new File([blob], 'cropped_image.jpg', { type: blob.type })
|
|
74
|
+
setPreviewImg(
|
|
75
|
+
file
|
|
76
|
+
? {
|
|
77
|
+
src: URL.createObjectURL(file),
|
|
78
|
+
alt: ''
|
|
79
|
+
}
|
|
80
|
+
: initialState
|
|
81
|
+
)
|
|
82
|
+
// You can use the file object to send it to a server or to download it
|
|
83
|
+
sendNotification({ title: 'Exito', description: 'Imagen editada' })
|
|
84
|
+
setExistImage(true)
|
|
85
|
+
handleOpenEditImage()
|
|
86
|
+
})
|
|
87
|
+
.catch(() => {
|
|
88
|
+
sendNotification({ title: 'Error', description: 'Ha ocurrido un error!' })
|
|
89
|
+
})
|
|
90
|
+
// You can use the file object to send it to a server or to download it
|
|
91
|
+
}
|
|
92
|
+
function getPixelCrop (image, crop, zoom) {
|
|
93
|
+
const imgWidth = image.naturalWidth
|
|
94
|
+
const imgHeight = image.naturalHeight
|
|
95
|
+
|
|
96
|
+
const scaledWidth = imgWidth * zoom
|
|
97
|
+
const scaledHeight = imgHeight * zoom
|
|
98
|
+
|
|
99
|
+
const x = (imgWidth * crop.x) / 100
|
|
100
|
+
const y = (imgHeight * crop.y) / 100
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
x,
|
|
104
|
+
y,
|
|
105
|
+
width: scaledWidth,
|
|
106
|
+
height: scaledHeight
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const handleEditImage = () => {
|
|
110
|
+
handleOpenEditImage()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const [Dimage, setImage] = useState('')
|
|
114
|
+
const [cropData, setCropData] = useState('#')
|
|
115
|
+
const [cropper, setCropper] = useState()
|
|
116
|
+
const onChange = (e) => {
|
|
117
|
+
e.preventDefault()
|
|
118
|
+
let files
|
|
119
|
+
if (e.dataTransfer) {
|
|
120
|
+
files = e.dataTransfer.files
|
|
121
|
+
} else if (e.target) {
|
|
122
|
+
files = e.target.files
|
|
123
|
+
}
|
|
124
|
+
const reader = new FileReader()
|
|
125
|
+
reader.onload = () => {
|
|
126
|
+
setImage(reader.result)
|
|
127
|
+
}
|
|
128
|
+
reader.readAsDataURL(files[0])
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const getCropData = () => {
|
|
132
|
+
if (typeof cropper !== 'undefined') {
|
|
133
|
+
setCropData(cropper.getCroppedCanvas().toDataURL())
|
|
134
|
+
fetch(cropper)
|
|
135
|
+
.then(response => { return response.blob() })
|
|
136
|
+
.then(blob => {
|
|
137
|
+
// Create a new File
|
|
138
|
+
const file = new File([blob], 'cropped_image.jpg', { type: blob.type })
|
|
139
|
+
setPreviewImg(
|
|
140
|
+
file
|
|
141
|
+
? {
|
|
142
|
+
src: URL.createObjectURL(file),
|
|
143
|
+
alt: ''
|
|
144
|
+
}
|
|
145
|
+
: initialState
|
|
146
|
+
)
|
|
147
|
+
// You can use the file object to send it to a server or to download it
|
|
148
|
+
sendNotification({ title: 'Exito', description: 'Imagen editada' })
|
|
149
|
+
setExistImage(true)
|
|
150
|
+
handleOpenEditImage()
|
|
151
|
+
})
|
|
152
|
+
.catch(() => {
|
|
153
|
+
sendNotification({ title: 'Error', description: 'Ha ocurrido un error!' })
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
img: null,
|
|
159
|
+
crop,
|
|
160
|
+
existImage,
|
|
161
|
+
zoom,
|
|
162
|
+
handleEditImage,
|
|
163
|
+
onCropChange
|
|
164
|
+
}
|
|
165
|
+
}
|