@lmnto/h-mall-shared 1.0.1

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 (262) hide show
  1. package/app.css +457 -0
  2. package/bitbucket-pipelines.yml +223 -0
  3. package/package.json +43 -0
  4. package/public/gif/balloon.gif +0 -0
  5. package/public/gif/gift.gif +0 -0
  6. package/public/img/ai-dialog.png +0 -0
  7. package/public/img/ai-x1-banner.png +0 -0
  8. package/public/img/ai-x1.png +0 -0
  9. package/public/img/alert-Icon.png +0 -0
  10. package/public/img/aleta-payment-kyc-require.png +0 -0
  11. package/public/img/aleta-payment-pending.png +0 -0
  12. package/public/img/aleta-payment-rejected.png +0 -0
  13. package/public/img/aleta-payment-subscription-required.png +0 -0
  14. package/public/img/boost-banner-bg.png +0 -0
  15. package/public/img/boost-banner-right.png +0 -0
  16. package/public/img/boost-banner.png +0 -0
  17. package/public/img/boost-dialog-bg.png +0 -0
  18. package/public/img/boostPower.png +0 -0
  19. package/public/img/boostTooltip.png +0 -0
  20. package/public/img/brand-icon.svg +23 -0
  21. package/public/img/brand-text.svg +11 -0
  22. package/public/img/card-icon.png +0 -0
  23. package/public/img/cashback-Icon.png +0 -0
  24. package/public/img/crown.svg +9 -0
  25. package/public/img/empty-box.png +0 -0
  26. package/public/img/gen3-dialog.png +0 -0
  27. package/public/img/gen3-home-banner-bg.png +0 -0
  28. package/public/img/gen3-image.png +0 -0
  29. package/public/img/gift.png +0 -0
  30. package/public/img/img-placeholder-illustration.svg +6 -0
  31. package/public/img/logo.svg +31 -0
  32. package/public/img/offerBanner.png +0 -0
  33. package/public/img/pagenotfound.png +0 -0
  34. package/public/img/partial-pay-payment-successful.png +0 -0
  35. package/public/img/phoneShippingBG.png +0 -0
  36. package/public/img/placeholder-image.jpg +0 -0
  37. package/public/img/powerIcon.png +0 -0
  38. package/public/img/product-01.png +0 -0
  39. package/public/img/product-02.jpg +0 -0
  40. package/public/img/product-03.jpg +0 -0
  41. package/public/img/product-04.jpg +0 -0
  42. package/public/img/product-05.png +0 -0
  43. package/public/img/product-06.png +0 -0
  44. package/public/img/profile-avatar.svg +12 -0
  45. package/public/img/promotion-icon.png +0 -0
  46. package/public/img/session-expired.png +0 -0
  47. package/public/img/shipping-alert-icon.png +0 -0
  48. package/public/img/shippingIcon.png +0 -0
  49. package/public/img/smart-pay-banner-how.png +0 -0
  50. package/public/img/smart-pay-banner-own.png +0 -0
  51. package/public/img/smart-pay-chose.png +0 -0
  52. package/public/img/smart-pay-easy.png +0 -0
  53. package/public/img/smart-pay-payment.png +0 -0
  54. package/public/img/smart-plan-fire.gif +0 -0
  55. package/public/img/smart-plan-sparkle.gif +0 -0
  56. package/public/img/special.png +0 -0
  57. package/public/img/specialOfferBg.png +0 -0
  58. package/public/img/stop-shipping-banner.png +0 -0
  59. package/public/img/subscriptionBanner.png +0 -0
  60. package/public/img/subscriptionIcon.png +0 -0
  61. package/public/img/successIcon.png +0 -0
  62. package/public/img/wallet-icon.png +0 -0
  63. package/public/img/world-wide-shipping.png +0 -0
  64. package/public/next.svg +1 -0
  65. package/public/vercel.svg +1 -0
  66. package/shared/components/AddressFormComponent.tsx +215 -0
  67. package/shared/components/AddressShippingFormComponent.tsx +223 -0
  68. package/shared/components/AiPaymentDialog.tsx +95 -0
  69. package/shared/components/AppLoadingComponent.tsx +15 -0
  70. package/shared/components/AppLoadingComponentV2.tsx +18 -0
  71. package/shared/components/Button.tsx +48 -0
  72. package/shared/components/BuySubscriptionDialog.tsx +75 -0
  73. package/shared/components/CartDrawerComponent.tsx +324 -0
  74. package/shared/components/CashbackComponent.tsx +48 -0
  75. package/shared/components/CashbackMigrationComponent.tsx +41 -0
  76. package/shared/components/CommissionNonEligibleComponent.tsx +27 -0
  77. package/shared/components/CustomNextImage.tsx +50 -0
  78. package/shared/components/CustomNextLink.tsx +46 -0
  79. package/shared/components/EditAddressFormComponent.tsx +254 -0
  80. package/shared/components/EmptyCartMessageComponent.tsx +25 -0
  81. package/shared/components/EmptyCartMessageForCartPage.tsx +61 -0
  82. package/shared/components/EmptyLegacyOrderMessageForOrdersPage.tsx +52 -0
  83. package/shared/components/EmptyOrderMessageForOrdersPage.tsx +62 -0
  84. package/shared/components/EmptyOrderMessageForShippingOrdersPage.tsx +62 -0
  85. package/shared/components/Footer.tsx +71 -0
  86. package/shared/components/GreetingDialog.tsx +96 -0
  87. package/shared/components/Header.tsx +106 -0
  88. package/shared/components/HoldShippingDialog.tsx +165 -0
  89. package/shared/components/HomeBanners.tsx +298 -0
  90. package/shared/components/InactiveCartDialog.tsx +69 -0
  91. package/shared/components/InputCartQuantity.tsx +342 -0
  92. package/shared/components/Inputfield.tsx +110 -0
  93. package/shared/components/ListItemComponent.tsx +82 -0
  94. package/shared/components/LoadingIconComponent.tsx +284 -0
  95. package/shared/components/OrderNotFoundComponent.tsx +56 -0
  96. package/shared/components/PageHeader.tsx +42 -0
  97. package/shared/components/PhoneNumberCountries.tsx +133 -0
  98. package/shared/components/PhoneShippingDialog.tsx +77 -0
  99. package/shared/components/PickupDialog.tsx +92 -0
  100. package/shared/components/ProductNotFoundComponent.tsx +56 -0
  101. package/shared/components/ProductPriceComponent.tsx +32 -0
  102. package/shared/components/ProfileMenu.tsx +120 -0
  103. package/shared/components/RequestCreditNoteInvoiceDialog.tsx +214 -0
  104. package/shared/components/RequestInvoiceDialog.tsx +194 -0
  105. package/shared/components/SelectCities.tsx +133 -0
  106. package/shared/components/SelectComponent.tsx +334 -0
  107. package/shared/components/SelectCountries.tsx +179 -0
  108. package/shared/components/SelectPickUpStore.tsx +131 -0
  109. package/shared/components/SelectStates.tsx +144 -0
  110. package/shared/components/ServerTime.tsx +68 -0
  111. package/shared/components/SessionDialogComponent.tsx +60 -0
  112. package/shared/components/ShippingAddressFormDialogComponent.tsx +51 -0
  113. package/shared/components/Sidebar.tsx +281 -0
  114. package/shared/components/SpecialOfferDialog.tsx +193 -0
  115. package/shared/components/StatusComponents.tsx +25 -0
  116. package/shared/components/StepperComponent.tsx +79 -0
  117. package/shared/components/StepperSmartPayComponent.tsx +97 -0
  118. package/shared/components/SubscriptionPurchaseDialogComponent.tsx +81 -0
  119. package/shared/components/TableComponent.tsx +144 -0
  120. package/shared/components/TablePaginationComponent.tsx +151 -0
  121. package/shared/components/aleta/AletaManagerComponent.tsx +52 -0
  122. package/shared/components/aleta/KycPendingStatus.tsx +33 -0
  123. package/shared/components/aleta/KycRejectedStatus.tsx +53 -0
  124. package/shared/components/aleta/KycRequiredStatus.tsx +53 -0
  125. package/shared/components/aleta/SubscriptionRequiredStatus.tsx +45 -0
  126. package/shared/components/icons/AletaWalletIcon.tsx +21 -0
  127. package/shared/components/icons/BrandIcon.tsx +97 -0
  128. package/shared/components/icons/BrandText.tsx +47 -0
  129. package/shared/components/icons/CartIcon.tsx +21 -0
  130. package/shared/components/icons/DoneIcon.tsx +27 -0
  131. package/shared/components/icons/HomnifiIcon.tsx +23 -0
  132. package/shared/components/icons/InfoIcon.tsx +16 -0
  133. package/shared/components/icons/SmartPayProductIcon.tsx +31 -0
  134. package/shared/components/payments/DisclaimerAlertDialog.tsx +205 -0
  135. package/shared/components/payments/EmptyAssets.tsx +23 -0
  136. package/shared/components/payments/PaybyWalletItemComponent.tsx +116 -0
  137. package/shared/components/payments/PaymentAssetItemComponent.tsx +101 -0
  138. package/shared/components/payments/RequestProcessingDialog.tsx +123 -0
  139. package/shared/components/payments/WalletSectionManager.tsx +82 -0
  140. package/shared/components/payments/WalletSliderComponent.tsx +326 -0
  141. package/shared/components/payments/WalletTermsAndConditionComponent.tsx +88 -0
  142. package/shared/constants/address-shipping.schema.ts +56 -0
  143. package/shared/constants/address.schema.ts +56 -0
  144. package/shared/constants/app.ts +323 -0
  145. package/shared/constants/environment.ts +23 -0
  146. package/shared/constants/feature-flags.ts +15 -0
  147. package/shared/constants/query-keys.ts +106 -0
  148. package/shared/constants/routes.ts +41 -0
  149. package/shared/constants/socket.ts +15 -0
  150. package/shared/contexts/HomeProductsContext.tsx +51 -0
  151. package/shared/contexts/MainWrapperContext.tsx +289 -0
  152. package/shared/contexts/WebSocketContext.tsx +155 -0
  153. package/shared/hooks/useAddressForm.ts +169 -0
  154. package/shared/hooks/useAddresses.ts +28 -0
  155. package/shared/hooks/useAppForm.ts +39 -0
  156. package/shared/hooks/useCart.ts +207 -0
  157. package/shared/hooks/useCopy.ts +45 -0
  158. package/shared/hooks/useCountries.ts +27 -0
  159. package/shared/hooks/useCustomRouter.ts +51 -0
  160. package/shared/hooks/useDebounce.ts +21 -0
  161. package/shared/hooks/useInvoice.ts +41 -0
  162. package/shared/hooks/useOnlineUser.ts +38 -0
  163. package/shared/hooks/usePayments.ts +101 -0
  164. package/shared/hooks/useShippingAddressForm.ts +70 -0
  165. package/shared/hooks/useShippingAddresses.ts +33 -0
  166. package/shared/hooks/useStores.ts +29 -0
  167. package/shared/hooks/useUserActivity.ts +43 -0
  168. package/shared/i18n/client.ts +27 -0
  169. package/shared/i18n/locales/en.ts +383 -0
  170. package/shared/i18n/locales/it.ts +373 -0
  171. package/shared/i18n/server.ts +7 -0
  172. package/shared/services/addresses.service.ts +27 -0
  173. package/shared/services/api/core/ApiError.ts +29 -0
  174. package/shared/services/api/core/ApiRequestOptions.ts +25 -0
  175. package/shared/services/api/core/ApiResult.ts +11 -0
  176. package/shared/services/api/core/CancelablePromise.ts +130 -0
  177. package/shared/services/api/core/OpenAPI.ts +37 -0
  178. package/shared/services/api/core/request.ts +376 -0
  179. package/shared/services/api/index.ts +64 -0
  180. package/shared/services/api/models/AddAllProductToShippingCartDto.ts +7 -0
  181. package/shared/services/api/models/AddProductToCartDto.ts +8 -0
  182. package/shared/services/api/models/AddProductToShippingCartDto.ts +8 -0
  183. package/shared/services/api/models/AdminPlaceOrderDto.ts +16 -0
  184. package/shared/services/api/models/AssignPickupSerialNumberDto.ts +10 -0
  185. package/shared/services/api/models/CreateUserAddressDto.ts +19 -0
  186. package/shared/services/api/models/DeletCartProductsArrayDto.ts +7 -0
  187. package/shared/services/api/models/GenerateInvoiceDto.ts +7 -0
  188. package/shared/services/api/models/OrderConfirmationEmailDto.ts +8 -0
  189. package/shared/services/api/models/PlaceOrderDto.ts +9 -0
  190. package/shared/services/api/models/PlaceShipmentOrderDto.ts +8 -0
  191. package/shared/services/api/models/ProductBoostDto.ts +18 -0
  192. package/shared/services/api/models/RemoveAssignedSerialNumberDto.ts +9 -0
  193. package/shared/services/api/models/RemoveProductToCartDto.ts +8 -0
  194. package/shared/services/api/models/ShipmentItem.ts +8 -0
  195. package/shared/services/api/models/ShippingCartUpdateBillingAddressesDto.ts +7 -0
  196. package/shared/services/api/models/ShippingCartUpdateShippingMethodDto.ts +7 -0
  197. package/shared/services/api/models/UnfreezeWalletDto.ts +8 -0
  198. package/shared/services/api/models/UpdateCartBillingAddressesDto.ts +7 -0
  199. package/shared/services/api/models/UpdateCartPaymentMethodDto.ts +9 -0
  200. package/shared/services/api/models/UpdateCartShippingMethodDto.ts +7 -0
  201. package/shared/services/api/models/UpdateCartStoreDto.ts +7 -0
  202. package/shared/services/api/models/UpdateProductDto.ts +11 -0
  203. package/shared/services/api/models/UpdateShipmentItemStatusDto.ts +24 -0
  204. package/shared/services/api/models/UpdateShippingCartPaymentMethodDto.ts +9 -0
  205. package/shared/services/api/models/UpdateUserAddressDto.ts +19 -0
  206. package/shared/services/api/models/ValidateAuthCodeDto.ts +8 -0
  207. package/shared/services/api/models/WithdrawOrderWalletDto.ts +8 -0
  208. package/shared/services/api/services/AddressesService.ts +160 -0
  209. package/shared/services/api/services/AdminsDevicesService.ts +28 -0
  210. package/shared/services/api/services/AdminsOrdersService.ts +117 -0
  211. package/shared/services/api/services/AdminsPickupsService.ts +57 -0
  212. package/shared/services/api/services/AdminsProductsService.ts +86 -0
  213. package/shared/services/api/services/CartsService.ts +190 -0
  214. package/shared/services/api/services/CashBackQueueService.ts +39 -0
  215. package/shared/services/api/services/CategoriesService.ts +65 -0
  216. package/shared/services/api/services/DefaultService.ts +19 -0
  217. package/shared/services/api/services/FeaturesFlagsService.ts +20 -0
  218. package/shared/services/api/services/IossQueueService.ts +39 -0
  219. package/shared/services/api/services/OrderCallbackService.ts +67 -0
  220. package/shared/services/api/services/OrderEmailsService.ts +40 -0
  221. package/shared/services/api/services/OrderImportService.ts +228 -0
  222. package/shared/services/api/services/OrdersService.ts +183 -0
  223. package/shared/services/api/services/PaymentGatewayService.ts +19 -0
  224. package/shared/services/api/services/PaymentsService.ts +88 -0
  225. package/shared/services/api/services/ProductsService.ts +67 -0
  226. package/shared/services/api/services/ShipmentOrderCallbackService.ts +67 -0
  227. package/shared/services/api/services/ShipmentOrdersService.ts +88 -0
  228. package/shared/services/api/services/ShipmentsService.ts +30 -0
  229. package/shared/services/api/services/ShippingCartService.ts +247 -0
  230. package/shared/services/api/services/ShippingMethodsService.ts +20 -0
  231. package/shared/services/api/services/StoresService.ts +25 -0
  232. package/shared/services/api/services/SyncServiceQueueService.ts +39 -0
  233. package/shared/services/api/services/UpgradeOrdersService.ts +26 -0
  234. package/shared/services/api/services/UsersAuthService.ts +45 -0
  235. package/shared/services/api/services/UsersService.ts +53 -0
  236. package/shared/services/api/services/XeraQueueService.ts +39 -0
  237. package/shared/services/index.ts +0 -0
  238. package/shared/services/payment-method.service.ts +29 -0
  239. package/shared/stores/cartStore.ts +108 -0
  240. package/shared/stores/countriesStore.ts +62 -0
  241. package/shared/stores/formStore.ts +19 -0
  242. package/shared/stores/loadingStore.ts +12 -0
  243. package/shared/stores/userStore.ts +32 -0
  244. package/shared/types/SelectComponent.types.ts +31 -0
  245. package/shared/types/addressForm.ts +27 -0
  246. package/shared/types/cart.ts +208 -0
  247. package/shared/types/category.ts +6 -0
  248. package/shared/types/creditNote.ts +0 -0
  249. package/shared/types/feature-flags.ts +5 -0
  250. package/shared/types/icon.ts +5 -0
  251. package/shared/types/index.d.ts +84 -0
  252. package/shared/types/order.ts +332 -0
  253. package/shared/types/pagination.ts +5 -0
  254. package/shared/types/payments.ts +68 -0
  255. package/shared/types/product.ts +54 -0
  256. package/shared/types/shoppingCart.ts +219 -0
  257. package/shared/types/upgradeCart.ts +226 -0
  258. package/shared/types/user.ts +36 -0
  259. package/shared/utils/app.util.ts +261 -0
  260. package/shared/utils/notifications.util.ts +39 -0
  261. package/shared/utils/user-session.util.ts +171 -0
  262. package/tailwind.config.ts +234 -0
@@ -0,0 +1,169 @@
1
+ import { useMutation, useQuery } from "@tanstack/react-query";
2
+ import { useEffect } from "react";
3
+
4
+ import { ADDRESS_TYPES } from "../constants/app";
5
+ import { QueryKeys } from "../constants/query-keys";
6
+ import {
7
+ proceedGetCitiesAsync,
8
+ proceedGetStatesAsync,
9
+ } from "../services/addresses.service";
10
+ import {
11
+ AddressesService,
12
+ StoresService,
13
+ UpdateUserAddressDto,
14
+ } from "../services/api";
15
+ import { useCartStore } from "../stores/cartStore";
16
+ import { countriesStore } from "../stores/countriesStore";
17
+ import { notification } from "../utils/notifications.util";
18
+ import { useShippingAddressForm } from "./useShippingAddressForm";
19
+
20
+ export function useAddressForm() {
21
+ //
22
+ const {
23
+ setStates,
24
+ setShippingStates,
25
+ setCities,
26
+ setShippingCities,
27
+ setLoading,
28
+ setLoadingCities,
29
+ setShippingLoadingCities,
30
+ setStores,
31
+ } = countriesStore();
32
+ const { userBillingAddress, setUserBillingAddress } = useCartStore();
33
+
34
+ const { getShippingAddress } = useShippingAddressForm();
35
+
36
+ const getCityByStateAndCountry = useMutation({
37
+ mutationKey: [QueryKeys.users.GET_SHIPPING_STATE_BY_COUNTRY],
38
+ mutationFn: ({
39
+ countryId,
40
+ stateId,
41
+ }: {
42
+ countryId: number;
43
+ stateId?: number;
44
+ }) => proceedGetCitiesAsync(countryId, stateId),
45
+ onSuccess: (data) => {
46
+ setCities(data);
47
+ setLoadingCities(false);
48
+ },
49
+ onError: () => {},
50
+ });
51
+ const getShippingCityByStateAndCountry = useMutation({
52
+ mutationKey: [QueryKeys.users.GET_SHIPPING_CITY_BY_STATE_AND_COUNTRY],
53
+ mutationFn: ({
54
+ countryId,
55
+ stateId,
56
+ }: {
57
+ countryId: number;
58
+ stateId?: number;
59
+ }) => proceedGetCitiesAsync(countryId, stateId),
60
+ onSuccess: (data) => {
61
+ setShippingCities(data);
62
+ setShippingLoadingCities(false);
63
+ },
64
+ onError: () => {},
65
+ });
66
+
67
+ const getStatesByCountry = useMutation({
68
+ mutationKey: [QueryKeys.users.GET_STATE_BY_COUNTRY],
69
+ mutationFn: proceedGetStatesAsync,
70
+ onSuccess: async (data: any[]) => {
71
+ setStates(data);
72
+ setLoading(false);
73
+ },
74
+ onError: () => {},
75
+ });
76
+ const getShippingStatesByCountry = useMutation({
77
+ mutationKey: [QueryKeys.users.GET_SHIPPING_STATE_BY_COUNTRY],
78
+ mutationFn: proceedGetStatesAsync,
79
+ onSuccess: async (data: any[]) => {
80
+ setShippingStates(data);
81
+ setLoading(false);
82
+ },
83
+ onError: () => {},
84
+ });
85
+
86
+ const getStoreByCountry = useMutation({
87
+ mutationKey: [QueryKeys.users.GET_STORE_BY_COUNTRY],
88
+ mutationFn: StoresService.storesControllerFindAll,
89
+ onSuccess: async (data: any[]) => {
90
+ setStores(data);
91
+ setLoading(false);
92
+ },
93
+ onError: () => {},
94
+ });
95
+
96
+ const addNewAddress = useMutation({
97
+ mutationKey: [QueryKeys.users.ADD_NEW_ADDRESS],
98
+ mutationFn: AddressesService.userAddressesControllerAddNewAddress,
99
+ onSuccess: () => {
100
+ setStates([]);
101
+ setShippingStates([]);
102
+ setCities([]);
103
+ setShippingCities([]);
104
+ getAddress();
105
+ },
106
+ onError: () => {},
107
+ });
108
+
109
+ const updateAddress = useMutation({
110
+ mutationKey: [QueryKeys.users.UPDATE_ADDRESS],
111
+ mutationFn: ({
112
+ id,
113
+ requestBody,
114
+ }: {
115
+ id: number;
116
+ requestBody: UpdateUserAddressDto;
117
+ }) =>
118
+ AddressesService.userAddressesControllerUpdateAddress(id, requestBody),
119
+ onSuccess: () => {
120
+ notification.notifySuccess("Your address has been updated successfully");
121
+ getAddress();
122
+ getShippingAddress();
123
+ },
124
+ onError: () => {},
125
+ });
126
+
127
+ const deleteAddress = useMutation({
128
+ mutationKey: [QueryKeys.users.DELETE_ADDRESS],
129
+ mutationFn: ({ id }: { id: number }) =>
130
+ AddressesService.userAddressesControllerDeleteAddress(id),
131
+ onSuccess: () => {
132
+ notification.notifySuccess("Your address has been deleted successfully");
133
+ getAddress();
134
+ getShippingAddress();
135
+ },
136
+ onError: () => {},
137
+ });
138
+
139
+ const {
140
+ data: userBilling,
141
+ isLoading: isLoadingAddresses,
142
+ refetch: getAddress,
143
+ } = useQuery({
144
+ queryKey: [QueryKeys.users.GET_ADDRESSES],
145
+ queryFn: () =>
146
+ AddressesService.userAddressesControllerGetAllActiveUserAddresses(
147
+ ADDRESS_TYPES.billing.value,
148
+ ),
149
+ enabled: !userBillingAddress,
150
+ });
151
+
152
+ useEffect(() => {
153
+ setUserBillingAddress(userBilling);
154
+ }, [userBilling, setUserBillingAddress]);
155
+
156
+ return {
157
+ getStatesByCountry,
158
+ getShippingStatesByCountry,
159
+ getStoreByCountry,
160
+ getCityByStateAndCountry,
161
+ getShippingCityByStateAndCountry,
162
+ addNewAddress,
163
+ updateAddress,
164
+ deleteAddress,
165
+ billingAddress: userBillingAddress,
166
+ isLoadingAddresses,
167
+ getAddress,
168
+ };
169
+ }
@@ -0,0 +1,28 @@
1
+ import { useRef } from "react";
2
+
3
+ import { AddressSchema } from "../constants/address.schema";
4
+ import useAppForm from "../hooks/useAppForm";
5
+
6
+ export default function useAddresses() {
7
+ const formId = useRef("billingAddress");
8
+
9
+ const { handleSubmit, reset, setValue } = useAppForm({
10
+ schema: AddressSchema(),
11
+ defaultValues: {
12
+ firstName: "",
13
+ lastName: "",
14
+ address: "",
15
+ type: "",
16
+ countryId: null,
17
+ state: "",
18
+ city: "",
19
+ postalCode: "",
20
+ phone: "",
21
+ zipCodeRegex: "",
22
+ zipCodeExample: [],
23
+ minPhoneLength: "5",
24
+ },
25
+ id: formId.current,
26
+ });
27
+ return { formId, handleSubmit, resetForm: reset, setFormValue: setValue };
28
+ }
@@ -0,0 +1,39 @@
1
+ import { yupResolver } from "@hookform/resolvers/yup";
2
+ import { useLayoutEffect } from "react";
3
+ import { DefaultValues, useForm, UseFormReturn } from "react-hook-form";
4
+
5
+ import { useFormStore } from "../stores/formStore";
6
+
7
+ type FormValues = { [key: string]: any }; // Dynamic type for form values
8
+
9
+ interface UseFormProps<T extends FormValues> {
10
+ schema: any; // Yup schema for validation
11
+ defaultValues?: T | DefaultValues<T> | undefined; // Optional default values for the form
12
+ id: string;
13
+ }
14
+
15
+ const useAppForm = <T extends FormValues>({
16
+ schema,
17
+ defaultValues,
18
+ id,
19
+ }: UseFormProps<T>): UseFormReturn<T> => {
20
+ const { setReactHookUseForm } = useFormStore();
21
+
22
+ const hookForm = useForm({
23
+ // mode: "all",
24
+ resolver: yupResolver(schema) as any, // Integrate Yup for validation
25
+ defaultValues: defaultValues as DefaultValues<T> | undefined,
26
+ reValidateMode: "onChange",
27
+ });
28
+
29
+ useLayoutEffect(() => {
30
+ setReactHookUseForm({
31
+ [id]: hookForm,
32
+ });
33
+ // eslint-disable-next-line react-hooks/exhaustive-deps
34
+ }, [id, setReactHookUseForm]);
35
+
36
+ return hookForm;
37
+ };
38
+
39
+ export default useAppForm;
@@ -0,0 +1,207 @@
1
+ import { useMutation, useQuery } from "@tanstack/react-query";
2
+ import { useCallback, useEffect, useState } from "react";
3
+
4
+ import { QueryKeys } from "../constants/query-keys";
5
+ import { useMainContext } from "../contexts/MainWrapperContext";
6
+ import { CartsService } from "../services/api";
7
+ import { ShippingMethodsService } from "../services/api";
8
+ import { useCartStore } from "../stores/cartStore";
9
+ import { countriesStore } from "../stores/countriesStore";
10
+ import { withTimeout } from "../utils/app.util";
11
+
12
+ export function useCart() {
13
+ const [revalidateCartSuccess, setRevalidateCartSuccess] = useState(false);
14
+ const { triggerInvalidDialog } = useMainContext();
15
+ const { setShippingCountries } = countriesStore();
16
+
17
+ //
18
+ const { cart, commissionNonEligibleFound, setLoading, setCart } =
19
+ useCartStore();
20
+
21
+ const { data: cartData, refetch: getCart } = useQuery({
22
+ queryKey: [QueryKeys.cart.GET_CART],
23
+ queryFn: CartsService.cartsControllerGetCart,
24
+ enabled: true,
25
+ });
26
+
27
+ useEffect(() => {
28
+ // Update cart store whenever cartData changes, including when it's null (empty cart)
29
+ if (cartData !== undefined && revalidateCartSuccess) {
30
+ setCart(cartData);
31
+ }
32
+ }, [cartData, setCart, revalidateCartSuccess]);
33
+
34
+ const revalidateCart = useCallback(async () => {
35
+ await setRevalidateCartSuccess(false);
36
+ const result = await getCart();
37
+ await setRevalidateCartSuccess(result.status === "success");
38
+ }, [getCart]);
39
+
40
+ const addToCart = useMutation({
41
+ mutationKey: [QueryKeys.cart.ADD_TO_CART],
42
+ mutationFn: CartsService.cartsControllerAddCartProduct,
43
+ onMutate: () => setLoading(true),
44
+ onSuccess: () => {
45
+ //
46
+ revalidateCart();
47
+ },
48
+ onError: (error: any) => {
49
+ setLoading(false);
50
+ if (error?.status === 404) {
51
+ triggerInvalidDialog();
52
+ return;
53
+ }
54
+ },
55
+ });
56
+
57
+ const removeProductFromCart = useMutation({
58
+ mutationKey: [QueryKeys.cart.REMOVE_FROM_CART],
59
+ mutationFn: CartsService.cartsControllerRemoveCartProduct,
60
+ onMutate: () => setLoading(true),
61
+ onSuccess: () => {
62
+ revalidateCart();
63
+ },
64
+ onError: () => setLoading(false),
65
+ });
66
+
67
+ const removeProductsFromCart = useMutation({
68
+ mutationKey: [QueryKeys.cart.REMOVE_PRODUCT_FROM_CART],
69
+ mutationFn: CartsService.cartsControllerDeleteCartProducts,
70
+ onMutate: () => setLoading(true),
71
+ onSuccess: () => {
72
+ revalidateCart();
73
+ },
74
+ onError: () => setLoading(false),
75
+ });
76
+
77
+ const updateCartState = useMutation({
78
+ mutationKey: [QueryKeys.cart.UPDATE_CART_STATE],
79
+ mutationFn: CartsService.cartsControllerUpdateCartState,
80
+ onMutate: () => setLoading(true),
81
+ onSuccess: async () => {
82
+ revalidateCart();
83
+ },
84
+ onError: () => setLoading(false),
85
+ });
86
+
87
+ const updateCartAddresses = useMutation({
88
+ mutationKey: [QueryKeys.cart.UPDATE_ADDRESSES],
89
+ mutationFn: CartsService.cartsControllerUpdateAddresses,
90
+ onMutate: () => setLoading(true),
91
+ onSuccess: () => revalidateCart(),
92
+ onError: () => setLoading(false),
93
+ });
94
+
95
+ //#TODO Update with the Update shipping address API
96
+ const updateCartShippingAddresses = useMutation({
97
+ mutationKey: [QueryKeys.cart.UPDATE_SHIPPING_ADDRESSES],
98
+ mutationFn: CartsService.cartsControllerShippingAddresses,
99
+ onMutate: () => setLoading(true),
100
+ onSuccess: () => revalidateCart(),
101
+ onError: () => setLoading(false),
102
+ });
103
+
104
+ const updatePaymentMethod = useMutation({
105
+ mutationKey: [QueryKeys.cart.UPDATE_PAYMENT_METHOD],
106
+ mutationFn: ({
107
+ paymentMethodId,
108
+ paymentOptionId,
109
+ fromAssetSelectedPercentage,
110
+ }: {
111
+ paymentMethodId: number;
112
+ paymentOptionId: number;
113
+ fromAssetSelectedPercentage: number;
114
+ }) =>
115
+ CartsService.cartsControllerUpdatePaymentMethod({
116
+ paymentMethodId: paymentMethodId,
117
+ paymentOptionId: paymentOptionId,
118
+ fromAssetSelectedPercentage: fromAssetSelectedPercentage,
119
+ }),
120
+ onMutate: () => setLoading(true),
121
+ onSuccess: () => revalidateCart(),
122
+ onError: () => setLoading(false),
123
+ });
124
+
125
+ const deleteCart = useMutation({
126
+ mutationKey: [QueryKeys.cart.DELETE_CART],
127
+ mutationFn: CartsService.cartsControllerDeleteCart,
128
+ onMutate: () => setLoading(true),
129
+ onSuccess: () => {
130
+ revalidateCart();
131
+ },
132
+ onError: () => setLoading(false),
133
+ });
134
+
135
+ const refreshCart = useMutation({
136
+ mutationKey: [QueryKeys.cart.REFRESH_CART],
137
+ mutationFn: async (mode: string) => {
138
+ try {
139
+ await CartsService.cartsControllerValidateCart(mode);
140
+ return true;
141
+ } catch (error) {
142
+ console.log("🚀 ~ useCart ~ error:", error);
143
+ return false;
144
+ }
145
+ },
146
+ onMutate: () => setLoading(true),
147
+ onSuccess: () => revalidateCart(),
148
+ onError: () => setLoading(false),
149
+ });
150
+
151
+ const getShippingMethods = useMutation({
152
+ mutationKey: [QueryKeys.shippingCart.GET_SHIPPING_METHODS],
153
+ //#TODO Update with the Get shipping methods API for the new cart flow
154
+ mutationFn: () => ShippingMethodsService.shippingMethodControllerFindAll(),
155
+ onSuccess: async () => {},
156
+ onError: () => setLoading(false),
157
+ });
158
+
159
+ const getCountriesByShippingMethodId = useMutation({
160
+ mutationKey: [QueryKeys.upgradeCart.GET_COUNTRIES_BY_SHIPPING_METHOD],
161
+ retry: 5,
162
+ retryDelay: 1000,
163
+ mutationFn: ({ shippingMethodId }: { shippingMethodId: number }) =>
164
+ // proceedGetShippingCountriesAsync(shippingMethodId),
165
+ withTimeout(
166
+ CartsService.getCountriesByShippingMethod(shippingMethodId),
167
+ 3000, // 3 seconds timeout
168
+ ),
169
+
170
+ onSuccess: (data: any) => {
171
+ setShippingCountries(data);
172
+ },
173
+ onError: (error: any) => {
174
+ console.log("🚀 ~ useMigrationCart ~ error:", error);
175
+ },
176
+ });
177
+
178
+ const resetCartAddress = useMutation({
179
+ mutationKey: [QueryKeys.cart.RESET_CART_ADDRESS],
180
+ mutationFn: (type: string) => CartsService.resetCartAddresses(type),
181
+ onMutate: () => setLoading(true),
182
+ onSuccess: async () => {
183
+ revalidateCart();
184
+ },
185
+
186
+ onError: () => setLoading(false),
187
+ });
188
+
189
+ return {
190
+ cart,
191
+ getCart,
192
+ addToCart,
193
+ deleteCart,
194
+ updateCartState,
195
+ // deleteFromCart,
196
+ updateCartAddresses: updateCartAddresses,
197
+ updateCartShippingAddresses: updateCartShippingAddresses,
198
+ resetCartAddress: resetCartAddress,
199
+ updatePaymentMethod,
200
+ removeProductFromCart,
201
+ commissionNonEligibleFound,
202
+ removeProductsFromCart,
203
+ refreshCart,
204
+ getShippingMethods,
205
+ getCountriesByShippingMethodId,
206
+ };
207
+ }
@@ -0,0 +1,45 @@
1
+ import { useCallback } from "react";
2
+
3
+ import { notification } from "../utils/notifications.util";
4
+
5
+ const useCopy = () => {
6
+ const handleCopy = useCallback((text: string) => {
7
+ if (
8
+ typeof window !== "undefined" &&
9
+ navigator.clipboard &&
10
+ navigator.clipboard.writeText
11
+ ) {
12
+ navigator.clipboard
13
+ .writeText(text)
14
+ .then(() => {
15
+ notification.notifySuccess("Copied to clipboard!");
16
+ })
17
+ .catch(() => {
18
+ notification.notifyError("Failed to copy text");
19
+ });
20
+ } else {
21
+ // Fallback for environments without clipboard API
22
+ try {
23
+ const textArea = document.createElement("textarea");
24
+ textArea.value = text;
25
+ textArea.style.position = "fixed"; // Prevent scrolling to bottom of page
26
+ textArea.style.opacity = "0"; // Hide the element
27
+ document.body.appendChild(textArea);
28
+ textArea.select();
29
+ document.execCommand("copy");
30
+ document.body.removeChild(textArea);
31
+
32
+ notification.notifySuccess("Copied to clipboard!");
33
+ } catch (err) {
34
+ console.log("🚀 ~ useCopy ~ err:", err);
35
+ notification.notifyError("Failed to copy text");
36
+ }
37
+ }
38
+ }, []);
39
+
40
+ return {
41
+ handleCopy,
42
+ };
43
+ };
44
+
45
+ export default useCopy;
@@ -0,0 +1,27 @@
1
+ import { useQuery } from "@tanstack/react-query";
2
+ import { useEffect } from "react";
3
+
4
+ import { QueryKeys } from "../constants/query-keys";
5
+ import { AddressesService } from "../services/api";
6
+ import { countriesStore } from "../stores/countriesStore";
7
+
8
+ export function useCountries() {
9
+ //
10
+ const { countries, setCountries, setLoading } = countriesStore();
11
+
12
+ const { data: countriesData, refetch: getCountries } = useQuery({
13
+ queryKey: [QueryKeys.users.GET_COUNTRIES],
14
+ queryFn: AddressesService.addressesControllerGetCountries,
15
+ enabled: !countries,
16
+ });
17
+
18
+ useEffect(() => {
19
+ setCountries(countriesData);
20
+ setLoading(false);
21
+ // eslint-disable-next-line react-hooks/exhaustive-deps
22
+ }, [countriesData, setCountries]);
23
+
24
+ return {
25
+ getCountries,
26
+ };
27
+ }
@@ -0,0 +1,51 @@
1
+ import { NavigateOptions } from "next/dist/shared/lib/app-router-context.shared-runtime";
2
+ import { usePathname, useRouter } from "next/navigation";
3
+ import { useCallback } from "react";
4
+
5
+ import { useLoadingStore } from "../stores/loadingStore";
6
+
7
+ const useCustomRouter = () => {
8
+ //
9
+ const { setLoading } = useLoadingStore();
10
+ const { push, replace, refresh } = useRouter();
11
+ const pathname = usePathname();
12
+
13
+ const customPush = useCallback(
14
+ (link: string, options?: NavigateOptions | undefined) => {
15
+ if (pathname != link && !link.startsWith("http")) {
16
+ setLoading(true);
17
+
18
+ setTimeout(() => {
19
+ setLoading(false);
20
+ }, 5000);
21
+ }
22
+ push(link, options);
23
+ },
24
+ [push, pathname, setLoading],
25
+ );
26
+
27
+ const customReplace = useCallback(
28
+ (link: string, options?: NavigateOptions | undefined) => {
29
+ if (pathname != link && !link.startsWith("http")) {
30
+ setLoading(true);
31
+
32
+ setTimeout(() => {
33
+ setLoading(false);
34
+ }, 5000);
35
+ }
36
+ replace(link, options);
37
+ },
38
+ [replace, pathname, setLoading],
39
+ );
40
+
41
+ const customRouter = {
42
+ push: customPush,
43
+ replace: customReplace,
44
+ refresh,
45
+ pathname,
46
+ };
47
+
48
+ return customRouter;
49
+ };
50
+
51
+ export default useCustomRouter;
@@ -0,0 +1,21 @@
1
+ export default function useDebounce(func: any, delay: number) {
2
+ let timeoutId: NodeJS.Timeout | undefined = undefined;
3
+
4
+ return function (...args: any) {
5
+ clearTimeout(timeoutId);
6
+ timeoutId = setTimeout(() => {
7
+ func.apply(this, args);
8
+ }, delay);
9
+ };
10
+ }
11
+
12
+ let timeoutGlobalId: NodeJS.Timeout | undefined = undefined;
13
+
14
+ export function useGlobalDebounce(func: any, delay: number) {
15
+ return function (...args: any) {
16
+ clearTimeout(timeoutGlobalId);
17
+ timeoutGlobalId = setTimeout(() => {
18
+ func.apply(this, args);
19
+ }, delay);
20
+ };
21
+ }
@@ -0,0 +1,41 @@
1
+ import { useMutation } from "@tanstack/react-query";
2
+
3
+ import { QueryKeys } from "../constants/query-keys";
4
+ import { OrdersService, ShipmentOrdersService } from "../services/api";
5
+
6
+ export function useInvoice() {
7
+ //
8
+
9
+ const generateOrderInvoiceAPI = useMutation({
10
+ mutationKey: [QueryKeys.invoices.GENERATE_INVOICES],
11
+ mutationFn: ({ orderId }: { orderId: string }) =>
12
+ OrdersService.ordersControllerGetOrderInvoice(orderId),
13
+ // onMutate: () => setLoading(true),
14
+ onSuccess: async () => {},
15
+ onError: () => {},
16
+ });
17
+
18
+ const generateCreditNoteInvoiceAPI = useMutation({
19
+ mutationKey: [QueryKeys.invoices.GENERATE_INVOICES],
20
+ mutationFn: ({ creditNote, type }: { creditNote: string; type: string }) =>
21
+ OrdersService.ordersControllerGetCreditNoteInvoice(creditNote, type),
22
+ // onMutate: () => setLoading(true),
23
+ onSuccess: async () => {},
24
+ onError: () => {},
25
+ });
26
+
27
+ const generateShippingOrderInvoiceAPI = useMutation({
28
+ mutationKey: [QueryKeys.invoices.GENERATE_SHIPPING_INVOICES],
29
+ mutationFn: ({ orderId }: { orderId: string }) =>
30
+ ShipmentOrdersService.shippingOrdersControllerGetOrderInvoice(orderId),
31
+ // onMutate: () => setLoading(true),
32
+ onSuccess: async () => {},
33
+ onError: () => {},
34
+ });
35
+
36
+ return {
37
+ generateOrderInvoiceAPI,
38
+ generateShippingOrderInvoiceAPI,
39
+ generateCreditNoteInvoiceAPI,
40
+ };
41
+ }
@@ -0,0 +1,38 @@
1
+ import { useQuery } from "@tanstack/react-query";
2
+ import { useEffect, useState } from "react";
3
+
4
+ import { QueryKeys } from "../constants/query-keys";
5
+ import { UsersService } from "../services/api";
6
+ import { IUserProfile } from "../types/user";
7
+
8
+ const useOnlineUser = () => {
9
+ const [onlineUser, setOnlineUser] = useState<IUserProfile>();
10
+
11
+ const { data: onlineData, refetch: getUser } = useQuery({
12
+ queryKey: [QueryKeys.users.GET_USER],
13
+ queryFn: () => UsersService.usersControllerGetProfile(),
14
+ enabled: true,
15
+ });
16
+
17
+ const { refetch: getAletaAuth } = useQuery({
18
+ queryKey: ["ALETA_AUTH"],
19
+ queryFn: () => UsersService.paymentGatewayControllerGetProfile(),
20
+ enabled: false,
21
+ });
22
+
23
+ useEffect(() => {
24
+ (async () => await setOnlineUser(onlineData))();
25
+ }, [setOnlineUser, onlineData]);
26
+
27
+ useEffect(() => {
28
+ getUser();
29
+ }, [getUser]);
30
+
31
+ return {
32
+ onlineUser,
33
+ getUser,
34
+ getAletaAuth,
35
+ };
36
+ };
37
+
38
+ export default useOnlineUser;