npm-pkg-hook 1.12.3 → 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 (315) 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 -146
  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/useProductsFood/index.js +0 -253
  204. package/src/hooks/useProductsFood/queriesStore.js +0 -964
  205. package/src/hooks/useProductsFood/useEditProduct.js +0 -48
  206. package/src/hooks/useProductsFood/usetagsProducts.js +0 -98
  207. package/src/hooks/useProviders/index.js +0 -3
  208. package/src/hooks/useProviders/queries.js +0 -31
  209. package/src/hooks/useProviders/useProvidersCreateStore/index.js +0 -12
  210. package/src/hooks/useProviders/useProvidersDataStore/index.js +0 -24
  211. package/src/hooks/useProvidersStore/index.js +0 -24
  212. package/src/hooks/useProvidersStore/queries.js +0 -31
  213. package/src/hooks/usePushNotificationOrder/index.js +0 -52
  214. package/src/hooks/usePushNotifications/helpers/index.js +0 -114
  215. package/src/hooks/usePushNotifications/index.js +0 -149
  216. package/src/hooks/useQueryLocationsMap/index.js +0 -19
  217. package/src/hooks/useQueryLocationsMap/queries.js +0 -40
  218. package/src/hooks/useRatingArrayData/index.js +0 -54
  219. package/src/hooks/useRatingArrayData/queries.js +0 -19
  220. package/src/hooks/useReactToPrint/index.js +0 -1223
  221. package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +0 -23
  222. package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +0 -48
  223. package/src/hooks/useReport/index.js +0 -47
  224. package/src/hooks/useReport/queries.js +0 -123
  225. package/src/hooks/useRestaurant/helpers/index.js +0 -24
  226. package/src/hooks/useRestaurant/helpers/manageStatusOpen.js +0 -26
  227. package/src/hooks/useRestaurant/index.js +0 -69
  228. package/src/hooks/useRestaurant/queries.js +0 -81
  229. package/src/hooks/useRoads/index.js +0 -19
  230. package/src/hooks/useRoads/queries.js +0 -13
  231. package/src/hooks/useRoles/index.js +0 -4
  232. package/src/hooks/useRoles/queries.js +0 -70
  233. package/src/hooks/useRoles/useCreateRole.js +0 -37
  234. package/src/hooks/useRoles/useGetRoles.js +0 -36
  235. package/src/hooks/useRoles/useRemoveRoles.js +0 -40
  236. package/src/hooks/useRoles/useUpdateRolesPriority.js +0 -44
  237. package/src/hooks/useSales/helpers/index.js +0 -55
  238. package/src/hooks/useSales/index.js +0 -1381
  239. package/src/hooks/useSales/queries.js +0 -424
  240. package/src/hooks/useSales/useGetAllSales/index.js +0 -25
  241. package/src/hooks/useSales/useGetSale.js +0 -13
  242. package/src/hooks/useSales/useTotalSales.js +0 -23
  243. package/src/hooks/useSaveAvailableProduct/helpers/index.js +0 -38
  244. package/src/hooks/useSaveAvailableProduct/index.js +0 -31
  245. package/src/hooks/useSaveAvailableProduct/queries.js +0 -10
  246. package/src/hooks/useSaveLocation/index.js +0 -16
  247. package/src/hooks/useSaveLocation/queries.js +0 -19
  248. package/src/hooks/useSchedule/index.js +0 -78
  249. package/src/hooks/useSchedule/index.jsx +0 -22
  250. package/src/hooks/useSchedule/queries.js +0 -43
  251. package/src/hooks/useScheduleData/index.js +0 -123
  252. package/src/hooks/useScroll/index.js +0 -56
  253. package/src/hooks/useScrollRotate/index.js +0 -16
  254. package/src/hooks/useSetImageProducts/index.js +0 -57
  255. package/src/hooks/useSetImageProducts/queries.js +0 -18
  256. package/src/hooks/useSetSession/index.js +0 -44
  257. package/src/hooks/useSetState/index.js +0 -24
  258. package/src/hooks/useSetupSchedule/helpers/index.js +0 -85
  259. package/src/hooks/useSetupSchedule/index.js +0 -272
  260. package/src/hooks/useStatusOpenStore/helpers/index.js +0 -101
  261. package/src/hooks/useStatusOpenStore/index.js +0 -179
  262. package/src/hooks/useStatusOrdersClient/helpers/index.js +0 -14
  263. package/src/hooks/useStatusOrdersClient/index.js +0 -17
  264. package/src/hooks/useStatusOrdersClient/queries.js +0 -80
  265. package/src/hooks/useStockMovements/helpers/index.js +0 -16
  266. package/src/hooks/useStockMovements/index.js +0 -38
  267. package/src/hooks/useStore/index.js +0 -80
  268. package/src/hooks/useStore/queries.js +0 -163
  269. package/src/hooks/useStoreCalendar/index.js +0 -5
  270. package/src/hooks/useStoreContacts/index.js +0 -47
  271. package/src/hooks/useStoreContacts/queries.js +0 -48
  272. package/src/hooks/useStoreTable/index.js +0 -2
  273. package/src/hooks/useStoreTable/queries.js +0 -47
  274. package/src/hooks/useStoreTable/useStoreTableCreate.js +0 -76
  275. package/src/hooks/useStoreTable/useStoreTables.js +0 -14
  276. package/src/hooks/useSubscriptionValidation/index.js +0 -41
  277. package/src/hooks/useTagProducts/index.ts +0 -3
  278. package/src/hooks/useTagProducts/useDeleteOneTag.ts +0 -106
  279. package/src/hooks/useTagProducts/useGetAllTags.ts +0 -68
  280. package/src/hooks/useTagProducts/useRegisterMultipleTags.ts +0 -156
  281. package/src/hooks/useTimeAgo/useTimeAgo.js +0 -39
  282. package/src/hooks/useTokenCards/index.js +0 -41
  283. package/src/hooks/useTopProductsMovements/index.js +0 -27
  284. package/src/hooks/useTotalAllSales/index.js +0 -25
  285. package/src/hooks/useTotalProductsInStock/index.js +0 -23
  286. package/src/hooks/useTotalProductsSold/index.js +0 -23
  287. package/src/hooks/useTotalProductsSolded/index.js +0 -20
  288. package/src/hooks/useUpdateCart/index.js +0 -130
  289. package/src/hooks/useUpdateCartCookie/index.js +0 -43
  290. package/src/hooks/useUpdateDashboardComponent/index.ts +0 -91
  291. package/src/hooks/useUpdateExistingOrders/index.js +0 -85
  292. package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +0 -60
  293. package/src/hooks/useUpdateModuleOrder/index.js +0 -37
  294. package/src/hooks/useUpdateMultipleExtProduct/index.js +0 -33
  295. package/src/hooks/useUpdateMultipleExtProduct/queries.js +0 -33
  296. package/src/hooks/useUpdateMultipleProducts/index.js +0 -80
  297. package/src/hooks/useUpdateMultipleProducts/queries.js +0 -51
  298. package/src/hooks/useUploadProducts/helpers/index.js +0 -1
  299. package/src/hooks/useUploadProducts/helpers/parseNumber.js +0 -37
  300. package/src/hooks/useUploadProducts/helpers/validateProductDataExcel.js +0 -73
  301. package/src/hooks/useUploadProducts/index.js +0 -422
  302. package/src/hooks/useUpsertGoal/index.js +0 -68
  303. package/src/hooks/useUser/index.js +0 -23
  304. package/src/hooks/useUser/queries.js +0 -131
  305. package/src/hooks/useWeeklyStockMovement/helpers/index.js +0 -32
  306. package/src/hooks/useWeeklyStockMovement/index.js +0 -51
  307. package/src/hooks/useWindowSize/index.js +0 -38
  308. package/src/index.jsx +0 -9
  309. package/src/mock/dessert/index.js +0 -16
  310. package/src/mock/index.js +0 -1
  311. package/src/security/index.js +0 -1
  312. package/src/services/index.js +0 -0
  313. package/src/utils/UtilDateRange.js +0 -31
  314. package/src/utils/index.js +0 -306
  315. package/tsconfig.json +0 -5
@@ -1,68 +0,0 @@
1
- import { useQuery, gql } from '@apollo/client'
2
-
3
- /**
4
- * GraphQL query to fetch all tags
5
- */
6
- export const GET_ALL_TAGS = gql`
7
- query getAllTags {
8
- getAllTags {
9
- success
10
- message
11
- pagination {
12
- totalRecords
13
- totalPages
14
- currentPage
15
- }
16
- data {
17
- tgId
18
- idUser
19
- idStore
20
- pId
21
- nameTag
22
- aName
23
- }
24
- errors {
25
- path
26
- message
27
- type
28
- context {
29
- limit
30
- value
31
- label
32
- key
33
- }
34
- }
35
- }
36
- }
37
- `
38
-
39
- /**
40
- * Custom hook to fetch all tags
41
- *
42
- * @returns {{
43
- * tags: any[],
44
- * loading: boolean,
45
- * error: Error | null,
46
- * message: string,
47
- * success: boolean,
48
- * pagination: { totalRecords: number, totalPages: number, currentPage: number } | null,
49
- * errors: any[] | null
50
- * }}
51
- */
52
- export const useGetAllTags = () => {
53
- const { data, loading, error } = useQuery(GET_ALL_TAGS, {
54
- fetchPolicy: 'network-only',
55
- })
56
-
57
- const result = data?.getAllTags ?? {}
58
-
59
- return {
60
- tags: result?.data || [],
61
- loading,
62
- error,
63
- message: result?.message ?? '',
64
- success: result?.success ?? false,
65
- pagination: result?.pagination ?? null,
66
- errors: result?.errors ?? null,
67
- }
68
- }
@@ -1,156 +0,0 @@
1
- import { useMutation, gql, useApolloClient } from '@apollo/client'
2
- import { GET_ALL_TAGS } from './useGetAllTags'
3
-
4
- /**
5
- * GraphQL mutation to register multiple tags.
6
- */
7
- const REGISTER_MULTIPLE_TAGS = gql`
8
- mutation registerMultipleTags($input: [String!]!) {
9
- registerMultipleTags(input: $input) {
10
- success
11
- message
12
- errors {
13
- path
14
- message
15
- }
16
- data {
17
- tgId
18
- nameTag
19
- idStore
20
- idUser
21
- }
22
- }
23
- }
24
- `
25
-
26
- /**
27
- * Response structure for tag registration errors.
28
- */
29
- interface ITagError {
30
- path: string
31
- message: string
32
- }
33
-
34
- /**
35
- * Structure for a registered tag.
36
- */
37
- interface ITag {
38
- tgId: string
39
- nameTag: string
40
- idStore: string
41
- idUser: string
42
- }
43
-
44
- /**
45
- * General GraphQL response for registering tags.
46
- */
47
- interface IResponseTag {
48
- success: boolean
49
- message: string
50
- errors: ITagError[]
51
- data: ITag[]
52
- }
53
-
54
- /**
55
- * Options for the useRegisterMultipleTags hook.
56
- */
57
- interface UseRegisterMultipleTagsOptions {
58
- callback?: (response: IResponseTag) => void
59
- }
60
-
61
- /**
62
- * Return type for the useRegisterMultipleTags hook.
63
- */
64
- type UseRegisterMultipleTagsReturn = [
65
- (tags: string[]) => Promise<IResponseTag>,
66
- {
67
- loading: boolean
68
- error: any
69
- data: IResponseTag | null
70
- }
71
- ]
72
-
73
- /**
74
- * Hook to register multiple tags via GraphQL mutation.
75
- *
76
- * @param {UseRegisterMultipleTagsOptions} [options] - Optional callback for post-mutation handling.
77
- * @returns {UseRegisterMultipleTagsReturn} - Mutation handler and state.
78
- */
79
- export const useRegisterMultipleTags = (
80
- { callback = () => { } }: UseRegisterMultipleTagsOptions = {}
81
- ): UseRegisterMultipleTagsReturn => {
82
- const client = useApolloClient()
83
- const [registerMultipleTags, { loading, error, data }] = useMutation<
84
- { registerMultipleTags: IResponseTag },
85
- { input: string[] }
86
- >(REGISTER_MULTIPLE_TAGS, {
87
- onCompleted: (data) => {
88
- if (typeof callback === 'function') {
89
- callback(data.registerMultipleTags)
90
- }
91
- }
92
- })
93
-
94
- /**
95
- * Register multiple tags with the provided names.
96
- *
97
- * @param {string[]} tags - Array of tag names.
98
- * @returns {Promise<IResponseTag>} - Mutation response.
99
- */
100
- const handleRegisterTags = async (tags: string[]): Promise<IResponseTag> => {
101
- if (!Array.isArray(tags) || tags.length === 0 || tags.some(tag => typeof tag !== 'string')) {
102
- throw new Error('Tag list must be a non-empty array of strings.')
103
- }
104
-
105
- const response = await registerMultipleTags({
106
- variables: {
107
- input: tags
108
- },
109
- update: (cache, { data }) => {
110
- if (!data?.registerMultipleTags?.data?.length) return;
111
-
112
- const newTags = data.registerMultipleTags.data;
113
-
114
- try {
115
- const existing = client.readQuery({ query: GET_ALL_TAGS });
116
-
117
- const updatedTags = [
118
- ...newTags,
119
- ...(existing?.getAllTags?.data || [])
120
- ];
121
-
122
- cache.writeQuery({
123
- query: GET_ALL_TAGS,
124
- data: {
125
- getAllTags: {
126
- ...existing.getAllTags,
127
- data: updatedTags,
128
- pagination: {
129
- ...existing.getAllTags.pagination,
130
- totalRecords: updatedTags.length,
131
- },
132
- }
133
- }
134
- });
135
- } catch (error) {
136
- console.warn('Failed to update cache for GET_ALL_TAGS:', error);
137
- }
138
- },
139
- })
140
- return response.data?.registerMultipleTags ?? {
141
- success: false,
142
- message: 'No response from server',
143
- errors: [],
144
- data: []
145
- }
146
- }
147
-
148
- return [
149
- handleRegisterTags,
150
- {
151
- loading,
152
- error,
153
- data: data?.registerMultipleTags ?? null
154
- }
155
- ]
156
- }
@@ -1,39 +0,0 @@
1
- import { useEffect, useState } from 'react'
2
-
3
- const DATE_UNITS = [
4
- ['day', 86400],
5
- ['hour', 3600],
6
- ['minute', 60],
7
- ['second', 1]
8
- ]
9
-
10
- const getDateDiffs = (timestamp) => {
11
- const now = Date.now()
12
- const elapsed = (timestamp - now) / 1000
13
-
14
- for (const [unit, secondsInUnit] of DATE_UNITS) {
15
- if (Math.abs(elapsed) > secondsInUnit || unit === 'second') {
16
- const value = Math.round(elapsed / secondsInUnit)
17
- return { value, unit }
18
- }
19
- }
20
- }
21
-
22
- export const useTimeAgo = (timestamp) => {
23
- const [timeAgo, setTimeAgo] = useState(() => { return getDateDiffs(timestamp) })
24
-
25
- useEffect(() => {
26
- const interval = setInterval(() => {
27
- const newTimeAgo = getDateDiffs(timestamp)
28
- setTimeAgo(newTimeAgo)
29
- }, 5000)
30
-
31
- return () => { return clearInterval(interval) }
32
- }, [timestamp])
33
-
34
- const rtf = new Intl.RelativeTimeFormat('es', { style: 'short' })
35
-
36
- const { value, unit } = timeAgo
37
-
38
- return rtf && rtf?.format(value, unit)
39
- }
@@ -1,41 +0,0 @@
1
- import { useState } from 'react'
2
-
3
- export const useTokenCards = () => {
4
- const [loading, setLoading] = useState(false)
5
- const [error, setError] = useState(null)
6
- const [responseData, setResponseData] = useState(null)
7
-
8
- const handleTokenCardsSubmit = async (postData) => {
9
- setLoading(true)
10
- setError(null)
11
- try {
12
- const headers = {
13
- 'Content-Type': 'application/json'
14
- }
15
- const url = 'http://localhost:3000/api/v1/wompi/transaction/tokens/cards'
16
-
17
- const response = await fetch(url, {
18
- method: 'POST',
19
- headers,
20
- body: JSON.stringify(postData)
21
- })
22
-
23
- const responseData = await response.json()
24
-
25
- if (!response.ok) {
26
- throw new Error(responseData.message || 'Something went wrong')
27
- }
28
- setResponseData(responseData)
29
- return responseData
30
- } catch (error) {
31
- setError(error.message)
32
- return {
33
-
34
- }
35
- } finally {
36
- setLoading(false)
37
- }
38
- }
39
-
40
- return { loading, error, responseData, handleTokenCardsSubmit }
41
- }
@@ -1,27 +0,0 @@
1
- import { useQuery, gql } from '@apollo/client'
2
-
3
- /**
4
- * GraphQL query to fetch top-selling products movements
5
- */
6
- const GET_TOP_PRODUCTS_MOVEMENTS = gql`
7
- query {
8
- getTopProductsMovements {
9
- productName
10
- idProduct
11
- totalMovements
12
- }
13
- }
14
- `
15
-
16
- /**
17
- * Custom hook to fetch and return the top-selling products movements
18
- * @returns {Object} - { data, loading, error }
19
- */
20
- export const useTopProductsMovements = () => {
21
- const { data, loading, error } = useQuery(GET_TOP_PRODUCTS_MOVEMENTS)
22
-
23
- return [data?.getTopProductsMovements, {
24
- loading,
25
- error
26
- }]
27
- }
@@ -1,25 +0,0 @@
1
- import { useQuery, gql } from '@apollo/client'
2
-
3
- const GET_TOTAL_SALES = gql`
4
- query totalSales {
5
- totalSales {
6
- success
7
- message
8
- totalSales
9
- }
10
- }
11
- `
12
-
13
- /**
14
- * Custom hook to fetch total sales from GraphQL API.
15
- * @returns {Object} An object containing total sales, loading state, error, and refetch function.
16
- */
17
- export const useTotalAllSales = () => {
18
- const { data, loading, error, refetch } = useQuery(GET_TOTAL_SALES)
19
-
20
- return [data?.totalSales?.totalSales, {
21
- loading,
22
- error,
23
- refetch
24
- }]
25
- }
@@ -1,23 +0,0 @@
1
- import { useQuery, gql } from '@apollo/client'
2
-
3
- /**
4
- * GraphQL query to fetch total products in stock.
5
- */
6
- const GET_TOTAL_PRODUCTS_IN_STOCK = gql`
7
- query getTotalProductsInStock {
8
- getTotalProductsInStock
9
- }
10
- `
11
-
12
- /**
13
- * Custom hook to fetch total products in stock.
14
- * @returns {Object} - { totalProductsInStock, loading, error }
15
- */
16
- export const useTotalProductsInStock = () => {
17
- const { data, loading, error } = useQuery(GET_TOTAL_PRODUCTS_IN_STOCK)
18
-
19
- return [data?.getTotalProductsInStock ?? 0, {
20
- loading,
21
- error
22
- }]
23
- }
@@ -1,23 +0,0 @@
1
- import { useQuery, gql } from '@apollo/client'
2
-
3
- /**
4
- * GraphQL query to fetch total products sold.
5
- */
6
- const GET_TOTAL_PRODUCTS_SOLD = gql`
7
- query getTotalSalesSold {
8
- getTotalSalesSold
9
- }
10
- `
11
-
12
- /**
13
- * Custom hook to fetch total products sold.
14
- * @returns {Object} - { totalProductsSold, loading, error }
15
- */
16
- export const useTotalProductsSold = () => {
17
- const { data, loading, error } = useQuery(GET_TOTAL_PRODUCTS_SOLD)
18
-
19
- return [data?.getTotalSalesSold || 0, {
20
- loading,
21
- error
22
- }]
23
- }
@@ -1,20 +0,0 @@
1
- import { useQuery, gql } from '@apollo/client'
2
-
3
- const GET_TOTAL_PRODUCTS_SOLD = gql`
4
- query {
5
- getTotalProductsSold
6
- }
7
- `
8
-
9
- /**
10
- * Custom hook to fetch the total number of products sold.
11
- * @returns {{ totalSold: number, loading: boolean, error: any }}
12
- */
13
- export const useTotalProductsSolded = () => {
14
- const { data, loading, error } = useQuery(GET_TOTAL_PRODUCTS_SOLD)
15
-
16
- return [data?.getTotalProductsSold, {
17
- loading,
18
- error
19
- }]
20
- }
@@ -1,130 +0,0 @@
1
- import debounce from 'lodash'
2
- import { useState, useEffect } from 'react'
3
- import { getCurrentDomain } from '../../utils'
4
- import { trigger } from '../useEvent'
5
- import { Cookies } from '../../cookies'
6
-
7
- // EXAMPLE
8
- // https://codesandbox.io/s/nextjs-cart-system-tfg1e?file=/pages/_app.js
9
-
10
- // Method to execute the event to add all items of the app.cart cookie
11
- const updateCart = debounce.debounce((items = []) => {
12
- trigger({ eventType: 'app.cart', data: { loading: true, items } })
13
- }, 3000)
14
-
15
- const EMPTY_CART = {
16
- items: [],
17
- total: 0
18
- }
19
-
20
- export const useUpdateCart = () => {
21
- const domain = getCurrentDomain()
22
- const keyToSaveData = 'app.cart'
23
- const saveDataState = JSON.parse(Cookies.get(keyToSaveData) || '[]')
24
- const [cart, setCart] = useState(EMPTY_CART)
25
-
26
- useEffect(() => {
27
- // restore cart from cookie, this could also be tracked in a db
28
- const cart = Cookies.get(keyToSaveData)
29
-
30
- // if items in cart, set items and total to state
31
- if (typeof cart === 'string' && cart !== 'undefined') {
32
- const cartData = JSON.parse(cart)
33
- const total = cartData.reduce(
34
- (total, item) => { return total + item.price * item.quantity },
35
- 0
36
- )
37
-
38
- setCart({ items: cartData, total })
39
- }
40
- }, [])
41
-
42
- useEffect(() => {
43
- Cookies.set(keyToSaveData, JSON.stringify(cart.items), { domain, path: '/' })
44
- }, [cart, domain])
45
-
46
- const handleAdd = (item) => {
47
- // check for item already in cart
48
- // if not in cart, add item else if item is found increment quantity
49
- const itemExists = cart.items.find((i) => { return i.pId === item.pId })
50
-
51
- if (!itemExists) {
52
- setCart((prevCart) => {
53
- return {
54
- items: [...prevCart.items, { ...item, quantity: 1 }],
55
- total: prevCart.total + item.price
56
- }
57
- })
58
-
59
- return
60
- }
61
-
62
- setCart((prevCart) => {
63
- return {
64
- items: prevCart.items.map((i) => {
65
- if (i.pId === item.pId) {
66
- return { ...i, quantity: i.quantity + 1 }
67
- }
68
-
69
- return i
70
- }),
71
- total: prevCart.total + item.price
72
- }
73
- })
74
- updateCart(cart)
75
- }
76
-
77
- const deleteProductCart = (item) => {
78
- setCart((prevCart) => {
79
- const items = prevCart.items
80
- const index = items.findIndex((i) => { return i.pId === item.pId })
81
-
82
- items.splice(index, 1)
83
-
84
- const total = items.reduce((t, i) => { return t + i.quantity * i.price }, 0)
85
-
86
- return { items, total }
87
- })
88
- }
89
-
90
- const decreaseItemFromCart = (item) => {
91
- // check for item already in cart
92
- // if quantity is more then in cart, subtract item else remove item
93
- const itemInCart = cart.items.find((i) => { return i.pId === item.pId })
94
-
95
- if (!itemInCart) {
96
- return
97
- }
98
-
99
- if (itemInCart.quantity === 1) {
100
- deleteProductCart(item)
101
-
102
- return
103
- }
104
-
105
- setCart((prevCart) => {
106
- return {
107
- items: prevCart.items.map((i) => {
108
- if (i.pId === item.pId) {
109
- return { ...i, quantity: item.quantity - 1 }
110
- }
111
-
112
- return i
113
- }),
114
- total: prevCart.total - item.price
115
- }
116
- })
117
- }
118
-
119
- const clearCart = () => {
120
- setCart(EMPTY_CART)
121
- }
122
-
123
- return {
124
- saveDataState,
125
- clearCart,
126
- deleteProductCart,
127
- decreaseItemFromCart,
128
- handleAdd
129
- }
130
- }
@@ -1,43 +0,0 @@
1
- import { useEffect, useReducer } from 'react'
2
- import { initializer } from '../useSales'
3
- import { Cookies } from '../../cookies'
4
- import { getCurrentDomain } from '../../utils'
5
-
6
- export const useUpdateCartCookie = () => {
7
- const keyToSaveData = process.env.LOCAL_SALES_STORE
8
- const domain = getCurrentDomain()
9
-
10
- const PRODUCT = (state, action) => {
11
- switch (action.type) {
12
- case 'REMOVE_PRODUCT_TO_CART':
13
- return {
14
- ...state,
15
- PRODUCT: state?.PRODUCT?.filter((t) => {
16
- return t.pId !== action?.payload.pId
17
- }),
18
- counter: state.counter - action.payload.ProQuantity
19
- }
20
- case 'ADD_PRODUCT_TO_CART':
21
- // Add code for 'ADD_PRODUCT_TO_CART' case
22
- return state
23
- case 'UPDATE_PRODUCT_IN_CART':
24
- // Add code for 'UPDATE_PRODUCT_IN_CART' case
25
- return state
26
- default:
27
- return state
28
- }
29
- }
30
- const [data, dispatch] = useReducer(PRODUCT, { PRODUCT: [], counter: 0 }, initializer)
31
-
32
- const handleRemoveProductToCookieCart = (product) => {
33
- dispatch({ type: 'REMOVE_PRODUCT_TO_CART', payload: product })
34
- }
35
- useEffect(() => {
36
- // @ts-ignore
37
- Cookies.set(keyToSaveData, JSON.stringify(data), { domain, path: '/' })
38
- }, [data, domain])
39
-
40
- return {
41
- handleRemoveProductToCookieCart
42
- }
43
- }
@@ -1,91 +0,0 @@
1
- import { gql, useMutation } from '@apollo/client';
2
-
3
- /**
4
- * GraphQL mutation for updating a dashboard component.
5
- */
6
- const UPDATE_DASHBOARD_COMPONENT = gql`
7
- mutation UpdateDashboardComponent($input: [DashboardComponentUpdateInput]) {
8
- updateDashboardComponent(input: $input) {
9
- success
10
- message
11
- data {
12
- id
13
- idStore
14
- idUser
15
- coordinates
16
- createAt
17
- updateAt
18
- title
19
- }
20
- errors {
21
- path
22
- message
23
- type
24
- }
25
- }
26
- }
27
- `;
28
-
29
- /**
30
- * Types for the mutation response and input.
31
- */
32
- interface DashboardComponent {
33
- id: string;
34
- idStore: string;
35
- idUser: string;
36
- coordinates: any;
37
- createAt: string;
38
- updateAt: string;
39
- title: string;
40
- }
41
-
42
- interface ErrorResponse {
43
- message: string;
44
- field?: string;
45
- }
46
-
47
- interface UpdateDashboardComponentResponse {
48
- updateDashboardComponent: {
49
- success: boolean;
50
- message?: string;
51
- data?: DashboardComponent;
52
- errors?: ErrorResponse[];
53
- };
54
- }
55
-
56
- interface UpdateDashboardComponentInput {
57
- id: string;
58
- coordinates?: any;
59
- title?: string;
60
- }
61
-
62
- /**
63
- * Custom hook to update a dashboard component.
64
- */
65
- export const useUpdateDashboardComponent = () => {
66
- const [mutate, { loading, error, data }] = useMutation<
67
- UpdateDashboardComponentResponse,
68
- { input: UpdateDashboardComponentInput[] }
69
- >(UPDATE_DASHBOARD_COMPONENT);
70
-
71
- /**
72
- * Calls the mutation with the provided input.
73
- * @param input DashboardComponentUpdateInput
74
- */
75
- const updateComponent = async (input: UpdateDashboardComponentInput[]) => {
76
- try {
77
- const response = await mutate({ variables: { input } });
78
- return response.data?.updateDashboardComponent;
79
- } catch (err) {
80
- console.error('UpdateDashboardComponent Error:', err);
81
- throw err;
82
- }
83
- };
84
-
85
- return {
86
- updateComponent,
87
- loading,
88
- error,
89
- data: data?.updateDashboardComponent,
90
- };
91
- };