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,268 @@
|
|
|
1
|
+
import { useMutation } from '@apollo/client'
|
|
2
|
+
import { useRef, useState } from 'react'
|
|
3
|
+
import { convertBase64, RandomCode } from '../../utils'
|
|
4
|
+
import useLocalStorage from '../useLocalSorage'
|
|
5
|
+
import {
|
|
6
|
+
GET_ALL_FOOD_PRODUCTS,
|
|
7
|
+
UPDATE_IMAGE_PRODUCT_FOOD,
|
|
8
|
+
UPDATE_PRODUCT_FOOD
|
|
9
|
+
} from '../useProductsFood/queriesStore'
|
|
10
|
+
import { useStore } from '../useStore'
|
|
11
|
+
import { useTagsProducts } from './../useProductsFood/usetagsProducts'
|
|
12
|
+
import { useEditImageProduct } from './helpers/useEditImageProduct'
|
|
13
|
+
|
|
14
|
+
export const useCreateProduct = ({
|
|
15
|
+
setAlertBox = () => { },
|
|
16
|
+
router,
|
|
17
|
+
sendNotification = () => { }
|
|
18
|
+
}) => {
|
|
19
|
+
const [errors, setErrors] = useState({
|
|
20
|
+
names: ''
|
|
21
|
+
})
|
|
22
|
+
const [values, setValues] = useState({})
|
|
23
|
+
const [names, setName] = useLocalStorage('namefood', '')
|
|
24
|
+
const [showMore, setShowMore] = useState(50)
|
|
25
|
+
const [search, setSearch] = useState('')
|
|
26
|
+
const [imageBase64, setImageBase64] = useState(null)
|
|
27
|
+
const [active, setActive] = useState(0)
|
|
28
|
+
const [pId, setPid] = useState(null)
|
|
29
|
+
|
|
30
|
+
const [searchFilter, setSearchFilter] = useState({ gender: [], desc: [], speciality: [] })
|
|
31
|
+
const [filter, setFilter] = useState({ gender: [], desc: [], speciality: [] })
|
|
32
|
+
const initialState = { alt: '/ images/DEFAULTBANNER.png', src: '/images/DEFAULTBANNER.png' }
|
|
33
|
+
const [image, setImage] = useState(null)
|
|
34
|
+
const [{ alt, src }, setPreviewImg] = useState(initialState)
|
|
35
|
+
const fileInputRef = useRef(null)
|
|
36
|
+
const [arrTags, setTags] = useState([])
|
|
37
|
+
|
|
38
|
+
const [dataStore] = useStore()
|
|
39
|
+
const {
|
|
40
|
+
handleRegister: handleRegisterTags,
|
|
41
|
+
data,
|
|
42
|
+
handleAddTag,
|
|
43
|
+
tags
|
|
44
|
+
} = useTagsProducts()
|
|
45
|
+
|
|
46
|
+
// HANDLESS
|
|
47
|
+
const [check, setCheck] = useState({
|
|
48
|
+
availability: true,
|
|
49
|
+
noAvailability: false,
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const handleCheck = (e) => {
|
|
53
|
+
const { name, checked } = e.target
|
|
54
|
+
return setCheck({ ...check, [name]: checked ? true : false })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const handleUpdateBanner = event => {
|
|
58
|
+
const { files } = event.target
|
|
59
|
+
setPreviewImg(
|
|
60
|
+
files.length
|
|
61
|
+
? {
|
|
62
|
+
src: URL.createObjectURL(files[0]),
|
|
63
|
+
alt: files[0].name
|
|
64
|
+
}
|
|
65
|
+
: initialState
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
const handleChange = (e, error) => {
|
|
69
|
+
setValues({ ...values, [e.target.name]: e.target.value })
|
|
70
|
+
setErrors({ ...errors, [e.target.name]: error })
|
|
71
|
+
}
|
|
72
|
+
const handleChangeFilter = e => {
|
|
73
|
+
setSearch(e.target.value)
|
|
74
|
+
}
|
|
75
|
+
const onClickSearch = () => {
|
|
76
|
+
setSearchFilter({ ...filter })
|
|
77
|
+
}
|
|
78
|
+
const onClickClear = () => {
|
|
79
|
+
setSearchFilter({})
|
|
80
|
+
}
|
|
81
|
+
const handleChangeClick = e => {
|
|
82
|
+
const {
|
|
83
|
+
name,
|
|
84
|
+
value,
|
|
85
|
+
checked
|
|
86
|
+
} = e.target
|
|
87
|
+
!checked
|
|
88
|
+
? setFilter(s => { return { ...s, [name]: s[name].filter(f => { return f !== value }) } })
|
|
89
|
+
: setFilter({ ...filter, [name]: [...filter[name], value] })
|
|
90
|
+
setSearchFilter({ ...filter })
|
|
91
|
+
}
|
|
92
|
+
const handleCheckFreeShipping = e => {
|
|
93
|
+
// setCheck(e.target.checked)
|
|
94
|
+
handleCheck(e)
|
|
95
|
+
setValues({
|
|
96
|
+
...values,
|
|
97
|
+
ValueDelivery: '',
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const [updateProductFoods] = useMutation(UPDATE_PRODUCT_FOOD, {
|
|
102
|
+
})
|
|
103
|
+
const [setImageProducts] = useMutation(UPDATE_IMAGE_PRODUCT_FOOD, {
|
|
104
|
+
context: { clientName: 'admin-server' }
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const onFileInputChange = async event => {
|
|
108
|
+
const { files } = event.target
|
|
109
|
+
|
|
110
|
+
const file = event.target.files[0]
|
|
111
|
+
setImage(file)
|
|
112
|
+
const base64 = await convertBase64(file)
|
|
113
|
+
// eslint-disable-next-line
|
|
114
|
+
// const [size, { unit }] = await getFileSizeByUnit(file, "B");
|
|
115
|
+
setImageBase64(base64)
|
|
116
|
+
setPreviewImg(
|
|
117
|
+
files.length
|
|
118
|
+
? {
|
|
119
|
+
src: URL.createObjectURL(files[0]),
|
|
120
|
+
alt: files[0].name
|
|
121
|
+
}
|
|
122
|
+
: initialState
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
const onTargetClick = () => {
|
|
126
|
+
fileInputRef.current.click()
|
|
127
|
+
}
|
|
128
|
+
const { img } = useEditImageProduct({ sendNotification, initialState })
|
|
129
|
+
const handleRegister = async () => {
|
|
130
|
+
const {
|
|
131
|
+
ProPrice,
|
|
132
|
+
ProDescuento,
|
|
133
|
+
ProDescription,
|
|
134
|
+
ProWeight,
|
|
135
|
+
ProHeight,
|
|
136
|
+
ValueDelivery,
|
|
137
|
+
carProId
|
|
138
|
+
} = values
|
|
139
|
+
if (!carProId && !names) return setErrors({ ...errors, carProId: true })
|
|
140
|
+
|
|
141
|
+
if (!ProPrice?.length > 0) {
|
|
142
|
+
return setErrors({ ...errors, ProPrice: true })
|
|
143
|
+
}
|
|
144
|
+
const ProImage = `${process.env.URL_ADMIN_SERVER}static/platos/${image?.name}`
|
|
145
|
+
const pCode = RandomCode(9)
|
|
146
|
+
const formatPrice = ProPrice ? parseFloat(ProPrice.replace(/\./g, '')) : 0
|
|
147
|
+
try {
|
|
148
|
+
updateProductFoods({
|
|
149
|
+
variables: {
|
|
150
|
+
input: {
|
|
151
|
+
idStore: dataStore?.getStore?.idStore || '',
|
|
152
|
+
ProPrice: check ? 0 : formatPrice,
|
|
153
|
+
ProDescuento: check ? 0 : parseInt(ProDescuento),
|
|
154
|
+
ValueDelivery: check ? 0 : parseFloat(ValueDelivery),
|
|
155
|
+
ProDescription,
|
|
156
|
+
pName: names,
|
|
157
|
+
pCode,
|
|
158
|
+
carProId,
|
|
159
|
+
pState: 1,
|
|
160
|
+
sTateLogistic: 1,
|
|
161
|
+
ProStar: 0,
|
|
162
|
+
ProImage,
|
|
163
|
+
ProHeight: parseFloat(ProHeight),
|
|
164
|
+
ProWeight,
|
|
165
|
+
ProOutstanding: check ? 1 : 0,
|
|
166
|
+
ProDelivery: check ? 1 : 0
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
update (cache) {
|
|
170
|
+
cache.modify({
|
|
171
|
+
fields: {
|
|
172
|
+
productFoodsAll (dataOld = []) {
|
|
173
|
+
return cache.writeQuery({ query: GET_ALL_FOOD_PRODUCTS, data: dataOld })
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
}).then((res) => {
|
|
179
|
+
const { updateProductFoods } = res?.data || {}
|
|
180
|
+
const { pId } = updateProductFoods || {}
|
|
181
|
+
setPid(pId ?? null)
|
|
182
|
+
router.push(
|
|
183
|
+
{
|
|
184
|
+
query: {
|
|
185
|
+
...router.query,
|
|
186
|
+
food: pId
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
undefined,
|
|
190
|
+
{ shallow: true }
|
|
191
|
+
)
|
|
192
|
+
sendNotification({ title: 'Success', description: `El producto ${names} subido con éxito` })
|
|
193
|
+
const objTag = {
|
|
194
|
+
aName: tags.tag,
|
|
195
|
+
pId
|
|
196
|
+
}
|
|
197
|
+
handleRegisterTags(objTag)
|
|
198
|
+
// setValues({})
|
|
199
|
+
}).catch(err => { return sendNotification({ title: `${err}`, description: 'Error inesperado' }) })
|
|
200
|
+
if (image !== null) {
|
|
201
|
+
setImageProducts({
|
|
202
|
+
variables: {
|
|
203
|
+
input: {
|
|
204
|
+
file: image,
|
|
205
|
+
pCode
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}).then((response) => {
|
|
209
|
+
}).catch((error) => {
|
|
210
|
+
sendNotification({ title: `Ocurrió un error en la imagen en el producto ${names}`, description: 'error' })
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
} catch (error) {
|
|
214
|
+
setAlertBox({ message: `${error.message}`, duration: 7000 })
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Manage tags
|
|
219
|
+
const changeHandler = (name, value) => {
|
|
220
|
+
if (name === 'tags') {
|
|
221
|
+
setTags(value)
|
|
222
|
+
if (value.length > 0 && errors.tags) {
|
|
223
|
+
setErrors(prev => {
|
|
224
|
+
const prevErrors = { ...prev }
|
|
225
|
+
delete prevErrors.tags
|
|
226
|
+
return prevErrors
|
|
227
|
+
})
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
errors,
|
|
233
|
+
src,
|
|
234
|
+
names,
|
|
235
|
+
setName,
|
|
236
|
+
alt,
|
|
237
|
+
showMore,
|
|
238
|
+
success: true,
|
|
239
|
+
fileInputRef,
|
|
240
|
+
values,
|
|
241
|
+
search,
|
|
242
|
+
pId,
|
|
243
|
+
dataTags: data,
|
|
244
|
+
tags,
|
|
245
|
+
tags,
|
|
246
|
+
active,
|
|
247
|
+
idStore: dataStore?.getStore?.idStore || '',
|
|
248
|
+
arrTags,
|
|
249
|
+
setPid,
|
|
250
|
+
handleChange,
|
|
251
|
+
onClickClear,
|
|
252
|
+
handleChangeClick,
|
|
253
|
+
handleChangeFilter,
|
|
254
|
+
handleUpdateBanner,
|
|
255
|
+
onClickSearch,
|
|
256
|
+
changeHandler,
|
|
257
|
+
setErrors,
|
|
258
|
+
handleRegister,
|
|
259
|
+
setActive,
|
|
260
|
+
onFileInputChange,
|
|
261
|
+
handleRegisterTags,
|
|
262
|
+
setShowMore,
|
|
263
|
+
onTargetClick,
|
|
264
|
+
handleAddTag,
|
|
265
|
+
handleCheckFreeShipping,
|
|
266
|
+
check
|
|
267
|
+
}
|
|
268
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { MockData } from '../../mock'
|
|
3
|
+
import { RandomCode } from '../../utils'
|
|
4
|
+
import { useUpdateExtProductFoodsOptional } from '../updateExtProductFoodsOptional'
|
|
5
|
+
import { useUpdateExtProductFoodsSubOptional } from '../useUpdateExtProductFoodsSubOptional'
|
|
6
|
+
|
|
7
|
+
export const useDessert = ({ pId }) => {
|
|
8
|
+
// STATES
|
|
9
|
+
const [setCheck, setChecker] = useState({})
|
|
10
|
+
const [valueItems, setValueItems] = useState('')
|
|
11
|
+
const [title, setTitle] = useState('')
|
|
12
|
+
const [data, setData] = useState(MockData)
|
|
13
|
+
const dataListIds = data?.listIds?.filter(x => { return x !== '01list' })
|
|
14
|
+
// HOOKS
|
|
15
|
+
const { handleMutateExtProductFoodsSubOptional } = useUpdateExtProductFoodsSubOptional()
|
|
16
|
+
const { handleUpdateExtProduct } = useUpdateExtProductFoodsOptional()
|
|
17
|
+
|
|
18
|
+
// HANDLESS
|
|
19
|
+
const handleCheck = (e) => {
|
|
20
|
+
const { name, checked } = e.target
|
|
21
|
+
setChecker({ ...setCheck, [name]: checked ? true : false })
|
|
22
|
+
}
|
|
23
|
+
const handleRemoveList = i => {
|
|
24
|
+
const Lines = data?.listIds?.filter((_, index) => { return index !== i })
|
|
25
|
+
setData({
|
|
26
|
+
listIds: [...Lines],
|
|
27
|
+
lists: {
|
|
28
|
+
...data.lists
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
const removeOneItem = ({ listID, id }) => {
|
|
33
|
+
const currentList = data.lists[listID]
|
|
34
|
+
const totalCart = currentList?.cards?.filter((cart) => { return cart.id !== id })
|
|
35
|
+
setData({
|
|
36
|
+
listIds: [...data.listIds],
|
|
37
|
+
lists: {
|
|
38
|
+
...data.lists,
|
|
39
|
+
[listID]: {
|
|
40
|
+
...currentList,
|
|
41
|
+
cards: totalCart
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
const addCard = async (title, listId) => {
|
|
47
|
+
const id = await RandomCode(9)
|
|
48
|
+
const newCard = {
|
|
49
|
+
id: id,
|
|
50
|
+
title: title,
|
|
51
|
+
numberLimit: 5,
|
|
52
|
+
value: '',
|
|
53
|
+
required: setCheck.exState ? 1 : 0
|
|
54
|
+
}
|
|
55
|
+
const list = data.lists[listId]
|
|
56
|
+
list.cards = [...list.cards, newCard]
|
|
57
|
+
setData({
|
|
58
|
+
...data,
|
|
59
|
+
lists: {
|
|
60
|
+
...data.lists,
|
|
61
|
+
[listId]: list
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
handleMutateExtProductFoodsSubOptional({
|
|
65
|
+
pId,
|
|
66
|
+
title,
|
|
67
|
+
listId,
|
|
68
|
+
id,
|
|
69
|
+
state: 1
|
|
70
|
+
})
|
|
71
|
+
setTitle('')
|
|
72
|
+
}
|
|
73
|
+
const handleAdd = ({ listId }) => {
|
|
74
|
+
if (valueItems !== '') {
|
|
75
|
+
addCard(valueItems, listId)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
const handleAddList = async ({ title, numberLimit }) => {
|
|
81
|
+
if (title !== '') {
|
|
82
|
+
const newListId = await RandomCode(9)
|
|
83
|
+
setData({
|
|
84
|
+
listIds: [...data.listIds, newListId],
|
|
85
|
+
lists: {
|
|
86
|
+
...data.lists,
|
|
87
|
+
[newListId]: {
|
|
88
|
+
id: newListId,
|
|
89
|
+
title: title,
|
|
90
|
+
required: setCheck.exState ? 1 : 0,
|
|
91
|
+
numberLimit: numberLimit,
|
|
92
|
+
value: '',
|
|
93
|
+
cards: []
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
handleUpdateExtProduct({
|
|
98
|
+
pId,
|
|
99
|
+
code: newListId,
|
|
100
|
+
OptionalProName: title,
|
|
101
|
+
required: setCheck.exState ? 1 : 0,
|
|
102
|
+
numbersOptionalOnly: numberLimit
|
|
103
|
+
})
|
|
104
|
+
setTitle('')
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const handleChangeItems = ({ listID, value: e }) => {
|
|
108
|
+
const value = e.target.value
|
|
109
|
+
setValueItems(value)
|
|
110
|
+
const currentList = data.lists[listID]
|
|
111
|
+
return dataListIds.map((salesLine) => {
|
|
112
|
+
if (salesLine === listID) {
|
|
113
|
+
setData({
|
|
114
|
+
listIds: [...data.listIds],
|
|
115
|
+
lists: {
|
|
116
|
+
...data.lists,
|
|
117
|
+
[listID]: {
|
|
118
|
+
...currentList,
|
|
119
|
+
value: value,
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
setCheck,
|
|
128
|
+
data,
|
|
129
|
+
dataListIds,
|
|
130
|
+
title,
|
|
131
|
+
handleChangeItems,
|
|
132
|
+
handleCheck,
|
|
133
|
+
addCard,
|
|
134
|
+
setTitle,
|
|
135
|
+
handleAddList,
|
|
136
|
+
handleAdd,
|
|
137
|
+
removeOneItem,
|
|
138
|
+
handleRemoveList,
|
|
139
|
+
setData,
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { useEffect } from 'react'
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
2
|
|
|
3
|
-
export function useDrag2(ref) {
|
|
3
|
+
export function useDrag2 (ref) {
|
|
4
4
|
useEffect(() => {
|
|
5
5
|
const target = ref.current
|
|
6
6
|
if (!target) return
|
|
7
7
|
const previousOffset = { x: 0, y: 0 }
|
|
8
8
|
let originMouseX
|
|
9
9
|
let originMouseY
|
|
10
|
-
function onMousemove(e) {
|
|
10
|
+
function onMousemove (e) {
|
|
11
11
|
const { pageX, pageY } = e
|
|
12
12
|
const x = pageX - originMouseX + previousOffset.x
|
|
13
13
|
const y = pageY - originMouseY + previousOffset.y
|
|
14
|
-
target.style.transform = `translate(${
|
|
14
|
+
target.style.transform = `translate(${x}px, ${y}px)`
|
|
15
15
|
}
|
|
16
|
-
function onMouseup(e) {
|
|
16
|
+
function onMouseup (e) {
|
|
17
17
|
previousOffset.x += e.pageX - originMouseX
|
|
18
18
|
previousOffset.y += e.pageY - originMouseY
|
|
19
19
|
window.removeEventListener('mousemove', onMousemove)
|
|
20
20
|
window.removeEventListener('mouseup', onMouseup)
|
|
21
21
|
}
|
|
22
|
-
function onMousedown(e) {
|
|
22
|
+
function onMousedown (e) {
|
|
23
23
|
originMouseX = e.pageX
|
|
24
24
|
originMouseY = e.pageY
|
|
25
25
|
window.addEventListener('mousemove', onMousemove)
|
|
@@ -33,7 +33,6 @@ export function useDrag2(ref) {
|
|
|
33
33
|
}
|
|
34
34
|
}, [ref])
|
|
35
35
|
}
|
|
36
|
-
import { useState } from 'react'
|
|
37
36
|
|
|
38
37
|
export const useDrag = (x, y) => {
|
|
39
38
|
const [move, setMove] = useState(false)
|
|
@@ -53,5 +52,11 @@ export const useDrag = (x, y) => {
|
|
|
53
52
|
setMove(false)
|
|
54
53
|
}
|
|
55
54
|
|
|
56
|
-
return {
|
|
57
|
-
|
|
55
|
+
return {
|
|
56
|
+
move,
|
|
57
|
+
moveTo,
|
|
58
|
+
handelDown,
|
|
59
|
+
handelUp,
|
|
60
|
+
handleMove
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import React, {
|
|
2
|
-
useState,
|
|
3
2
|
useEffect,
|
|
4
|
-
useRef
|
|
3
|
+
useRef, useState
|
|
5
4
|
} from 'react'
|
|
6
5
|
|
|
7
|
-
export const useFetchMoreInteractions = ({
|
|
6
|
+
export const useFetchMoreInteractions = ({
|
|
7
|
+
render,
|
|
8
|
+
fetchMore = true,
|
|
9
|
+
callback = () => {}
|
|
10
|
+
}) => {
|
|
8
11
|
const loadingRef = useRef()
|
|
9
12
|
|
|
10
13
|
const useOnScreen = ref => {
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
useCallback,
|
|
3
3
|
useEffect,
|
|
4
4
|
useState
|
|
5
|
-
|
|
5
|
+
} from 'react'
|
|
6
6
|
import { validationSubmitHooks } from '../../utils'
|
|
7
7
|
/**
|
|
8
8
|
* @version 0.0.1
|
|
@@ -14,7 +14,6 @@ export const useFormTools = () => {
|
|
|
14
14
|
const [errorForm, setErrorForm] = useState({})
|
|
15
15
|
const [errorSubmit, setErrorSubmit] = useState(false)
|
|
16
16
|
const [calledSubmit, setCalledSubmit] = useState(false)
|
|
17
|
-
|
|
18
17
|
// Handle Change
|
|
19
18
|
const handleChange = useCallback((e, error) => {
|
|
20
19
|
setDataForm({ ...dataForm, [e.target.name]: e.target.value })
|
|
@@ -32,6 +31,11 @@ export const useFormTools = () => {
|
|
|
32
31
|
}, [setErrorForm])
|
|
33
32
|
|
|
34
33
|
// Handle submit, al enviar formulario
|
|
34
|
+
const listErrors = Object.values(errorForm)
|
|
35
|
+
const errors = listErrors.find((error) => {
|
|
36
|
+
return error ===true
|
|
37
|
+
})
|
|
38
|
+
|
|
35
39
|
const handleSubmit = useCallback(({ event, action, msgSuccess, msgError, actionAfterSuccess }) => {
|
|
36
40
|
!!event && event.preventDefault()
|
|
37
41
|
setCalledSubmit(true)
|
|
@@ -42,11 +46,17 @@ export const useFormTools = () => {
|
|
|
42
46
|
if (errorForm[x]) errSub = true
|
|
43
47
|
}
|
|
44
48
|
|
|
45
|
-
|
|
49
|
+
if (errors) {
|
|
50
|
+
setErrorSubmit(true)
|
|
51
|
+
return setForcedError({ ...errorForm })
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (errSub) return setErrorSubmit(errSub)
|
|
46
55
|
|
|
47
56
|
// Valida los errores desde el evento
|
|
48
57
|
const errores = validationSubmitHooks(event.target.elements)
|
|
49
58
|
setErrorForm(errores)
|
|
59
|
+
console.log("🚀 ~ file: index.js ~ line 50 ~ handleSubmit ~ errores", errores)
|
|
50
60
|
for (const x in errores) {
|
|
51
61
|
if (errores[x]) errSub = true
|
|
52
62
|
}
|
|
@@ -66,6 +76,9 @@ export const useFormTools = () => {
|
|
|
66
76
|
}, [errorForm, setErrorForm])
|
|
67
77
|
|
|
68
78
|
useEffect(() => {return setCalledSubmit(false)}, [calledSubmit])
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
return setCalledSubmit(false)},
|
|
81
|
+
[])
|
|
69
82
|
|
|
70
83
|
return [handleChange, handleSubmit, handleForcedData, { dataForm, errorForm, errorSubmit, calledSubmit, setForcedError }]
|
|
71
84
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const useFormatDate = ({
|
|
2
|
+
date,
|
|
3
|
+
local = 'ES'
|
|
4
|
+
}) => {
|
|
5
|
+
const dateToFormat = new Date(date ?? Date.now())
|
|
6
|
+
const fullDate = dateToFormat.toLocaleDateString(local, { year: 'numeric', month: '2-digit', day: '2-digit' })
|
|
7
|
+
const day = fullDate.split('/')[0]
|
|
8
|
+
const month = fullDate.split('/')[1]
|
|
9
|
+
const year = fullDate.split('/')[2]
|
|
10
|
+
const yearMonthDay = dateToFormat.toLocaleDateString('en-CA')
|
|
11
|
+
const numberDay = dateToFormat.getDay()
|
|
12
|
+
const shortDayName = dateToFormat.toLocaleDateString(local, { weekday: 'short' })
|
|
13
|
+
const longDayName = dateToFormat.toLocaleDateString(local, { weekday: 'long' })
|
|
14
|
+
const hourMinutes12 = dateToFormat.toLocaleTimeString('ES-CO', { hour: '2-digit', minute: '2-digit' })
|
|
15
|
+
const hourMinutes24 = dateToFormat.toLocaleTimeString('ES-CO', { hour: '2-digit', minute: '2-digit', hour12: false })
|
|
16
|
+
const handleHourPmAM = (hour) => {
|
|
17
|
+
const hourPmAm = new Date(`1/1/1999 ${hour}`).toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true })
|
|
18
|
+
return hour ? hourPmAm : ''
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
day,
|
|
22
|
+
fullDate,
|
|
23
|
+
hourMinutes12,
|
|
24
|
+
numberDay,
|
|
25
|
+
yearMonthDay,
|
|
26
|
+
hourMinutes24,
|
|
27
|
+
longDayName,
|
|
28
|
+
shortDayName,
|
|
29
|
+
month,
|
|
30
|
+
year,
|
|
31
|
+
handleHourPmAM,
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
// use it
|
|
3
|
+
// const imageUrl = 'https://example.com/image.jpg';
|
|
4
|
+
// const optimizedUrl = useImageOptimization(imageUrl);
|
|
5
|
+
|
|
6
|
+
export function useImageOptimization(imageUrl) {
|
|
7
|
+
const [optimizedUrl, setOptimizedUrl] = useState(null);
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const image = new Image();
|
|
11
|
+
image.src = imageUrl;
|
|
12
|
+
|
|
13
|
+
image.onload = () => {
|
|
14
|
+
const canvas = document.createElement('canvas');
|
|
15
|
+
const ctx = canvas.getContext('2d');
|
|
16
|
+
|
|
17
|
+
canvas.width = image.width;
|
|
18
|
+
canvas.height = image.height;
|
|
19
|
+
|
|
20
|
+
ctx.drawImage(image, 0, 0, image.width, image.height);
|
|
21
|
+
|
|
22
|
+
const optimizedUrl = canvas.toDataURL('image/jpeg', 0.8);
|
|
23
|
+
setOptimizedUrl(optimizedUrl);
|
|
24
|
+
};
|
|
25
|
+
}, [imageUrl]);
|
|
26
|
+
|
|
27
|
+
return optimizedUrl;
|
|
28
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useImageWeight(imageUrl) {
|
|
4
|
+
const [weight, setWeight] = useState(null);
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const image = new Image();
|
|
8
|
+
image.src = imageUrl;
|
|
9
|
+
|
|
10
|
+
image.onload = () => {
|
|
11
|
+
const xhr = new XMLHttpRequest();
|
|
12
|
+
xhr.open('HEAD', imageUrl, true);
|
|
13
|
+
xhr.onreadystatechange = () => {
|
|
14
|
+
if (xhr.readyState === 4 && xhr.status === 200) {
|
|
15
|
+
const contentLength = xhr.getResponseHeader('Content-Length');
|
|
16
|
+
setWeight(contentLength);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
xhr.send();
|
|
20
|
+
};
|
|
21
|
+
}, [imageUrl]);
|
|
22
|
+
|
|
23
|
+
return weight;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// I use
|
|
27
|
+
// function MyComponent() {
|
|
28
|
+
// const imageUrl = 'https://example.com/image.jpg';
|
|
29
|
+
// const weight = useImageWeight(imageUrl);
|
|
30
|
+
|
|
31
|
+
// return (
|
|
32
|
+
// <div>
|
|
33
|
+
// <img src={imageUrl} alt="My Image" />
|
|
34
|
+
// {weight ? `Peso de imagen: ${weight} bytes` : 'Cargando...'}
|
|
35
|
+
// </div>
|
|
36
|
+
// );
|
|
37
|
+
// }
|
|
38
|
+
|
|
39
|
+
// const weightInMB = weight / (1024 * 1024);
|
|
40
|
+
|
|
41
|
+
// function MyComponent() {
|
|
42
|
+
// const imageUrl = 'https://example.com/image.jpg';
|
|
43
|
+
// const weight = useImageWeight(imageUrl);
|
|
44
|
+
|
|
45
|
+
// return (
|
|
46
|
+
// <div>
|
|
47
|
+
// <img src={imageUrl} alt="My Image" />
|
|
48
|
+
// {weight ? `Peso de imagen: ${(weight / (1024 * 1024)).toFixed(2)} MB` : 'Cargando...'}
|
|
49
|
+
// </div>
|
|
50
|
+
// );
|
|
51
|
+
// }
|
|
52
|
+
|