npm-pkg-hook 1.12.4 → 1.12.7

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 (316) hide show
  1. package/dist/index.cjs +20089 -0
  2. package/dist/index.js +19854 -0
  3. package/dist/index.mjs +19854 -0
  4. package/package.json +28 -6
  5. package/.babelrc +0 -0
  6. package/.env +0 -5
  7. package/.eslintrc.js +0 -38
  8. package/.eslintrc.json +0 -127
  9. package/.github/pull_request_template.md +0 -18
  10. package/.github/workflows/pepeline.yaml +0 -30
  11. package/expire.json +0 -1
  12. package/jsconfig.json +0 -28
  13. package/script.txt +0 -7
  14. package/src/config/client/errors.js +0 -26
  15. package/src/config/client/index.js +0 -1
  16. package/src/config/content/en.json +0 -5
  17. package/src/config/content/es.json +0 -5
  18. package/src/config/content/index.js +0 -16
  19. package/src/cookies/index.js +0 -3
  20. package/src/hooks/addTenMinutes/index.js +0 -14
  21. package/src/hooks/calculateLogLatHaversine/index.js +0 -30
  22. package/src/hooks/completeSchedules/index.js +0 -22
  23. package/src/hooks/convertToMilitaryTime/index.js +0 -14
  24. package/src/hooks/generateStoreURL/index.js +0 -38
  25. package/src/hooks/generateTemplate/index.js +0 -62
  26. package/src/hooks/getCardType/index.js +0 -24
  27. package/src/hooks/getCategoriesWithProduct/helpers/index.js +0 -7
  28. package/src/hooks/getCategoriesWithProduct/index.js +0 -62
  29. package/src/hooks/getGlobalSession/index.js +0 -49
  30. package/src/hooks/getSession/index.js +0 -18
  31. package/src/hooks/getTodayTimestamps/index.js +0 -64
  32. package/src/hooks/getTotalHours/index.js +0 -48
  33. package/src/hooks/handleLogin/index.js +0 -10
  34. package/src/hooks/index.ts +0 -147
  35. package/src/hooks/isTokenExpired/index.js +0 -17
  36. package/src/hooks/newMessageSubscription/index.js +0 -28
  37. package/src/hooks/newStoreOrderSubscription/index.js +0 -26
  38. package/src/hooks/statusOpenStores/helpers/index.js +0 -101
  39. package/src/hooks/statusOpenStores/index.js +0 -156
  40. package/src/hooks/updateExtProductFoodsOptional/index.js +0 -40
  41. package/src/hooks/useAcumulateDate/index.js +0 -16
  42. package/src/hooks/useAllStoresPendingToRegister/index.js +0 -34
  43. package/src/hooks/useAmountInput/index.ts +0 -117
  44. package/src/hooks/useAnimationFrame/index.js +0 -45
  45. package/src/hooks/useAnimationText/index.jsx +0 -31
  46. package/src/hooks/useAsideCart/helpers/index.js +0 -22
  47. package/src/hooks/useAsideCart/index.js +0 -214
  48. package/src/hooks/useAsideCart/queries.js +0 -10
  49. package/src/hooks/useBanner/index.js +0 -19
  50. package/src/hooks/useCart/index.js +0 -2
  51. package/src/hooks/useCart/queries.js +0 -174
  52. package/src/hooks/useCart/useCart/helpers/index.js +0 -75
  53. package/src/hooks/useCart/useCart/index.js +0 -412
  54. package/src/hooks/useCart/useGetCart/index.js +0 -33
  55. package/src/hooks/useCatWithProduct/index.js +0 -48
  56. package/src/hooks/useCatWithProduct/queries.js +0 -200
  57. package/src/hooks/useCatWithProductClient/index.js +0 -56
  58. package/src/hooks/useCatWithProductClient/queries.js +0 -56
  59. package/src/hooks/useCategoriesProduct/index.js +0 -13
  60. package/src/hooks/useCategoriesProduct/queries.js +0 -16
  61. package/src/hooks/useCategoryInStore/index.js +0 -100
  62. package/src/hooks/useCategoryInStore/queries.js +0 -78
  63. package/src/hooks/useCategoryStore/index.js +0 -7
  64. package/src/hooks/useCategoryStore/queries.js +0 -16
  65. package/src/hooks/useChartData/index.js +0 -170
  66. package/src/hooks/useChartData/useChartData/index.js +0 -199
  67. package/src/hooks/useChartData/useChartDataAllOrders/index.js +0 -94
  68. package/src/hooks/useChatRoomSubscription/index.js +0 -28
  69. package/src/hooks/useCheckbox/index.js +0 -115
  70. package/src/hooks/useCities/index.js +0 -13
  71. package/src/hooks/useCities/queries.js +0 -12
  72. package/src/hooks/useClients/index.js +0 -96
  73. package/src/hooks/useClients/queries.js +0 -212
  74. package/src/hooks/useColorByLetters/helpers/alea.js +0 -54
  75. package/src/hooks/useColorByLetters/helpers/colors.js +0 -45
  76. package/src/hooks/useColorByLetters/helpers/index.js +0 -18
  77. package/src/hooks/useColorByLetters/helpers/mersenne_twister.js +0 -118
  78. package/src/hooks/useColorByLetters/index.js +0 -27
  79. package/src/hooks/useConnection/index.js +0 -24
  80. package/src/hooks/useCountries/index.js +0 -19
  81. package/src/hooks/useCountries/queries.js +0 -12
  82. package/src/hooks/useCreateDeliveryTime/index.js +0 -51
  83. package/src/hooks/useCreateOrderStatusType/index.ts +0 -132
  84. package/src/hooks/useCreateProduct/helpers/index.js +0 -23
  85. package/src/hooks/useCreateProduct/helpers/manageCacheDataCatProduct/index.js +0 -52
  86. package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +0 -176
  87. package/src/hooks/useCreateProduct/index.js +0 -334
  88. package/src/hooks/useCreateStorePendingToRegister/index.js +0 -13
  89. package/src/hooks/useCreateStorePendingToRegister/queries.js +0 -10
  90. package/src/hooks/useDashboardComponents/index.js +0 -50
  91. package/src/hooks/useDeleteExtraProductFoods/index.js +0 -12
  92. package/src/hooks/useDeleteSubProductOptional/index.js +0 -30
  93. package/src/hooks/useDeleteSubProductOptional/queries.js +0 -10
  94. package/src/hooks/useDeliveryTime/index.js +0 -27
  95. package/src/hooks/useDepartments/index.js +0 -13
  96. package/src/hooks/useDepartments/queries.js +0 -13
  97. package/src/hooks/useDessert/helpers/index.js +0 -51
  98. package/src/hooks/useDessert/index.js +0 -525
  99. package/src/hooks/useDessertWithPrice/helpers/index.js +0 -76
  100. package/src/hooks/useDessertWithPrice/index.js +0 -373
  101. package/src/hooks/useDessertWithPrice/queries.js +0 -18
  102. package/src/hooks/useDevWS/index.ts +0 -53
  103. package/src/hooks/useDevices/index.js +0 -2
  104. package/src/hooks/useDevices/queries.js +0 -28
  105. package/src/hooks/useDevices/useGetDevices.js +0 -28
  106. package/src/hooks/useDevices/useRegisterDevices.js +0 -75
  107. package/src/hooks/useDownloadReports/helpers/downloadFileFromResponse.ts +0 -21
  108. package/src/hooks/useDownloadReports/index.ts +0 -2
  109. package/src/hooks/useDownloadReports/useDownloadReportByDay/index.ts +0 -103
  110. package/src/hooks/useDownloadReports/useGetReportByDateRange/index.ts +0 -115
  111. package/src/hooks/useDrag/index.js +0 -63
  112. package/src/hooks/useDropzone/index.js +0 -94
  113. package/src/hooks/useDynamicAuth/index.js +0 -13
  114. package/src/hooks/useDynamicAuth/queries.js +0 -24
  115. package/src/hooks/useEditCategory/index.js +0 -41
  116. package/src/hooks/useEditOneExtProductFoodOptional/index.js +0 -28
  117. package/src/hooks/useEditOneExtProductFoodOptional/queries.js +0 -16
  118. package/src/hooks/useEditSubProductOptional/index.js +0 -11
  119. package/src/hooks/useEditSubProductOptional/queries.js +0 -10
  120. package/src/hooks/useEmployee/index.js +0 -17
  121. package/src/hooks/useEmployee/queries.js +0 -85
  122. package/src/hooks/useEmployee/useCreateEmployee.js +0 -86
  123. package/src/hooks/useEvent/index.js +0 -34
  124. package/src/hooks/useFavoriteStores/index.js +0 -29
  125. package/src/hooks/useFavoriteStores/queries.js +0 -54
  126. package/src/hooks/useFetchJson/index.js +0 -25
  127. package/src/hooks/useFetchMoreInteractions/index.jsx +0 -39
  128. package/src/hooks/useFingerprintjs/index.js +0 -172
  129. package/src/hooks/useFormTools/index.js +0 -116
  130. package/src/hooks/useFormatDate/index.js +0 -86
  131. package/src/hooks/useFormatNumberPhone/index.js +0 -23
  132. package/src/hooks/useFullScreenMode/index.js +0 -65
  133. package/src/hooks/useGenerateNumberArray/index.js +0 -17
  134. package/src/hooks/useGetAllLocationUser/index.js +0 -12
  135. package/src/hooks/useGetAllLocationUser/queries.js +0 -44
  136. package/src/hooks/useGetCookies/index.js +0 -43
  137. package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.js +0 -14
  138. package/src/hooks/useGetFoodRecomended/index.js +0 -32
  139. package/src/hooks/useGetFoodRecomended/queries.js +0 -47
  140. package/src/hooks/useGetMessagesToRoom/index.js +0 -23
  141. package/src/hooks/useGetMinPrice/index.js +0 -12
  142. package/src/hooks/useGetMinPrice/queries.js +0 -7
  143. package/src/hooks/useGetOneStoreRating/index.js +0 -40
  144. package/src/hooks/useGetOneStoreRating/queries.js +0 -18
  145. package/src/hooks/useGetSalesAmountToday/index.js +0 -31
  146. package/src/hooks/useGetStoreCookie/index.js +0 -21
  147. package/src/hooks/useGoogleLogin/index.js +0 -160
  148. package/src/hooks/useGoogleLogin/loadScript.js +0 -15
  149. package/src/hooks/useGoogleLogin/removeScript.js +0 -7
  150. package/src/hooks/useHover/index.js +0 -29
  151. package/src/hooks/useImageOptimization/index.js +0 -28
  152. package/src/hooks/useImageUploaderProduct/helper/canvasUtils.ts +0 -130
  153. package/src/hooks/useImageUploaderProduct/helper/getOrientation.ts +0 -53
  154. package/src/hooks/useImageUploaderProduct/helper/index.ts +0 -5
  155. package/src/hooks/useImageUploaderProduct/index.ts +0 -292
  156. package/src/hooks/useImageWeight/index.js +0 -51
  157. package/src/hooks/useImagesStore/index.js +0 -225
  158. package/src/hooks/useImagesStore/queries.js +0 -193
  159. package/src/hooks/useImagesStore/utils/index.js +0 -4
  160. package/src/hooks/useIncomingOrders/index.js +0 -10
  161. package/src/hooks/useIncomingOrders/queries.js +0 -87
  162. package/src/hooks/useInnerHtml/index.js +0 -39
  163. package/src/hooks/useIntersection/index.js +0 -84
  164. package/src/hooks/useInventory/index.js +0 -2
  165. package/src/hooks/useInventory/queries.js +0 -58
  166. package/src/hooks/useInventory/useGetProductsInStock.js +0 -15
  167. package/src/hooks/useInventory/useUpdateManageStock.js +0 -41
  168. package/src/hooks/useKeypress/index.js +0 -28
  169. package/src/hooks/useLazyScript/index.js +0 -71
  170. package/src/hooks/useLocalBackendIp/index.js +0 -34
  171. package/src/hooks/useLocalSorage/index.js +0 -36
  172. package/src/hooks/useLocationManager/index.js +0 -63
  173. package/src/hooks/useLocationNavigate/index.js +0 -54
  174. package/src/hooks/useLoginEmployeeInStore/index.js +0 -38
  175. package/src/hooks/useLogout/helpers/BroadcastChannel.js +0 -31
  176. package/src/hooks/useLogout/helpers/apiBaseUrl.js +0 -8
  177. package/src/hooks/useLogout/helpers/fetchData.js +0 -28
  178. package/src/hooks/useLogout/helpers/getCsrfToken.js +0 -30
  179. package/src/hooks/useLogout/helpers/index.js +0 -57
  180. package/src/hooks/useLogout/helpers/logger.js +0 -70
  181. package/src/hooks/useLogout/helpers/parseUrl.js +0 -36
  182. package/src/hooks/useLogout/index.js +0 -96
  183. package/src/hooks/useManageNewOrder/helpers/index.js +0 -45
  184. package/src/hooks/useManageNewOrder/helpers/mock.js +0 -0
  185. package/src/hooks/useManageNewOrder/index.js +0 -102
  186. package/src/hooks/useManageQueryParams/index.js +0 -40
  187. package/src/hooks/useMobile/index.js +0 -65
  188. package/src/hooks/useModules/helpers/index.js +0 -1
  189. package/src/hooks/useModules/helpers/validateModules.js +0 -29
  190. package/src/hooks/useModules/index.js +0 -58
  191. package/src/hooks/useMouse/index.ts +0 -50
  192. package/src/hooks/useMutateHeight/index.js +0 -36
  193. package/src/hooks/useOrderClient/index.js +0 -5
  194. package/src/hooks/useOrderStatusTypes/index.ts +0 -2
  195. package/src/hooks/useOrderStatusTypes/useOrderStatusTypes/index.ts +0 -133
  196. package/src/hooks/useOrderStatusTypes/useUpdateOrderStatusPriorities/index.ts +0 -97
  197. package/src/hooks/useOrders/index.js +0 -3
  198. package/src/hooks/useOrders/queries.js +0 -89
  199. package/src/hooks/useOrders/useChangeOrderState/index.ts +0 -125
  200. package/src/hooks/useOrders/useOrdersFromStore/index.ts +0 -77
  201. package/src/hooks/usePWAInstall/index.js +0 -38
  202. package/src/hooks/usePortFetcher/index.ts +0 -33
  203. package/src/hooks/usePrintSaleTicket/index.ts +0 -64
  204. package/src/hooks/useProductsFood/index.js +0 -253
  205. package/src/hooks/useProductsFood/queriesStore.js +0 -964
  206. package/src/hooks/useProductsFood/useEditProduct.js +0 -48
  207. package/src/hooks/useProductsFood/usetagsProducts.js +0 -98
  208. package/src/hooks/useProviders/index.js +0 -3
  209. package/src/hooks/useProviders/queries.js +0 -31
  210. package/src/hooks/useProviders/useProvidersCreateStore/index.js +0 -12
  211. package/src/hooks/useProviders/useProvidersDataStore/index.js +0 -24
  212. package/src/hooks/useProvidersStore/index.js +0 -24
  213. package/src/hooks/useProvidersStore/queries.js +0 -31
  214. package/src/hooks/usePushNotificationOrder/index.js +0 -52
  215. package/src/hooks/usePushNotifications/helpers/index.js +0 -114
  216. package/src/hooks/usePushNotifications/index.js +0 -149
  217. package/src/hooks/useQueryLocationsMap/index.js +0 -19
  218. package/src/hooks/useQueryLocationsMap/queries.js +0 -40
  219. package/src/hooks/useRatingArrayData/index.js +0 -54
  220. package/src/hooks/useRatingArrayData/queries.js +0 -19
  221. package/src/hooks/useReactToPrint/index.js +0 -1223
  222. package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +0 -23
  223. package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +0 -48
  224. package/src/hooks/useReport/index.js +0 -47
  225. package/src/hooks/useReport/queries.js +0 -123
  226. package/src/hooks/useRestaurant/helpers/index.js +0 -24
  227. package/src/hooks/useRestaurant/helpers/manageStatusOpen.js +0 -26
  228. package/src/hooks/useRestaurant/index.js +0 -69
  229. package/src/hooks/useRestaurant/queries.js +0 -81
  230. package/src/hooks/useRoads/index.js +0 -19
  231. package/src/hooks/useRoads/queries.js +0 -13
  232. package/src/hooks/useRoles/index.js +0 -4
  233. package/src/hooks/useRoles/queries.js +0 -70
  234. package/src/hooks/useRoles/useCreateRole.js +0 -37
  235. package/src/hooks/useRoles/useGetRoles.js +0 -36
  236. package/src/hooks/useRoles/useRemoveRoles.js +0 -40
  237. package/src/hooks/useRoles/useUpdateRolesPriority.js +0 -44
  238. package/src/hooks/useSales/helpers/index.js +0 -55
  239. package/src/hooks/useSales/index.js +0 -1381
  240. package/src/hooks/useSales/queries.js +0 -424
  241. package/src/hooks/useSales/useGetAllSales/index.js +0 -25
  242. package/src/hooks/useSales/useGetSale.js +0 -13
  243. package/src/hooks/useSales/useTotalSales.js +0 -23
  244. package/src/hooks/useSaveAvailableProduct/helpers/index.js +0 -38
  245. package/src/hooks/useSaveAvailableProduct/index.js +0 -31
  246. package/src/hooks/useSaveAvailableProduct/queries.js +0 -10
  247. package/src/hooks/useSaveLocation/index.js +0 -16
  248. package/src/hooks/useSaveLocation/queries.js +0 -19
  249. package/src/hooks/useSchedule/index.js +0 -78
  250. package/src/hooks/useSchedule/index.jsx +0 -22
  251. package/src/hooks/useSchedule/queries.js +0 -43
  252. package/src/hooks/useScheduleData/index.js +0 -123
  253. package/src/hooks/useScroll/index.js +0 -56
  254. package/src/hooks/useScrollRotate/index.js +0 -16
  255. package/src/hooks/useSetImageProducts/index.js +0 -57
  256. package/src/hooks/useSetImageProducts/queries.js +0 -18
  257. package/src/hooks/useSetSession/index.js +0 -44
  258. package/src/hooks/useSetState/index.js +0 -24
  259. package/src/hooks/useSetupSchedule/helpers/index.js +0 -85
  260. package/src/hooks/useSetupSchedule/index.js +0 -272
  261. package/src/hooks/useStatusOpenStore/helpers/index.js +0 -101
  262. package/src/hooks/useStatusOpenStore/index.js +0 -179
  263. package/src/hooks/useStatusOrdersClient/helpers/index.js +0 -14
  264. package/src/hooks/useStatusOrdersClient/index.js +0 -17
  265. package/src/hooks/useStatusOrdersClient/queries.js +0 -80
  266. package/src/hooks/useStockMovements/helpers/index.js +0 -16
  267. package/src/hooks/useStockMovements/index.js +0 -38
  268. package/src/hooks/useStore/index.js +0 -80
  269. package/src/hooks/useStore/queries.js +0 -163
  270. package/src/hooks/useStoreCalendar/index.js +0 -5
  271. package/src/hooks/useStoreContacts/index.js +0 -47
  272. package/src/hooks/useStoreContacts/queries.js +0 -48
  273. package/src/hooks/useStoreTable/index.js +0 -2
  274. package/src/hooks/useStoreTable/queries.js +0 -47
  275. package/src/hooks/useStoreTable/useStoreTableCreate.js +0 -76
  276. package/src/hooks/useStoreTable/useStoreTables.js +0 -14
  277. package/src/hooks/useSubscriptionValidation/index.js +0 -41
  278. package/src/hooks/useTagProducts/index.ts +0 -3
  279. package/src/hooks/useTagProducts/useDeleteOneTag.ts +0 -106
  280. package/src/hooks/useTagProducts/useGetAllTags.ts +0 -68
  281. package/src/hooks/useTagProducts/useRegisterMultipleTags.ts +0 -156
  282. package/src/hooks/useTimeAgo/useTimeAgo.js +0 -39
  283. package/src/hooks/useTokenCards/index.js +0 -41
  284. package/src/hooks/useTopProductsMovements/index.js +0 -27
  285. package/src/hooks/useTotalAllSales/index.js +0 -25
  286. package/src/hooks/useTotalProductsInStock/index.js +0 -23
  287. package/src/hooks/useTotalProductsSold/index.js +0 -23
  288. package/src/hooks/useTotalProductsSolded/index.js +0 -20
  289. package/src/hooks/useUpdateCart/index.js +0 -130
  290. package/src/hooks/useUpdateCartCookie/index.js +0 -43
  291. package/src/hooks/useUpdateDashboardComponent/index.ts +0 -91
  292. package/src/hooks/useUpdateExistingOrders/index.js +0 -85
  293. package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +0 -60
  294. package/src/hooks/useUpdateModuleOrder/index.js +0 -37
  295. package/src/hooks/useUpdateMultipleExtProduct/index.js +0 -33
  296. package/src/hooks/useUpdateMultipleExtProduct/queries.js +0 -33
  297. package/src/hooks/useUpdateMultipleProducts/index.js +0 -80
  298. package/src/hooks/useUpdateMultipleProducts/queries.js +0 -51
  299. package/src/hooks/useUploadProducts/helpers/index.js +0 -1
  300. package/src/hooks/useUploadProducts/helpers/parseNumber.js +0 -37
  301. package/src/hooks/useUploadProducts/helpers/validateProductDataExcel.js +0 -73
  302. package/src/hooks/useUploadProducts/index.js +0 -422
  303. package/src/hooks/useUpsertGoal/index.js +0 -68
  304. package/src/hooks/useUser/index.js +0 -23
  305. package/src/hooks/useUser/queries.js +0 -131
  306. package/src/hooks/useWeeklyStockMovement/helpers/index.js +0 -32
  307. package/src/hooks/useWeeklyStockMovement/index.js +0 -51
  308. package/src/hooks/useWindowSize/index.js +0 -38
  309. package/src/index.jsx +0 -9
  310. package/src/mock/dessert/index.js +0 -16
  311. package/src/mock/index.js +0 -1
  312. package/src/security/index.js +0 -1
  313. package/src/services/index.js +0 -0
  314. package/src/utils/UtilDateRange.js +0 -31
  315. package/src/utils/index.js +0 -306
  316. package/tsconfig.json +0 -5
@@ -1,292 +0,0 @@
1
- import { useRef, useState } from 'react'
2
- import { ORIENTATION_TO_ANGLE } from './helper'
3
- import { getCroppedImg, getRotatedImage } from './helper/canvasUtils'
4
- import { getOrientation } from './helper/getOrientation'
5
-
6
- function readFile(file: File): Promise<string> {
7
- return new Promise((resolve) => {
8
- const reader = new FileReader()
9
- reader.addEventListener('load', () => resolve(reader.result as string), false)
10
- reader.readAsDataURL(file)
11
- })
12
- }
13
-
14
- export type SendNotificationFn = (params: {
15
- description: string
16
- title: string
17
- backgroundColor: string
18
- }) => void
19
-
20
- interface UseImageUploaderOptions {
21
- maxSizeMB?: number
22
- minHeight?: number
23
- minWidth?: number
24
- validTypes?: string[]
25
- sendNotification: SendNotificationFn
26
- }
27
-
28
- interface UseImageUploaderResult {
29
- crop: { x: number, y: number }
30
- croppedImage: string | null
31
- error: string
32
- image: File
33
- imageSrc: string | null
34
- inputRef: React.RefObject<HTMLInputElement>
35
- loading: boolean
36
- open: boolean
37
- preview: string | null
38
- formattedList: string
39
- rotation: number
40
- zoom: number
41
- validTypes: string[]
42
- handleClose: () => void
43
- handleRemoveImage: () => void
44
- onCropComplete: (croppedArea: any, croppedPixels: any) => void
45
- onFileChange: (e: React.ChangeEvent<HTMLInputElement>) => Promise<void>
46
- setCrop: React.Dispatch<React.SetStateAction<{ x: number, y: number }>>
47
- setRotation: React.Dispatch<React.SetStateAction<number>>
48
- setZoom: React.Dispatch<React.SetStateAction<number>>
49
- handleDrop: (event: React.DragEvent<HTMLDivElement>) => Promise<void>
50
- showCroppedImage: () => Promise<void>
51
- }
52
-
53
- /**
54
- * Hook for managing image selection, preview, validation and cropping
55
- * @param {UseImageUploaderOptions} options
56
- * @returns {UseImageUploaderResult}
57
- */
58
- export const useImageUploaderProduct = (
59
- options?: UseImageUploaderOptions
60
- ): UseImageUploaderResult => {
61
- const {
62
- validTypes = ['image/jpeg', 'image/jpg', 'image/png'],
63
- maxSizeMB = 20,
64
- minWidth = 300,
65
- minHeight = 275,
66
- sendNotification
67
- } = options ?? {
68
-
69
- }
70
- const readableFormats = validTypes
71
- .map((type) => type.split('/')[1].toUpperCase())
72
-
73
- const formatter = new Intl.ListFormat('es', {
74
- style: 'long',
75
- type: 'conjunction'
76
- })
77
-
78
- const formattedList = formatter.format(readableFormats)
79
-
80
- const [loading, setLoading] = useState(false)
81
- const inputRef = useRef<HTMLInputElement>(null)
82
- const [open, setOpen] = useState(false)
83
- const [preview, setPreview] = useState<string | null>(null)
84
- const [imageSrc, setImageSrc] = useState<string | null>(null)
85
- const [croppedImage, setCroppedImage] = useState<string | null>(null)
86
- const [crop, setCrop] = useState({ x: 0, y: 0 })
87
- const [zoom, setZoom] = useState(1)
88
- const [rotation, setRotation] = useState(0)
89
- const [croppedAreaPixels, setCroppedAreaPixels] = useState(null)
90
- const [error, setError] = useState('')
91
- const [image, setImage] = useState<File | null>(null)
92
-
93
-
94
- const onCropComplete = (_: any, croppedPixels: any) => {
95
- setCroppedAreaPixels(croppedPixels)
96
- }
97
-
98
- const showCroppedImage = async () => {
99
- if (!imageSrc || !croppedAreaPixels) return
100
- try {
101
- setLoading(true)
102
- const base64Image = await getCroppedImg(imageSrc, croppedAreaPixels, rotation) as string
103
-
104
- setCroppedImage(base64Image)
105
- setPreview(base64Image)
106
-
107
- // ✅ Convert base64 to blob and file
108
- const blob = await (await fetch(base64Image)).blob()
109
- const file = new File([blob], image?.name ?? 'cropped.jpeg', { type: blob.type })
110
- setImage(file)
111
- setLoading(false)
112
- } catch (e) {
113
- setLoading(false)
114
- return sendNotification({
115
- description: e ?? 'Ocurrió un error',
116
- title: 'Error',
117
- backgroundColor: 'error'
118
- })
119
- }
120
- }
121
-
122
- /**
123
- * Removes the selected image and resets relevant states
124
- */
125
- const handleRemoveImage = () => {
126
- setImage(null)
127
- setPreview(null)
128
- setImageSrc(null)
129
- setCroppedImage(null)
130
- setZoom(1)
131
- setCrop({ x: 0, y: 0 })
132
- setRotation(0)
133
- setError('')
134
- if (inputRef.current) inputRef.current.value = ''
135
- }
136
-
137
- const onFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
138
- const file = e.target.files?.[0]
139
- handleRemoveImage()
140
- if (!file) return
141
-
142
- if (!validTypes.includes(file.type)) {
143
-
144
-
145
- const error = `Formato inválido. Solo se permiten: ${formattedList}.`
146
- sendNotification({
147
- description: error,
148
- title: 'Error',
149
- backgroundColor: 'error'
150
- })
151
- return setError(error)
152
- }
153
-
154
- if (file.size > maxSizeMB * 1024 * 1024) {
155
- const error = `El archivo supera los ${maxSizeMB} MB.`
156
- sendNotification({
157
- description: error,
158
- title: 'Error',
159
- backgroundColor: 'error'
160
- })
161
- return setError(`El archivo supera los ${maxSizeMB} MB.`)
162
- }
163
-
164
- let imageDataUrl = await readFile(file)
165
-
166
- try {
167
- const orientation = await getOrientation(file, validTypes)
168
- const rotation = ORIENTATION_TO_ANGLE[orientation]
169
- if (rotation) {
170
- imageDataUrl = await getRotatedImage(imageDataUrl, rotation) as string
171
- setRotation(rotation)
172
- }
173
- } catch (e) {
174
- return sendNotification({
175
- description: 'Error desconocido',
176
- title: 'Error',
177
- backgroundColor: 'error'
178
- })
179
- }
180
-
181
- const image = new Image()
182
- image.src = imageDataUrl
183
- image.onload = () => {
184
- if (image.width < minWidth || image.height < minHeight) {
185
- const error = `Resolución mínima: ${minWidth}x${minHeight}px.`
186
- sendNotification({
187
- description: error,
188
- title: 'Error',
189
- backgroundColor: 'error'
190
- })
191
- setError(error)
192
- return
193
- }
194
- setImageSrc(imageDataUrl)
195
- setOpen(true)
196
- }
197
- }
198
-
199
- const handleClose = () => {
200
- setOpen(!open)
201
- }
202
-
203
- const handleDrop = async (event: React.DragEvent<HTMLDivElement>): Promise<void> => {
204
- event.preventDefault()
205
- handleRemoveImage()
206
- const file = event.dataTransfer.files?.[0]
207
- if (!file) return
208
-
209
- if (!validTypes.includes(file.type)) {
210
- const error = `Formato inválido. Solo se permiten: ${formattedList}.`
211
- sendNotification({
212
- description: error,
213
- title: 'Error',
214
- backgroundColor: 'error'
215
- })
216
- return setError(error)
217
- }
218
-
219
- if (file.size > maxSizeMB * 1024 * 1024) {
220
- const error = `El archivo supera los ${maxSizeMB} MB.`
221
- sendNotification({
222
- description: error,
223
- title: 'Error',
224
- backgroundColor: 'error'
225
- })
226
- return setError(error)
227
- }
228
-
229
- let imageDataUrl = await readFile(file)
230
-
231
- try {
232
- const orientation = await getOrientation(file, validTypes)
233
- const rotation = ORIENTATION_TO_ANGLE[orientation]
234
- if (rotation) {
235
- imageDataUrl = await getRotatedImage(imageDataUrl, rotation) as string
236
- setRotation(rotation)
237
- }
238
- } catch (e) {
239
- return sendNotification({
240
- description: 'Error al procesar la orientación de la imagen',
241
- title: 'Error',
242
- backgroundColor: 'error'
243
- })
244
- }
245
-
246
- const image = new Image()
247
- image.src = imageDataUrl
248
- image.onload = () => {
249
- if (image.width < minWidth || image.height < minHeight) {
250
- const error = `Resolución mínima: ${minWidth}x${minHeight}px.`
251
- sendNotification({
252
- description: error,
253
- title: 'Error',
254
- backgroundColor: 'error'
255
- })
256
- setError(error)
257
- return
258
- }
259
- setImageSrc(imageDataUrl)
260
- setImage(file)
261
- setOpen(true)
262
- }
263
- }
264
-
265
-
266
-
267
-
268
- return {
269
- inputRef,
270
- open,
271
- imageSrc,
272
- preview,
273
- croppedImage,
274
- crop,
275
- zoom,
276
- image,
277
- rotation,
278
- error,
279
- formattedList,
280
- loading,
281
- validTypes,
282
- onCropComplete,
283
- showCroppedImage,
284
- handleRemoveImage,
285
- handleDrop,
286
- onFileChange,
287
- handleClose,
288
- setCrop,
289
- setZoom,
290
- setRotation,
291
- }
292
- }
@@ -1,51 +0,0 @@
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
- // }
@@ -1,225 +0,0 @@
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
- import { color } from './utils'
15
- export * from './queries'
16
-
17
- export const useImageStore = ({ idStore, sendNotification = () => { } } = {}) => {
18
- // STATES
19
- const fileInputRef = useRef(null)
20
- const initialState = { alt: '/images/DEFAULTBANNER.png', src: '/images/DEFAULTBANNER.png' }
21
- const initialStateLogo = { altLogo: '/images/DEFAULTLOGO.png', srcLogo: '/images/DEFAULTLOGO.png' }
22
- const [{ altLogo, srcLogo }, setPreviewImgLogo] = useState(initialStateLogo)
23
- const [{ alt, src }, setPreviewImg] = useState(initialState)
24
- const fileInputRefLogo = useRef(null)
25
-
26
- // HOOKS
27
- const [registerBanner] = useMutation(CREATE_BANNER_STORE, {
28
- onCompleted: (data) => {
29
- const { registerBanner } = data || {}
30
- const { message = '', success = false } = registerBanner || {}
31
- if (!success) {
32
- setPreviewImg(initialState)
33
- return
34
- }
35
- sendNotification({
36
- title: success ? 'Banner subido' : 'Error al subir banner',
37
- description: message,
38
- backgroundColor: success ? color.success : color.error
39
- })
40
- }
41
-
42
- })
43
- const [registerLogo] = useMutation(CREATE_LOGO, {
44
- onCompleted: (data) => {
45
- const { registerLogo } = data || {}
46
- const { message = '', success = false } = registerLogo ?? {
47
- message: 'Error al subir logo',
48
- success: false,
49
- data: null
50
- }
51
- if (!success) {
52
- setPreviewImgLogo(initialStateLogo)
53
- return
54
- }
55
-
56
- sendNotification({
57
- title: success ? 'Logo creado con exito' : color.error,
58
- description: message,
59
- backgroundColor: success ? color.success : color.error
60
- })
61
- }
62
- })
63
- const [deleteOneBanner] = useMutation(DELETE_ONE_BANNER_STORE, {
64
- onCompleted: (data) => {
65
- const { deleteOneBanner } = data || {}
66
- const { message = '', success = false } = deleteOneBanner || {}
67
- return sendNotification({
68
- title: success ? 'Logo subido' : color.error,
69
- description: message,
70
- backgroundColor: success ? color.success : color.error
71
- })
72
- }
73
- })
74
- const [deleteALogoStore] = useMutation(DELETE_ONE_LOGO_STORE, {
75
- onCompleted: (data) => {
76
- const { deleteALogoStore } = data || {}
77
- const { message = '', success = false } = deleteALogoStore || {}
78
- sendNotification({
79
- title: success ? 'Logo Eliminado' : 'Error al eliminar el logo',
80
- description: message,
81
- backgroundColor: success ? color.success : color.error
82
- })
83
- setPreviewImgLogo(initialStateLogo)
84
- },
85
- update (cache) {
86
- cache.modify({
87
- fields: {
88
- getStore (dataOld = {}) {
89
- return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld })
90
- }
91
- }
92
- })
93
- }
94
- })
95
- // HANDLESS
96
- const handleDeleteLogo = () => {
97
- return deleteALogoStore({
98
- variables: {
99
- Image: ''
100
- }
101
- })
102
- }
103
-
104
- const handleUpdateBanner = event => {
105
- try {
106
- const { files } = event.target
107
- setPreviewImg(
108
- files.length
109
- ? {
110
- src: URL.createObjectURL(files[0]),
111
- alt: files[0].name
112
- }
113
- : initialState
114
- )
115
- registerBanner({
116
- variables: {
117
- input: {
118
- bnImage: files[0],
119
- idStore
120
- }
121
- },
122
- update (cache) {
123
- cache.modify({
124
- fields: {
125
- getStore (dataOld = {}) {
126
- return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld })
127
- }
128
- }
129
- })
130
- }
131
- })
132
- } catch {
133
- setPreviewImg(initialState)
134
- }
135
- }
136
- /**
137
- * Handle store logo upload and update cache Image field
138
- * @param {React.ChangeEvent<HTMLInputElement>} event - File input change event
139
- * @returns {void}
140
- */
141
- const handleInputChangeLogo = async (event) => {
142
- const { files } = event.target
143
-
144
- if (!files || files.length === 0) {
145
- sendNotification({
146
- title: 'Debes seleccionar un archivo',
147
- description: color.error,
148
- backgroundColor: color.error
149
- })
150
- return
151
- }
152
-
153
- const file = files[0]
154
-
155
- const result = await registerLogo({
156
- variables: { logo: file, idStore }
157
- })
158
- const {
159
- data: {
160
- registerLogo: {
161
- success = false,
162
- data: url = ''
163
- } = {}
164
- } = {}
165
- } = result ?? {
166
- data: '',
167
- success: false,
168
- message: ''
169
- }
170
- if (!success) {
171
- setPreviewImgLogo(initialStateLogo)
172
- return
173
- }
174
- setPreviewImgLogo({
175
- srcLogo: URL.createObjectURL(file),
176
- altLogo: url
177
- })
178
- }
179
-
180
- const HandleDeleteBanner = async () => {
181
- setPreviewImg(initialStateLogo)
182
- deleteOneBanner({
183
- variables: {
184
- idStore
185
- },
186
- update (cache) {
187
- cache.modify({
188
- fields: {
189
- getOneBanners (dataOld = []) {
190
- return cache.writeQuery({ query: GET_ONE_BANNER_STORE, data: dataOld })
191
- }
192
- }
193
- })
194
- }
195
- }).then(() => {
196
- setPreviewImg(initialState)
197
- })
198
- }
199
- const onTargetClickLogo = e => {
200
- e.preventDefault()
201
- fileInputRefLogo.current.click()
202
- }
203
- const onTargetClick = e => {
204
- e.preventDefault()
205
- fileInputRef.current.click()
206
- }
207
-
208
- return {
209
- fileInputRefLogo,
210
- src,
211
- alt,
212
- initialState,
213
- srcLogo,
214
- altLogo,
215
- fileInputRef,
216
- handleDeleteLogo,
217
- setPreviewImgLogo,
218
- setPreviewImg,
219
- onTargetClick,
220
- onTargetClickLogo,
221
- HandleDeleteBanner,
222
- handleInputChangeLogo,
223
- handleUpdateBanner
224
- }
225
- }