@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,226 @@
1
+ import { Store } from "./order";
2
+ import { Commission } from "./payments";
3
+
4
+ export interface IUpgradeCart {
5
+ userBID: string;
6
+ reference: string;
7
+ cartProducts: any &
8
+ {
9
+ shippingItems: Array<
10
+ any & {
11
+ oneCareIncluded: boolean;
12
+ }
13
+ >;
14
+ }[];
15
+ billingAddressId: number | null;
16
+ shippingAddressId: number | null;
17
+ storeId: number | null;
18
+ paymentMethodId: number | null;
19
+ id: number;
20
+ cartState: string;
21
+ subTotal: string;
22
+ feesTotal: string;
23
+ shippingTotal?: string;
24
+ taxTotal: string;
25
+ grandTotal: string;
26
+ isActive: boolean;
27
+ createdAt: string;
28
+ updatedAt: string;
29
+ fees: Fee[];
30
+ taxes: Tax[];
31
+ cartAsset: CartAsset;
32
+ store?: Store;
33
+ cashBacks?: null | CashBack[];
34
+
35
+ commissionSubTotal: string;
36
+ oneCareTotal: string;
37
+ orderId: string;
38
+ pickupCostTotal: string;
39
+ shippingCartAssetId: string;
40
+ shippingMethodId: number;
41
+ shippingMethod: ShippingMethod;
42
+ shippingCostTotal: string;
43
+ upgradeCostTotal: string;
44
+ userSubscriptionType: string;
45
+ shippingAddress: UserAddress;
46
+ billingAddress: UserAddress;
47
+ isShippingApplicable?: boolean;
48
+ paymentMethod: {
49
+ code: string;
50
+ id: number;
51
+ name: string;
52
+ };
53
+
54
+ shippingCartAsset: CartAsset;
55
+ }
56
+
57
+ type ShippingMethod = {
58
+ code: string;
59
+ description: string;
60
+ displayName: string;
61
+ };
62
+ type CartAsset = {
63
+ id: number;
64
+ cartId: number;
65
+ assetOption: {
66
+ id: number;
67
+ name: string;
68
+ symbol: string;
69
+ isActive: boolean;
70
+ optionId: number;
71
+ provider: string;
72
+ createdAt: string;
73
+ deletedAt: string;
74
+ isDeleted: boolean;
75
+ updatedAt: string;
76
+ isVariable: boolean;
77
+ optionName: string;
78
+ displayOrder: number;
79
+ optionSymbol: string;
80
+ isAssetActive: boolean;
81
+ minPercentage: number;
82
+ optionIsActive: boolean;
83
+ paymentMethodId: number;
84
+ isCommissionEnabled: boolean;
85
+ commissionMultiplier: {
86
+ base: {
87
+ cv: number;
88
+ vp: number;
89
+ };
90
+ option: {
91
+ cv: number;
92
+ vp: number;
93
+ };
94
+ };
95
+ };
96
+ calculatedCommision: Commission;
97
+ baseAssetName: string;
98
+ baseAssetSymbol: string;
99
+ baseAssetAmount: number;
100
+ baseAssetPercentage: number;
101
+ optionAssetName: string;
102
+ optionAssetSymbol: string;
103
+ optionAssetAmount: number;
104
+ optionAssetPercentage: string;
105
+ createdAt: string;
106
+ updatedAt: string;
107
+ };
108
+ type Fee = {
109
+ amount: string;
110
+ cartId: number;
111
+ feeCategory: string;
112
+ feeName: string;
113
+ id: number;
114
+ type: string;
115
+ value: string;
116
+ };
117
+ type Tax = {
118
+ amount: string;
119
+ cartId: number;
120
+ id: number;
121
+ taxCategory: string;
122
+ taxName: string;
123
+ type: string;
124
+ value: string;
125
+ };
126
+
127
+ export type CashBack = {
128
+ id: number;
129
+ shippingCartId: number;
130
+ assetName: string;
131
+ assetSymbol: string;
132
+ cashbackAssetId: number;
133
+ totalAmount: string;
134
+ };
135
+
136
+ export type cartProduct = {
137
+ id: number;
138
+ sku: string;
139
+ name: string;
140
+ featureImage: string;
141
+ category: cartProductCategory;
142
+ price: number;
143
+ canProductBeRemoved: boolean;
144
+ canUserPurchaseTheProduct: boolean;
145
+ feedBackMessage: string;
146
+ maximumUserCanPurchase: number | null;
147
+ totalOrderExistsForProduct: number | null;
148
+ userPurchaseLimit: number | null;
149
+ };
150
+
151
+ export type cartProductCategory = {
152
+ id: number;
153
+ code: string;
154
+ name: string;
155
+ };
156
+
157
+ export type CartTableItemComponentProps = {
158
+ id: number;
159
+ product: cartProduct;
160
+ quantity: number;
161
+ cartProducts: number;
162
+ userPurchaseLimit: number | null;
163
+ maximumUserCanPurchase: number | null;
164
+ totalOrderExistsForProduct: number | null;
165
+ feedBackMessage: string;
166
+ canUserPurchaseTheProduct: boolean;
167
+ canProductBeRemoved: boolean;
168
+ };
169
+
170
+ export type BillingAddress = {
171
+ address: string;
172
+ buildingInfo: string;
173
+ city: string;
174
+ country: string;
175
+ countryId: number;
176
+ createdAt: string;
177
+ deletedAt: string;
178
+ id: number;
179
+ isActive: boolean;
180
+ isDefault: boolean;
181
+ isDeleted: boolean;
182
+ latitude: string;
183
+ longitude: string;
184
+ state: string;
185
+ type: string;
186
+ updatedAt: string;
187
+ userId: number;
188
+ };
189
+ export type UserAddress = {
190
+ id: number;
191
+ userBID: string;
192
+ firstName: string;
193
+ lastName: string;
194
+ phone: string;
195
+ email: string;
196
+ countryId: 3;
197
+ countryCode: string;
198
+ city: string;
199
+ state: string;
200
+ postalCode: string;
201
+ address: string;
202
+ buildingInfo: string;
203
+ latitude: string;
204
+ longitude: string;
205
+ type: string;
206
+ isDefault: boolean;
207
+ isActive: boolean;
208
+ isDeleted: boolean;
209
+ createdAt: string;
210
+ updatedAt: string;
211
+ deletedAt: string;
212
+ country: {
213
+ id: 3;
214
+ name: string;
215
+ code: string;
216
+ alphaCode: string;
217
+ callingCode: string;
218
+ zipCodeExists: boolean;
219
+ zipCodeRegex: string;
220
+ isActive: boolean;
221
+ isDeleted: boolean;
222
+ createdAt: string;
223
+ updatedAt: string;
224
+ deletedAt: string;
225
+ };
226
+ };
@@ -0,0 +1,36 @@
1
+ import { KYC_STATUS } from "../constants/app";
2
+
3
+ export interface IUserProfile {
4
+ id: number;
5
+ bid: string;
6
+ email: string;
7
+ userName: string;
8
+ firstName: string;
9
+ lastName: string;
10
+ phone: string;
11
+ activeMembership: boolean;
12
+ walletConsentConfirmed: boolean;
13
+ originType: string;
14
+ subscriptionType: string | null;
15
+ accountType: string;
16
+ membershipExpiryDate: string | null;
17
+ picture: string;
18
+ pgUser: {
19
+ clientUserId: string;
20
+ status: KycStatus;
21
+ aletaHomnifiConsent: boolean;
22
+ aletaHomnifiConsentDate: string;
23
+ aletaState: KycStatus;
24
+ createdAt: string;
25
+ updatedAt: string;
26
+ };
27
+ subscriptionActivationPending?: boolean;
28
+ }
29
+
30
+ export interface DecodedToken {
31
+ exp: number;
32
+ iat: number;
33
+ [key: string]: any;
34
+ }
35
+
36
+ export type KycStatus = (typeof KYC_STATUS)[keyof typeof KYC_STATUS];
@@ -0,0 +1,261 @@
1
+ import React from "react";
2
+
3
+ import { CATEGORY_FOR_AI_COMPUTING } from "../constants/app";
4
+ import { DecodedToken } from "../types/user";
5
+
6
+ export const timeUntilDate = (targetDateString: string | null): string => {
7
+ if (!targetDateString) {
8
+ return "N/A";
9
+ }
10
+ const targetDate = new Date(targetDateString);
11
+ const currentDate = new Date();
12
+
13
+ let years = targetDate.getFullYear() - currentDate.getFullYear();
14
+ let months = targetDate.getMonth() - currentDate.getMonth();
15
+ let days = targetDate.getDate() - currentDate.getDate();
16
+
17
+ if (days < 0) {
18
+ months--;
19
+ days += new Date(
20
+ currentDate.getFullYear(),
21
+ currentDate.getMonth() + 1,
22
+ 0,
23
+ ).getDate();
24
+ }
25
+
26
+ if (months < 0) {
27
+ years--;
28
+ months += 12;
29
+ }
30
+
31
+ let timeRemaining: string;
32
+
33
+ if (years > 0) {
34
+ timeRemaining = `${years} year${years > 1 ? "s" : ""}`;
35
+ } else if (months > 0) {
36
+ timeRemaining = `${months} month${months > 1 ? "s" : ""}`;
37
+ } else if (days < 30) {
38
+ timeRemaining = `${days} day${days > 1 ? "s" : ""}`;
39
+ } else {
40
+ timeRemaining = "";
41
+ }
42
+
43
+ return timeRemaining
44
+ ? `in ${timeRemaining} (${targetDate.toLocaleDateString()})`
45
+ : "Date has passed";
46
+ };
47
+
48
+ export const handleDownload = async (
49
+ invoiceUrl: string,
50
+ orderId: string,
51
+ prefix: string = "INV",
52
+ ) => {
53
+ try {
54
+ const response = await fetch(invoiceUrl);
55
+
56
+ const blob = await response.blob();
57
+
58
+ const url = window.URL.createObjectURL(blob);
59
+
60
+ const link = document.createElement("a");
61
+ link.href = url;
62
+ link.download = `${prefix}_${orderId}.pdf`;
63
+
64
+ document.body.appendChild(link);
65
+ link.click();
66
+ document.body.removeChild(link);
67
+
68
+ window.URL.revokeObjectURL(url);
69
+ } catch (error) {
70
+ console.error("Download failed:", error);
71
+ }
72
+ };
73
+
74
+ export const displayExactWalletBalance = (balance: string) => {
75
+ const data = balance.split(".");
76
+ if (!data?.[1]) return data[0];
77
+
78
+ return data[0] + "." + data[1].substring(0, 5);
79
+ };
80
+
81
+ export const customGroupBy = (
82
+ objectArray: any[],
83
+ key: any,
84
+ arrayValue: boolean = true,
85
+ ) => {
86
+ return objectArray.reduce((result, item) => {
87
+ const groupKey = typeof key === "function" ? key(item) : item[key];
88
+ if (!result[groupKey]) {
89
+ result[groupKey] = [];
90
+ }
91
+ if (arrayValue) {
92
+ result[groupKey].push(item);
93
+ } else {
94
+ result[groupKey] = item;
95
+ }
96
+
97
+ return result;
98
+ }, {});
99
+ };
100
+
101
+ export const replaceForbiddenKeyword = (input: string): string => {
102
+ return input.replace(/minter/gi, "Computer Device");
103
+ };
104
+ export const replaceComputerDevice = (input: string): string => {
105
+ return input.replace(/computer device/gi, "minter");
106
+ };
107
+
108
+ /**
109
+ * Function to check if any items in the data have a category code of "minter"
110
+ * @param {Array} orderItems - Array of order items to check
111
+ * @return {Boolean} - Returns true if any item has category code "minter", otherwise false
112
+ */
113
+ export const hasMinterCategory = (orderItems) => {
114
+ const MINTER = "minter";
115
+ const SMART_PAY = "smart-pay";
116
+
117
+ // Check if orderItems is valid
118
+ if (!Array.isArray(orderItems) || orderItems.length === 0) {
119
+ console.log("No items to check or invalid data format");
120
+ return false;
121
+ }
122
+
123
+ // Check each item for category code "minter"
124
+ for (const item of orderItems) {
125
+ // Case 1: Direct categoryCode property (first data structure)
126
+ if (item.categoryCode === MINTER || item.categoryCode === SMART_PAY) {
127
+ return true;
128
+ }
129
+
130
+ // Case 2: Nested product.category.code (second data structure)
131
+ if (
132
+ (item.product &&
133
+ item.product.category &&
134
+ item?.product?.category?.code === MINTER) ||
135
+ item?.product?.category?.code === SMART_PAY
136
+ ) {
137
+ return true;
138
+ }
139
+
140
+ // Also check in kitData if it exists (for first data structure)
141
+ if (Array.isArray(item.kitData) && item.kitData.length > 0) {
142
+ for (const kitItem of item.kitData) {
143
+ if (
144
+ kitItem.categoryCode === MINTER ||
145
+ kitItem.categoryCode === SMART_PAY
146
+ ) {
147
+ return true;
148
+ }
149
+ }
150
+ }
151
+ }
152
+
153
+ // No minter category found
154
+ return false;
155
+ };
156
+
157
+ export const hasAICategory = (orderItems) => {
158
+ // Check if orderItems is valid
159
+ if (!Array.isArray(orderItems) || orderItems.length === 0) {
160
+ console.log("No items to check or invalid data format");
161
+ return false;
162
+ }
163
+
164
+ // Check each item for category code "minter"
165
+ for (const item of orderItems) {
166
+ // Case 1: Direct categoryCode property (first data structure)
167
+ if (item.categoryCode === CATEGORY_FOR_AI_COMPUTING) {
168
+ return true;
169
+ }
170
+
171
+ // Case 2: Nested product.category.code (second data structure)
172
+ if (
173
+ item.product &&
174
+ item.product.category &&
175
+ item?.product?.category?.code === CATEGORY_FOR_AI_COMPUTING
176
+ ) {
177
+ return true;
178
+ }
179
+
180
+ // Also check in kitData if it exists (for first data structure)
181
+ if (Array.isArray(item.kitData) && item.kitData.length > 0) {
182
+ for (const kitItem of item.kitData) {
183
+ if (kitItem.categoryCode === CATEGORY_FOR_AI_COMPUTING) {
184
+ return true;
185
+ }
186
+ }
187
+ }
188
+ }
189
+
190
+ // No minter category found
191
+ return false;
192
+ };
193
+
194
+ export const truncateString = (
195
+ str: string,
196
+ startLength: number = 5,
197
+ endLength: number = 3,
198
+ ): string => {
199
+ if (str.length <= startLength + endLength) {
200
+ return str;
201
+ }
202
+
203
+ return (
204
+ str.substring(0, startLength) +
205
+ "..." +
206
+ str.substring(str.length - endLength)
207
+ );
208
+ };
209
+
210
+ export const decodeJwt = (token: string): DecodedToken | null => {
211
+ try {
212
+ const base64Url = token.split(".")[1];
213
+ const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
214
+ const jsonPayload = decodeURIComponent(
215
+ atob(base64)
216
+ .split("")
217
+ .map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2))
218
+ .join(""),
219
+ );
220
+ return JSON.parse(jsonPayload);
221
+ } catch (error) {
222
+ console.error("Error decoding JWT:", error);
223
+ return null;
224
+ }
225
+ };
226
+
227
+ export function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
228
+ return new Promise((resolve, reject) => {
229
+ const timeout = setTimeout(() => {
230
+ reject(new Error(`Request timed out after ${ms}ms`));
231
+ }, ms);
232
+
233
+ promise
234
+ .then((res) => {
235
+ clearTimeout(timeout);
236
+ resolve(res);
237
+ })
238
+ .catch((err) => {
239
+ clearTimeout(timeout);
240
+ reject(err);
241
+ });
242
+ });
243
+ }
244
+
245
+ /**
246
+ * Renders a title with red asterisk if the title contains " *"
247
+ * @param {string} title - The title string that may contain an asterisk
248
+ * @returns {React.ReactNode} - JSX element with the title and red asterisk if present
249
+ */
250
+ export const renderTitleWithRedAsterisk = (title: string): React.ReactNode => {
251
+ if (title.includes(" *")) {
252
+ const parts = title.split(" *");
253
+ return React.createElement(
254
+ React.Fragment,
255
+ null,
256
+ parts[0],
257
+ React.createElement("span", { className: "text-red-500" }, " *"),
258
+ );
259
+ }
260
+ return title;
261
+ };
@@ -0,0 +1,39 @@
1
+ import { toast, ToastContent, ToastOptions } from "react-toastify";
2
+
3
+ import { ApiResponseDto } from "../types";
4
+
5
+ const defaultOptions: ToastOptions = {
6
+ position: "bottom-right",
7
+ autoClose: 1000,
8
+ hideProgressBar: false,
9
+ closeOnClick: true,
10
+ pauseOnHover: true,
11
+ };
12
+
13
+ const notifySuccess = (content: ToastContent) => {
14
+ return toast.success(content ?? "Wow so easy!", defaultOptions);
15
+ };
16
+
17
+ const notifyError = (content: ToastContent) =>
18
+ toast.error(content ?? "Wow so easy!", defaultOptions);
19
+
20
+ const notifyWarning = (content: ToastContent) =>
21
+ toast.warning(content ?? "Wow so easy!", defaultOptions);
22
+
23
+ const apiNotify = <T>(data: ApiResponseDto<T | any>) => {
24
+ if (data?.status) {
25
+ const message = data?.data?.message ?? data.message;
26
+ notifySuccess(message);
27
+ } else if (data?.statusCode == 4040) {
28
+ notifyError("Please verify your internet connection");
29
+ } else {
30
+ notifyError(data?.msg ?? data?.message ?? "");
31
+ }
32
+ };
33
+
34
+ export const notification = {
35
+ apiNotify,
36
+ notifySuccess,
37
+ notifyError,
38
+ notifyWarning,
39
+ };