@mx-cartographer/experiences 9.4.57 → 9.4.59

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 (47) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cashflow/CashflowOnboarding.es.js +6 -6
  3. package/dist/cashflow/CashflowOnboarding.es.js.map +1 -1
  4. package/dist/core/api/UserApi.d.ts +2 -1
  5. package/dist/core/api/UserApi.es.js +6 -5
  6. package/dist/core/api/UserApi.es.js.map +1 -1
  7. package/dist/core/constants/ApiEndpoints.d.ts +1 -0
  8. package/dist/core/constants/ApiEndpoints.es.js +1 -0
  9. package/dist/core/constants/ApiEndpoints.es.js.map +1 -1
  10. package/dist/core/stores/AccountStore.d.ts +2 -1
  11. package/dist/core/stores/AccountStore.es.js +16 -16
  12. package/dist/core/stores/AccountStore.es.js.map +1 -1
  13. package/dist/core/stores/BeatStore.d.ts +6 -0
  14. package/dist/core/stores/BeatStore.es.js +30 -17
  15. package/dist/core/stores/BeatStore.es.js.map +1 -1
  16. package/dist/core/stores/BudgetsStore.d.ts +2 -1
  17. package/dist/core/stores/BudgetsStore.es.js +8 -8
  18. package/dist/core/stores/BudgetsStore.es.js.map +1 -1
  19. package/dist/core/stores/InsightsV2Store.es.js.map +1 -1
  20. package/dist/core/stores/SettingsStore.d.ts +2 -1
  21. package/dist/core/stores/SettingsStore.es.js +11 -11
  22. package/dist/core/stores/SettingsStore.es.js.map +1 -1
  23. package/dist/core/stores/TransactionStore.d.ts +4 -2
  24. package/dist/core/stores/TransactionStore.es.js +6 -6
  25. package/dist/core/stores/TransactionStore.es.js.map +1 -1
  26. package/dist/core/stores/UserStore.d.ts +15 -1
  27. package/dist/core/stores/UserStore.es.js +21 -3
  28. package/dist/core/stores/UserStore.es.js.map +1 -1
  29. package/dist/core/types/RepeatingTransaction.d.ts +2 -0
  30. package/dist/core/types/RepeatingTransaction.es.js.map +1 -1
  31. package/dist/core/types/User.d.ts +11 -0
  32. package/dist/core/types/index.d.ts +1 -1
  33. package/dist/core/types/localization/InsightsFeedCopy.d.ts +4 -0
  34. package/dist/insights-v2/components/BaseLayout.d.ts +5 -1
  35. package/dist/insights-v2/components/BaseLayout.es.js +56 -52
  36. package/dist/insights-v2/components/BaseLayout.es.js.map +1 -1
  37. package/dist/insights-v2/components/ErrorCard.d.ts +15 -0
  38. package/dist/insights-v2/components/ErrorCard.es.js +85 -0
  39. package/dist/insights-v2/components/ErrorCard.es.js.map +1 -0
  40. package/dist/insights-v2/components/LoadingCard.d.ts +11 -0
  41. package/dist/insights-v2/components/LoadingCard.es.js +25 -0
  42. package/dist/insights-v2/components/LoadingCard.es.js.map +1 -0
  43. package/dist/insights-v2/components/shared/images/ErrorViewCibc.es.js +57 -0
  44. package/dist/insights-v2/components/shared/images/ErrorViewCibc.es.js.map +1 -0
  45. package/dist/insights-v2/index.d.ts +2 -0
  46. package/dist/insights-v2/index.es.js +44 -40
  47. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## [9.4.59] - 10-07-2026
2
+
3
+ - **ADDED** - `UserInsightProfile` type, `ApiEndpoints.USER_INSIGHT_PROFILE`, `UserApi.updateUserInsightProfile` (`PUT user_insight_profile`) and `UserStore.userInsightProfile` with `setUserInsightProfile` (the host seeds the profile it loaded) and `updateUserInsightProfile`, which merges the changed fields over the seeded profile and PUTs the whole profile (the endpoint upserts every field, so a partial body would null the rest), refuses to PUT before the profile is seeded, and rethrows so a caller can surface a failed save (WEC-1852)
4
+ - **ADDED** - `BeatStore.updateOffer` (`PUT offers/:guid`) to flag a marketing offer as clicked; rethrows on failure (WEC-1852)
5
+ - **ADDED** - `RepeatingTransaction.user_response` field (WEC-1852)
6
+ - **CHANGED** - `AccountStore.updateAccount`, `SettingsStore.updateNotificationProfile`, `TransactionStore.updateTransaction`, `TransactionStore.addOrUpdateTransactionRule` and `BudgetsStore.addBudget` now resolve `true` on success and `false` when the API call fails, instead of resolving `undefined` either way. They still catch and report their own errors and never throw, so existing callers are unaffected; the flag lets a caller distinguish a failed write (WEC-1852)
7
+ - **ADDED** - MSW handlers and mock data for `PUT user_insight_profile` and `PUT offers/:guid` (WEC-1852)
8
+
9
+ ## [9.4.58] - 10-07-2026
10
+
11
+ - **ADDED** - Insights V2 `ErrorCard` and `LoadingCard` components, plus `isError`/`isLoading` props on `BaseLayout`: `isError` replaces the entire card with the `ErrorCard` (heading, message, and a "Try Again" retry button that reloads by default), while `isLoading` swaps only the block slot for the `LoadingCard`. `ErrorCard` derives the CIBC illustration variant from the app's `custom_copy_namespace`. Added `error_heading`, `error_message`, `loading`, and `try_again` copy keys under `insights_feed.general`, with stories for all three states (WEC-1854)
12
+ - **CHANGED** - `LoadingCard` now uses the hosted `MD_Assets` `loading.gif` and the bundled `Loading.gif` asset was removed from the package (WEC-1854)
13
+
1
14
  ## [9.4.57] - 10-06-2026
2
15
 
3
16
  - **FIXED** - Spending transaction list puts a transaction in the same month as the chart when the bank dates it at midnight UTC MEW-4191
@@ -78,7 +78,7 @@ var ve = Te`
78
78
  },
79
79
  children: [
80
80
  f === 1 && /* @__PURE__ */ e(p, {
81
- sx: { ...c ? {
81
+ sx: c ? {
82
82
  display: "flex",
83
83
  flexDirection: "column",
84
84
  maxWidth: "100%",
@@ -87,11 +87,11 @@ var ve = Te`
87
87
  maxWidth: 590,
88
88
  ml: "40%",
89
89
  mr: 90
90
- } },
90
+ },
91
91
  children: /* @__PURE__ */ e(ye, { handleNextStep: I })
92
92
  }),
93
93
  f === 2 && /* @__PURE__ */ e(p, {
94
- sx: { ...c ? {
94
+ sx: c ? {
95
95
  display: "flex",
96
96
  flexDirection: "column",
97
97
  maxWidth: "100%",
@@ -100,11 +100,11 @@ var ve = Te`
100
100
  maxWidth: 590,
101
101
  ml: "40%",
102
102
  mr: 90
103
- } },
103
+ },
104
104
  children: /* @__PURE__ */ e(_e, {})
105
105
  }),
106
106
  f === 3 && /* @__PURE__ */ i(p, {
107
- sx: { ...c ? {
107
+ sx: c ? {
108
108
  display: "flex",
109
109
  flexDirection: "column",
110
110
  maxWidth: "100%",
@@ -113,7 +113,7 @@ var ve = Te`
113
113
  maxWidth: 590,
114
114
  ml: "40%",
115
115
  mr: 90
116
- } },
116
+ },
117
117
  children: [
118
118
  /* @__PURE__ */ e(be, {
119
119
  pb: 12,
@@ -1 +1 @@
1
- {"version":3,"file":"CashflowOnboarding.es.js","names":[],"sources":["../../src/cashflow/CashflowOnboarding.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { observer } from 'mobx-react-lite'\nimport { formatISO } from 'date-fns/formatISO'\nimport { fromUnixTime } from 'date-fns/fromUnixTime'\nimport { getUnixTime } from 'date-fns/getUnixTime'\nimport { startOfMonth } from 'date-fns/startOfMonth'\nimport { startOfToday } from 'date-fns/startOfToday'\nimport { subDays } from 'date-fns/subDays'\n\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Divider from '@mui/material/Divider'\nimport List from '@mui/material/List'\nimport Stack from '@mui/material/Stack'\nimport { keyframes } from '@mui/material/styles'\nimport { useTheme } from '@mui/material/styles'\n\nimport { H2, Icon, P } from '@mxenabled/mxui'\n\nimport StepOne from './components/onboarding/StepOne'\nimport StepTwo from './components/onboarding/StepTwo'\n\nimport {\n Loader,\n useCashflowStore,\n useGlobalCopyStore,\n useGlobalUiStore,\n useRecurringTransactionsStore,\n useScreenSize,\n useTransactionStore,\n useUserStore,\n} from '../common'\nimport { type RepeatingTransaction, type Transaction, RepeatingType, Frequency } from '../core'\nimport SubheaderRow from '../common/components/SubheaderRow'\n\nimport { useCashflowUiStore } from './context/hooks'\n\nimport { TransactionRow } from '../transactions'\nimport { incomeFilter, incomeFilterSearch } from '../transactions/utils/Filters'\n\nimport { AddRecurringTransactionDetails } from '../recurringtransactions'\nimport { SelectTransaction } from '../recurringtransactions'\nimport { getNextPaymentDate } from '../core/utils/RecurringTransactionsUtil'\n\nimport { fromUnixToDayOfWeekAndDate } from '../core/utils/DateUtil'\nimport { CASHFLOW_IMAGES } from './constants/CashflowImages'\n\ninterface UpcomingTransactions extends Transaction {\n nextDate: Date | null\n frequency: Frequency\n}\n\nconst spin = keyframes`\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n`\n\nconst CashflowOnboarding: React.FC = () => {\n const { addRepeatingTransaction, repeatingTransactions } = useRecurringTransactionsStore()\n const { cashflow: customCopy, common: commonCopy } = useGlobalCopyStore()\n const { user } = useUserStore()\n const { completeOnboarding } = useCashflowStore()\n const { isDirty } = useCashflowUiStore()\n const { isMobile } = useScreenSize()\n const { isCopyLoaded, setDisplayedDate } = useGlobalUiStore()\n const { filter, setFilter, transactions } = useTransactionStore()\n const theme = useTheme()\n\n const [addIncome, setAddIncome] = useState(true)\n const [frequency, setFrequency] = React.useState(Frequency.EveryMonth)\n const [firstDay, setFirstDay] = React.useState(1)\n const [secondDay, setSecondDay] = React.useState(15)\n const [isSubmitting, setIsSubmitting] = useState(false)\n // const [nextDate, setNextDate] = React.useState<Date | null>(null)\n const [step, setStep] = useState(1)\n const [selectedTransactions, setSelectedTransactions] = useState<UpcomingTransactions[] | []>([])\n const [transactionGuid, setTransactionGuid] = useState('')\n\n const transaction = React.useMemo(\n () => transactions.find((t) => t.guid === transactionGuid),\n [transactionGuid, transactions],\n )\n\n const canSubmit = !!repeatingTransactions.filter(\n (r) => r.repeating_transaction_type === RepeatingType.Income,\n ).length\n\n const handleGetTransactions = async () => {\n setStep(2)\n // set transaction date range and filter by income\n setDisplayedDate(\n // Beginning of the month, 90 days before today\n startOfMonth(subDays(startOfToday(), 90)),\n startOfToday(),\n )\n\n setFilter({ ...filter, custom: incomeFilter })\n\n setStep(3)\n }\n\n const handleAddIncome = async () => {\n if (selectedTransactions.length < 1) {\n return\n }\n setIsSubmitting(true)\n\n // Create Repeating Transactions\n for (let i = 0; i < selectedTransactions.length; i++) {\n const upcomingTransaction = selectedTransactions[i]\n\n const nextDate = getNextPaymentDate(frequency, fromUnixTime(upcomingTransaction.date))\n\n const repeatingTransaction = {\n account_guid: upcomingTransaction.account_guid,\n amount: upcomingTransaction.amount,\n created_by: 0, //user\n merchant_guid: upcomingTransaction.merchant_guid,\n description: upcomingTransaction.feed_description || upcomingTransaction.description,\n predicted_occurs_on: formatISO(nextDate, { representation: 'date' }),\n recurrence_day: nextDate.getDay(),\n recurrence_type: frequency,\n repeating_transaction_type: RepeatingType.Income,\n second_recurrence_day: secondDay,\n transaction_type: upcomingTransaction.transaction_type,\n user_guid: user.guid,\n } as RepeatingTransaction\n\n await addRepeatingTransaction(repeatingTransaction, upcomingTransaction)\n }\n await completeOnboarding()\n }\n\n const showSelectIncome =\n (!transaction && addIncome) || (!transaction && selectedTransactions.length < 1)\n\n if (!isCopyLoaded) {\n return <Loader />\n }\n\n return (\n <Box\n sx={{\n display: 'flex',\n alignItems: !isMobile ? 'center' : 'flex-start',\n backgroundColor: theme.palette.background.paper,\n backgroundImage: !isMobile ? `url(${CASHFLOW_IMAGES.CASHFLOW_ONBOARDING})` : null,\n backgroundRepeat: 'no-repeat',\n backgroundPosition: 'left 100px',\n backgroundSize: '35%',\n py: 24,\n }}\n >\n {step === 1 && (\n <Box\n sx={{\n ...(isMobile\n ? { display: 'flex', flexDirection: 'column', maxWidth: '100%', padding: '0 16px' }\n : { maxWidth: 590, ml: '40%', mr: 90 }),\n }}\n >\n <StepOne handleNextStep={handleGetTransactions} />\n </Box>\n )}\n {step === 2 && (\n <Box\n sx={{\n ...(isMobile\n ? { display: 'flex', flexDirection: 'column', maxWidth: '100%', padding: '0 16px' }\n : { maxWidth: 590, ml: '40%', mr: 90 }),\n }}\n >\n <StepTwo />\n </Box>\n )}\n {step === 3 && (\n <Box\n sx={{\n ...(isMobile\n ? { display: 'flex', flexDirection: 'column', maxWidth: '100%', padding: '0 16px' }\n : { maxWidth: 590, ml: '40%', mr: 90 }),\n }}\n >\n <H2 pb={12} variant=\"h1\">\n {customCopy.add_income_title}\n </H2>\n <P mb={24}>{customCopy.add_income_description}</P>\n\n {selectedTransactions.length > 0 && !transaction && (\n <>\n <List>\n {selectedTransactions.map((transaction, index) => {\n return (\n <React.Fragment key={transaction.guid}>\n <SubheaderRow bgcolor=\"background.paper\">\n {fromUnixToDayOfWeekAndDate(\n getUnixTime(transaction.nextDate || transaction.date),\n )}\n </SubheaderRow>\n <TransactionRow transaction={transaction} />\n {index !== selectedTransactions.length - 1 && <Divider />}\n </React.Fragment>\n )\n })}\n </List>\n <Stack alignItems=\"center\" direction=\"row\">\n <Divider sx={{ flexGrow: 1 }} />\n <Button\n onClick={() => setAddIncome(true)}\n startIcon={<Icon name=\"add\" size={20} />}\n >\n {customCopy.add_income}\n </Button>\n </Stack>\n </>\n )}\n\n {showSelectIncome && (\n <SelectTransaction\n bgcolor=\"background.paper\"\n onSearch={(searchValue) =>\n setFilter({\n ...filter,\n custom: (transaction: Transaction) =>\n searchValue\n ? incomeFilterSearch(transaction, searchValue)\n : incomeFilter(transaction),\n })\n }\n onSelected={(guid) => {\n setTransactionGuid(guid)\n setAddIncome(false)\n }}\n />\n )}\n\n {!canSubmit && isDirty && (\n <P color=\"error\" mt={16}>\n {customCopy.confirm_error}\n </P>\n )}\n\n {transaction && (\n <>\n <AddRecurringTransactionDetails\n bgcolor=\"background.paper\"\n firstDay={firstDay}\n frequency={frequency}\n onFirstDayChange={setFirstDay}\n onFrequencyChange={setFrequency}\n onSecondDayChange={setSecondDay}\n secondDay={secondDay}\n transaction={transaction}\n />\n <Stack direction=\"row\" gap={16} ml={24} mt={32}>\n <Button\n aria-disabled={!transaction}\n onClick={() => {\n const updatedTransactions = [...selectedTransactions]\n updatedTransactions.push({\n ...transaction,\n nextDate: getNextPaymentDate(frequency, fromUnixTime(transaction.date)),\n frequency,\n })\n\n setSelectedTransactions(updatedTransactions)\n setTransactionGuid('')\n }}\n variant=\"contained\"\n >\n {commonCopy.confirm_button}\n </Button>\n <Button\n onClick={() => {\n setTransactionGuid('')\n setAddIncome(true)\n handleGetTransactions().finally()\n }}\n variant=\"text\"\n >\n {commonCopy.cancel_button}\n </Button>\n </Stack>\n </>\n )}\n\n {selectedTransactions.length > 0 && !transaction && (\n <Stack direction=\"row\" gap={16} ml={24} mt={32}>\n <Button\n aria-disabled={selectedTransactions.length < 1 || isSubmitting}\n onClick={handleAddIncome}\n startIcon={\n isSubmitting ? (\n <Icon\n name=\"progress_activity\"\n sx={{\n animation: `${spin} 2s linear infinite`,\n }}\n />\n ) : null\n }\n variant=\"contained\"\n >\n {customCopy.confirm_income_button}\n </Button>\n <Button onClick={completeOnboarding} variant=\"text\">\n {customCopy.skip_button}\n </Button>\n </Stack>\n )}\n </Box>\n )}\n </Box>\n )\n}\n\nexport default observer(CashflowOnboarding)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,IAAM,KAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GASP,KAAA,MAAqC;AACzC,QAAM,EAAE,yBAAA,GAAyB,uBAAA,EAAA,IAA0B,GAA8B,GACnF,EAAE,UAAU,GAAY,QAAQ,EAAA,IAAe,GAAmB,GAClE,EAAE,MAAA,EAAA,IAAS,GAAa,GACxB,EAAE,oBAAA,EAAA,IAAuB,GAAiB,GAC1C,EAAE,SAAA,EAAA,IAAY,GAAmB,GACjC,EAAE,UAAA,EAAA,IAAa,GAAc,GAC7B,EAAE,cAAA,GAAc,kBAAA,EAAA,IAAqB,GAAiB,GACtD,EAAE,QAAA,GAAQ,WAAA,GAAW,cAAA,EAAA,IAAiB,GAAoB,GAC1D,IAAQ,GAAS,GAEjB,CAAC,GAAW,CAAA,IAAgB,EAAS,EAAI,GACzC,CAAC,GAAW,CAAA,IAAgB,EAAM,SAAS,GAAU,UAAU,GAC/D,CAAC,GAAU,CAAA,IAAe,EAAM,SAAS,CAAC,GAC1C,CAAC,GAAW,CAAA,IAAgB,EAAM,SAAS,EAAE,GAC7C,CAAC,GAAc,CAAA,IAAmB,EAAS,EAAK,GAEhD,CAAC,GAAM,CAA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AAD;AAAA,YAAO,WAAU;AAAA,YAAM,KAAK;AAAA,YAAI,IAAI;AAAA,YAAI,IAAI;AAAA,YAA5C,UAAA,CACE,gBAAA,EAAC,GAAD;AAAA,cACE,iBAAe,EAAqB,SAAS,KAAK;AAAA,cAClD,SAAS;AAAA,cACT,WACE,IACE,gBAAA,EAAC,GAAD;AAAA,gBACE,MAAK;AAAA,gBACL,IAAI,EACF,WAAW,GAAG,EAAA,sBAChB;AAAA,cACD,CAAA,IACC;AAAA,cAEN,SAAQ;AAAA,cAEP,UAAA,EAAW;AAAA,YACN,CAAA,GACR,gBAAA,EAAC,GAAD;AAAA,cAAQ,SAAS;AAAA,cAAoB,SAAQ;AAAA,cAC1C,UAAA,EAAW;AAAA,YACN,CAAA,CACH;AAAA;QAEN;AAAA;IAEJ;AAAA,OA/KE,gBAAA,EAAC,IAAD,CAAS,CAAA;AAiLpB,GAEA,KAAe,GAAS,EAAkB"}
1
+ {"version":3,"file":"CashflowOnboarding.es.js","names":[],"sources":["../../src/cashflow/CashflowOnboarding.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { observer } from 'mobx-react-lite'\nimport { formatISO } from 'date-fns/formatISO'\nimport { fromUnixTime } from 'date-fns/fromUnixTime'\nimport { getUnixTime } from 'date-fns/getUnixTime'\nimport { startOfMonth } from 'date-fns/startOfMonth'\nimport { startOfToday } from 'date-fns/startOfToday'\nimport { subDays } from 'date-fns/subDays'\n\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Divider from '@mui/material/Divider'\nimport List from '@mui/material/List'\nimport Stack from '@mui/material/Stack'\nimport { keyframes } from '@mui/material/styles'\nimport { useTheme } from '@mui/material/styles'\n\nimport { H2, Icon, P } from '@mxenabled/mxui'\n\nimport StepOne from './components/onboarding/StepOne'\nimport StepTwo from './components/onboarding/StepTwo'\n\nimport {\n Loader,\n useCashflowStore,\n useGlobalCopyStore,\n useGlobalUiStore,\n useRecurringTransactionsStore,\n useScreenSize,\n useTransactionStore,\n useUserStore,\n} from '../common'\nimport { type RepeatingTransaction, type Transaction, RepeatingType, Frequency } from '../core'\nimport SubheaderRow from '../common/components/SubheaderRow'\n\nimport { useCashflowUiStore } from './context/hooks'\n\nimport { TransactionRow } from '../transactions'\nimport { incomeFilter, incomeFilterSearch } from '../transactions/utils/Filters'\n\nimport { AddRecurringTransactionDetails } from '../recurringtransactions'\nimport { SelectTransaction } from '../recurringtransactions'\nimport { getNextPaymentDate } from '../core/utils/RecurringTransactionsUtil'\n\nimport { fromUnixToDayOfWeekAndDate } from '../core/utils/DateUtil'\nimport { CASHFLOW_IMAGES } from './constants/CashflowImages'\n\ninterface UpcomingTransactions extends Transaction {\n nextDate: Date | null\n frequency: Frequency\n}\n\nconst spin = keyframes`\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n`\n\nconst CashflowOnboarding: React.FC = () => {\n const { addRepeatingTransaction, repeatingTransactions } = useRecurringTransactionsStore()\n const { cashflow: customCopy, common: commonCopy } = useGlobalCopyStore()\n const { user } = useUserStore()\n const { completeOnboarding } = useCashflowStore()\n const { isDirty } = useCashflowUiStore()\n const { isMobile } = useScreenSize()\n const { isCopyLoaded, setDisplayedDate } = useGlobalUiStore()\n const { filter, setFilter, transactions } = useTransactionStore()\n const theme = useTheme()\n\n const [addIncome, setAddIncome] = useState(true)\n const [frequency, setFrequency] = React.useState(Frequency.EveryMonth)\n const [firstDay, setFirstDay] = React.useState(1)\n const [secondDay, setSecondDay] = React.useState(15)\n const [isSubmitting, setIsSubmitting] = useState(false)\n // const [nextDate, setNextDate] = React.useState<Date | null>(null)\n const [step, setStep] = useState(1)\n const [selectedTransactions, setSelectedTransactions] = useState<UpcomingTransactions[] | []>([])\n const [transactionGuid, setTransactionGuid] = useState('')\n\n const transaction = React.useMemo(\n () => transactions.find((t) => t.guid === transactionGuid),\n [transactionGuid, transactions],\n )\n\n const canSubmit = !!repeatingTransactions.filter(\n (r) => r.repeating_transaction_type === RepeatingType.Income,\n ).length\n\n const handleGetTransactions = async () => {\n setStep(2)\n // set transaction date range and filter by income\n setDisplayedDate(\n // Beginning of the month, 90 days before today\n startOfMonth(subDays(startOfToday(), 90)),\n startOfToday(),\n )\n\n setFilter({ ...filter, custom: incomeFilter })\n\n setStep(3)\n }\n\n const handleAddIncome = async () => {\n if (selectedTransactions.length < 1) {\n return\n }\n setIsSubmitting(true)\n\n // Create Repeating Transactions\n for (let i = 0; i < selectedTransactions.length; i++) {\n const upcomingTransaction = selectedTransactions[i]\n\n const nextDate = getNextPaymentDate(frequency, fromUnixTime(upcomingTransaction.date))\n\n const repeatingTransaction = {\n account_guid: upcomingTransaction.account_guid,\n amount: upcomingTransaction.amount,\n created_by: 0, //user\n merchant_guid: upcomingTransaction.merchant_guid,\n description: upcomingTransaction.feed_description || upcomingTransaction.description,\n predicted_occurs_on: formatISO(nextDate, { representation: 'date' }),\n recurrence_day: nextDate.getDay(),\n recurrence_type: frequency,\n repeating_transaction_type: RepeatingType.Income,\n second_recurrence_day: secondDay,\n transaction_type: upcomingTransaction.transaction_type,\n user_guid: user.guid,\n } as RepeatingTransaction\n\n await addRepeatingTransaction(repeatingTransaction, upcomingTransaction)\n }\n await completeOnboarding()\n }\n\n const showSelectIncome =\n (!transaction && addIncome) || (!transaction && selectedTransactions.length < 1)\n\n if (!isCopyLoaded) {\n return <Loader />\n }\n\n return (\n <Box\n sx={{\n display: 'flex',\n alignItems: !isMobile ? 'center' : 'flex-start',\n backgroundColor: theme.palette.background.paper,\n backgroundImage: !isMobile ? `url(${CASHFLOW_IMAGES.CASHFLOW_ONBOARDING})` : null,\n backgroundRepeat: 'no-repeat',\n backgroundPosition: 'left 100px',\n backgroundSize: '35%',\n py: 24,\n }}\n >\n {step === 1 && (\n <Box\n sx={(isMobile\n ? { display: 'flex', flexDirection: 'column', maxWidth: '100%', padding: '0 16px' }\n : { maxWidth: 590, ml: '40%', mr: 90 })}\n >\n <StepOne handleNextStep={handleGetTransactions} />\n </Box>\n )}\n {step === 2 && (\n <Box\n sx={(isMobile\n ? { display: 'flex', flexDirection: 'column', maxWidth: '100%', padding: '0 16px' }\n : { maxWidth: 590, ml: '40%', mr: 90 })}\n >\n <StepTwo />\n </Box>\n )}\n {step === 3 && (\n <Box\n sx={(isMobile\n ? { display: 'flex', flexDirection: 'column', maxWidth: '100%', padding: '0 16px' }\n : { maxWidth: 590, ml: '40%', mr: 90 })}\n >\n <H2 pb={12} variant=\"h1\">\n {customCopy.add_income_title}\n </H2>\n <P mb={24}>{customCopy.add_income_description}</P>\n\n {selectedTransactions.length > 0 && !transaction && (\n <>\n <List>\n {selectedTransactions.map((transaction, index) => {\n return (\n <React.Fragment key={transaction.guid}>\n <SubheaderRow bgcolor=\"background.paper\">\n {fromUnixToDayOfWeekAndDate(\n getUnixTime(transaction.nextDate || transaction.date),\n )}\n </SubheaderRow>\n <TransactionRow transaction={transaction} />\n {index !== selectedTransactions.length - 1 && <Divider />}\n </React.Fragment>\n )\n })}\n </List>\n <Stack alignItems=\"center\" direction=\"row\">\n <Divider sx={{ flexGrow: 1 }} />\n <Button\n onClick={() => setAddIncome(true)}\n startIcon={<Icon name=\"add\" size={20} />}\n >\n {customCopy.add_income}\n </Button>\n </Stack>\n </>\n )}\n\n {showSelectIncome && (\n <SelectTransaction\n bgcolor=\"background.paper\"\n onSearch={(searchValue) =>\n setFilter({\n ...filter,\n custom: (transaction: Transaction) =>\n searchValue\n ? incomeFilterSearch(transaction, searchValue)\n : incomeFilter(transaction),\n })\n }\n onSelected={(guid) => {\n setTransactionGuid(guid)\n setAddIncome(false)\n }}\n />\n )}\n\n {!canSubmit && isDirty && (\n <P color=\"error\" mt={16}>\n {customCopy.confirm_error}\n </P>\n )}\n\n {transaction && (\n <>\n <AddRecurringTransactionDetails\n bgcolor=\"background.paper\"\n firstDay={firstDay}\n frequency={frequency}\n onFirstDayChange={setFirstDay}\n onFrequencyChange={setFrequency}\n onSecondDayChange={setSecondDay}\n secondDay={secondDay}\n transaction={transaction}\n />\n <Stack direction=\"row\" gap={16} ml={24} mt={32}>\n <Button\n aria-disabled={!transaction}\n onClick={() => {\n const updatedTransactions = [...selectedTransactions]\n updatedTransactions.push({\n ...transaction,\n nextDate: getNextPaymentDate(frequency, fromUnixTime(transaction.date)),\n frequency,\n })\n\n setSelectedTransactions(updatedTransactions)\n setTransactionGuid('')\n }}\n variant=\"contained\"\n >\n {commonCopy.confirm_button}\n </Button>\n <Button\n onClick={() => {\n setTransactionGuid('')\n setAddIncome(true)\n handleGetTransactions().finally()\n }}\n variant=\"text\"\n >\n {commonCopy.cancel_button}\n </Button>\n </Stack>\n </>\n )}\n\n {selectedTransactions.length > 0 && !transaction && (\n <Stack direction=\"row\" gap={16} ml={24} mt={32}>\n <Button\n aria-disabled={selectedTransactions.length < 1 || isSubmitting}\n onClick={handleAddIncome}\n startIcon={\n isSubmitting ? (\n <Icon\n name=\"progress_activity\"\n sx={{\n animation: `${spin} 2s linear infinite`,\n }}\n />\n ) : null\n }\n variant=\"contained\"\n >\n {customCopy.confirm_income_button}\n </Button>\n <Button onClick={completeOnboarding} variant=\"text\">\n {customCopy.skip_button}\n </Button>\n </Stack>\n )}\n </Box>\n )}\n </Box>\n )\n}\n\nexport default observer(CashflowOnboarding)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,IAAM,KAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GASP,KAAA,MAAqC;AACzC,QAAM,EAAE,yBAAA,GAAyB,uBAAA,EAAA,IAA0B,GAA8B,GACnF,EAAE,UAAU,GAAY,QAAQ,EAAA,IAAe,GAAmB,GAClE,EAAE,MAAA,EAAA,IAAS,GAAa,GACxB,EAAE,oBAAA,EAAA,IAAuB,GAAiB,GAC1C,EAAE,SAAA,EAAA,IAAY,GAAmB,GACjC,EAAE,UAAA,EAAA,IAAa,GAAc,GAC7B,EAAE,cAAA,GAAc,kBAAA,EAAA,IAAqB,GAAiB,GACtD,EAAE,QAAA,GAAQ,WAA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AA,EAAC,GAAD;AAAA,cACE,SAAA,MAAe;AACb,gBAAA,EAAmB,EAAE,GACrB,EAAa,EAAI,GACjB,EAAsB,EAAE,QAAQ;AAAA,cAClC;AAAA,cACA,SAAQ;AAAA,cAEP,UAAA,EAAW;AAAA,YACN,CAAA,CACH;AAAA,UACP,CAAA,CAAA,EAAA,CAAA;AAAA,UAGH,EAAqB,SAAS,KAAK,CAAC,KACnC,gBAAA,EAAC,GAAD;AAAA,YAAO,WAAU;AAAA,YAAM,KAAK;AAAA,YAAI,IAAI;AAAA,YAAI,IAAI;AAAA,YAA5C,UAAA,CACE,gBAAA,EAAC,GAAD;AAAA,cACE,iBAAe,EAAqB,SAAS,KAAK;AAAA,cAClD,SAAS;AAAA,cACT,WACE,IACE,gBAAA,EAAC,GAAD;AAAA,gBACE,MAAK;AAAA,gBACL,IAAI,EACF,WAAW,GAAG,EAAA,sBAChB;AAAA,cACD,CAAA,IACC;AAAA,cAEN,SAAQ;AAAA,cAEP,UAAA,EAAW;AAAA,YACN,CAAA,GACR,gBAAA,EAAC,GAAD;AAAA,cAAQ,SAAS;AAAA,cAAoB,SAAQ;AAAA,cAC1C,UAAA,EAAW;AAAA,YACN,CAAA,CACH;AAAA;QAEN;AAAA;IAEJ;AAAA,OAzKE,gBAAA,EAAC,IAAD,CAAS,CAAA;AA2KpB,GAEA,KAAe,GAAS,EAAkB"}
@@ -1,9 +1,10 @@
1
1
  import { Fetch } from '../utils';
2
- import { GlobalErrorHandler, User, UserProfile } from '..';
2
+ import { GlobalErrorHandler, User, UserInsightProfile, UserProfile } from '..';
3
3
  export declare class UserApi {
4
4
  fetchInstance: Fetch;
5
5
  constructor(endpoint: string, token: string, onError?: GlobalErrorHandler);
6
6
  getUserFeatures: () => Promise<any>;
7
7
  updateUser: (user: User) => Promise<any>;
8
8
  updateUserProfile: (userProfile: UserProfile) => Promise<any>;
9
+ updateUserInsightProfile: (profile: Partial<UserInsightProfile>) => Promise<UserInsightProfile>;
9
10
  }
@@ -2,12 +2,13 @@ import { ApiEndpoints as s } from "../constants/ApiEndpoints.es.js";
2
2
  import { Fetch as r } from "../utils/Fetch.es.js";
3
3
  var h = class {
4
4
  fetchInstance;
5
- constructor(t, e, n) {
6
- this.fetchInstance = new r(t, e, void 0, n);
5
+ constructor(e, t, n) {
6
+ this.fetchInstance = new r(e, t, void 0, n);
7
7
  }
8
- getUserFeatures = async () => this.fetchInstance.get(s.USER_FEATURES).then((t) => t.user_features);
9
- updateUser = async (t) => this.fetchInstance.put(s.USER, t).then((e) => e.user);
10
- updateUserProfile = async (t) => this.fetchInstance.put(`${s.USER_PROFILES}/${t.guid}`, t).then((e) => e.user_profile);
8
+ getUserFeatures = async () => this.fetchInstance.get(s.USER_FEATURES).then((e) => e.user_features);
9
+ updateUser = async (e) => this.fetchInstance.put(s.USER, e).then((t) => t.user);
10
+ updateUserProfile = async (e) => this.fetchInstance.put(`${s.USER_PROFILES}/${e.guid}`, e).then((t) => t.user_profile);
11
+ updateUserInsightProfile = async (e) => this.fetchInstance.put(s.USER_INSIGHT_PROFILE, { user_insight_profile: e }).then((t) => t.user_insight_profile);
11
12
  };
12
13
  export {
13
14
  h as UserApi
@@ -1 +1 @@
1
- {"version":3,"file":"UserApi.es.js","names":[],"sources":["../../../src/core/api/UserApi.ts"],"sourcesContent":["import { Fetch } from '../utils'\nimport { ApiEndpoints } from '../constants'\nimport type { GlobalErrorHandler, User, UserProfile } from '..'\n\nexport class UserApi {\n fetchInstance: Fetch\n\n constructor(endpoint: string, token: string, onError?: GlobalErrorHandler) {\n this.fetchInstance = new Fetch(endpoint, token, undefined, onError)\n }\n\n getUserFeatures = async () => {\n return this.fetchInstance.get(ApiEndpoints.USER_FEATURES).then((data) => data.user_features)\n }\n\n updateUser = async (user: User) => {\n return this.fetchInstance.put(ApiEndpoints.USER, user).then((data) => data.user)\n }\n\n updateUserProfile = async (userProfile: UserProfile) => {\n return this.fetchInstance\n .put(`${ApiEndpoints.USER_PROFILES}/${userProfile.guid}`, userProfile)\n .then((data) => data.user_profile)\n }\n}\n"],"mappings":";;AAIA,IAAa,IAAb,MAAqB;AAAA,EACnB;AAAA,EAEA,YAAY,GAAkB,GAAe,GAA8B;AACzE,SAAK,gBAAgB,IAAI,EAAM,GAAU,GAAO,QAAW,CAAO;AAAA,EACpE;AAAA,EAEA,kBAAkB,YACT,KAAK,cAAc,IAAI,EAAa,aAAa,EAAE,KAAA,CAAM,MAAS,EAAK,aAAa;AAAA,EAG7F,aAAa,OAAO,MACX,KAAK,cAAc,IAAI,EAAa,MAAM,CAAI,EAAE,KAAA,CAAM,MAAS,EAAK,IAAI;AAAA,EAGjF,oBAAoB,OAAO,MAClB,KAAK,cACT,IAAI,GAAG,EAAa,aAAA,IAAiB,EAAY,IAAA,IAAQ,CAAW,EACpE,KAAA,CAAM,MAAS,EAAK,YAAY;AAEvC"}
1
+ {"version":3,"file":"UserApi.es.js","names":[],"sources":["../../../src/core/api/UserApi.ts"],"sourcesContent":["import { Fetch } from '../utils'\nimport { ApiEndpoints } from '../constants'\nimport type { GlobalErrorHandler, User, UserInsightProfile, UserProfile } from '..'\n\nexport class UserApi {\n fetchInstance: Fetch\n\n constructor(endpoint: string, token: string, onError?: GlobalErrorHandler) {\n this.fetchInstance = new Fetch(endpoint, token, undefined, onError)\n }\n\n getUserFeatures = async () => {\n return this.fetchInstance.get(ApiEndpoints.USER_FEATURES).then((data) => data.user_features)\n }\n\n updateUser = async (user: User) => {\n return this.fetchInstance.put(ApiEndpoints.USER, user).then((data) => data.user)\n }\n\n updateUserProfile = async (userProfile: UserProfile) => {\n return this.fetchInstance\n .put(`${ApiEndpoints.USER_PROFILES}/${userProfile.guid}`, userProfile)\n .then((data) => data.user_profile)\n }\n\n // The endpoint is singular per user, so no guid in the path (mirrors pulse FireflyAPI).\n updateUserInsightProfile = async (\n profile: Partial<UserInsightProfile>,\n ): Promise<UserInsightProfile> => {\n return this.fetchInstance\n .put(ApiEndpoints.USER_INSIGHT_PROFILE, { user_insight_profile: profile })\n .then((data) => data.user_insight_profile)\n }\n}\n"],"mappings":";;AAIA,IAAa,IAAb,MAAqB;AAAA,EACnB;AAAA,EAEA,YAAY,GAAkB,GAAe,GAA8B;AACzE,SAAK,gBAAgB,IAAI,EAAM,GAAU,GAAO,QAAW,CAAO;AAAA,EACpE;AAAA,EAEA,kBAAkB,YACT,KAAK,cAAc,IAAI,EAAa,aAAa,EAAE,KAAA,CAAM,MAAS,EAAK,aAAa;AAAA,EAG7F,aAAa,OAAO,MACX,KAAK,cAAc,IAAI,EAAa,MAAM,CAAI,EAAE,KAAA,CAAM,MAAS,EAAK,IAAI;AAAA,EAGjF,oBAAoB,OAAO,MAClB,KAAK,cACT,IAAI,GAAG,EAAa,aAAA,IAAiB,EAAY,IAAA,IAAQ,CAAW,EACpE,KAAA,CAAM,MAAS,EAAK,YAAY;AAAA,EAIrC,2BAA2B,OACzB,MAEO,KAAK,cACT,IAAI,EAAa,sBAAsB,EAAE,sBAAsB,EAAQ,CAAC,EACxE,KAAA,CAAM,MAAS,EAAK,oBAAoB;AAE/C"}
@@ -42,6 +42,7 @@ export declare const ApiEndpoints: {
42
42
  USER: string;
43
43
  USER_COMMUNICATION_PROFILE: string;
44
44
  USER_FEATURES: string;
45
+ USER_INSIGHT_PROFILE: string;
45
46
  USER_PROFILES: string;
46
47
  WIDGET_URLS: string;
47
48
  };
@@ -42,6 +42,7 @@ var _ = {
42
42
  USER: "user",
43
43
  USER_COMMUNICATION_PROFILE: "user_communication_profile",
44
44
  USER_FEATURES: "user_features",
45
+ USER_INSIGHT_PROFILE: "user_insight_profile",
45
46
  USER_PROFILES: "user_profiles",
46
47
  WIDGET_URLS: "widget_urls"
47
48
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ApiEndpoints.es.js","names":[],"sources":["../../../src/core/constants/ApiEndpoints.ts"],"sourcesContent":["export const ApiEndpoints = {\n ACCOUNTS: 'accounts',\n ANALYTICS_EVENTS: 'analytics_events',\n ANALYTICS_FEATURE_VISITS: 'feature_visits',\n ANALYTICS_PAGEVIEWS: 'analytics_pageviews',\n ANALYTICS_SESSION: 'analytics_sessions',\n APP_DATA: 'raja/data?type=master',\n BEATS: 'beats',\n BUDGETS: 'budgets',\n CATEGORIES: 'categories',\n CHANGE_PASSWORD: 'user/change_password',\n DATE_RANGE_CATEGORY_TOTALS: 'date_range_category_totals',\n DEVICES: 'devices',\n EMAIL_VERIFICATIONS: 'email_verifications',\n GOALS: 'goals',\n HEALTH_SCORES: 'health_scores',\n HOLDINGS: 'holdings',\n INSTITUTIONS: 'institutions',\n INSIGHTS_NOTIFICATION_PROFILES: 'insight_notification_profiles',\n LOCALIZED_COPY: 'localized_copies',\n LOCALIZED_CONTENT: 'localized_content',\n MEMBERS: 'members',\n MERCHANTS: 'merchants',\n MERCHANT_BUDGETS: 'merchant_budgets',\n MONTHLY_CASH_FLOW_PROFILE: 'monthly_cash_flow_profile',\n MONTHLY_CATEGORY_TOTALS: 'monthly_category_totals',\n OFFERS: 'offers',\n NOTIFICATION_PROFILES: 'notification_profiles',\n NOTIFICATIONS: 'notifications',\n PHONE_VERIFICATIONS: 'sms_verification',\n PULSE_COMMUNICATIONS: 'pulse_communications',\n REPEATING_TRANSACTIONS: 'repeating_transactions',\n RETIREMENT_GOALS: 'retirement_goals',\n RETIREMENT_GOAL_ACCOUNTS: 'retirement_goal_accounts',\n SCHEDULED_PAYMENTS: 'scheduled_payments',\n SPENDING_PLANS: 'spending_plans',\n SUPPORT_TICKETS: 'support_tickets',\n TAGGINGS: 'taggings',\n TAGS: 'tags',\n TRANSACTION_RULES: 'transaction_rules',\n TRANSACTIONS: 'transactions',\n USER: 'user',\n USER_COMMUNICATION_PROFILE: 'user_communication_profile',\n USER_FEATURES: 'user_features',\n USER_PROFILES: 'user_profiles',\n WIDGET_URLS: 'widget_urls',\n}\n"],"mappings":"AAAA,IAAa,IAAe;AAAA,EAC1B,UAAU;AAAA,EACV,kBAAkB;AAAA,EAClB,0BAA0B;AAAA,EAC1B,qBAAqB;AAAA,EACrB,mBAAmB;AAAA,EACnB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,iBAAiB;AAAA,EACjB,4BAA4B;AAAA,EAC5B,SAAS;AAAA,EACT,qBAAqB;AAAA,EACrB,OAAO;AAAA,EACP,eAAe;AAAA,EACf,UAAU;AAAA,EACV,cAAc;AAAA,EACd,gCAAgC;AAAA,EAChC,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,SAAS;AAAA,EACT,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB,2BAA2B;AAAA,EAC3B,yBAAyB;AAAA,EACzB,QAAQ;AAAA,EACR,uBAAuB;AAAA,EACvB,eAAe;AAAA,EACf,qBAAqB;AAAA,EACrB,sBAAsB;AAAA,EACtB,wBAAwB;AAAA,EACxB,kBAAkB;AAAA,EAClB,0BAA0B;AAAA,EAC1B,oBAAoB;AAAA,EACpB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,UAAU;AAAA,EACV,MAAM;AAAA,EACN,mBAAmB;AAAA,EACnB,cAAc;AAAA,EACd,MAAM;AAAA,EACN,4BAA4B;AAAA,EAC5B,eAAe;AAAA,EACf,eAAe;AAAA,EACf,aAAa;AACf"}
1
+ {"version":3,"file":"ApiEndpoints.es.js","names":[],"sources":["../../../src/core/constants/ApiEndpoints.ts"],"sourcesContent":["export const ApiEndpoints = {\n ACCOUNTS: 'accounts',\n ANALYTICS_EVENTS: 'analytics_events',\n ANALYTICS_FEATURE_VISITS: 'feature_visits',\n ANALYTICS_PAGEVIEWS: 'analytics_pageviews',\n ANALYTICS_SESSION: 'analytics_sessions',\n APP_DATA: 'raja/data?type=master',\n BEATS: 'beats',\n BUDGETS: 'budgets',\n CATEGORIES: 'categories',\n CHANGE_PASSWORD: 'user/change_password',\n DATE_RANGE_CATEGORY_TOTALS: 'date_range_category_totals',\n DEVICES: 'devices',\n EMAIL_VERIFICATIONS: 'email_verifications',\n GOALS: 'goals',\n HEALTH_SCORES: 'health_scores',\n HOLDINGS: 'holdings',\n INSTITUTIONS: 'institutions',\n INSIGHTS_NOTIFICATION_PROFILES: 'insight_notification_profiles',\n LOCALIZED_COPY: 'localized_copies',\n LOCALIZED_CONTENT: 'localized_content',\n MEMBERS: 'members',\n MERCHANTS: 'merchants',\n MERCHANT_BUDGETS: 'merchant_budgets',\n MONTHLY_CASH_FLOW_PROFILE: 'monthly_cash_flow_profile',\n MONTHLY_CATEGORY_TOTALS: 'monthly_category_totals',\n OFFERS: 'offers',\n NOTIFICATION_PROFILES: 'notification_profiles',\n NOTIFICATIONS: 'notifications',\n PHONE_VERIFICATIONS: 'sms_verification',\n PULSE_COMMUNICATIONS: 'pulse_communications',\n REPEATING_TRANSACTIONS: 'repeating_transactions',\n RETIREMENT_GOALS: 'retirement_goals',\n RETIREMENT_GOAL_ACCOUNTS: 'retirement_goal_accounts',\n SCHEDULED_PAYMENTS: 'scheduled_payments',\n SPENDING_PLANS: 'spending_plans',\n SUPPORT_TICKETS: 'support_tickets',\n TAGGINGS: 'taggings',\n TAGS: 'tags',\n TRANSACTION_RULES: 'transaction_rules',\n TRANSACTIONS: 'transactions',\n USER: 'user',\n USER_COMMUNICATION_PROFILE: 'user_communication_profile',\n USER_FEATURES: 'user_features',\n USER_INSIGHT_PROFILE: 'user_insight_profile',\n USER_PROFILES: 'user_profiles',\n WIDGET_URLS: 'widget_urls',\n}\n"],"mappings":"AAAA,IAAa,IAAe;AAAA,EAC1B,UAAU;AAAA,EACV,kBAAkB;AAAA,EAClB,0BAA0B;AAAA,EAC1B,qBAAqB;AAAA,EACrB,mBAAmB;AAAA,EACnB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,iBAAiB;AAAA,EACjB,4BAA4B;AAAA,EAC5B,SAAS;AAAA,EACT,qBAAqB;AAAA,EACrB,OAAO;AAAA,EACP,eAAe;AAAA,EACf,UAAU;AAAA,EACV,cAAc;AAAA,EACd,gCAAgC;AAAA,EAChC,gBAAgB;AAAA,EAChB,mBAAmB;AAAA,EACnB,SAAS;AAAA,EACT,WAAW;AAAA,EACX,kBAAkB;AAAA,EAClB,2BAA2B;AAAA,EAC3B,yBAAyB;AAAA,EACzB,QAAQ;AAAA,EACR,uBAAuB;AAAA,EACvB,eAAe;AAAA,EACf,qBAAqB;AAAA,EACrB,sBAAsB;AAAA,EACtB,wBAAwB;AAAA,EACxB,kBAAkB;AAAA,EAClB,0BAA0B;AAAA,EAC1B,oBAAoB;AAAA,EACpB,gBAAgB;AAAA,EAChB,iBAAiB;AAAA,EACjB,UAAU;AAAA,EACV,MAAM;AAAA,EACN,mBAAmB;AAAA,EACnB,cAAc;AAAA,EACd,MAAM;AAAA,EACN,4BAA4B;AAAA,EAC5B,eAAe;AAAA,EACf,sBAAsB;AAAA,EACtB,eAAe;AAAA,EACf,aAAa;AACf"}
@@ -53,7 +53,8 @@ export declare class AccountStore {
53
53
  refreshAccounts: () => Promise<void>;
54
54
  refreshMembers: () => Promise<void>;
55
55
  removeAccount: (accountGuid: string) => Promise<void>;
56
- updateAccount: (account: Account) => Promise<void>;
56
+ /** Resolves `true` when the account was saved, `false` when the API call failed. */
57
+ updateAccount: (account: Account) => Promise<boolean>;
57
58
  updateAccountBalance: (accountGuid: string, balanceChange: number) => void;
58
59
  updateAccountFilter: (accountMap: Map<string, boolean>) => Promise<void>;
59
60
  }
@@ -37,8 +37,8 @@ var C = class {
37
37
  get accountsByTypeMap() {
38
38
  return this.detailedAccounts.reduce((t, e) => {
39
39
  const s = e.account_type;
40
- let o = t.get(s);
41
- return o || (o = []), o.push(e), t.set(s, o), t;
40
+ let n = t.get(s);
41
+ return n || (n = []), n.push(e), t.set(s, n), t;
42
42
  }, /* @__PURE__ */ new Map());
43
43
  }
44
44
  get cashAccounts() {
@@ -163,9 +163,9 @@ var C = class {
163
163
  try {
164
164
  const e = await this.api.mergeAccounts(t), s = e[Object.keys(e)[0]];
165
165
  d(() => {
166
- const o = this.accounts.findIndex((n) => n.guid === t[1]);
167
- this.accounts.splice(o, 1);
168
- const i = this.accounts.findIndex((n) => n.guid === t[0]);
166
+ const n = this.accounts.findIndex((o) => o.guid === t[1]);
167
+ this.accounts.splice(n, 1);
168
+ const i = this.accounts.findIndex((o) => o.guid === t[0]);
169
169
  this.accounts.splice(i, 1, s);
170
170
  });
171
171
  } catch (e) {
@@ -197,14 +197,14 @@ var C = class {
197
197
  };
198
198
  updateAccount = async (t) => {
199
199
  try {
200
- const e = await this.api.updateAccount(t), s = this.accounts.findIndex((o) => o.guid === e.guid);
201
- this.accounts.splice(s, 1, e);
200
+ const e = await this.api.updateAccount(t), s = this.accounts.findIndex((n) => n.guid === e.guid);
201
+ return this.accounts.splice(s, 1, e), !0;
202
202
  } catch (e) {
203
- console.error("Error occurred while updating account:", e), this.globalStore.captureException(e, { store: "AccountStore" });
203
+ return console.error("Error occurred while updating account:", e), this.globalStore.captureException(e, { store: "AccountStore" }), !1;
204
204
  }
205
205
  };
206
206
  updateAccountBalance = (t, e) => {
207
- const s = this.accounts.find((o) => o.guid === t);
207
+ const s = this.accounts.find((n) => n.guid === t);
208
208
  s && d(() => {
209
209
  s.balance = (s.balance || 0) + e;
210
210
  });
@@ -212,22 +212,22 @@ var C = class {
212
212
  updateAccountFilter = async (t) => {
213
213
  try {
214
214
  const e = [];
215
- for (const [i, n] of t.entries()) {
215
+ for (const [i, o] of t.entries()) {
216
216
  const r = this.accounts.find((u) => u.guid === i);
217
- if (r && r.is_excluded_from_accounts === n) {
217
+ if (r && r.is_excluded_from_accounts === o) {
218
218
  const u = {
219
219
  ...r,
220
- is_excluded_from_accounts: !n
220
+ is_excluded_from_accounts: !o
221
221
  };
222
222
  e.push(this.api.updateAccount(u).catch((l) => (console.error("Error occurred while updating account filter:", l), this.globalStore.captureException(l, { store: "AccountStore" }), null)));
223
223
  }
224
224
  }
225
- const s = (await Promise.all(e)).filter((i) => i !== null), o = [...this.accounts];
225
+ const s = (await Promise.all(e)).filter((i) => i !== null), n = [...this.accounts];
226
226
  for (const i of s) {
227
- const n = o.findIndex((r) => r.guid === i.guid);
228
- n !== -1 && o.splice(n, 1, i);
227
+ const o = n.findIndex((r) => r.guid === i.guid);
228
+ o !== -1 && n.splice(o, 1, i);
229
229
  }
230
- this.setAccounts(o);
230
+ this.setAccounts(n);
231
231
  } catch (e) {
232
232
  console.error("Error occurred while updating account filter:", e), this.globalStore.captureException(e, { store: "AccountStore" });
233
233
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AccountStore.es.js","names":[],"sources":["../../../src/core/stores/AccountStore.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from 'mobx'\n\nimport { AccountApi } from '../api'\nimport { upsertByGuid } from '../utils/upsertByGuid'\nimport {\n type Account,\n type DetailedAccount,\n type Institution,\n type Member,\n AccountType,\n AccountSubType,\n} from '../types'\nimport { augmentAccounts } from '../utils/AccountUtils'\nimport { isFeatureEnabled } from '../utils/UserUtils'\n\nimport { GlobalStore } from './GlobalStore'\n\nexport class AccountStore {\n globalStore: GlobalStore\n api: AccountApi = new AccountApi('/', '')\n\n accounts: Account[] = []\n accountsLoaded: boolean = false\n accountsLoading: boolean = false\n institutions: Institution[] = []\n institutionsLoaded: boolean = false\n institutionsLoading: boolean = false\n members: Member[] = []\n membersLoaded: boolean = false\n membersLoading: boolean = false\n uiStore: UiStore\n\n constructor(globalStore: GlobalStore) {\n this.globalStore = globalStore\n this.uiStore = new UiStore()\n this.api = new AccountApi(globalStore.endpoint, globalStore.sessionToken, globalStore.onError)\n\n makeAutoObservable(this)\n }\n\n loadAccountData = async () => {\n await Promise.all([this.loadAccounts(), this.loadMembers(), this.loadInstitutions()])\n }\n\n get isAccountDataLoaded(): boolean {\n return this.accountsLoaded && this.membersLoaded && this.institutionsLoaded\n }\n\n get detailedAccounts(): DetailedAccount[] {\n const userFeatures = this.globalStore.userStore.userFeatures\n const excludeExternal = isFeatureEnabled(userFeatures, 'MD_EXCLUDE_EXTERNAL_ACCOUNTS')\n\n // Hide held account when this flag is toggled and this is the individual accounts widget\n const excludeHeld =\n this.globalStore.appConfig.config.display_only_external_accounts_in_accounts &&\n this.globalStore.appConfig.options.subtype === 'accounts' // Indicates this is an individual widget\n\n return augmentAccounts(\n this.accounts,\n this.institutions,\n this.members,\n excludeExternal,\n excludeHeld,\n )\n }\n\n get accountsByTypeMap(): Map<AccountType, DetailedAccount[]> {\n return this.detailedAccounts.reduce((typeMap: Map<AccountType, DetailedAccount[]>, account) => {\n const accountType = account.account_type\n\n let accounts = typeMap.get(accountType)\n if (!accounts) {\n accounts = []\n }\n accounts.push(account)\n typeMap.set(accountType, accounts)\n\n return typeMap\n }, new Map<AccountType, DetailedAccount[]>())\n }\n\n get cashAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter(\n (account: Account) =>\n account.account_type === AccountType.CASH ||\n account.account_type === AccountType.CHECKING ||\n account.account_type === AccountType.PREPAID ||\n account.account_type === AccountType.SAVINGS ||\n account.account_type === AccountType.CHECKING_LINE_OF_CREDIT,\n )\n }\n\n get cashBalance(): number {\n return this.cashAccounts.reduce((total, account) => total + (account?.balance || 0), 0)\n }\n\n get checkingAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter((a: Account) => a.account_type === AccountType.CHECKING)\n }\n\n get debtAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter(\n (account: Account) =>\n account.account_type === AccountType.CREDIT_CARD ||\n account.account_type === AccountType.LOAN ||\n account.account_type === AccountType.MORTGAGE ||\n account.account_type === AccountType.LINE_OF_CREDIT ||\n account.account_type === AccountType.CHECKING_LINE_OF_CREDIT,\n )\n }\n\n get finstrongAccounts(): DetailedAccount[] {\n const eligibleTypes = new Set([\n AccountType.CHECKING,\n AccountType.SAVINGS,\n AccountType.CREDIT_CARD,\n AccountType.INVESTMENT,\n ])\n\n return this.detailedAccounts.filter((account) => eligibleTypes.has(account.account_type))\n }\n\n get investmentAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter(\n (account: Account) => account.account_type === AccountType.INVESTMENT,\n )\n }\n\n get manualAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter((account) => account.is_manual)\n }\n\n get savingsAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter((a: Account) => a.account_type === AccountType.SAVINGS)\n }\n\n get retirementAccounts(): Account[] {\n return this.detailedAccounts.filter(\n (account: Account) =>\n account.account_type === AccountType.INVESTMENT ||\n account.account_type === AccountType.SAVINGS ||\n account.account_type === AccountType.CHECKING ||\n account.account_type === AccountType.CASH ||\n account.account_type === AccountType.PROPERTY ||\n (account.account_type === AccountType.INSURANCE &&\n (account.account_subtype === AccountSubType.WHOLE_LIFE ||\n account.account_subtype === AccountSubType.UNIVERSAL_LIFE ||\n account.account_subtype === AccountSubType.VARIABLE_UNIVERSAL_LIFE)),\n )\n }\n\n get visibleAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter((a: Account) => !a.is_hidden && !a.is_closed)\n }\n\n get visibleCashAccounts(): DetailedAccount[] {\n return this.cashAccounts.filter((account: Account) => !account.is_hidden)\n }\n\n get visibleCashBalance(): number {\n return this.visibleCashAccounts.reduce((total, account) => total + (account?.balance || 0), 0)\n }\n\n get visibleCheckingAccounts(): DetailedAccount[] {\n return this.checkingAccounts.filter((account: Account) => !account.is_hidden)\n }\n\n get visibleDebtAccounts(): DetailedAccount[] {\n return this.debtAccounts.filter((account: Account) => !account.is_hidden)\n }\n\n get visibleFinstrongAccounts(): DetailedAccount[] {\n return this.finstrongAccounts.filter(\n (account: Account) => !(account.is_closed || account.is_deleted || account.is_hidden),\n )\n }\n\n get visibleRetirementAccounts(): Account[] {\n return this.retirementAccounts.filter((account: Account) => !account.is_hidden)\n }\n\n get visibleInvestmentAccounts(): DetailedAccount[] {\n return this.investmentAccounts.filter((account: Account) => !account.is_hidden)\n }\n\n get visibleSavingsAccounts(): DetailedAccount[] {\n return this.savingsAccounts.filter((account: Account) => !account.is_hidden)\n }\n\n get savingsAndCheckingAccountsBalance(): number {\n const savingsAndCheckingAccountsList = this.savingsAndCheckingAccounts\n\n return savingsAndCheckingAccountsList.reduce(\n (total, account) => total + (account?.balance || 0),\n 0,\n )\n }\n\n get savingsAndCheckingAccounts(): Account[] {\n const savingsAndCheckingAccounts = this.accounts.filter(\n (account: Account) =>\n account.account_type === AccountType.SAVINGS ||\n account.account_type === AccountType.CHECKING,\n )\n\n return savingsAndCheckingAccounts\n }\n\n setAccounts = (accounts: Account[]) => {\n this.accounts = accounts\n this.accountsLoading = false\n this.accountsLoaded = true\n }\n\n setMembers = (members: Member[]) => {\n this.members = members\n this.membersLoading = false\n this.membersLoaded = true\n }\n\n setInstitutions = (institutions: Institution[]) => {\n this.institutions = institutions\n this.institutionsLoading = false\n this.institutionsLoaded = true\n }\n\n addAccount = async (account: Account) => {\n try {\n const newAccount = await this.api.createAccount(account)\n\n runInAction(() => {\n this.accounts = upsertByGuid(this.accounts, newAccount)\n })\n } catch (error) {\n console.error('Error occurred while adding an account:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n }\n }\n\n loadAccounts = async () => {\n if (this.accountsLoading) return\n\n this.accountsLoading = true\n try {\n const accounts = await this.api.getAccounts()\n this.setAccounts(accounts)\n } catch (error) {\n console.error('Error occurred while loading accounts:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n this.setAccounts([])\n }\n }\n\n loadInstitutions = async () => {\n if (this.institutionsLoading) return\n\n this.institutionsLoading = true\n try {\n const institutions = await this.api.getInstitutions()\n this.setInstitutions(institutions)\n } catch (error) {\n console.error('Error occurred while loading institutions:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n this.setInstitutions([])\n }\n }\n\n loadMembers = async () => {\n if (this.membersLoading) return\n\n this.membersLoading = true\n try {\n const members = await this.api.getMembers()\n this.setMembers(members)\n } catch (error) {\n console.error('Error occurred while loading members:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n this.setMembers([])\n }\n }\n\n mergeAccounts = async (accountGuids: string[]) => {\n try {\n const response = await this.api.mergeAccounts(accountGuids)\n // the response from the api is a funky database key here, so this is essentially just getting the first item in the returned object\n // to prevent making multiple api calls here\n const mergedAccount = response[Object.keys(response)[0]]\n\n runInAction(() => {\n const account2Index = this.accounts.findIndex((account) => account.guid === accountGuids[1])\n this.accounts.splice(account2Index, 1)\n\n const account1Index = this.accounts.findIndex((account) => account.guid === accountGuids[0])\n this.accounts.splice(account1Index, 1, mergedAccount)\n })\n } catch (error) {\n console.error('Error occurred while merging accounts:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n }\n }\n\n /**\n * DEPRECATED: Use loadAccountData instead\n */\n refreshAccounts = async () => {\n await Promise.all([this.loadAccounts(), this.loadInstitutions(), this.loadMembers()])\n }\n\n refreshMembers = async () => {\n try {\n await this.api.refreshAllMembers()\n } catch (error) {\n console.error('Error occurred while refreshing members:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n }\n }\n\n removeAccount = async (accountGuid: string) => {\n try {\n await this.api.deleteAccount(accountGuid)\n\n const deletedIndex = this.accounts.findIndex((account) => account.guid === accountGuid)\n this.accounts.splice(deletedIndex, 1)\n } catch (error) {\n console.error('Error occurred while removing an account:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n }\n }\n\n updateAccount = async (account: Account) => {\n try {\n const updatedAccount = await this.api.updateAccount(account)\n\n const updatedAccountIndex = this.accounts.findIndex(\n (account) => account.guid === updatedAccount.guid,\n )\n\n this.accounts.splice(updatedAccountIndex, 1, updatedAccount)\n } catch (error) {\n console.error('Error occurred while updating account:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n }\n }\n\n updateAccountBalance = (accountGuid: string, balanceChange: number) => {\n const account = this.accounts.find((a) => a.guid === accountGuid)\n\n if (account) {\n runInAction(() => {\n account.balance = (account.balance || 0) + balanceChange\n })\n }\n }\n\n updateAccountFilter = async (accountMap: Map<string, boolean>) => {\n try {\n const accountUpdates: Promise<Account | null>[] = []\n for (const [guid, isSelected] of accountMap.entries()) {\n const account = this.accounts.find((acc) => acc.guid === guid)\n\n if (account && account.is_excluded_from_accounts === isSelected) {\n const updatedPayload = { ...account, is_excluded_from_accounts: !isSelected }\n accountUpdates.push(\n this.api.updateAccount(updatedPayload).catch((error) => {\n console.error('Error occurred while updating account filter:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n return null\n }),\n )\n }\n }\n\n const results = await Promise.all(accountUpdates)\n const updatedAccounts: Account[] = results.filter((acc): acc is Account => acc !== null)\n\n const accounts = [...this.accounts]\n for (const updatedAccount of updatedAccounts) {\n const index = accounts.findIndex((acc) => acc.guid === updatedAccount.guid)\n if (index !== -1) {\n accounts.splice(index, 1, updatedAccount)\n }\n }\n this.setAccounts(accounts)\n } catch (error) {\n console.error('Error occurred while updating account filter:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n }\n }\n}\n\n// TODO: Move into AccountStore\nclass UiStore {\n selectedAccount: Account = {} as Account\n selectedMember: Member = {} as Member\n\n constructor() {\n makeAutoObservable(this)\n }\n\n setSelectedAccount = (account: Account) => (this.selectedAccount = account)\n setSelectedMember = (member: Member) => (this.selectedMember = member)\n}\n"],"mappings":";;;;;;AAiBA,IAAa,IAAb,MAA0B;AAAA,EACxB;AAAA,EACA,MAAkB,IAAI,EAAW,KAAK,EAAE;AAAA,EAExC,WAAsB,CAAC;AAAA,EACvB,iBAA0B;AAAA,EAC1B,kBAA2B;AAAA,EAC3B,eAA8B,CAAC;AAAA,EAC/B,qBAA8B;AAAA,EAC9B,sBAA+B;AAAA,EAC/B,UAAoB,CAAC;AAAA,EACrB,gBAAyB;AAAA,EACzB,iBAA0B;AAAA,EAC1B;AAAA,EAEA,YAAY,GAA0B;AACpC,SAAK,cAAc,GACnB,KAAK,UAAU,IAAI,EAAQ,GAC3B,KAAK,MAAM,IAAI,EAAW,EAAY,UAAU,EAAY,cAAc,EAAY,OAAO,GAE7F,EAAmB,IAAI;AAAA,EACzB;AAAA,EAEA,kBAAkB,YAAY;AAC5B,UAAM,QAA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CAAK,GACpE,KAAK,YAAY,iBAAiB,GAAO,EAAE,OAAO,eAAe,CAAC,GAC3D,KACR,CACH;AAAA,QACF;AAAA,MACF;AAGA,YAAM,KAA6B,MADb,QAAQ,IAAI,CAAc,GACL,OAAA,CAAQ,MAAwB,MAAQ,IAAI,GAEjF,IAAW,CAAC,GAAG,KAAK,QAAQ;AAClC,iBAAW,KAAkB,GAAiB;AAC5C,cAAM,IAAQ,EAAS,UAAA,CAAW,MAAQ,EAAI,SAAS,EAAe,IAAI;AAC1E,QAAI,MAAU,MACZ,EAAS,OAAO,GAAO,GAAG,CAAc;AAAA,MAE5C;AACA,WAAK,YAAY,CAAQ;AAAA,IAC3B,SAAS,GAAO;AACd,cAAQ,MAAM,iDAAiD,CAAK,GACpE,KAAK,YAAY,iBAAiB,GAAO,EAAE,OAAO,eAAe,CAAC;AAAA,IACpE;AAAA,EACF;AACF,GAGM,IAAN,MAAc;AAAA,EACZ,kBAA2B,CAAC;AAAA,EAC5B,iBAAyB,CAAC;AAAA,EAE1B,cAAc;AACZ,IAAA,EAAmB,IAAI;AAAA,EACzB;AAAA,EAEA,qBAAA,CAAsB,MAAsB,KAAK,kBAAkB;AAAA,EACnE,oBAAA,CAAqB,MAAoB,KAAK,iBAAiB;AACjE"}
1
+ {"version":3,"file":"AccountStore.es.js","names":[],"sources":["../../../src/core/stores/AccountStore.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from 'mobx'\n\nimport { AccountApi } from '../api'\nimport { upsertByGuid } from '../utils/upsertByGuid'\nimport {\n type Account,\n type DetailedAccount,\n type Institution,\n type Member,\n AccountType,\n AccountSubType,\n} from '../types'\nimport { augmentAccounts } from '../utils/AccountUtils'\nimport { isFeatureEnabled } from '../utils/UserUtils'\n\nimport { GlobalStore } from './GlobalStore'\n\nexport class AccountStore {\n globalStore: GlobalStore\n api: AccountApi = new AccountApi('/', '')\n\n accounts: Account[] = []\n accountsLoaded: boolean = false\n accountsLoading: boolean = false\n institutions: Institution[] = []\n institutionsLoaded: boolean = false\n institutionsLoading: boolean = false\n members: Member[] = []\n membersLoaded: boolean = false\n membersLoading: boolean = false\n uiStore: UiStore\n\n constructor(globalStore: GlobalStore) {\n this.globalStore = globalStore\n this.uiStore = new UiStore()\n this.api = new AccountApi(globalStore.endpoint, globalStore.sessionToken, globalStore.onError)\n\n makeAutoObservable(this)\n }\n\n loadAccountData = async () => {\n await Promise.all([this.loadAccounts(), this.loadMembers(), this.loadInstitutions()])\n }\n\n get isAccountDataLoaded(): boolean {\n return this.accountsLoaded && this.membersLoaded && this.institutionsLoaded\n }\n\n get detailedAccounts(): DetailedAccount[] {\n const userFeatures = this.globalStore.userStore.userFeatures\n const excludeExternal = isFeatureEnabled(userFeatures, 'MD_EXCLUDE_EXTERNAL_ACCOUNTS')\n\n // Hide held account when this flag is toggled and this is the individual accounts widget\n const excludeHeld =\n this.globalStore.appConfig.config.display_only_external_accounts_in_accounts &&\n this.globalStore.appConfig.options.subtype === 'accounts' // Indicates this is an individual widget\n\n return augmentAccounts(\n this.accounts,\n this.institutions,\n this.members,\n excludeExternal,\n excludeHeld,\n )\n }\n\n get accountsByTypeMap(): Map<AccountType, DetailedAccount[]> {\n return this.detailedAccounts.reduce((typeMap: Map<AccountType, DetailedAccount[]>, account) => {\n const accountType = account.account_type\n\n let accounts = typeMap.get(accountType)\n if (!accounts) {\n accounts = []\n }\n accounts.push(account)\n typeMap.set(accountType, accounts)\n\n return typeMap\n }, new Map<AccountType, DetailedAccount[]>())\n }\n\n get cashAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter(\n (account: Account) =>\n account.account_type === AccountType.CASH ||\n account.account_type === AccountType.CHECKING ||\n account.account_type === AccountType.PREPAID ||\n account.account_type === AccountType.SAVINGS ||\n account.account_type === AccountType.CHECKING_LINE_OF_CREDIT,\n )\n }\n\n get cashBalance(): number {\n return this.cashAccounts.reduce((total, account) => total + (account?.balance || 0), 0)\n }\n\n get checkingAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter((a: Account) => a.account_type === AccountType.CHECKING)\n }\n\n get debtAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter(\n (account: Account) =>\n account.account_type === AccountType.CREDIT_CARD ||\n account.account_type === AccountType.LOAN ||\n account.account_type === AccountType.MORTGAGE ||\n account.account_type === AccountType.LINE_OF_CREDIT ||\n account.account_type === AccountType.CHECKING_LINE_OF_CREDIT,\n )\n }\n\n get finstrongAccounts(): DetailedAccount[] {\n const eligibleTypes = new Set([\n AccountType.CHECKING,\n AccountType.SAVINGS,\n AccountType.CREDIT_CARD,\n AccountType.INVESTMENT,\n ])\n\n return this.detailedAccounts.filter((account) => eligibleTypes.has(account.account_type))\n }\n\n get investmentAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter(\n (account: Account) => account.account_type === AccountType.INVESTMENT,\n )\n }\n\n get manualAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter((account) => account.is_manual)\n }\n\n get savingsAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter((a: Account) => a.account_type === AccountType.SAVINGS)\n }\n\n get retirementAccounts(): Account[] {\n return this.detailedAccounts.filter(\n (account: Account) =>\n account.account_type === AccountType.INVESTMENT ||\n account.account_type === AccountType.SAVINGS ||\n account.account_type === AccountType.CHECKING ||\n account.account_type === AccountType.CASH ||\n account.account_type === AccountType.PROPERTY ||\n (account.account_type === AccountType.INSURANCE &&\n (account.account_subtype === AccountSubType.WHOLE_LIFE ||\n account.account_subtype === AccountSubType.UNIVERSAL_LIFE ||\n account.account_subtype === AccountSubType.VARIABLE_UNIVERSAL_LIFE)),\n )\n }\n\n get visibleAccounts(): DetailedAccount[] {\n return this.detailedAccounts.filter((a: Account) => !a.is_hidden && !a.is_closed)\n }\n\n get visibleCashAccounts(): DetailedAccount[] {\n return this.cashAccounts.filter((account: Account) => !account.is_hidden)\n }\n\n get visibleCashBalance(): number {\n return this.visibleCashAccounts.reduce((total, account) => total + (account?.balance || 0), 0)\n }\n\n get visibleCheckingAccounts(): DetailedAccount[] {\n return this.checkingAccounts.filter((account: Account) => !account.is_hidden)\n }\n\n get visibleDebtAccounts(): DetailedAccount[] {\n return this.debtAccounts.filter((account: Account) => !account.is_hidden)\n }\n\n get visibleFinstrongAccounts(): DetailedAccount[] {\n return this.finstrongAccounts.filter(\n (account: Account) => !(account.is_closed || account.is_deleted || account.is_hidden),\n )\n }\n\n get visibleRetirementAccounts(): Account[] {\n return this.retirementAccounts.filter((account: Account) => !account.is_hidden)\n }\n\n get visibleInvestmentAccounts(): DetailedAccount[] {\n return this.investmentAccounts.filter((account: Account) => !account.is_hidden)\n }\n\n get visibleSavingsAccounts(): DetailedAccount[] {\n return this.savingsAccounts.filter((account: Account) => !account.is_hidden)\n }\n\n get savingsAndCheckingAccountsBalance(): number {\n const savingsAndCheckingAccountsList = this.savingsAndCheckingAccounts\n\n return savingsAndCheckingAccountsList.reduce(\n (total, account) => total + (account?.balance || 0),\n 0,\n )\n }\n\n get savingsAndCheckingAccounts(): Account[] {\n const savingsAndCheckingAccounts = this.accounts.filter(\n (account: Account) =>\n account.account_type === AccountType.SAVINGS ||\n account.account_type === AccountType.CHECKING,\n )\n\n return savingsAndCheckingAccounts\n }\n\n setAccounts = (accounts: Account[]) => {\n this.accounts = accounts\n this.accountsLoading = false\n this.accountsLoaded = true\n }\n\n setMembers = (members: Member[]) => {\n this.members = members\n this.membersLoading = false\n this.membersLoaded = true\n }\n\n setInstitutions = (institutions: Institution[]) => {\n this.institutions = institutions\n this.institutionsLoading = false\n this.institutionsLoaded = true\n }\n\n addAccount = async (account: Account) => {\n try {\n const newAccount = await this.api.createAccount(account)\n\n runInAction(() => {\n this.accounts = upsertByGuid(this.accounts, newAccount)\n })\n } catch (error) {\n console.error('Error occurred while adding an account:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n }\n }\n\n loadAccounts = async () => {\n if (this.accountsLoading) return\n\n this.accountsLoading = true\n try {\n const accounts = await this.api.getAccounts()\n this.setAccounts(accounts)\n } catch (error) {\n console.error('Error occurred while loading accounts:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n this.setAccounts([])\n }\n }\n\n loadInstitutions = async () => {\n if (this.institutionsLoading) return\n\n this.institutionsLoading = true\n try {\n const institutions = await this.api.getInstitutions()\n this.setInstitutions(institutions)\n } catch (error) {\n console.error('Error occurred while loading institutions:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n this.setInstitutions([])\n }\n }\n\n loadMembers = async () => {\n if (this.membersLoading) return\n\n this.membersLoading = true\n try {\n const members = await this.api.getMembers()\n this.setMembers(members)\n } catch (error) {\n console.error('Error occurred while loading members:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n this.setMembers([])\n }\n }\n\n mergeAccounts = async (accountGuids: string[]) => {\n try {\n const response = await this.api.mergeAccounts(accountGuids)\n // the response from the api is a funky database key here, so this is essentially just getting the first item in the returned object\n // to prevent making multiple api calls here\n const mergedAccount = response[Object.keys(response)[0]]\n\n runInAction(() => {\n const account2Index = this.accounts.findIndex((account) => account.guid === accountGuids[1])\n this.accounts.splice(account2Index, 1)\n\n const account1Index = this.accounts.findIndex((account) => account.guid === accountGuids[0])\n this.accounts.splice(account1Index, 1, mergedAccount)\n })\n } catch (error) {\n console.error('Error occurred while merging accounts:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n }\n }\n\n /**\n * DEPRECATED: Use loadAccountData instead\n */\n refreshAccounts = async () => {\n await Promise.all([this.loadAccounts(), this.loadInstitutions(), this.loadMembers()])\n }\n\n refreshMembers = async () => {\n try {\n await this.api.refreshAllMembers()\n } catch (error) {\n console.error('Error occurred while refreshing members:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n }\n }\n\n removeAccount = async (accountGuid: string) => {\n try {\n await this.api.deleteAccount(accountGuid)\n\n const deletedIndex = this.accounts.findIndex((account) => account.guid === accountGuid)\n this.accounts.splice(deletedIndex, 1)\n } catch (error) {\n console.error('Error occurred while removing an account:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n }\n }\n\n /** Resolves `true` when the account was saved, `false` when the API call failed. */\n updateAccount = async (account: Account): Promise<boolean> => {\n try {\n const updatedAccount = await this.api.updateAccount(account)\n\n const updatedAccountIndex = this.accounts.findIndex(\n (account) => account.guid === updatedAccount.guid,\n )\n\n this.accounts.splice(updatedAccountIndex, 1, updatedAccount)\n return true\n } catch (error) {\n console.error('Error occurred while updating account:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n return false\n }\n }\n\n updateAccountBalance = (accountGuid: string, balanceChange: number) => {\n const account = this.accounts.find((a) => a.guid === accountGuid)\n\n if (account) {\n runInAction(() => {\n account.balance = (account.balance || 0) + balanceChange\n })\n }\n }\n\n updateAccountFilter = async (accountMap: Map<string, boolean>) => {\n try {\n const accountUpdates: Promise<Account | null>[] = []\n for (const [guid, isSelected] of accountMap.entries()) {\n const account = this.accounts.find((acc) => acc.guid === guid)\n\n if (account && account.is_excluded_from_accounts === isSelected) {\n const updatedPayload = { ...account, is_excluded_from_accounts: !isSelected }\n accountUpdates.push(\n this.api.updateAccount(updatedPayload).catch((error) => {\n console.error('Error occurred while updating account filter:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n return null\n }),\n )\n }\n }\n\n const results = await Promise.all(accountUpdates)\n const updatedAccounts: Account[] = results.filter((acc): acc is Account => acc !== null)\n\n const accounts = [...this.accounts]\n for (const updatedAccount of updatedAccounts) {\n const index = accounts.findIndex((acc) => acc.guid === updatedAccount.guid)\n if (index !== -1) {\n accounts.splice(index, 1, updatedAccount)\n }\n }\n this.setAccounts(accounts)\n } catch (error) {\n console.error('Error occurred while updating account filter:', error)\n this.globalStore.captureException(error, { store: 'AccountStore' })\n }\n }\n}\n\n// TODO: Move into AccountStore\nclass UiStore {\n selectedAccount: Account = {} as Account\n selectedMember: Member = {} as Member\n\n constructor() {\n makeAutoObservable(this)\n }\n\n setSelectedAccount = (account: Account) => (this.selectedAccount = account)\n setSelectedMember = (member: Member) => (this.selectedMember = member)\n}\n"],"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A,qBAAA,CAAsB,MAAsB,KAAK,kBAAkB;AAAA,EACnE,oBAAA,CAAqB,MAAoB,KAAK,iBAAiB;AACjE"}
@@ -8,6 +8,12 @@ export declare class BeatStore {
8
8
  isLoading: boolean;
9
9
  constructor(globalStore: GlobalStore);
10
10
  loadBeats: () => Promise<void>;
11
+ /**
12
+ * Persists changes to an offer-backed beat (pulse marketing offers, `PUT offers/:guid`),
13
+ * e.g. flagging `has_been_clicked` when its CTA is pressed. Rethrows so callers driving
14
+ * UI state can surface the failure.
15
+ */
16
+ updateOffer: (beat: Beat) => Promise<any>;
11
17
  getFilteredBeats(filter: {
12
18
  categoryGuids?: string[];
13
19
  templates?: string[];
@@ -1,43 +1,56 @@
1
- import { BeatApi as s } from "../api/BeatApi.es.js";
1
+ import { BeatApi as i } from "../api/BeatApi.es.js";
2
2
  import { orderArray as o, transformOfferIntoBeatLikeObject as n } from "../utils/BeatUtils.es.js";
3
- import { makeAutoObservable as l, runInAction as i } from "mobx";
4
- var B = class {
3
+ import { makeAutoObservable as c, runInAction as s } from "mobx";
4
+ var u = class {
5
5
  globalStore;
6
- api = new s("/", "");
6
+ api = new i("/", "");
7
7
  beats = [];
8
8
  isLoading = !1;
9
9
  constructor(t) {
10
- this.globalStore = t, this.api = new s(t.endpoint, t.sessionToken, t.onError), l(this);
10
+ this.globalStore = t, this.api = new i(t.endpoint, t.sessionToken, t.onError), c(this);
11
11
  }
12
12
  loadBeats = async () => {
13
13
  this.isLoading = !0;
14
14
  try {
15
- const t = await this.api.getBeats(), r = (await this.api.getOffers()).map((a) => n(a));
16
- i(() => {
17
- this.beats = o(t, r, "active_at", "desc");
15
+ const t = await this.api.getBeats(), e = (await this.api.getOffers()).map((r) => n(r));
16
+ s(() => {
17
+ this.beats = o(t, e, "active_at", "desc");
18
18
  });
19
19
  } catch (t) {
20
20
  console.error("Error occurred while loading beats:", t), this.globalStore.captureException(t, { store: "BeatStore" });
21
21
  } finally {
22
- i(() => {
22
+ s(() => {
23
23
  this.isLoading = !1;
24
24
  });
25
25
  }
26
26
  };
27
+ updateOffer = async (t) => {
28
+ try {
29
+ const e = await this.api.updateOffer(t);
30
+ return s(() => {
31
+ this.beats = this.beats.map((r) => r.guid === t.guid ? {
32
+ ...r,
33
+ ...e
34
+ } : r);
35
+ }), e;
36
+ } catch (e) {
37
+ throw console.error("Error occurred while updating offer:", e), this.globalStore.captureException(e, { store: "BeatStore" }), e;
38
+ }
39
+ };
27
40
  getFilteredBeats(t) {
28
- const { categoryGuids: r, templates: a } = t;
29
- let e = this.beats;
30
- return r && (e = this.filterBeatsByCategory(e, r)), a && (e = this.filterBeatsByTemplate(e, a)), e;
41
+ const { categoryGuids: e, templates: r } = t;
42
+ let a = this.beats;
43
+ return e && (a = this.filterBeatsByCategory(a, e)), r && (a = this.filterBeatsByTemplate(a, r)), a;
31
44
  }
32
- filterBeatsByCategory(t, r) {
33
- return t.filter((a) => a.category_guids?.some((e) => r.includes(e)));
45
+ filterBeatsByCategory(t, e) {
46
+ return t.filter((r) => r.category_guids?.some((a) => e.includes(a)));
34
47
  }
35
- filterBeatsByTemplate(t, r) {
36
- return t.filter((a) => r.some((e) => a.template === e));
48
+ filterBeatsByTemplate(t, e) {
49
+ return t.filter((r) => e.some((a) => r.template === a));
37
50
  }
38
51
  };
39
52
  export {
40
- B as BeatStore
53
+ u as BeatStore
41
54
  };
42
55
 
43
56
  //# sourceMappingURL=BeatStore.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BeatStore.es.js","names":[],"sources":["../../../src/core/stores/BeatStore.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from 'mobx'\n\nimport { BeatApi } from '../api'\nimport type { Beat, Offer } from '../types'\nimport { orderArray, transformOfferIntoBeatLikeObject } from '../utils/BeatUtils'\n\nimport { GlobalStore } from './GlobalStore'\n\nexport class BeatStore {\n globalStore: GlobalStore\n api: BeatApi = new BeatApi('/', '')\n beats: Beat[] = []\n isLoading = false\n\n constructor(globalStore: GlobalStore) {\n this.globalStore = globalStore\n this.api = new BeatApi(globalStore.endpoint, globalStore.sessionToken, globalStore.onError)\n\n makeAutoObservable(this)\n }\n\n loadBeats = async () => {\n this.isLoading = true\n try {\n const beats = await this.api.getBeats()\n const offers = await this.api.getOffers()\n const beatLikeOffers = offers.map((o: Offer) => transformOfferIntoBeatLikeObject(o))\n\n runInAction(() => {\n this.beats = orderArray(beats, beatLikeOffers, 'active_at', 'desc')\n })\n } catch (error) {\n console.error('Error occurred while loading beats:', error)\n this.globalStore.captureException(error, { store: 'BeatStore' })\n } finally {\n runInAction(() => {\n this.isLoading = false\n })\n }\n }\n\n getFilteredBeats(filter: { categoryGuids?: string[]; templates?: string[] }): Beat[] {\n const { categoryGuids, templates } = filter\n let filteredBeats = this.beats\n if (categoryGuids) filteredBeats = this.filterBeatsByCategory(filteredBeats, categoryGuids)\n if (templates) filteredBeats = this.filterBeatsByTemplate(filteredBeats, templates)\n return filteredBeats\n }\n\n // Return beats with any beat.category_guids that are in categoryGuids\n filterBeatsByCategory(beats: Beat[], categoryGuids: string[]): Beat[] {\n return beats.filter((beat) => {\n return beat.category_guids?.some((guid) => categoryGuids.includes(guid))\n })\n }\n\n // Return beats with a beat.template that is in templates\n filterBeatsByTemplate(beats: Beat[], templates: string[]): Beat[] {\n return beats.filter((beat) => {\n return templates.some((template) => beat.template === template)\n })\n }\n}\n"],"mappings":";;;AAQA,IAAa,IAAb,MAAuB;AAAA,EACrB;AAAA,EACA,MAAe,IAAI,EAAQ,KAAK,EAAE;AAAA,EAClC,QAAgB,CAAC;AAAA,EACjB,YAAY;AAAA,EAEZ,YAAY,GAA0B;AACpC,SAAK,cAAc,GACnB,KAAK,MAAM,IAAI,EAAQ,EAAY,UAAU,EAAY,cAAc,EAAY,OAAO,GAE1F,EAAmB,IAAI;AAAA,EACzB;AAAA,EAEA,YAAY,YAAY;AACtB,SAAK,YAAY;AACjB,QAAI;AACF,YAAM,IAAQ,MAAM,KAAK,IAAI,SAAS,GAEhC,KAAiB,MADF,KAAK,IAAI,UAAU,GACV,IAAA,CAAK,MAAa,EAAiC,CAAC,CAAC;AAEnF,MAAA,EAAA,MAAkB;AAChB,aAAK,QAAQ,EAAW,GAAO,GAAgB,aAAa,MAAM;AAAA,MACpE,CAAC;AAAA,IACH,SAAS,GAAO;AACd,cAAQ,MAAM,uCAAuC,CAAK,GAC1D,KAAK,YAAY,iBAAiB,GAAO,EAAE,OAAO,YAAY,CAAC;AAAA,IACjE,UAAA;AACE,MAAA,EAAA,MAAkB;AAChB,aAAK,YAAY;AAAA,MACnB,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAEA,iBAAiB,GAAoE;AACnF,UAAM,EAAE,eAAA,GAAe,WAAA,EAAA,IAAc;AACrC,QAAI,IAAgB,KAAK;AACzB,WAAI,MAAe,IAAgB,KAAK,sBAAsB,GAAe,CAAa,IACtF,MAAW,IAAgB,KAAK,sBAAsB,GAAe,CAAS,IAC3E;AAAA,EACT;AAAA,EAGA,sBAAsB,GAAe,GAAiC;AACpE,WAAO,EAAM,OAAA,CAAQ,MACZ,EAAK,gBAAgB,KAAA,CAAM,MAAS,EAAc,SAAS,CAAI,CAAC,CACxE;AAAA,EACH;AAAA,EAGA,sBAAsB,GAAe,GAA6B;AAChE,WAAO,EAAM,OAAA,CAAQ,MACZ,EAAU,KAAA,CAAM,MAAa,EAAK,aAAa,CAAQ,CAC/D;AAAA,EACH;AACF"}
1
+ {"version":3,"file":"BeatStore.es.js","names":[],"sources":["../../../src/core/stores/BeatStore.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from 'mobx'\n\nimport { BeatApi } from '../api'\nimport type { Beat, Offer } from '../types'\nimport { orderArray, transformOfferIntoBeatLikeObject } from '../utils/BeatUtils'\n\nimport { GlobalStore } from './GlobalStore'\n\nexport class BeatStore {\n globalStore: GlobalStore\n api: BeatApi = new BeatApi('/', '')\n beats: Beat[] = []\n isLoading = false\n\n constructor(globalStore: GlobalStore) {\n this.globalStore = globalStore\n this.api = new BeatApi(globalStore.endpoint, globalStore.sessionToken, globalStore.onError)\n\n makeAutoObservable(this)\n }\n\n loadBeats = async () => {\n this.isLoading = true\n try {\n const beats = await this.api.getBeats()\n const offers = await this.api.getOffers()\n const beatLikeOffers = offers.map((o: Offer) => transformOfferIntoBeatLikeObject(o))\n\n runInAction(() => {\n this.beats = orderArray(beats, beatLikeOffers, 'active_at', 'desc')\n })\n } catch (error) {\n console.error('Error occurred while loading beats:', error)\n this.globalStore.captureException(error, { store: 'BeatStore' })\n } finally {\n runInAction(() => {\n this.isLoading = false\n })\n }\n }\n\n /**\n * Persists changes to an offer-backed beat (pulse marketing offers, `PUT offers/:guid`),\n * e.g. flagging `has_been_clicked` when its CTA is pressed. Rethrows so callers driving\n * UI state can surface the failure.\n */\n updateOffer = async (beat: Beat) => {\n try {\n const updated = await this.api.updateOffer(beat)\n\n runInAction(() => {\n this.beats = this.beats.map((b) => (b.guid === beat.guid ? { ...b, ...updated } : b))\n })\n\n return updated\n } catch (error) {\n console.error('Error occurred while updating offer:', error)\n this.globalStore.captureException(error, { store: 'BeatStore' })\n throw error\n }\n }\n\n getFilteredBeats(filter: { categoryGuids?: string[]; templates?: string[] }): Beat[] {\n const { categoryGuids, templates } = filter\n let filteredBeats = this.beats\n if (categoryGuids) filteredBeats = this.filterBeatsByCategory(filteredBeats, categoryGuids)\n if (templates) filteredBeats = this.filterBeatsByTemplate(filteredBeats, templates)\n return filteredBeats\n }\n\n // Return beats with any beat.category_guids that are in categoryGuids\n filterBeatsByCategory(beats: Beat[], categoryGuids: string[]): Beat[] {\n return beats.filter((beat) => {\n return beat.category_guids?.some((guid) => categoryGuids.includes(guid))\n })\n }\n\n // Return beats with a beat.template that is in templates\n filterBeatsByTemplate(beats: Beat[], templates: string[]): Beat[] {\n return beats.filter((beat) => {\n return templates.some((template) => beat.template === template)\n })\n }\n}\n"],"mappings":";;;AAQA,IAAa,IAAb,MAAuB;AAAA,EACrB;AAAA,EACA,MAAe,IAAI,EAAQ,KAAK,EAAE;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e,CAAa,IACtF,MAAW,IAAgB,KAAK,sBAAsB,GAAe,CAAS,IAC3E;AAAA,EACT;AAAA,EAGA,sBAAsB,GAAe,GAAiC;AACpE,WAAO,EAAM,OAAA,CAAQ,MACZ,EAAK,gBAAgB,KAAA,CAAM,MAAS,EAAc,SAAS,CAAI,CAAC,CACxE;AAAA,EACH;AAAA,EAGA,sBAAsB,GAAe,GAA6B;AAChE,WAAO,EAAM,OAAA,CAAQ,MACZ,EAAU,KAAA,CAAM,MAAa,EAAK,aAAa,CAAQ,CAC/D;AAAA,EACH;AACF"}
@@ -22,7 +22,8 @@ export declare class BudgetsStore {
22
22
  get incomeBudget(): number | undefined;
23
23
  get unbudgetedCategories(): DetailedCategory[];
24
24
  get totalBudgeted(): number;
25
- addBudget: (category: Category, amount: number, parentGuid?: string | null) => Promise<void>;
25
+ /** Resolves `true` when the budget was created, `false` when the API call failed. */
26
+ addBudget: (category: Category, amount: number, parentGuid?: string | null) => Promise<boolean>;
26
27
  deleteBudget: (guid: string) => Promise<boolean>;
27
28
  loadBudgets: () => Promise<void>;
28
29
  setAlert: (alert: {
@@ -1,18 +1,18 @@
1
1
  import { CategoryGuids as o } from "../constants/Category.es.js";
2
2
  import { BudgetsApi as g } from "../api/BudgetsApi.es.js";
3
3
  import { upsertByGuid as n } from "../utils/upsertByGuid.es.js";
4
- import { augmentBudgets as c, findBudget as l, findSubBudget as p } from "../utils/BudgetUtil.es.js";
4
+ import { augmentBudgets as c, findBudget as h, findSubBudget as p } from "../utils/BudgetUtil.es.js";
5
5
  import { endOfMonth as B } from "date-fns/endOfMonth";
6
6
  import { startOfMonth as f } from "date-fns/startOfMonth";
7
- import { startOfToday as h } from "date-fns/startOfToday";
7
+ import { startOfToday as l } from "date-fns/startOfToday";
8
8
  import { makeAutoObservable as S, reaction as b, runInAction as i } from "mobx";
9
9
  var A = class {
10
10
  api = new g("/", "");
11
11
  globalStore;
12
12
  alert = null;
13
13
  dateRange = {
14
- start: f(h()),
15
- end: B(h())
14
+ start: f(l()),
15
+ end: B(l())
16
16
  };
17
17
  budgets = [];
18
18
  selectedBudget;
@@ -27,7 +27,7 @@ var A = class {
27
27
  this.globalStore.recurringTransactionsStore.isDataLoaded || await this.globalStore.recurringTransactionsStore.loadRepeatingTransactionData(), await this.loadBudgets(), b(() => this.detailedBudgets, (t) => {
28
28
  if (t) {
29
29
  const e = this.selectedBudget;
30
- e && (this.selectedBudget = l(t, e.guid));
30
+ e && (this.selectedBudget = h(t, e.guid));
31
31
  const r = this.selectedSubBudget;
32
32
  r && r.parent_guid && (this.selectedSubBudget = p(t, r.guid, r.parent_guid));
33
33
  }
@@ -48,11 +48,11 @@ var A = class {
48
48
  addBudget = async (t, e, r = null) => {
49
49
  try {
50
50
  const s = await this.api.addBudget(t, e, r);
51
- i(() => {
51
+ return i(() => {
52
52
  this.budgets = n(this.budgets, s);
53
- });
53
+ }), !0;
54
54
  } catch (s) {
55
- console.error("Error adding budget:", s), this.globalStore.captureException(s, { store: "BudgetsStore" });
55
+ return console.error("Error adding budget:", s), this.globalStore.captureException(s, { store: "BudgetsStore" }), !1;
56
56
  }
57
57
  };
58
58
  deleteBudget = async (t) => {