@mx-cartographer/experiences 4.0.13 → 4.0.14-alpha.JB1

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 (513) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/debts/components/SnowballCard.d.ts +3 -1
  3. package/dist/debts/components/SnowballDrawer.d.ts +9 -0
  4. package/dist/index.es.js +3905 -3522
  5. package/dist/index.es.js.map +1 -1
  6. package/package.json +23 -3
  7. package/src/accounts/AccountsMiniWidget.tsx +62 -0
  8. package/src/accounts/AccountsWidget.tsx +93 -0
  9. package/src/accounts/ConnectMiniWidget.tsx +36 -0
  10. package/src/accounts/__tests__/Accounts.test.tsx +561 -0
  11. package/src/accounts/api/AccountApi.ts +74 -0
  12. package/src/accounts/api/__mocks__/AccountApi.ts +46 -0
  13. package/src/accounts/components/AccountListItem.tsx +102 -0
  14. package/src/accounts/components/AccountsList.tsx +133 -0
  15. package/src/accounts/components/ConnectImage.tsx +314 -0
  16. package/src/accounts/components/ConnectMiniWidgetCard.tsx +41 -0
  17. package/src/accounts/components/ConnectStatus.tsx +44 -0
  18. package/src/accounts/components/ConnectionStatusIcons.tsx +26 -0
  19. package/src/accounts/components/ConnectionsDrawer.tsx +84 -0
  20. package/src/accounts/components/detailsdrawer/Accounts/AccountActions.tsx +177 -0
  21. package/src/accounts/components/detailsdrawer/Accounts/AccountActionsRow.tsx +33 -0
  22. package/src/accounts/components/detailsdrawer/Accounts/AccountConnection.tsx +139 -0
  23. package/src/accounts/components/detailsdrawer/Accounts/AccountDetailEdit.tsx +162 -0
  24. package/src/accounts/components/detailsdrawer/Accounts/AccountDetails.tsx +98 -0
  25. package/src/accounts/components/detailsdrawer/Accounts/AccountDetailsChart.tsx +63 -0
  26. package/src/accounts/components/detailsdrawer/Accounts/AccountDetailsContent.tsx +52 -0
  27. package/src/accounts/components/detailsdrawer/Accounts/AccountDetailsHeader.tsx +71 -0
  28. package/src/accounts/components/detailsdrawer/Accounts/AccountDetailsTab.tsx +25 -0
  29. package/src/accounts/components/detailsdrawer/Accounts/ConnectionErrorMessage.tsx +99 -0
  30. package/src/accounts/components/detailsdrawer/Transactions/TransactionsTab.tsx +51 -0
  31. package/src/accounts/constants/Accounts.ts +11 -0
  32. package/src/accounts/hooks/useGetMergeableAccounts.tsx +13 -0
  33. package/src/accounts/hooks/useUiStore.ts +12 -0
  34. package/src/accounts/index.ts +8 -0
  35. package/src/accounts/stores/AccountStore.ts +220 -0
  36. package/src/accounts/stores/UiStore.ts +18 -0
  37. package/src/accounts/stores/__tests__/AccountStore.test.ts +204 -0
  38. package/src/accounts/utils/AccountFields.tsx +248 -0
  39. package/src/accounts/utils/Accounts.ts +28 -0
  40. package/src/accounts/utils/__tests__/AccountFieldsUtils.test.tsx +215 -0
  41. package/src/accounts/utils/__tests__/AccountsUtils.test.tsx +104 -0
  42. package/src/accounts/utils/getConnectionMessages.tsx +198 -0
  43. package/src/accounts/utils/index.ts +1 -0
  44. package/src/budgets/BubbleBudgetsMiniWidget.tsx +57 -0
  45. package/src/budgets/BubbleBudgetsWidget.tsx +154 -0
  46. package/src/budgets/__tests__/BubbleBudgetsWidget.test.tsx +40 -0
  47. package/src/budgets/__tests__/BudgetList.test.tsx +38 -0
  48. package/src/budgets/__tests__/BudgetsStore.test.tsx +48 -0
  49. package/src/budgets/__tests__/Overview.test.tsx +38 -0
  50. package/src/budgets/api/BudgetsApi.ts +43 -0
  51. package/src/budgets/api/__mocks__/BudgetsApi.ts +7 -0
  52. package/src/budgets/components/AddBudgets.tsx +50 -0
  53. package/src/budgets/components/BubbleBudgets.tsx +73 -0
  54. package/src/budgets/components/BubbleChart.tsx +50 -0
  55. package/src/budgets/components/BudgetDetailsDrawer.tsx +134 -0
  56. package/src/budgets/components/BudgetList.tsx +50 -0
  57. package/src/budgets/components/Overview.tsx +156 -0
  58. package/src/budgets/components/ZeroState.tsx +23 -0
  59. package/src/budgets/components/addbudget/Header.tsx +59 -0
  60. package/src/budgets/components/addbudget/RecalculateBudgetRow.tsx +53 -0
  61. package/src/budgets/components/addbudget/RecalculateBudgets.tsx +69 -0
  62. package/src/budgets/components/addbudget/UnbudgetedRow.tsx +57 -0
  63. package/src/budgets/components/bubblechart/Bubble.tsx +148 -0
  64. package/src/budgets/components/bubblechart/Mercury.tsx +57 -0
  65. package/src/budgets/components/budgetdetails/AddSubBudget.tsx +111 -0
  66. package/src/budgets/components/budgetdetails/BudgetDetails.tsx +93 -0
  67. package/src/budgets/components/budgetdetails/Header.tsx +48 -0
  68. package/src/budgets/components/budgetdetails/SubBudgetList.tsx +148 -0
  69. package/src/budgets/components/budgetlist/BudgetRow.tsx +63 -0
  70. package/src/budgets/components/budgetlist/SubBudgetRow.tsx +64 -0
  71. package/src/budgets/components/budgetlist/SubBudgetZeroState.tsx +22 -0
  72. package/src/budgets/components/shared/BudgetAmount.tsx +54 -0
  73. package/src/budgets/index.ts +2 -0
  74. package/src/budgets/store/BudgetsStore.ts +183 -0
  75. package/src/budgets/utils/BubblesSVG.ts +142 -0
  76. package/src/budgets/utils/BudgetUtil.ts +140 -0
  77. package/src/cashflow/CashflowMiniWidget.tsx +25 -0
  78. package/src/cashflow/CashflowOnboarding.tsx +298 -0
  79. package/src/cashflow/CashflowWidget.tsx +111 -0
  80. package/src/cashflow/api/CashflowApi.ts +62 -0
  81. package/src/cashflow/api/__mocks__/CashflowApi.ts +15 -0
  82. package/src/cashflow/components/CashflowAmountHeading.tsx +46 -0
  83. package/src/cashflow/components/CashflowContent.tsx +63 -0
  84. package/src/cashflow/components/CashflowHeading.tsx +172 -0
  85. package/src/cashflow/components/CashflowWidgetContent.tsx +225 -0
  86. package/src/cashflow/components/DetailsExpenseHeader.tsx +47 -0
  87. package/src/cashflow/components/DetailsExpenseRow.tsx +46 -0
  88. package/src/cashflow/components/DetailsFooter.tsx +28 -0
  89. package/src/cashflow/components/DetailsTab.tsx +128 -0
  90. package/src/cashflow/components/RemainingCash.tsx +44 -0
  91. package/src/cashflow/components/SummaryTab.tsx +247 -0
  92. package/src/cashflow/components/onboarding/StepOne.tsx +90 -0
  93. package/src/cashflow/components/onboarding/StepTwo.tsx +23 -0
  94. package/src/cashflow/context/hooks.tsx +12 -0
  95. package/src/cashflow/images/cashflow-onboarding.png +0 -0
  96. package/src/cashflow/images/loading-animation.gif +0 -0
  97. package/src/cashflow/index.ts +5 -0
  98. package/src/cashflow/stores/CashflowStore.ts +26 -0
  99. package/src/cashflow/stores/UiStore.ts +48 -0
  100. package/src/cashflow/stores/__tests__/CashflowStore.test.ts +16 -0
  101. package/src/cashflow/util/Filters.ts +15 -0
  102. package/src/categories/components/CategoryList.tsx +64 -0
  103. package/src/categories/components/CategoryRow.tsx +68 -0
  104. package/src/categories/components/CategorySelector.tsx +80 -0
  105. package/src/categories/components/CategorySelectorDrawer.tsx +41 -0
  106. package/src/categories/components/CustomCategories/AddSubcategory.tsx +65 -0
  107. package/src/categories/components/CustomCategories/CustomCategoryModal.tsx +99 -0
  108. package/src/categories/components/CustomCategories/DeleteSubcategory.tsx +49 -0
  109. package/src/categories/components/CustomCategories/RenameSubcategory.tsx +48 -0
  110. package/src/categories/components/CustomCategories/index.ts +4 -0
  111. package/src/categories/components/SubcategoryList.tsx +47 -0
  112. package/src/categories/components/SubcategoryRow.tsx +123 -0
  113. package/src/categories/constants/Analytics.ts +89 -0
  114. package/src/categories/constants/OnClickEvents.ts +13 -0
  115. package/src/categories/context/hooks.ts +12 -0
  116. package/src/categories/index.ts +5 -0
  117. package/src/categories/stores/CategoryStore.ts +184 -0
  118. package/src/categories/stores/UiStore.ts +36 -0
  119. package/src/categories/stores/__tests__/CategoryStore.test.ts +54 -0
  120. package/src/categories/util/CategoryUtil.ts +136 -0
  121. package/src/common/api/AnalyticsApi.ts +49 -0
  122. package/src/common/api/BeatApi.ts +32 -0
  123. package/src/common/api/CategoryApi.ts +52 -0
  124. package/src/common/api/GlobalCopyApi.ts +17 -0
  125. package/src/common/api/LocalizedCopyApi.ts +21 -0
  126. package/src/common/api/NotificationApi.ts +40 -0
  127. package/src/common/api/ScheduledPaymentsApi.ts +37 -0
  128. package/src/common/api/UserApi.ts +23 -0
  129. package/src/common/api/WidgetApi.ts +15 -0
  130. package/src/common/api/__mocks__/BeatApi.ts +8 -0
  131. package/src/common/api/__mocks__/CategoryApi.ts +15 -0
  132. package/src/common/api/__mocks__/GlobalCopyApi.ts +7 -0
  133. package/src/common/api/__mocks__/NotificationApi.ts +11 -0
  134. package/src/common/api/__mocks__/ScheduledPaymentsApi.ts +7 -0
  135. package/src/common/api/__mocks__/UserApi.ts +9 -0
  136. package/src/common/api/__mocks__/WidgetApi.ts +11 -0
  137. package/src/common/api/index.ts +9 -0
  138. package/src/common/components/ConnectDrawer.tsx +87 -0
  139. package/src/common/components/CurrencyInput.tsx +147 -0
  140. package/src/common/components/CurrencyText.tsx +44 -0
  141. package/src/common/components/DataRow.tsx +52 -0
  142. package/src/common/components/IconBacking.tsx +41 -0
  143. package/src/common/components/InformationTooltip.tsx +52 -0
  144. package/src/common/components/ListItemWrapper.tsx +49 -0
  145. package/src/common/components/Loader.tsx +24 -0
  146. package/src/common/components/MiniWidgetContainer.tsx +64 -0
  147. package/src/common/components/ResponsiveButton.tsx +65 -0
  148. package/src/common/components/SearchBox.tsx +64 -0
  149. package/src/common/components/SelectionBox.tsx +64 -0
  150. package/src/common/components/SubheaderRow.tsx +22 -0
  151. package/src/common/components/TabContentContainer.tsx +28 -0
  152. package/src/common/components/WidgetContainer.tsx +239 -0
  153. package/src/common/components/accountfilter/AccountFilter.tsx +133 -0
  154. package/src/common/components/accountfilter/AccountFilterOptions.tsx +263 -0
  155. package/src/common/components/accountfilter/index.ts +1 -0
  156. package/src/common/components/barchart/Bar.tsx +123 -0
  157. package/src/common/components/barchart/BarChart.tsx +136 -0
  158. package/src/common/components/barchart/BarColumn.tsx +150 -0
  159. package/src/common/components/barchart/Legend.tsx +60 -0
  160. package/src/common/components/barchart/Util.ts +54 -0
  161. package/src/common/components/barchart/__tests__/BarChart.test.tsx +46 -0
  162. package/src/common/components/barchart/index.ts +1 -0
  163. package/src/common/components/calendar/Calendar.tsx +223 -0
  164. package/src/common/components/calendar/Day.tsx +127 -0
  165. package/src/common/components/calendar/Header.tsx +58 -0
  166. package/src/common/components/calendar/__tests__/Calendar.test.tsx +50 -0
  167. package/src/common/components/calendar/index.ts +1 -0
  168. package/src/common/components/calendar/upcomingActivity/CalendarIcons.tsx +40 -0
  169. package/src/common/components/charts/Donut.tsx +82 -0
  170. package/src/common/components/charts/LineChart.tsx +204 -0
  171. package/src/common/components/charts/StackedLineChart.tsx +292 -0
  172. package/src/common/components/charts/StatusBar.tsx +41 -0
  173. package/src/common/components/charts/index.ts +4 -0
  174. package/src/common/components/charts/linechart/CustomLegend.tsx +49 -0
  175. package/src/common/components/charts/linechart/CustomLine.tsx +31 -0
  176. package/src/common/components/charts/linechart/CustomMark.tsx +68 -0
  177. package/src/common/components/charts/stackedlinechart/CategoryIconLabel.tsx +29 -0
  178. package/src/common/components/charts/stackedlinechart/CustomAreaTooltip.tsx +115 -0
  179. package/src/common/components/charts/stackedlinechart/CustomLegend.tsx +73 -0
  180. package/src/common/components/charts/stackedlinechart/CustomPointTooltip.tsx +41 -0
  181. package/src/common/components/charts/stackedlinechart/utils.ts +13 -0
  182. package/src/common/components/daterangeselector/DateRangeSelector.tsx +383 -0
  183. package/src/common/components/daterangeselector/index.ts +1 -0
  184. package/src/common/components/dialog/Dialog.tsx +92 -0
  185. package/src/common/components/dialog/index.ts +1 -0
  186. package/src/common/components/donuts/MultiSegmentDonut.tsx +89 -0
  187. package/src/common/components/donuts/SingleSegmentDonut.tsx +75 -0
  188. package/src/common/components/donuts/index.ts +2 -0
  189. package/src/common/components/drawer/Drawer.tsx +97 -0
  190. package/src/common/components/drawer/Header.tsx +64 -0
  191. package/src/common/components/drawer/index.ts +1 -0
  192. package/src/common/components/index.ts +22 -0
  193. package/src/common/constants/Account.ts +30 -0
  194. package/src/common/constants/Analytics.ts +70 -0
  195. package/src/common/constants/ApiEndpoints.ts +30 -0
  196. package/src/common/constants/Category.ts +302 -0
  197. package/src/common/constants/Connect.ts +2 -0
  198. package/src/common/constants/DateFormats.ts +122 -0
  199. package/src/common/constants/Donut.ts +2 -0
  200. package/src/common/constants/Numbers.ts +6 -0
  201. package/src/common/constants/ScheduledPayment.ts +21 -0
  202. package/src/common/constants/Sizes.ts +7 -0
  203. package/src/common/constants/SpendingPlan.ts +17 -0
  204. package/src/common/constants/Table.ts +13 -0
  205. package/src/common/constants/index.ts +21 -0
  206. package/src/common/context/GlobalDataProvider.tsx +31 -0
  207. package/src/common/context/WidgetContainerProvider.tsx +24 -0
  208. package/src/common/context/__mocks__/GlobalDataProvider.tsx +25 -0
  209. package/src/common/context/hooks.tsx +57 -0
  210. package/src/common/context/index.ts +22 -0
  211. package/src/common/hooks/__tests__/useDimensions.test.tsx +190 -0
  212. package/src/common/hooks/index.ts +3 -0
  213. package/src/common/hooks/useCombineEvents.tsx +53 -0
  214. package/src/common/hooks/useDimensions.tsx +78 -0
  215. package/src/common/hooks/usePrevious.tsx +10 -0
  216. package/src/common/hooks/useScreenSize.tsx +15 -0
  217. package/src/common/index.ts +23 -0
  218. package/src/common/stores/ConnectStore.ts +26 -0
  219. package/src/common/stores/GlobalCopyStore.ts +36 -0
  220. package/src/common/stores/GlobalStore.ts +83 -0
  221. package/src/common/stores/GlobalUiStore.ts +66 -0
  222. package/src/common/stores/UserStore.ts +45 -0
  223. package/src/common/stores/__tests__/GlobalCopyStore.test.ts +23 -0
  224. package/src/common/stores/__tests__/GlobalStore.test.ts +24 -0
  225. package/src/common/stores/index.ts +3 -0
  226. package/src/common/types/Account.ts +406 -0
  227. package/src/common/types/Activity.ts +31 -0
  228. package/src/common/types/Analytics.ts +70 -0
  229. package/src/common/types/Beat.ts +71 -0
  230. package/src/common/types/Budget.ts +29 -0
  231. package/src/common/types/Cashflow.ts +110 -0
  232. package/src/common/types/Category.ts +68 -0
  233. package/src/common/types/Date.ts +2 -0
  234. package/src/common/types/Debt.ts +19 -0
  235. package/src/common/types/Expense.ts +20 -0
  236. package/src/common/types/Global.ts +13 -0
  237. package/src/common/types/GlobalCopy.ts +37 -0
  238. package/src/common/types/Goal.ts +59 -0
  239. package/src/common/types/Institution.ts +11 -0
  240. package/src/common/types/LocalizedContent.ts +9 -0
  241. package/src/common/types/Merchant.ts +6 -0
  242. package/src/common/types/Notification.ts +15 -0
  243. package/src/common/types/ScheduledPayment.ts +15 -0
  244. package/src/common/types/ScreenSize.tsx +4 -0
  245. package/src/common/types/SpendingPlan.ts +48 -0
  246. package/src/common/types/Transaction.ts +91 -0
  247. package/src/common/types/User.ts +20 -0
  248. package/src/common/types/Widgets.ts +11 -0
  249. package/src/common/types/index.ts +93 -0
  250. package/src/common/types/localization/AccountFilterCopy.ts +12 -0
  251. package/src/common/types/localization/AccountTypeCopy.ts +16 -0
  252. package/src/common/types/localization/AccountsCopy.ts +113 -0
  253. package/src/common/types/localization/BudgetsCopy.ts +52 -0
  254. package/src/common/types/localization/CashflowCopy.ts +77 -0
  255. package/src/common/types/localization/CategoryCopy.ts +18 -0
  256. package/src/common/types/localization/CommonCopy.ts +30 -0
  257. package/src/common/types/localization/ConnectCopy.ts +74 -0
  258. package/src/common/types/localization/CurrencyInputCopy.ts +6 -0
  259. package/src/common/types/localization/DateRangePickerCopy.ts +23 -0
  260. package/src/common/types/localization/GoalsCopy.ts +37 -0
  261. package/src/common/types/localization/InsightsFeedCopy.ts +26 -0
  262. package/src/common/types/localization/MicroInsightsCopy.ts +28 -0
  263. package/src/common/types/localization/NetWorthCopy.ts +14 -0
  264. package/src/common/types/localization/NotificationsCopy.ts +7 -0
  265. package/src/common/types/localization/RecurringCopy.ts +76 -0
  266. package/src/common/types/localization/SpendingCopy.ts +16 -0
  267. package/src/common/types/localization/TransactionsCopy.ts +81 -0
  268. package/src/common/types/localization/TrendsCopy.ts +10 -0
  269. package/src/common/types/localization/index.ts +19 -0
  270. package/src/common/utils/AccountFilter.ts +45 -0
  271. package/src/common/utils/Analytics.ts +51 -0
  272. package/src/common/utils/Categories.ts +75 -0
  273. package/src/common/utils/DateUtil.ts +67 -0
  274. package/src/common/utils/Fetch.ts +115 -0
  275. package/src/common/utils/Localization.ts +67 -0
  276. package/src/common/utils/NumberFormatting.ts +65 -0
  277. package/src/common/utils/__tests__/Fetch.test.tsx +34 -0
  278. package/src/common/utils/index.ts +18 -0
  279. package/src/dashboard/Dashboard.tsx +92 -0
  280. package/src/dashboard/Greeting.tsx +75 -0
  281. package/src/dashboard/__tests__/Dashboard.test.tsx +84 -0
  282. package/src/dashboard/constants/Dashboard.ts +4 -0
  283. package/src/dashboard/index.ts +3 -0
  284. package/src/dashboard/types/DashboardTypes.ts +9 -0
  285. package/src/debts/DebtsWidget.tsx +90 -0
  286. package/src/debts/components/DebtsChart.tsx +190 -0
  287. package/src/debts/components/DebtsTable.tsx +209 -0
  288. package/src/debts/components/SnowballCard.tsx +70 -0
  289. package/src/debts/components/SnowballDrawer.tsx +384 -0
  290. package/src/debts/components/debtstable/AccountCell.tsx +25 -0
  291. package/src/debts/components/debtstable/PriorityCell.tsx +46 -0
  292. package/src/debts/index.ts +4 -0
  293. package/src/debts/store/DebtsStore.ts +20 -0
  294. package/src/debts/utils/DebtStore.ts +75 -0
  295. package/src/debts/utils/DebtsWidget.ts +32 -0
  296. package/src/debts/utils/SnowballCard.tsx +48 -0
  297. package/src/goals/GoalsWidget.tsx +128 -0
  298. package/src/goals/api/GoalApi.ts +29 -0
  299. package/src/goals/components/GoalDetails.tsx +240 -0
  300. package/src/goals/components/GoalList.tsx +101 -0
  301. package/src/goals/components/GoalStatusCard.tsx +87 -0
  302. package/src/goals/components/TabTitle.tsx +21 -0
  303. package/src/goals/constants/CopyKeys.ts +29 -0
  304. package/src/goals/index.ts +2 -0
  305. package/src/goals/stores/GoalStore.ts +47 -0
  306. package/src/goals/util/GoalsUtil.ts +61 -0
  307. package/src/index.ts +17 -0
  308. package/src/insights/README.md +16 -0
  309. package/src/insights/contexts/ToastContext.tsx +62 -0
  310. package/src/insights/index.ts +5 -0
  311. package/src/insights/settings/SettingsDrawer.tsx +40 -0
  312. package/src/insights/settings/__tests__/SettingsDrawer.test.tsx +50 -0
  313. package/src/insights/settings/components/PulseSubheaderRow.tsx +34 -0
  314. package/src/insights/settings/components/SettingsItem.tsx +55 -0
  315. package/src/insights/settings/components/Toast.tsx +69 -0
  316. package/src/insights/settings/hiddeninsights/__tests__/HiddenInsightsDrawer.test.tsx +108 -0
  317. package/src/insights/settings/hiddeninsights/__tests__/SubCategoryDrawer.test.tsx +150 -0
  318. package/src/insights/settings/hiddeninsights/components/CategoryEmptyState.tsx +50 -0
  319. package/src/insights/settings/hiddeninsights/components/HiddenInsightsDrawer.tsx +222 -0
  320. package/src/insights/settings/hiddeninsights/components/HiddenInsightsDrawerWrapper.tsx +24 -0
  321. package/src/insights/settings/hiddeninsights/components/SubCategoryDrawer.tsx +256 -0
  322. package/src/insights/settings/hiddeninsights/images/no-insights.png +0 -0
  323. package/src/insights/settings/hiddeninsights/types/index.ts +74 -0
  324. package/src/insights/settings/manageaccounts/__tests__/AccountGroup.test.tsx +92 -0
  325. package/src/insights/settings/manageaccounts/__tests__/ManageAccountsDrawer.test.tsx +83 -0
  326. package/src/insights/settings/manageaccounts/components/AccountGroup.tsx +109 -0
  327. package/src/insights/settings/manageaccounts/components/ManageAccountsDrawer.tsx +63 -0
  328. package/src/insights/settings/manageaccounts/types/index.ts +13 -0
  329. package/src/insights/settings/types/index.ts +4 -0
  330. package/src/insights/store/BeatStore.ts +25 -0
  331. package/src/insights/utils/beatTemplateCategories.ts +103 -0
  332. package/src/merchants/api/MerchantApi.ts +33 -0
  333. package/src/merchants/components/MerchantLookup.tsx +117 -0
  334. package/src/merchants/index.ts +2 -0
  335. package/src/merchants/stores/MerchantStore.ts +42 -0
  336. package/src/microinsights/analytics.ts +31 -0
  337. package/src/microinsights/components/beatCard/BeatCard.tsx +124 -0
  338. package/src/microinsights/components/beaticons/BeatCategoryIcon.tsx +20 -0
  339. package/src/microinsights/components/beaticons/BeatIcon.tsx +45 -0
  340. package/src/microinsights/components/beaticons/BeatMerchantLogo.tsx +33 -0
  341. package/src/microinsights/components/beaticons/ChartFilledIcon.tsx +37 -0
  342. package/src/microinsights/components/beaticons/MonthlySpendComparisonIcon.tsx +30 -0
  343. package/src/microinsights/components/beaticons/ZeroStateIcon.tsx +558 -0
  344. package/src/microinsights/components/beaticons/index.tsx +7 -0
  345. package/src/microinsights/components/carouselheader/CarouselHeader.tsx +111 -0
  346. package/src/microinsights/components/insightsmicrowidget/InsightsMicroWidget.tsx +163 -0
  347. package/src/microinsights/components/microBeatCarousel/CarouselControls.tsx +99 -0
  348. package/src/microinsights/components/microBeatCarousel/MicroBeatCarousel.tsx +207 -0
  349. package/src/microinsights/components/microInsightCard/MicroInsightCard.tsx +173 -0
  350. package/src/microinsights/components/noRelevantInsightsCard/NoRelevantInsightsCard.tsx +89 -0
  351. package/src/microinsights/components/spinner/Spinner.tsx +21 -0
  352. package/src/microinsights/components/viewMoreMicroCard/ViewMoreMicroCard.tsx +101 -0
  353. package/src/microinsights/components/zeroStateCard/ZeroStateCard.tsx +62 -0
  354. package/src/microinsights/constants/Analytics.ts +192 -0
  355. package/src/microinsights/constants/App.ts +53 -0
  356. package/src/microinsights/constants/Insights.tsx +3 -0
  357. package/src/microinsights/constants/OnClickEvents.ts +3 -0
  358. package/src/microinsights/context/InsightsMicroWidgetDataProvider.tsx +24 -0
  359. package/src/microinsights/context/hooks.tsx +65 -0
  360. package/src/microinsights/index.ts +16 -0
  361. package/src/microinsights/interfaces.ts +28 -0
  362. package/src/microinsights/stores/AppStore.ts +34 -0
  363. package/src/microinsights/stores/CopyStore.ts +38 -0
  364. package/src/microinsights/stores/InsightsMicroWidgetStore.ts +61 -0
  365. package/src/microinsights/types/BeatUIComponent.ts +5 -0
  366. package/src/microinsights/utils/DataSeries.ts +20 -0
  367. package/src/networth/NetWorthWidget.tsx +171 -0
  368. package/src/networth/__tests__/AssetsLiabilitiesDetail.test.tsx +94 -0
  369. package/src/networth/__tests__/NetWorthChart.test.tsx +31 -0
  370. package/src/networth/__tests__/NetWorthList.test.tsx +33 -0
  371. package/src/networth/components/AssetsLiabilitiesDetail.tsx +146 -0
  372. package/src/networth/components/GainsLossesDetail.tsx +110 -0
  373. package/src/networth/components/NetWorthChange.tsx +51 -0
  374. package/src/networth/components/NetWorthChart.tsx +71 -0
  375. package/src/networth/components/NetWorthList.tsx +91 -0
  376. package/src/networth/components/NetWorthListItem.tsx +72 -0
  377. package/src/networth/components/NetWorthSummary.tsx +36 -0
  378. package/src/networth/index.ts +5 -0
  379. package/src/networth/stores/NetWorthStore.ts +99 -0
  380. package/src/networth/stores/__tests__/NetWorthStore.test.ts +32 -0
  381. package/src/networth/types/NetWorth.ts +59 -0
  382. package/src/networth/utils/NetWorthUtils.ts +177 -0
  383. package/src/networth/utils/__tests__/NetWorthUtils.test.ts +198 -0
  384. package/src/notifications/__tests__/NotificationList.test.tsx +67 -0
  385. package/src/notifications/components/DateRow.tsx +21 -0
  386. package/src/notifications/components/NotificationBadge.tsx +51 -0
  387. package/src/notifications/components/NotificationCard.tsx +63 -0
  388. package/src/notifications/components/NotificationList.tsx +65 -0
  389. package/src/notifications/constants/NotificationConstants.ts +104 -0
  390. package/src/notifications/index.ts +3 -0
  391. package/src/notifications/stores/NotificationStore.ts +62 -0
  392. package/src/notifications/utils/NotificationUtils.ts +21 -0
  393. package/src/recurringactivity/RecurringActivityMiniWidget.tsx +45 -0
  394. package/src/recurringactivity/RecurringActivityWidget.tsx +89 -0
  395. package/src/recurringactivity/__tests__/BuildActivities.test.ts +30 -0
  396. package/src/recurringactivity/__tests__/BuildNewActivity.test.ts +59 -0
  397. package/src/recurringactivity/__tests__/RecurringActivityWidget.test.tsx +33 -0
  398. package/src/recurringactivity/components/ActivityBadges.tsx +40 -0
  399. package/src/recurringactivity/components/ActivityDetails.tsx +196 -0
  400. package/src/recurringactivity/components/ActivityList.tsx +141 -0
  401. package/src/recurringactivity/components/ActivityRow.tsx +161 -0
  402. package/src/recurringactivity/components/ActivityStatus.tsx +82 -0
  403. package/src/recurringactivity/components/MiniWidgetContent.tsx +61 -0
  404. package/src/recurringactivity/components/RecurringActivity.tsx +165 -0
  405. package/src/recurringactivity/components/actions/FrequencyAction.tsx +130 -0
  406. package/src/recurringactivity/components/actions/PaymentDateAction.tsx +99 -0
  407. package/src/recurringactivity/components/activitycalendar/ActivityCalendar.tsx +100 -0
  408. package/src/recurringactivity/components/activitycalendar/ActivityDay.tsx +88 -0
  409. package/src/recurringactivity/components/activitycalendar/Legend.tsx +42 -0
  410. package/src/recurringactivity/components/shared/ActivitySettings.tsx +43 -0
  411. package/src/recurringactivity/components/shared/activitysettings/AddActivity.tsx +175 -0
  412. package/src/recurringactivity/components/shared/activitysettings/AddActivityDetails.tsx +148 -0
  413. package/src/recurringactivity/components/shared/activitysettings/ManageExpenses.tsx +84 -0
  414. package/src/recurringactivity/components/shared/activitysettings/ManageIncome.tsx +102 -0
  415. package/src/recurringactivity/components/shared/activitysettings/SelectTransaction.tsx +45 -0
  416. package/src/recurringactivity/index.ts +5 -0
  417. package/src/recurringactivity/stores/RecurringActivityStore.ts +312 -0
  418. package/src/recurringactivity/util/RecurringActivityUtils.ts +40 -0
  419. package/src/recurringactivity/util/buildActivities.ts +334 -0
  420. package/src/recurringactivity/util/buildNewActivity.ts +111 -0
  421. package/src/recurringactivity/util/getRecurrence.ts +50 -0
  422. package/src/recurringactivity/util/getStatus.ts +32 -0
  423. package/src/recurringactivity/util/updateActivity.ts +66 -0
  424. package/src/spending/SpendingMiniWidget.tsx +23 -0
  425. package/src/spending/SpendingWidget.tsx +71 -0
  426. package/src/spending/__tests__/MiniSpendingChart.test.tsx +43 -0
  427. package/src/spending/__tests__/SpendingData.test.ts +38 -0
  428. package/src/spending/__tests__/SpendingMiniWidget.test.tsx +49 -0
  429. package/src/spending/__tests__/SpendingWidget.test.tsx +49 -0
  430. package/src/spending/components/MiniSpendingChart.tsx +125 -0
  431. package/src/spending/components/Spending.tsx +175 -0
  432. package/src/spending/components/SpendingChart.tsx +74 -0
  433. package/src/spending/components/SpendingDonut.tsx +125 -0
  434. package/src/spending/components/SpendingLegend.tsx +41 -0
  435. package/src/spending/components/SpendingList.tsx +112 -0
  436. package/src/spending/components/SpendingTabLabel.tsx +25 -0
  437. package/src/spending/index.ts +2 -0
  438. package/src/spending/utils/SpendingData.ts +196 -0
  439. package/src/transactions/TransactionWidget.tsx +319 -0
  440. package/src/transactions/analytics.ts +12 -0
  441. package/src/transactions/api/TransactionApi.ts +204 -0
  442. package/src/transactions/api/__mocks__/TransactionApi.ts +20 -0
  443. package/src/transactions/components/shared/TransactionDetails.tsx +140 -0
  444. package/src/transactions/components/shared/TransactionList.tsx +124 -0
  445. package/src/transactions/components/shared/TransactionTable.tsx +123 -0
  446. package/src/transactions/components/shared/transactiondetails/Description.tsx +97 -0
  447. package/src/transactions/components/shared/transactiondetails/FlagTransaction.tsx +63 -0
  448. package/src/transactions/components/shared/transactiondetails/ManualTransactionDetails.tsx +148 -0
  449. package/src/transactions/components/shared/transactiondetails/TransactionAmountHeader.tsx +39 -0
  450. package/src/transactions/components/shared/transactiondetails/actions/CategoryAction.tsx +149 -0
  451. package/src/transactions/components/shared/transactiondetails/actions/DateAction.tsx +119 -0
  452. package/src/transactions/components/shared/transactiondetails/actions/DeleteAction.tsx +85 -0
  453. package/src/transactions/components/shared/transactiondetails/actions/DeleteLogoAction.tsx +88 -0
  454. package/src/transactions/components/shared/transactiondetails/actions/HideAction.tsx +126 -0
  455. package/src/transactions/components/shared/transactiondetails/actions/MemoAction.tsx +112 -0
  456. package/src/transactions/components/shared/transactiondetails/actions/SplitAction.tsx +234 -0
  457. package/src/transactions/components/shared/transactiondetails/actions/TagsAction.tsx +119 -0
  458. package/src/transactions/components/shared/transactiondetails/actions/index.ts +8 -0
  459. package/src/transactions/components/shared/transactionlist/DateRow.tsx +33 -0
  460. package/src/transactions/components/shared/transactionlist/TransactionRow.tsx +92 -0
  461. package/src/transactions/components/shared/transactionlist/ZeroState.tsx +36 -0
  462. package/src/transactions/components/shared/transactiontable/cells/AccountCell.tsx +12 -0
  463. package/src/transactions/components/shared/transactiontable/cells/AmountCell.tsx +35 -0
  464. package/src/transactions/components/shared/transactiontable/cells/CategoryCell.tsx +37 -0
  465. package/src/transactions/components/shared/transactiontable/cells/DateCell.tsx +17 -0
  466. package/src/transactions/components/shared/transactiontable/cells/FlagCell.tsx +43 -0
  467. package/src/transactions/components/shared/transactiontable/cells/HeaderCell.tsx +11 -0
  468. package/src/transactions/components/shared/transactiontable/cells/PayeeCell.tsx +21 -0
  469. package/src/transactions/components/shared/transactiontable/cells/index.ts +7 -0
  470. package/src/transactions/components/splitmanager/SplitManager.tsx +93 -0
  471. package/src/transactions/components/splitmanager/SplitRow.tsx +149 -0
  472. package/src/transactions/components/splitmanager/index.ts +1 -0
  473. package/src/transactions/components/tagmanager/Header.tsx +100 -0
  474. package/src/transactions/components/tagmanager/SearchBox.tsx +60 -0
  475. package/src/transactions/components/tagmanager/TagManager.tsx +51 -0
  476. package/src/transactions/components/tagmanager/TagRow.tsx +145 -0
  477. package/src/transactions/components/tagmanager/index.ts +1 -0
  478. package/src/transactions/components/transactionwidget/AddAccountModal.tsx +30 -0
  479. package/src/transactions/components/transactionwidget/actions/AddTransactionAction.tsx +74 -0
  480. package/src/transactions/components/transactionwidget/actions/EditCategoryAction.tsx +80 -0
  481. package/src/transactions/components/transactionwidget/actions/ExportCsvAction.tsx +32 -0
  482. package/src/transactions/constants/Actions.ts +28 -0
  483. package/src/transactions/constants/Analytics.ts +272 -0
  484. package/src/transactions/constants/OnClickEvents.ts +45 -0
  485. package/src/transactions/constants/Transaction.ts +32 -0
  486. package/src/transactions/constants/TransactionsTable.ts +26 -0
  487. package/src/transactions/context/hooks.tsx +12 -0
  488. package/src/transactions/index.ts +12 -0
  489. package/src/transactions/stores/TransactionStore.ts +327 -0
  490. package/src/transactions/stores/UiStore.ts +72 -0
  491. package/src/transactions/stores/__tests__/TransactionStore.test.ts +80 -0
  492. package/src/transactions/utils/Filters.ts +35 -0
  493. package/src/transactions/utils/Transactions.ts +22 -0
  494. package/src/transactions/utils/buildDetailedTransactions.ts +66 -0
  495. package/src/transactions/utils/exportTransactionsToCSV.ts +85 -0
  496. package/src/transactions/utils/sortAndFilterTransactions.ts +127 -0
  497. package/src/trends/TrendsFullWidget.tsx +286 -0
  498. package/src/trends/TrendsMiniWidget.tsx +49 -0
  499. package/src/trends/__tests__/TrendsFullWidget.test.tsx +45 -0
  500. package/src/trends/__tests__/TrendsMiniWidget.test.tsx +35 -0
  501. package/src/trends/components/SpendingChart.tsx +29 -0
  502. package/src/trends/components/TrendsChart.tsx +75 -0
  503. package/src/trends/components/TrendsDrawer.tsx +74 -0
  504. package/src/trends/components/TrendsTable.tsx +161 -0
  505. package/src/trends/components/__tests__/SpendingChart.test.tsx +37 -0
  506. package/src/trends/components/trendstable/AmountCell.tsx +14 -0
  507. package/src/trends/components/trendstable/CategoryCell.tsx +39 -0
  508. package/src/trends/components/trendstable/HeaderCell.tsx +8 -0
  509. package/src/trends/index.ts +2 -0
  510. package/src/trends/mocks.ts +423 -0
  511. package/src/trends/utils/SpendingData.ts +76 -0
  512. package/src/trends/utils/TrendsData.ts +127 -0
  513. package/src/trends/utils/shared.ts +39 -0
@@ -0,0 +1,184 @@
1
+ import { makeAutoObservable, runInAction } from 'mobx'
2
+ import { getUnixTime } from 'date-fns/getUnixTime'
3
+ import { subMonths } from 'date-fns/subMonths'
4
+ import { startOfMonth } from 'date-fns/startOfMonth'
5
+ import { endOfMonth } from 'date-fns/endOfMonth'
6
+
7
+ import { Account, CategoryApi, CategoryGuids, CategoryGuidToName } from '../../common'
8
+
9
+ import type {
10
+ Category,
11
+ DetailedCategory,
12
+ DateRangeCategoryTotals,
13
+ GlobalStore,
14
+ MonthlyCategoryTotals,
15
+ } from '../../common'
16
+
17
+ import { augmentCategories } from '../util/CategoryUtil'
18
+ import { UiStore } from './UiStore'
19
+
20
+ export class CategoryStore {
21
+ api = new CategoryApi('/', '')
22
+ globalStore: GlobalStore
23
+ uiStore: UiStore
24
+
25
+ categories: Category[] = []
26
+ dateRangeCategoryTotals: DateRangeCategoryTotals[] = []
27
+ monthlyCategoryTotals: MonthlyCategoryTotals[] = []
28
+
29
+ isLoadingCategoryTotals = false
30
+
31
+ constructor(globalStore: GlobalStore) {
32
+ this.globalStore = globalStore
33
+ this.uiStore = new UiStore()
34
+
35
+ makeAutoObservable(this)
36
+ }
37
+
38
+ initialize = async (endpoint: string, token: string) => {
39
+ this.api = new CategoryApi(endpoint, token)
40
+
41
+ await this.loadCategories()
42
+ }
43
+
44
+ get detailedCategories(): DetailedCategory[] {
45
+ return augmentCategories(
46
+ this.categories,
47
+ this.dateRangeCategoryTotals,
48
+ this.monthlyCategoryTotals,
49
+ )
50
+ }
51
+
52
+ get incomeCategories(): DetailedCategory[] {
53
+ return this.detailedCategories.filter((c) => c.is_income)
54
+ }
55
+
56
+ get spendCategories(): DetailedCategory[] {
57
+ return this.detailedCategories.filter(
58
+ (c) => !c.is_income && !c.isTransfer && c.guid !== CategoryGuids.INVESTMENTS,
59
+ )
60
+ }
61
+
62
+ get transferCategories(): DetailedCategory[] {
63
+ return this.detailedCategories.filter((c) => c.isTransfer)
64
+ }
65
+
66
+ addCategory = async (name: string, parentGuid: string) => {
67
+ const category = { name, parent_guid: parentGuid } as Category
68
+
69
+ try {
70
+ await this.api.addCategory(category)
71
+ await this.loadCategories()
72
+ } catch (error) {
73
+ console.error(`Error occurred while adding category: ${error}`)
74
+ }
75
+ }
76
+
77
+ loadCategories = async () => {
78
+ try {
79
+ const categories = await this.api.getCategories()
80
+ const { default_categories } = this.globalStore.copyStore.copy.categories
81
+
82
+ runInAction(() => {
83
+ this.categories = categories.map((category: Category) => ({
84
+ ...category,
85
+ name: default_categories[category.guid]
86
+ ? default_categories[category.guid].replace(/&/g, '&')
87
+ : category.name,
88
+ }))
89
+ })
90
+ } catch (error) {
91
+ console.error(`Error occurred while getting categories: ${error}`)
92
+ }
93
+ }
94
+
95
+ loadDateRangeCategoryTotals = async (accounts: Account[], startDate: Date, endDate: Date) => {
96
+ this.setIsLoadingCategoryTotals(true)
97
+ try {
98
+ const totals = await this.api.getDateRangeCategoryTotals(
99
+ getUnixTime(startDate),
100
+ getUnixTime(endDate),
101
+ accounts,
102
+ )
103
+ runInAction(() => {
104
+ this.dateRangeCategoryTotals = totals
105
+ this.setIsLoadingCategoryTotals(false)
106
+ })
107
+ } catch (error) {
108
+ this.setIsLoadingCategoryTotals(false)
109
+ console.error(`Error occurred while getting date range category totals: ${error}`)
110
+ }
111
+ }
112
+
113
+ loadMonthlyCategoryTotals = async (
114
+ accounts: Account[] = this.globalStore.accountStore.accounts,
115
+ startDate?: Date,
116
+ endDate?: Date,
117
+ ) => {
118
+ const start = getUnixTime(startOfMonth(startDate ?? subMonths(new Date(), 11)))
119
+ const end = getUnixTime(endOfMonth(endDate ?? new Date()))
120
+
121
+ try {
122
+ const totals = await this.api.getMonthlyCategoryTotals(start, end, accounts)
123
+
124
+ runInAction(() => {
125
+ this.monthlyCategoryTotals = totals
126
+ })
127
+ } catch (error) {
128
+ console.error(`Error occurred while getting monthly category totals: ${error}`)
129
+ }
130
+ }
131
+
132
+ reloadCategoryTotals = async (accounts: Account[], startDate: Date, endDate: Date) => {
133
+ this.setIsLoadingCategoryTotals(true)
134
+ try {
135
+ const dateRangeTotals = await this.api.getDateRangeCategoryTotals(
136
+ getUnixTime(startDate),
137
+ getUnixTime(endDate),
138
+ accounts,
139
+ )
140
+
141
+ const monthlyTotals = await this.api.getMonthlyCategoryTotals(
142
+ getUnixTime(startOfMonth(subMonths(endDate, 11))),
143
+ getUnixTime(endOfMonth(endDate)),
144
+ accounts,
145
+ )
146
+
147
+ runInAction(() => {
148
+ this.dateRangeCategoryTotals = dateRangeTotals
149
+ this.monthlyCategoryTotals = monthlyTotals
150
+ this.setIsLoadingCategoryTotals(false)
151
+ })
152
+ } catch (error) {
153
+ console.error(`Error occurred while getting category totals: ${error}`)
154
+ }
155
+ }
156
+
157
+ removeCategory = async (guid: string) => {
158
+ try {
159
+ await this.api.removeCategory(guid)
160
+ await this.loadCategories()
161
+ } catch (error) {
162
+ console.error(`Error occurred while removing category: ${error}`)
163
+ }
164
+ }
165
+
166
+ setIsLoadingCategoryTotals = (isLoading: boolean) => {
167
+ this.isLoadingCategoryTotals = isLoading
168
+ }
169
+
170
+ updateCategory = async (category: Category) => {
171
+ try {
172
+ await this.api.updateCategory(category)
173
+ await this.loadCategories()
174
+ } catch (error) {
175
+ console.error(`Error occurred while updating category: ${error}`)
176
+ }
177
+ }
178
+
179
+ // TODO: Remove this after refactoring Trends components to use detailedCategories
180
+ getCategoryName = (guid: string) => {
181
+ const category = this.categories.find((c) => c.guid === guid)
182
+ return category?.name ?? CategoryGuidToName[guid]
183
+ }
184
+ }
@@ -0,0 +1,36 @@
1
+ import { makeAutoObservable } from 'mobx'
2
+
3
+ export class UiStore {
4
+ expandedGuid: string | null = null
5
+ selectedGuid: string | null = null
6
+ searchValue = ''
7
+ showSelected = true
8
+ shouldDisableDrawerScroll = false
9
+ unselectable: string[] = []
10
+ unselectableText = ''
11
+
12
+ savedOnSelect: any // todo
13
+
14
+ constructor() {
15
+ makeAutoObservable(this)
16
+ }
17
+
18
+ setExpandedGuid = (guid: string | null) => (this.expandedGuid = guid)
19
+
20
+ setSelectedGuid = (guid: string | null) => (this.selectedGuid = guid)
21
+
22
+ setSearchValue = (value: string) => (this.searchValue = value)
23
+
24
+ setShouldDisableDrawerScroll = (shouldDisable: boolean) =>
25
+ (this.shouldDisableDrawerScroll = shouldDisable)
26
+
27
+ setShowSelected = (showSelected: boolean) => (this.showSelected = showSelected)
28
+
29
+ setUnselectable = (unselectable: string[]) => (this.unselectable = unselectable)
30
+
31
+ setUnselectableText = (text: string) => (this.unselectableText = text)
32
+
33
+ onSelect = (guid: string) => this.savedOnSelect(guid)
34
+
35
+ setOnSelect = (callback: any) => (this.savedOnSelect = callback)
36
+ }
@@ -0,0 +1,54 @@
1
+ import { beforeEach, describe, expect, it } from 'vitest'
2
+ import { startOfMonth } from 'date-fns/startOfMonth'
3
+ import { endOfMonth } from 'date-fns/endOfMonth'
4
+
5
+ import { GlobalStore } from '../../../common'
6
+
7
+ describe('Testing the CategoryStore', () => {
8
+ let globalStore: GlobalStore
9
+
10
+ beforeEach(() => {
11
+ globalStore = new GlobalStore()
12
+ })
13
+
14
+ describe('augmentCategories()', () => {
15
+ it('successfully sets detailedCategories to state', async () => {
16
+ const { accountStore, categoryStore, copyStore } = globalStore
17
+
18
+ expect(categoryStore.detailedCategories).toHaveLength(0)
19
+ await copyStore.initialize('/', '')
20
+ await categoryStore.initialize('/', '')
21
+ await categoryStore.loadDateRangeCategoryTotals(
22
+ accountStore.accounts,
23
+ startOfMonth(new Date()),
24
+ endOfMonth(new Date()),
25
+ )
26
+ await categoryStore.loadMonthlyCategoryTotals()
27
+
28
+ // There are 21 top level categories
29
+ expect(categoryStore.detailedCategories).toHaveLength(21)
30
+
31
+ expect(categoryStore.incomeCategories).toHaveLength(1)
32
+ expect(categoryStore.spendCategories).toHaveLength(18)
33
+ expect(categoryStore.transferCategories).toHaveLength(1)
34
+ })
35
+ })
36
+
37
+ describe('loadCategories()', () => {
38
+ it('successfully sets localized categories to state', async () => {
39
+ const { categoryStore, copyStore } = globalStore
40
+
41
+ await copyStore.initialize('/', '')
42
+ await categoryStore.initialize('/', '')
43
+
44
+ // There are 119 total categories
45
+ expect(categoryStore.categories).toHaveLength(119)
46
+
47
+ const categoryNameWithAmpersandHTMLCode = categoryStore.categories.find(
48
+ (category) => category.guid === 'CAT-7829f71c-2e8c-afa5-2f55-fa3634b89874',
49
+ )
50
+
51
+ expect(categoryNameWithAmpersandHTMLCode?.name.includes('&')).toBeTruthy()
52
+ })
53
+ })
54
+ })
@@ -0,0 +1,136 @@
1
+ import { format } from 'date-fns/format'
2
+ import { startOfMonth } from 'date-fns/startOfMonth'
3
+ import { startOfToday } from 'date-fns/startOfToday'
4
+ import { subMonths } from 'date-fns/subMonths'
5
+
6
+ import {
7
+ type Category,
8
+ type DateRangeCategoryTotals,
9
+ type DetailedCategory,
10
+ type MonthlyAmount,
11
+ type MonthlyCategoryTotals,
12
+ CategoryColors,
13
+ CategoryGuids,
14
+ CategoryIcon,
15
+ DATE_FORMATS_INTL,
16
+ formatDate,
17
+ } from '../../common'
18
+
19
+ const MONTHLY_AVERAGE_LENGTH = 3
20
+ const MONTHS_OF_HISTORY = 12
21
+
22
+ /**
23
+ * Augment categories
24
+ * @param categories - Categories to augment
25
+ * @param monthlyCategoryTotals - Monthly category totals
26
+ * @param currentCategoryTotals - Current month category totals
27
+ */
28
+ export const augmentCategories = (
29
+ categories: Category[],
30
+ currentCategoryTotals: DateRangeCategoryTotals[],
31
+ monthlyCategoryTotals: MonthlyCategoryTotals[],
32
+ ): DetailedCategory[] => {
33
+ return categories
34
+ .filter((category) => !category.parent_guid)
35
+ .map((category) =>
36
+ getDetailedCategory(
37
+ category,
38
+ currentCategoryTotals,
39
+ monthlyCategoryTotals,
40
+ categories.filter((c) => c.parent_guid === category.guid),
41
+ ),
42
+ )
43
+ }
44
+
45
+ /**
46
+ * Get an augmented category with additional details
47
+ * @param category - The category to augment
48
+ * @param currentCategoryTotals - Current month category totals
49
+ * @param monthlyCategoryTotals - Past monthly category totals
50
+ * @param subCategories - Subcategories for the specified category (If applicable)
51
+ */
52
+ const getDetailedCategory = (
53
+ category: Category,
54
+ currentCategoryTotals: DateRangeCategoryTotals[],
55
+ monthlyCategoryTotals: MonthlyCategoryTotals[],
56
+ subCategories: Category[] = [],
57
+ ): DetailedCategory => {
58
+ const guid = category.guid
59
+ const parentGuid = category.parent_guid || guid
60
+ const isParent = guid === parentGuid
61
+
62
+ const currentAmount = currentCategoryTotals.find((t) => t.category_guid === guid)?.total || 0
63
+ const monthlyAmounts = getMonthlyAmounts(
64
+ monthlyCategoryTotals.filter((total) => total.category_guid === guid),
65
+ )
66
+ const totalMonthlyAmounts = getMonthlyAmounts(
67
+ monthlyCategoryTotals.filter(
68
+ (total) => total.category_guid === guid || total.top_level_category_guid === guid,
69
+ ),
70
+ )
71
+ const detailedSubCategories = subCategories.map((subCategory) =>
72
+ getDetailedCategory(subCategory, currentCategoryTotals, monthlyCategoryTotals),
73
+ )
74
+ const totalAmount = detailedSubCategories.reduce(
75
+ (total, current) => total + current.currentAmount,
76
+ currentAmount,
77
+ )
78
+
79
+ return {
80
+ ...category,
81
+ currentAmount,
82
+ averageAmount: getAverage(monthlyAmounts),
83
+ color: CategoryColors[parentGuid],
84
+ icon: CategoryIcon[parentGuid],
85
+ isTransfer: parentGuid === CategoryGuids.TRANSFER,
86
+ monthlyAmounts,
87
+ subCategories: detailedSubCategories,
88
+ totalAmount: isParent ? totalAmount : 0,
89
+ totalAverageAmount: getAverage(totalMonthlyAmounts),
90
+ totalMonthlyAmounts: isParent ? totalMonthlyAmounts : [],
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Get the average amount based on the number of months (numMonths) requested
96
+ * @param monthlyAmounts - Monthly amounts to calculate and average from
97
+ * @param numMonths - Number of months to base the average on (DEFAULT: 3)
98
+ */
99
+ const getAverage = (
100
+ monthlyAmounts: MonthlyAmount[],
101
+ numMonths: number = MONTHLY_AVERAGE_LENGTH,
102
+ ): number => {
103
+ const monthsBack = numMonths > history.length ? history.length : numMonths
104
+
105
+ return Math.ceil(
106
+ Math.max(
107
+ 0,
108
+ monthlyAmounts.slice(-monthsBack).reduce((total, current) => total + current.amount, 0) /
109
+ monthsBack,
110
+ ),
111
+ )
112
+ }
113
+
114
+ /**
115
+ * Get the last 12 months of amounts for a category
116
+ * @param categoryTotals - Monthly category totals
117
+ */
118
+ const getMonthlyAmounts = (categoryTotals: MonthlyCategoryTotals[]): MonthlyAmount[] => {
119
+ const monthlyAmounts: MonthlyAmount[] = []
120
+ const today = startOfToday()
121
+ for (let i = 0; i <= MONTHS_OF_HISTORY; i++) {
122
+ const historyDate = startOfMonth(subMonths(today, MONTHS_OF_HISTORY - i))
123
+ const monthlyTotals = categoryTotals.filter(
124
+ (total) => total.year_month === Number(format(historyDate, 'yyyyMM')),
125
+ )
126
+ const totalAmount = monthlyTotals.reduce((acc, curr) => acc + curr.total, 0)
127
+
128
+ monthlyAmounts.push({
129
+ amount: totalAmount,
130
+ isoDate: format(historyDate, 'yyyy-MM-dd'),
131
+ label: formatDate(historyDate, DATE_FORMATS_INTL.MONTH_YEAR),
132
+ })
133
+ }
134
+
135
+ return monthlyAmounts
136
+ }
@@ -0,0 +1,49 @@
1
+ import Bowser from 'bowser'
2
+
3
+ import { Fetch } from '../utils'
4
+
5
+ import { ApiEndpoints } from '../constants'
6
+ import { AnalyticsEvent } from '../types'
7
+
8
+ export class AnalyticsApi {
9
+ fetchInstance: Fetch
10
+
11
+ constructor(endpoint: string, token: string) {
12
+ this.fetchInstance = new Fetch(endpoint, token)
13
+ }
14
+
15
+ initializeAnalyticsSession = async (version: string, featureName?: string) => {
16
+ const browser = Bowser.getParser(window.navigator.userAgent)
17
+
18
+ const { analytics_session } = await this.fetchInstance.post(ApiEndpoints.ANALYTICS_SESSION, {
19
+ browser_name: browser.getBrowserName() || 'Unknown',
20
+ browser_version: browser.getBrowserVersion() || '0.0.0',
21
+ is_first_visit: false,
22
+ product_name: 'Individual Widget',
23
+ product_version: version,
24
+ })
25
+ if (!analytics_session) {
26
+ return { analytics_session: null }
27
+ }
28
+ this.fetchInstance.post(ApiEndpoints.ANALYTICS_FEATURE_VISITS, {
29
+ feature_visit: {
30
+ analytics_session_guid: analytics_session.guid,
31
+ feature_name: featureName ? featureName : 'Experiences',
32
+ is_first_visit: analytics_session.is_first_visit,
33
+ },
34
+ })
35
+ return { analytics_session }
36
+ }
37
+
38
+ sendAnalyticEvent = async (event: AnalyticsEvent) => {
39
+ return this.fetchInstance.post(ApiEndpoints.ANALYTICS_EVENTS, event).catch((err) => {
40
+ throw err
41
+ })
42
+ }
43
+
44
+ sendAnalyticsPageview = async (event: any) => {
45
+ return this.fetchInstance.post(ApiEndpoints.ANALYTICS_PAGEVIEWS, event).catch((err) => {
46
+ throw err
47
+ })
48
+ }
49
+ }
@@ -0,0 +1,32 @@
1
+ import Fetch from '../utils/Fetch'
2
+
3
+ import { ApiEndpoints } from '../constants'
4
+
5
+ import type { Beat } from '../types'
6
+
7
+ export class BeatApi {
8
+ fetchInstance: Fetch
9
+
10
+ constructor(endpoint: string, token: string) {
11
+ this.fetchInstance = new Fetch(endpoint, token)
12
+ }
13
+
14
+ getBeats = async (pageNum?: number, perPage?: number) => {
15
+ const beatParams = `page=${pageNum ? pageNum : 1}&per_page=${perPage ? perPage : 5}`
16
+
17
+ return this.fetchInstance.get(`${ApiEndpoints.BEATS}?${beatParams}`).then((data) => data.beats)
18
+ }
19
+
20
+ getBeatsWithAssociatedTransaction = async (fromDate?: string) => {
21
+ let beatParams = 'has_associated_transaction_guid=true'
22
+ beatParams += fromDate ? `&from_date=${fromDate}` : ''
23
+
24
+ return this.fetchInstance.get(`${ApiEndpoints.BEATS}?${beatParams}`).then((data) => data.beats)
25
+ }
26
+
27
+ updateBeat = async (beat: Beat) => {
28
+ return this.fetchInstance
29
+ .put(`${ApiEndpoints.BEATS}/${beat.guid}`, beat)
30
+ .then((data) => data.beat)
31
+ }
32
+ }
@@ -0,0 +1,52 @@
1
+ import Fetch from '../utils/Fetch'
2
+
3
+ import { ApiEndpoints } from '../constants/ApiEndpoints'
4
+
5
+ import type { Account } from '../types/Account'
6
+ import type { Category } from '../types/Category'
7
+
8
+ export class CategoryApi {
9
+ fetchInstance: Fetch
10
+
11
+ constructor(endpoint: string, token: string) {
12
+ this.fetchInstance = new Fetch(endpoint, token)
13
+ }
14
+
15
+ addCategory = async (category: Category) => {
16
+ return this.fetchInstance.post(ApiEndpoints.CATEGORIES, category).then((data) => data.category)
17
+ }
18
+
19
+ getCategories = async () => {
20
+ return this.fetchInstance.get(ApiEndpoints.CATEGORIES).then((data) => data.categories)
21
+ }
22
+
23
+ getDateRangeCategoryTotals = async (startDate: number, endDate: number, accounts: Account[]) => {
24
+ return this.fetchInstance
25
+ .post(`${ApiEndpoints.DATE_RANGE_CATEGORY_TOTALS}/from/${startDate}/to/${endDate}`, {
26
+ account_guid: accounts.map((account) => account.guid),
27
+ })
28
+ .then((data) => data.date_range_category_totals)
29
+ }
30
+
31
+ getMonthlyCategoryTotals = async (startDate: number, endDate: number, accounts?: Account[]) => {
32
+ return accounts
33
+ ? this.fetchInstance
34
+ .post(`${ApiEndpoints.MONTHLY_CATEGORY_TOTALS}/from/${startDate}/to/${endDate}`, {
35
+ account_guid: accounts.length === 0 ? [''] : accounts.map((account) => account.guid),
36
+ })
37
+ .then((data) => data.monthly_category_totals)
38
+ : this.fetchInstance
39
+ .get(`${ApiEndpoints.MONTHLY_CATEGORY_TOTALS}/from/${startDate}/to/${endDate}`)
40
+ .then((data) => data.monthly_category_totals)
41
+ }
42
+
43
+ removeCategory = async (guid: string) => {
44
+ return this.fetchInstance.delete(`${ApiEndpoints.CATEGORIES}/${guid}`)
45
+ }
46
+
47
+ updateCategory = async (category: Category) => {
48
+ return this.fetchInstance
49
+ .put(`${ApiEndpoints.CATEGORIES}/${category.guid}`, category)
50
+ .then((data) => data.category)
51
+ }
52
+ }
@@ -0,0 +1,17 @@
1
+ import Fetch from '../utils/Fetch'
2
+
3
+ import { ApiEndpoints } from '../constants/ApiEndpoints'
4
+
5
+ export class GlobalCopyApi {
6
+ fetchInstance: Fetch
7
+
8
+ constructor(endpoint: string, token: string) {
9
+ this.fetchInstance = new Fetch(endpoint, token)
10
+ }
11
+
12
+ getGlobalCopy = async (namespace: string, translationKey: string) => {
13
+ return this.fetchInstance
14
+ .post(`${ApiEndpoints.LOCALIZED_CONTENT}/${namespace}`, { translation_key: translationKey })
15
+ .then((data) => data)
16
+ }
17
+ }
@@ -0,0 +1,21 @@
1
+ import Fetch from '../utils/Fetch'
2
+
3
+ import { ApiEndpoints } from '../constants/ApiEndpoints'
4
+
5
+ export class LocalizedCopyApi {
6
+ fetchInstance: Fetch
7
+
8
+ constructor(endpoint: string, token: string) {
9
+ this.fetchInstance = new Fetch(endpoint, token)
10
+ }
11
+
12
+ getLocalizedCopy = async (req: any) => {
13
+ return this.fetchInstance.post(ApiEndpoints.LOCALIZED_COPY, req).then((data) => data)
14
+ }
15
+
16
+ getLocalizedContent = async (namespace: string) => {
17
+ return this.fetchInstance
18
+ .post(`${ApiEndpoints.LOCALIZED_CONTENT}/${namespace}`)
19
+ .then((data) => data)
20
+ }
21
+ }
@@ -0,0 +1,40 @@
1
+ import Fetch from '../utils/Fetch'
2
+
3
+ import { ApiEndpoints } from '../constants'
4
+
5
+ import type { Notification } from '../types'
6
+
7
+ export class NotificationApi {
8
+ fetchInstance: Fetch
9
+
10
+ constructor(endpoint: string, token: string) {
11
+ this.fetchInstance = new Fetch(endpoint, token)
12
+ }
13
+
14
+ getNotifications = () => {
15
+ return this.fetchInstance
16
+ .get(ApiEndpoints.NOTIFICATIONS)
17
+ .then((data) =>
18
+ data.notifications.map((obj: { notification: Notification }) => obj.notification),
19
+ )
20
+ .finally()
21
+ }
22
+
23
+ updateNotification = (notification: Notification) => {
24
+ return this.fetchInstance
25
+ .put(`${ApiEndpoints.NOTIFICATIONS}/${notification.guid}`, {
26
+ guid: notification.guid,
27
+ has_been_viewed: notification.has_been_viewed,
28
+ })
29
+ .then((data) => data.notification)
30
+ .finally()
31
+ }
32
+
33
+ // Note: The notifications/mark_all_as_viewed endpoint is broken, but still returns 202.
34
+ // A bug ticket has been filed to fix it, but should not require any changes here.
35
+ markAllAsViewed = (channel?: number) => {
36
+ return this.fetchInstance
37
+ .put(`${ApiEndpoints.NOTIFICATIONS}/mark_all_as_viewed`, { channel })
38
+ .finally()
39
+ }
40
+ }
@@ -0,0 +1,37 @@
1
+ import { ApiEndpoints, Fetch, type ScheduledPayment, TransactionType } from '../index'
2
+
3
+ export class ScheduledPaymentsApi {
4
+ fetchInstance: Fetch
5
+
6
+ constructor(endpoint: string, token: string) {
7
+ this.fetchInstance = new Fetch(endpoint, token)
8
+ }
9
+
10
+ addScheduledPayment = async (scheduledPayment: ScheduledPayment) => {
11
+ return this.fetchInstance
12
+ .post(ApiEndpoints.SCHEDULED_PAYMENTS, {
13
+ ...scheduledPayment,
14
+ is_recurring: 'true',
15
+ transaction_type: TransactionType.DEBIT,
16
+ })
17
+ .then((data) => data.scheduled_payment)
18
+ }
19
+
20
+ getScheduledPayments = async () => {
21
+ return this.fetchInstance
22
+ .get(ApiEndpoints.SCHEDULED_PAYMENTS)
23
+ .then((data) => data.scheduled_payments)
24
+ }
25
+
26
+ updateScheduledPayment = async (scheduledPayment: ScheduledPayment) => {
27
+ return this.fetchInstance
28
+ .put(`${ApiEndpoints.SCHEDULED_PAYMENTS}/${scheduledPayment.guid}`, scheduledPayment)
29
+ .then((data) => data.scheduled_payment)
30
+ }
31
+
32
+ deleteScheduledPayment = async (guid: string) => {
33
+ return this.fetchInstance
34
+ .delete(`${ApiEndpoints.SCHEDULED_PAYMENTS}/${guid}`)
35
+ .then((data) => data)
36
+ }
37
+ }
@@ -0,0 +1,23 @@
1
+ import Fetch from '../utils/Fetch'
2
+
3
+ import { ApiEndpoints } from '../constants'
4
+
5
+ import type { UserProfile } from '../types'
6
+
7
+ export class UserApi {
8
+ fetchInstance: Fetch
9
+
10
+ constructor(endpoint: string, token: string) {
11
+ this.fetchInstance = new Fetch(endpoint, token)
12
+ }
13
+
14
+ getUserProfile = async () => {
15
+ return this.fetchInstance.get(ApiEndpoints.APP_DATA).then((data) => data.user_profile)
16
+ }
17
+
18
+ updateUserProfile = async (userProfile: UserProfile) => {
19
+ return this.fetchInstance
20
+ .put(`${ApiEndpoints.USER_PROFILES}/${userProfile.guid}`, userProfile)
21
+ .then((data) => data.user_profile)
22
+ }
23
+ }