@mx-cartographer/experiences 9.7.34 → 9.7.36

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 (32) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +39 -106
  3. package/dist/core/types/localization/InsightsFeedCopy.d.ts +20 -0
  4. package/dist/core/types/localization/index.d.ts +1 -1
  5. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/BudgetDetailsBlock.d.ts +4 -0
  6. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/BudgetDetailsBlock.es.js +192 -0
  7. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/BudgetDetailsBlock.es.js.map +1 -0
  8. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/BudgetSummary.d.ts +13 -0
  9. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/BudgetSummary.es.js +94 -0
  10. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/BudgetSummary.es.js.map +1 -0
  11. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/index.d.ts +1 -0
  12. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/layout.d.ts +15 -0
  13. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/layout.es.js +37 -0
  14. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/layout.es.js.map +1 -0
  15. package/dist/insights-v2/actionBlocks/OverdraftBlock/ConfidenceMeter.d.ts +13 -0
  16. package/dist/insights-v2/actionBlocks/OverdraftBlock/ConfidenceMeter.es.js +62 -0
  17. package/dist/insights-v2/actionBlocks/OverdraftBlock/ConfidenceMeter.es.js.map +1 -0
  18. package/dist/insights-v2/actionBlocks/OverdraftBlock/OverdraftBlock.d.ts +11 -0
  19. package/dist/insights-v2/actionBlocks/OverdraftBlock/OverdraftBlock.es.js +100 -0
  20. package/dist/insights-v2/actionBlocks/OverdraftBlock/OverdraftBlock.es.js.map +1 -0
  21. package/dist/insights-v2/actionBlocks/OverdraftBlock/index.d.ts +1 -0
  22. package/dist/insights-v2/actionBlocks/OverdraftBlock/layout.d.ts +27 -0
  23. package/dist/insights-v2/actionBlocks/OverdraftBlock/layout.es.js +35 -0
  24. package/dist/insights-v2/actionBlocks/OverdraftBlock/layout.es.js.map +1 -0
  25. package/dist/insights-v2/ctaActions/ctaPostMessages.es.js +36 -23
  26. package/dist/insights-v2/ctaActions/ctaPostMessages.es.js.map +1 -1
  27. package/dist/insights-v2/mappings/actionBlocksKey.d.ts +2 -0
  28. package/dist/insights-v2/mappings/actionBlocksKey.es.js +3 -1
  29. package/dist/insights-v2/mappings/actionBlocksKey.es.js.map +1 -1
  30. package/dist/insights-v2/mappings/blocks.es.js +75 -63
  31. package/dist/insights-v2/mappings/blocks.es.js.map +1 -1
  32. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [9.7.36] - 10-23-2026
2
+
3
+ - **ADDED** - `budget_details_block` action block: the "View Budget" drawer for the Category Budget, Merchant Budget and Category Spending V2 beats, with spent against the limit, the tier bar and Edit / Delete / Create Budget. Copy from the new `insights_feed.budget_details` namespace (MEW2-3362)
4
+
5
+ ## [9.7.35] - 10-23-2026
6
+
7
+ - **ADDED** - `transparent_overdraft_block` action block for the Transparent Overdraft beat's "Learn more": the account, projected overdraft amount, 7-day line and a four-band confidence meter, with copy from the new `insights_feed.transparent_overdraft` namespace. "Transfer funds" posts op_1 with `projected_overdraft_amount`, `destination_account_ids` and `destination_account_id` through `ctaPostMessages`. Fixture, contract test, stories and `docs/action-blocks/overdraft-block.md` (MEW2-3355)
8
+
1
9
  ## [9.7.34] - 10-23-2026
2
10
 
3
11
  - **ADDED** - `atomic_flow` CTA action (ditto `primary_cta_action`, sent today by Set Up Direct Deposit's `not_set_up` state): delegates the press to the host's `atomicTransact` action and stops, with no drawer, post message or refetch from here. The host owns the Atomic SDK token, flow and lifecycle, so experiences knows nothing about Atomic beyond the action name. A host with no `onCtaAction` shows an error status on press; one that has it but does not know `atomicTransact` (pulse before !3858) logs a warning and the press records `done`, so ship the host side first. `HOST_ACTIONS.atomicTransact` added; `CtaActions › SetUpDirectDepositAtomicFlow` story (WEC-1899)
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @mx-cartographer/experiences
2
2
 
3
- @mx-cartographer/experiences is a React-based library of financial experience widgets designed for seamless integration within the MX ecosystem. It provides a robust collection of modular widgets (e.g., Accounts, Budgets, Cashflow) built on top of Material UI (MUI) [^MUI_VER] and the MXUI design system [^MXUI_VER], powered by MobX [^MOBX_VER] for scalable state management.
3
+ @mx-cartographer/experiences is a React library of financial widgets for MX applications. Each widget (for example Accounts, Budgets, and Cashflow) has its own entry point. The widgets use Material UI (MUI), the MXUI design system, and MobX for state management. The [package.json](package.json) file lists the versions of each package.
4
4
 
5
5
  ## Documentation
6
6
 
@@ -10,6 +10,7 @@
10
10
  - [API and Data](docs/API_AND_DATA.md)
11
11
  - [Styling and Theming](docs/STYLING_AND_THEMING.md)
12
12
  - [Testing](docs/TESTING.md)
13
+ - [Insights V2 Action Blocks](docs/action-blocks/README.md)
13
14
 
14
15
  ## Tech Stack
15
16
 
@@ -20,7 +21,7 @@ The library is built using a modern React stack, leveraging industry-standard to
20
21
  | **Framework** | [React](https://reactjs.org/) | Core library for building declarative UI components. |
21
22
  | **Language** | [TypeScript](https://www.typescriptlang.org/) | Provides static typing for improved maintainability and developer experience. |
22
23
  | **Styling** | [Material UI (MUI)](https://mui.com/) | Base UI component framework and styling system. |
23
- | **Design System** | [@mxenabled/mxui](https://mx.atlassian.net/wiki) | MX-themed overrides and consistent UI primitives. |
24
+ | **Design System** | [@mxenabled/mxui](https://mxcom.atlassian.net/wiki) | MX-themed overrides and consistent UI primitives. |
24
25
  | **State Management** | [MobX](https://mobx.js.org/) | Scalable and observable state management for complex widget interactions. |
25
26
  | **Data Visualization** | [D3.js](https://d3js.org/) | Powering complex charts and interactive data representations. |
26
27
  | **Build Tool** | [Vite](https://vitejs.dev/) | Next-generation frontend tooling for fast builds and development. |
@@ -32,7 +33,6 @@ The library is built using a modern React stack, leveraging industry-standard to
32
33
  - [Installation](#installation)
33
34
  - [Usage](#usage)
34
35
  - [Architecture](#architecture)
35
- - [Project Structure](#project-structure)
36
36
  - [Testing](#testing)
37
37
  - [Contributing](#contributing)
38
38
  - [Support](#support)
@@ -40,10 +40,11 @@ The library is built using a modern React stack, leveraging industry-standard to
40
40
  ## Getting Started
41
41
 
42
42
  ### Prerequisites
43
- - **Node.js**: v18.0.0 or higher
44
- - **Yarn**: 4.15.0 [^YARN_VER]
45
- - **React**: 19.x [^REACT_VER]
46
- - **MobX**: 6.15.0 [^MOBX_VER]
43
+
44
+ You need these tools to work in this repo:
45
+
46
+ - Node.js: the current LTS version. CI uses `node:lts-alpine`.
47
+ - Yarn: the version in the `packageManager` field of [package.json](package.json). Enable Corepack to get it.
47
48
 
48
49
  ### Installation
49
50
 
@@ -53,6 +54,8 @@ Install the library using yarn:
53
54
  yarn add @mx-cartographer/experiences
54
55
  ```
55
56
 
57
+ Your app must install the packages listed under `peerDependencies` in [package.json](package.json).
58
+
56
59
  Your app must also install the MUI X packages at the versions listed under `peerDependencies` in `package.json`. experiences, mxui, and your app then share one copy. The data grid packages are needed only for widgets that show a table.
57
60
 
58
61
  The QA storybook containing the latest Experience changes is [accessible here](https://experiences.kube.qa.internal.mx/?path=/docs/experiences-introduction--docs).
@@ -60,112 +63,51 @@ The QA storybook containing the latest Experience changes is [accessible here](h
60
63
  ## Usage
61
64
 
62
65
  ### Integrating a Widget
63
- To use an experience widget, import it from its feature-specific entry point. Most widgets are designed to automatically wrap themselves in a `WidgetContainer` for consistent layout.
66
+
67
+ Import each widget from its feature entry point. A widget reads its data from a `GlobalStore`, so render it inside a `GlobalDataProvider`. Most widgets wrap themselves in a `WidgetContainer` for a consistent layout.
64
68
 
65
69
  ```tsx
66
70
  import React from 'react';
71
+ import { GlobalDataProvider, GlobalStore } from '@mx-cartographer/experiences/common';
67
72
  import { AccountsWidget } from '@mx-cartographer/experiences/accounts';
68
73
 
69
- const MyDashboard = () => {
70
- return (
74
+ const globalStore = new GlobalStore();
75
+ globalStore.loadData();
76
+
77
+ const MyDashboard = () => (
78
+ <GlobalDataProvider
79
+ globalStore={globalStore}
80
+ onError={() => {}}
81
+ onEvent={() => {}}
82
+ onPageView={() => {}}
83
+ >
71
84
  <div style={{ height: '600px', width: '100%' }}>
72
- <AccountsWidget
73
- onBackClick={() => console.log('User clicked back')}
74
- />
85
+ <AccountsWidget onBackClick={() => console.log('User clicked back')} />
75
86
  </div>
76
- );
77
- };
87
+ </GlobalDataProvider>
88
+ );
78
89
  ```
79
90
 
80
91
  ### Common Configuration
81
- Widgets often accept `sx` props for styling and specific callbacks for navigation or analytics.
92
+
93
+ Most full widgets accept the `WidgetProps` type from `src/core/types/Widgets.ts`: an `sx` prop for styles, a `title`, and navigation callbacks such as `onBackClick` and `onMenuClick`.
82
94
 
83
95
  ```tsx
84
- import { BudgetsWidget } from '@mx-cartographer/experiences/budgets';
96
+ import { BubbleBudgetsWidget } from '@mx-cartographer/experiences/budgets';
85
97
 
86
- <BudgetsWidget
98
+ <BubbleBudgetsWidget
87
99
  sx={{ m: 2, borderRadius: '8px' }}
88
- onBudgetClick={(budgetId) => navigate(`/budgets/${budgetId}`)}
100
+ onBackClick={() => navigate('/')}
89
101
  />
90
102
  ```
91
103
 
92
104
  ## Architecture
93
105
 
94
- The project follows a modular architecture where feature widgets leverage shared infrastructure and a unified design system.
95
-
96
- ```mermaid
97
- graph TB
98
- subgraph "Consumer Application"
99
- App[React Application]
100
- end
101
-
102
- subgraph "@mx-cartographer/experiences"
103
- subgraph "Common Infrastructure (src/common)"
104
- WC[WidgetContainer]
105
- GP[WidgetContainerProvider]
106
- GS[GlobalUiStore / GlobalCopyStore]
107
- API[WidgetApi / Fetch]
108
- end
109
-
110
- subgraph "Experience Widgets (src/[feature])"
111
- AW[AccountsWidget]
112
- BW[BudgetsWidget]
113
- CW[CashflowWidget]
114
- end
115
-
116
- subgraph "State Management"
117
- MX[MobX]
118
- end
119
-
120
- subgraph "UI Foundation"
121
- MUI[Material UI]
122
- MXUI[@mxenabled/mxui]
123
- end
124
- end
125
-
126
- App --> AW
127
- App --> BW
128
- AW --> WC
129
- BW --> WC
130
- WC --> GP
131
- AW --> GS
132
- AW --> API
133
- GS --> MX
134
- AW --> MXUI
135
- MXUI --> MUI
136
- ```
137
-
138
- ### Key Design Patterns
139
- - **Container Pattern**: Widgets are wrapped in `WidgetContainer` [^1] to provide consistent headers, action buttons, and navigation.
140
- - **Context-Driven Layout**: The `WidgetContainerProvider` [^2] calculates container dimensions to enable internal responsive rendering logic.
141
- - **State Isolation**: Each feature (e.g., Budgets, Accounts) maintains its own MobX store, while sharing global state through `GlobalUiStore` and `GlobalCopyStore` [^3].
142
- - **Responsive Primitives**: All components use the `useScreenSize` hook [^4] for consistent behavior across mobile, tablet, and desktop viewports.
143
-
144
- ## Project Structure
145
-
146
- The codebase is organized by feature, with a shared `common` directory for cross-cutting concerns and a `core` directory for centralized types and constants.
147
-
148
- ```mermaid
149
- graph TD
150
- src["src/"]
151
- src --> core["core/ (Centralized TypeScript types and constants)"]
152
- src --> common["common/ (Shared components, hooks, stores, and API utilities)"]
153
- src --> accounts["accounts/ (Accounts summary, details, and connection management)"]
154
- src --> budgets["budgets/ (Budget tracking, bubble charts, and categorization)"]
155
- src --> cashflow["cashflow/ (Cashflow forecasting and event management)"]
156
- src --> dashboard["dashboard/ (Aggregate view of multiple experience widgets)"]
157
- src --> debts["debts/ (Debt tracking and payoff visualization)"]
158
- src --> finstrong["finstrong/ (Financial health scoring and reporting)"]
159
- src --> goals["goals/ (Savings goal setting, tracking, and progress visualization)"]
160
- src --> networth["networth/ (Asset and liability tracking with historical trends)"]
161
- src --> spending["spending/ (Categorized spending analysis)"]
162
- src --> transactions["transactions/ (Detailed transaction history and rules)"]
163
- src --> trends["trends/ (Longitudinal spending and income analysis)"]
164
- ```
106
+ Each feature widget uses shared code in `src/core` (types, constants, MobX stores, API classes, and utilities) and `src/common` (shared components, hooks, and context providers). The [Architecture Overview](docs/ARCHITECTURE.md) describes how these parts connect, and the [Widget Catalog](docs/WIDGETS.md) lists each feature directory and its entry points.
165
107
 
166
108
  ## Testing
167
109
 
168
- The library uses `Vitest` [^5] and `@testing-library/react` [^6] for comprehensive unit and integration testing.
110
+ The library uses Vitest and React Testing Library (`@testing-library/react`) for unit and integration tests.
169
111
 
170
112
  ```bash
171
113
  # Run all tests
@@ -178,7 +120,7 @@ yarn testui
178
120
  yarn citest
179
121
  ```
180
122
 
181
- Verification logic and test setups are maintained in [src/common/__tests__](src/common/__tests__) and [vitest.setup.insights.tsx](vitest.setup.insights.tsx).
123
+ The test configuration is in [vitest.config.ts](vitest.config.ts) and [tests/setup.ts](tests/setup.ts). [docs/TESTING.md](docs/TESTING.md) tells you how to write tests.
182
124
 
183
125
  ## Contributing
184
126
 
@@ -212,19 +154,10 @@ Verification logic and test setups are maintained in [src/common/__tests__](src/
212
154
 
213
155
  For technical assistance or internal inquiries:
214
156
  - **Team**: MX Cartographer
215
- - **Docs**: [MX Developer Portal](https://mx.atlassian.net/wiki)
157
+ - **Docs**: [MX Developer Portal](https://mxcom.atlassian.net/wiki)
216
158
  - **Slack**: https://mx.enterprise.slack.com/archives/C08M61HSWRF #web-experiences-dev-all
217
159
 
218
- ## Copyright (c) 2026 MX Technologies, Inc. All Rights Reserved.
219
-
220
- [^1]: [src/common/components/WidgetContainer.tsx:55](src/common/components/WidgetContainer.tsx#L55)
221
- [^2]: [src/common/context/WidgetContainerProvider.tsx:10](src/common/context/WidgetContainerProvider.tsx#L10)
222
- [^3]: [src/common/context/GlobalStoreProvider.tsx:10](src/common/context/GlobalStoreProvider.tsx#L10)
223
- [^4]: [src/common/hooks/useScreenSize.tsx:4](src/common/hooks/useScreenSize.tsx#L4)
224
- [^5]: [package.json:187](package.json#L187)
225
- [^6]: [package.json:229](package.json#L229)
226
- [^MUI_VER]: [package.json:195](package.json#L195)
227
- [^MXUI_VER]: [package.json:203](package.json#L203)
228
- [^MOBX_VER]: [package.json:209](package.json#L209)
229
- [^REACT_VER]: [package.json:213](package.json#L213)
230
- [^YARN_VER]: [package.json:297](package.json#L297)
160
+ ---
161
+
162
+ Copyright (c) 2026 MX Technologies, Inc. All Rights Reserved.
163
+
@@ -290,6 +290,17 @@ export interface GoalsBlockCopy {
290
290
  total_saved_label: string;
291
291
  complete_label: string;
292
292
  }
293
+ /** Labels for the Transparent Overdraft drawer: the account's overdraft figure and its confidence meter. */
294
+ export interface OverdraftCopy {
295
+ confidence_level: string;
296
+ /** Spoken name of the meter, e.g. "Confidence level that the account will overdraft". */
297
+ confidence_level_aria: string;
298
+ low: string;
299
+ medium: string;
300
+ high: string;
301
+ very_high: string;
302
+ to_occur_within_the_next_seven_days: string;
303
+ }
293
304
  /** Labels for the Credit Utilization drawer; the figures come off the beat. */
294
305
  export interface CreditUtilizationCopy {
295
306
  /** Drawer title. */
@@ -332,6 +343,13 @@ export interface PayoffCalculatorCopy {
332
343
  value_must_be_greater_than_or_equal_to: string;
333
344
  value_must_be_less_than_or_equal_to: string;
334
345
  }
346
+ export interface BudgetDetailsCopy {
347
+ days_left_until_end_of_month: string;
348
+ days_left_until_end_of_month_one: string;
349
+ previous_month_notice: string;
350
+ remaining: string;
351
+ total_out_of_limit_aria: string;
352
+ }
335
353
  export interface InsightsFeedCopy {
336
354
  general: GeneralInsightsFeedCopy;
337
355
  settings_menu: SettingsMenuCopy;
@@ -359,7 +377,9 @@ export interface InsightsFeedCopy {
359
377
  /** Optional until the localized-content service ships the namespace. */
360
378
  goals_block?: GoalsBlockCopy;
361
379
  /** Optional until the localized-content service ships the namespace. */
380
+ transparent_overdraft?: OverdraftCopy;
362
381
  credit_utilization?: CreditUtilizationCopy;
363
382
  payoff_calculator?: PayoffCalculatorCopy;
383
+ budget_details?: BudgetDetailsCopy;
364
384
  }
365
385
  export {};
@@ -13,7 +13,7 @@ export type { DebtsCopy } from './DebtsCopy';
13
13
  export type { FinstrongCopy } from './FinstrongCopy';
14
14
  export type { GoalsCopy } from './GoalsCopy';
15
15
  export type { HelpCopy, HelpByCategoryList } from './HelpCopy';
16
- export type { AmountInputModalCopy, AmountInputModalVariantCopy, EmergencySavingsCopy, InsightsFeedCopy, MakeTransferCopy, PayoffCalculatorCopy, RemainingCashCopy, CreditUtilizationCopy, OverflowMenuCopy, DismissInsightCopy, DismissInsightOptionCopy, HiddenConfirmationCopy, HideFeedbackCopy, FeedbackCopy, FeedbackBarCopy, } from './InsightsFeedCopy';
16
+ export type { AmountInputModalCopy, AmountInputModalVariantCopy, EmergencySavingsCopy, InsightsFeedCopy, MakeTransferCopy, PayoffCalculatorCopy, RemainingCashCopy, OverdraftCopy, CreditUtilizationCopy, OverflowMenuCopy, DismissInsightCopy, DismissInsightOptionCopy, HiddenConfirmationCopy, HideFeedbackCopy, FeedbackCopy, FeedbackBarCopy, } from './InsightsFeedCopy';
17
17
  export type { InvestmentsCopy } from './InvestmentsCopy';
18
18
  export type { MicroInsightsCopy } from './MicroInsightsCopy';
19
19
  export type { NetWorthCopy } from './NetWorthCopy';
@@ -0,0 +1,4 @@
1
+ import { ActionBlockProps } from '../../mappings/blocks';
2
+ export declare const BudgetDetailsBlock: (({ beat }: ActionBlockProps) => import("react/jsx-runtime").JSX.Element) & {
3
+ displayName: string;
4
+ };
@@ -0,0 +1,192 @@
1
+ import { buildDynamicCopy as I } from "../../../core/utils/Localization.es.js";
2
+ import { useBudgetsStore as Q, useCategoryStore as U, useGlobalCopyStore as X, useGlobalStore as Y } from "../../../common/context/hooks.es.js";
3
+ import { getCategoryColor as j } from "../../../core/utils/CategoryUtil.es.js";
4
+ import Z from "../../../common/components/Loader.es.js";
5
+ import ee from "../../../common/components/CurrencyDialog.es.js";
6
+ import te from "../../components/shared/StatusSnackbar.es.js";
7
+ import { daysLeftInBudgetMonth as oe, resolveBudgetFacts as re } from "./layout.es.js";
8
+ import { BudgetSummary as ae } from "./BudgetSummary.es.js";
9
+ import { useEffect as ie, useRef as se, useState as g } from "react";
10
+ import { observer as ne } from "mobx-react-lite";
11
+ import v from "@mui/material/Stack";
12
+ import { CategoryIcon as de, MerchantLogo as ce, Text as z } from "@mxenabled/mxui";
13
+ import k from "@mui/material/Button";
14
+ import { jsx as r, jsxs as P } from "react/jsx-runtime";
15
+ import { alpha as le, useTheme as ue } from "@mui/material/styles";
16
+ import me from "@mui/material/Skeleton";
17
+ var we = ne(function({ beat: _ }) {
18
+ const L = ue(), { copyStore: W } = Y(), { budgets: e, common: s, insights_feed: N } = X(), a = Q(), l = U(), [E, O] = g(!1), [i, D] = g(null), [T, p] = g(""), [y, f] = g(null), h = se(!1), w = N?.budget_details, { categories: R } = l, V = a.isDataLoaded && l.categoriesLoaded;
19
+ if (ie(() => {
20
+ Promise.allSettled([a.isDataLoaded || a.loadBudgets(), l.categoriesLoaded || l.loadCategories()]).then(() => O(!(a.isDataLoaded && l.categoriesLoaded)));
21
+ }, [a, l]), !W.isInitialized) return /* @__PURE__ */ r(Z, {});
22
+ if (!w) return /* @__PURE__ */ r(v, {
23
+ sx: { p: 24 },
24
+ children: /* @__PURE__ */ r(z, { children: s?.error_message })
25
+ });
26
+ const o = re(_), m = o.categoryGuid ? R.find(({ guid: t }) => t === o.categoryGuid) : void 0, n = o.categoryGuid ? a.budgets.find(({ category_guid: t }) => t === o.categoryGuid) : void 0, d = !o.categoryGuid && o.merchantGuid ? a.getMerchantBudgetByMerchantGuid(o.merchantGuid) : void 0, M = m?.name ?? d?.merchant_name ?? _.payload?.merchant_name ?? "", A = n?.amount ?? d?.amount ?? o.budgeted ?? 0, $ = o.spent ?? n?.transaction_total ?? d?.transaction_total ?? 0, q = o.categoryGuid ? /* @__PURE__ */ r(de, {
27
+ categoryGuid: o.categoryGuid,
28
+ size: 44,
29
+ sx: {
30
+ bgcolor: le(j(o.categoryGuid, L), 0.15),
31
+ border: `1px solid ${j(o.categoryGuid, L)}`,
32
+ color: "text.primary"
33
+ }
34
+ }) : /* @__PURE__ */ r(ce, {
35
+ categoryGuid: "",
36
+ merchantGuid: o.merchantGuid ?? "",
37
+ size: 44
38
+ }), b = (t) => {
39
+ p(t === "edit" ? String(A) : ""), D(t);
40
+ }, B = () => {
41
+ D(null), p("");
42
+ }, c = (t) => I(t, M), H = async (t, u) => {
43
+ if (d) {
44
+ if (t === "delete") {
45
+ const { isSuccess: S } = await a.deleteMerchantBudget(d.guid);
46
+ return {
47
+ ok: S,
48
+ success: c(e.success_alert_delete_merchant_budget),
49
+ failure: c(e.error_alert_delete_merchant_budget)
50
+ };
51
+ }
52
+ const { isSuccess: G } = await a.updateMerchantBudget({
53
+ ...d,
54
+ amount: u
55
+ });
56
+ return {
57
+ ok: G,
58
+ success: c(e.success_alert_edit_merchant_budget),
59
+ failure: c(e.error_alert_edit_merchant_budget)
60
+ };
61
+ }
62
+ return t === "delete" && n ? {
63
+ ok: await a.deleteBudget(n.guid),
64
+ success: c(e.alert_budget_deleted)
65
+ } : t === "edit" && n ? {
66
+ ok: await a.updateBudget({
67
+ ...n,
68
+ amount: u
69
+ }),
70
+ success: c(e.alert_budget_updated)
71
+ } : t === "create" && m ? {
72
+ ok: await a.addBudget(m, u),
73
+ success: c(e.alert_budget_created)
74
+ } : {
75
+ ok: !1,
76
+ success: ""
77
+ };
78
+ }, J = async () => {
79
+ if (h.current || !i) return;
80
+ const t = Number(T);
81
+ if (!(i !== "delete" && !(Number.isFinite(t) && t > 0))) {
82
+ h.current = !0;
83
+ try {
84
+ const { ok: u, success: G, failure: S } = await H(i, t);
85
+ f({
86
+ message: u ? G : S ?? s.error_message,
87
+ severity: u ? "success" : "error"
88
+ });
89
+ } catch {
90
+ f({
91
+ message: s.error_message,
92
+ severity: "error"
93
+ });
94
+ } finally {
95
+ h.current = !1, B();
96
+ }
97
+ }
98
+ }, F = !!(n ?? d), K = E ? /* @__PURE__ */ r(z, {
99
+ color: "text.secondary",
100
+ variant: "body2",
101
+ children: s.error_message
102
+ }) : V ? F ? /* @__PURE__ */ P(v, {
103
+ sx: {
104
+ flexDirection: "row",
105
+ gap: 12
106
+ },
107
+ children: [/* @__PURE__ */ r(k, {
108
+ fullWidth: !0,
109
+ onClick: () => b("edit"),
110
+ variant: "outlined",
111
+ children: e.details_edit_button
112
+ }), /* @__PURE__ */ r(k, {
113
+ color: "error",
114
+ fullWidth: !0,
115
+ onClick: () => b("delete"),
116
+ variant: "outlined",
117
+ children: e.details_delete_button
118
+ })]
119
+ }) : !F && m ? /* @__PURE__ */ r(k, {
120
+ fullWidth: !0,
121
+ onClick: () => b("create"),
122
+ variant: "contained",
123
+ children: e.dialog_primary_button_text
124
+ }) : null : /* @__PURE__ */ r(me, {
125
+ height: 40,
126
+ variant: "rounded"
127
+ }), x = i === "delete", C = {
128
+ create: {
129
+ content: e.add_description_bottom,
130
+ primaryText: e.dialog_primary_button_text,
131
+ title: e.dialog_create_budget_title
132
+ },
133
+ edit: {
134
+ content: e.edit_budget_content,
135
+ primaryText: e.add_save_button,
136
+ title: e.details_edit_title
137
+ },
138
+ delete: {
139
+ content: e.delete_description,
140
+ primaryText: e.details_delete_button,
141
+ title: e.delete_title
142
+ }
143
+ };
144
+ return /* @__PURE__ */ P(v, {
145
+ sx: {
146
+ bgcolor: "background.paper",
147
+ gap: 24,
148
+ p: 24
149
+ },
150
+ children: [
151
+ /* @__PURE__ */ r(ae, {
152
+ budgetsCopy: e,
153
+ copy: w,
154
+ daysLeft: oe(_),
155
+ icon: q,
156
+ limit: A,
157
+ spent: $
158
+ }),
159
+ K,
160
+ i && /* @__PURE__ */ r(ee, {
161
+ closeAriaLabel: s.close_aria,
162
+ content: I(C[i].content, /* @__PURE__ */ r("b", { children: M })),
163
+ handleInputChange: p,
164
+ handleModalClose: B,
165
+ handlePrimaryAction: () => {
166
+ J();
167
+ },
168
+ handleSecondaryAction: B,
169
+ inputLabel: x ? void 0 : e.add_label,
170
+ inputValue: T,
171
+ isOpen: !0,
172
+ primaryColor: x ? "error" : "primary",
173
+ primaryText: C[i].primaryText,
174
+ secondaryColor: x ? "inherit" : "primary",
175
+ secondaryText: s.cancel_button,
176
+ title: C[i].title
177
+ }),
178
+ /* @__PURE__ */ r(te, {
179
+ closeAriaLabel: s.close_aria,
180
+ message: y?.message ?? "",
181
+ onClose: () => f(null),
182
+ open: !!y,
183
+ severity: y?.severity
184
+ })
185
+ ]
186
+ });
187
+ });
188
+ export {
189
+ we as BudgetDetailsBlock
190
+ };
191
+
192
+ //# sourceMappingURL=BudgetDetailsBlock.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BudgetDetailsBlock.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/BudgetDetailsBlock/BudgetDetailsBlock.tsx"],"sourcesContent":["import { useEffect, useRef, useState, type ReactNode } from 'react'\n\nimport Button from '@mui/material/Button'\nimport Skeleton from '@mui/material/Skeleton'\nimport Stack from '@mui/material/Stack'\nimport { alpha, useTheme } from '@mui/material/styles'\n\nimport { CategoryIcon, MerchantLogo, Text } from '@mxenabled/mxui'\nimport { observer } from 'mobx-react-lite'\n\nimport { CurrencyDialog } from '../../../common/components'\nimport {\n Loader,\n useBudgetsStore,\n useCategoryStore,\n useGlobalCopyStore,\n useGlobalStore,\n} from '../../../common'\nimport { buildDynamicCopy } from '../../../core/utils/Localization'\nimport { getCategoryColor } from '../../../core/utils/CategoryUtil'\nimport type { Budget, MerchantBudget } from '../../../core'\nimport StatusSnackbar from '../../components/shared/StatusSnackbar'\nimport type { ActionBlockProps } from '../../mappings/blocks'\n\nimport { BudgetSummary } from './BudgetSummary'\nimport { daysLeftInBudgetMonth, resolveBudgetFacts } from './layout'\n\ntype DialogAction = 'create' | 'edit' | 'delete'\n\ninterface Toast {\n message: string\n severity: 'success' | 'error'\n}\n\nexport const BudgetDetailsBlock = observer(function BudgetDetailsBlock({ beat }: ActionBlockProps) {\n const theme = useTheme()\n const { copyStore } = useGlobalStore()\n const {\n budgets: budgetsCopy,\n common: commonCopy,\n insights_feed: insightsFeedCopy,\n } = useGlobalCopyStore()\n const budgetsStore = useBudgetsStore()\n const categoryStore = useCategoryStore()\n const [loadFailed, setLoadFailed] = useState(false)\n const [dialog, setDialog] = useState<DialogAction | null>(null)\n const [amount, setAmount] = useState('')\n const [toast, setToast] = useState<Toast | null>(null)\n const inProgress = useRef(false)\n const copy = insightsFeedCopy?.budget_details\n const { categories } = categoryStore\n const ready = budgetsStore.isDataLoaded && categoryStore.categoriesLoaded\n\n useEffect(() => {\n void Promise.allSettled([\n budgetsStore.isDataLoaded || budgetsStore.loadBudgets(),\n categoryStore.categoriesLoaded || categoryStore.loadCategories(),\n ]).then(() => setLoadFailed(!(budgetsStore.isDataLoaded && categoryStore.categoriesLoaded)))\n }, [budgetsStore, categoryStore])\n\n if (!copyStore.isInitialized) return <Loader />\n\n if (!copy) {\n return (\n <Stack sx={{ p: 24 }}>\n <Text>{commonCopy?.error_message}</Text>\n </Stack>\n )\n }\n\n const facts = resolveBudgetFacts(beat)\n const category = facts.categoryGuid\n ? categories.find(({ guid }) => guid === facts.categoryGuid)\n : undefined\n const budget: Budget | undefined = facts.categoryGuid\n ? budgetsStore.budgets.find(({ category_guid }) => category_guid === facts.categoryGuid)\n : undefined\n const merchantBudget: MerchantBudget | undefined =\n !facts.categoryGuid && facts.merchantGuid\n ? budgetsStore.getMerchantBudgetByMerchantGuid(facts.merchantGuid)\n : undefined\n const subject =\n category?.name ??\n merchantBudget?.merchant_name ??\n (beat.payload?.merchant_name as string | undefined) ??\n ''\n const limit = budget?.amount ?? merchantBudget?.amount ?? facts.budgeted ?? 0\n const spent = facts.spent ?? budget?.transaction_total ?? merchantBudget?.transaction_total ?? 0\n\n const icon = facts.categoryGuid ? (\n <CategoryIcon\n categoryGuid={facts.categoryGuid}\n size={44}\n sx={{\n bgcolor: alpha(getCategoryColor(facts.categoryGuid, theme), 0.15),\n border: `1px solid ${getCategoryColor(facts.categoryGuid, theme)}`,\n color: 'text.primary',\n }}\n />\n ) : (\n <MerchantLogo categoryGuid=\"\" merchantGuid={facts.merchantGuid ?? ''} size={44} />\n )\n\n const openDialog = (action: DialogAction) => {\n setAmount(action === 'edit' ? String(limit) : '')\n setDialog(action)\n }\n\n const closeDialog = () => {\n setDialog(null)\n setAmount('')\n }\n\n const dynamic = (key: string) => buildDynamicCopy(key, subject) as string\n\n const perform = async (\n action: DialogAction,\n value: number,\n ): Promise<{ ok: boolean; success: string; failure?: string }> => {\n if (merchantBudget) {\n if (action === 'delete') {\n const { isSuccess } = await budgetsStore.deleteMerchantBudget(merchantBudget.guid)\n return {\n ok: isSuccess,\n success: dynamic(budgetsCopy.success_alert_delete_merchant_budget),\n failure: dynamic(budgetsCopy.error_alert_delete_merchant_budget),\n }\n }\n const { isSuccess } = await budgetsStore.updateMerchantBudget({\n ...merchantBudget,\n amount: value,\n })\n return {\n ok: isSuccess,\n success: dynamic(budgetsCopy.success_alert_edit_merchant_budget),\n failure: dynamic(budgetsCopy.error_alert_edit_merchant_budget),\n }\n }\n if (action === 'delete' && budget) {\n return {\n ok: await budgetsStore.deleteBudget(budget.guid),\n success: dynamic(budgetsCopy.alert_budget_deleted),\n }\n }\n if (action === 'edit' && budget) {\n return {\n ok: await budgetsStore.updateBudget({ ...budget, amount: value }),\n success: dynamic(budgetsCopy.alert_budget_updated),\n }\n }\n if (action === 'create' && category) {\n return {\n ok: await budgetsStore.addBudget(category, value),\n success: dynamic(budgetsCopy.alert_budget_created),\n }\n }\n return { ok: false, success: '' }\n }\n\n const submit = async () => {\n if (inProgress.current || !dialog) return\n const value = Number(amount)\n if (dialog !== 'delete' && !(Number.isFinite(value) && value > 0)) return\n\n inProgress.current = true\n try {\n const { ok, success, failure } = await perform(dialog, value)\n setToast({\n message: ok ? success : (failure ?? commonCopy.error_message),\n severity: ok ? 'success' : 'error',\n })\n } catch {\n setToast({ message: commonCopy.error_message, severity: 'error' })\n } finally {\n inProgress.current = false\n closeDialog()\n }\n }\n\n const hasBudget = Boolean(budget ?? merchantBudget)\n const canCreate = !hasBudget && Boolean(category)\n\n const actions = loadFailed ? (\n <Text color=\"text.secondary\" variant=\"body2\">\n {commonCopy.error_message}\n </Text>\n ) : !ready ? (\n <Skeleton height={40} variant=\"rounded\" />\n ) : hasBudget ? (\n <Stack sx={{ flexDirection: 'row', gap: 12 }}>\n <Button fullWidth={true} onClick={() => openDialog('edit')} variant=\"outlined\">\n {budgetsCopy.details_edit_button}\n </Button>\n <Button\n color=\"error\"\n fullWidth={true}\n onClick={() => openDialog('delete')}\n variant=\"outlined\"\n >\n {budgetsCopy.details_delete_button}\n </Button>\n </Stack>\n ) : canCreate ? (\n <Button fullWidth={true} onClick={() => openDialog('create')} variant=\"contained\">\n {budgetsCopy.dialog_primary_button_text}\n </Button>\n ) : null\n\n const isDelete = dialog === 'delete'\n const dialogCopy = {\n create: {\n content: budgetsCopy.add_description_bottom,\n primaryText: budgetsCopy.dialog_primary_button_text,\n title: budgetsCopy.dialog_create_budget_title,\n },\n edit: {\n content: budgetsCopy.edit_budget_content,\n primaryText: budgetsCopy.add_save_button,\n title: budgetsCopy.details_edit_title,\n },\n delete: {\n content: budgetsCopy.delete_description,\n primaryText: budgetsCopy.details_delete_button,\n title: budgetsCopy.delete_title,\n },\n }\n\n return (\n <Stack sx={{ bgcolor: 'background.paper', gap: 24, p: 24 }}>\n <BudgetSummary\n budgetsCopy={budgetsCopy}\n copy={copy}\n daysLeft={daysLeftInBudgetMonth(beat)}\n icon={icon}\n limit={limit}\n spent={spent}\n />\n {actions}\n {dialog && (\n <CurrencyDialog\n closeAriaLabel={commonCopy.close_aria}\n content={buildDynamicCopy(dialogCopy[dialog].content, <b>{subject}</b>) as ReactNode}\n handleInputChange={setAmount}\n handleModalClose={closeDialog}\n handlePrimaryAction={() => void submit()}\n handleSecondaryAction={closeDialog}\n inputLabel={isDelete ? undefined : budgetsCopy.add_label}\n inputValue={amount}\n isOpen={true}\n primaryColor={isDelete ? 'error' : 'primary'}\n primaryText={dialogCopy[dialog].primaryText}\n secondaryColor={isDelete ? 'inherit' : 'primary'}\n secondaryText={commonCopy.cancel_button}\n title={dialogCopy[dialog].title}\n />\n )}\n <StatusSnackbar\n closeAriaLabel={commonCopy.close_aria}\n message={toast?.message ?? ''}\n onClose={() => setToast(null)}\n open={Boolean(toast)}\n severity={toast?.severity}\n />\n </Stack>\n )\n})\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,IAAa,KAAqB,GAAS,SAA4B,EAAE,MAAA,EAAA,GAA0B;AACjG,QAAM,IAAQ,GAAS,GACjB,EAAE,WAAA,EAAA,IAAc,EAAe,GAC/B,EACJ,SAAS,GACT,QAAQ,GACR,eAAe,EAAA,IACb,EAAmB,GACjB,IAAe,EAAgB,GAC/B,IAAgB,EAAiB,GACjC,CAAC,GAAY,CAAA,IAAiB,EAAS,EAAK,GAC5C,CAAC,GAAQ,CAAA,IAAa,EAA8B,IAAI,GACxD,CAAC,GAAQ,CAAA,IAAa,EAAS,EAAE,GACjC,CAAC,GAAO,CAAA,IAAY,EAAuB,IAAI,GAC/C,IAAa,GAAO,EAAK,GACzB,IAAO,GAAkB,gBACzB,EAAE,YAAA,EAAA,IAAe,GACjB,IAAQ,EAAa,gBAAgB,EAAc;AASzD,MAPA,GAAA,MAAgB;AACd,YAAa,WAAW,CACtB,EAAa,gBAAgB,EAAa,YAAY,GACtD,EAAc,oBAAoB,EAAc,eAAe,CACjE,CAAC,EAAE,KAAA,MAAW,EAAc,EAAE,EAAa,gBAAgB,EAAc,iBAAiB,CAAC;AAAA,EAC7F,GAAG,CAAC,GAAc,CAAa,CAAC,GAE5B,CAAC,EAAU,cAAe,QAAO,gBAAA,EAAC,GAAD,CAAS,CAAA;AAE9C,MAAI,CAAC,EACH,QACE,gBAAA,EAAC,GAAD;AAAA,IAAO,IAAI,EAAE,GAAG,GAAG;AAAA,IACjB,UAAA,gBAAA,EAAC,GAAD,EAAA,UAAO,GAAY,cAAoB,CAAA;AAAA,EAClC,CAAA;AAIX,QAAM,IAAQ,GAAmB,CAAI,GAC/B,IAAW,EAAM,eACn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aAAa,EAAY;AAAA,MACzB,OAAO,EAAY;AAAA,IACrB;AAAA,EACF;AAEA,SACE,gBAAA,EAAC,GAAD;AAAA,IAAO,IAAI;AAAA,MAAE,SAAS;AAAA,MAAoB,KAAK;AAAA,MAAI,GAAG;AAAA,IAAG;AAAA,IAAzD,UAAA;AAAA,MACE,gBAAA,EAAC,IAAD;AAAA,QACe,aAAA;AAAA,QACP,MAAA;AAAA,QACN,UAAU,GAAsB,CAAI;AAAA,QAC9B,MAAA;AAAA,QACC,OAAA;AAAA,QACA,OAAA;AAAA,MACR,CAAA;AAAA,MACA;AAAA,MACA,KACC,gBAAA,EAAC,IAAD;AAAA,QACE,gBAAgB,EAAW;AAAA,QAC3B,SAAS,EAAiB,EAAW,CAAA,EAAQ,SAAS,gBAAA,EAAC,KAAD,EAAA,UAAI,EAAW,CAAA,CAAC;AAAA,QACtE,mBAAmB;AAAA,QACnB,kBAAkB;AAAA,QAClB,qBAAA,MAAA;AAA2B,UAAK,EAAO;AAAA;AAAA,QACvC,uBAAuB;AAAA,QACvB,YAAY,IAAW,SAAY,EAAY;AAAA,QAC/C,YAAY;AAAA,QACZ,QAAQ;AAAA,QACR,cAAc,IAAW,UAAU;AAAA,QACnC,aAAa,EAAW,CAAA,EAAQ;AAAA,QAChC,gBAAgB,IAAW,YAAY;AAAA,QACvC,eAAe,EAAW;AAAA,QAC1B,OAAO,EAAW,CAAA,EAAQ;AAAA,MAC3B,CAAA;AAAA,MAEH,gBAAA,EAAC,IAAD;AAAA,QACE,gBAAgB,EAAW;AAAA,QAC3B,SAAS,GAAO,WAAW;AAAA,QAC3B,SAAA,MAAe,EAAS,IAAI;AAAA,QAC5B,MAAM,EAAQ;AAAA,QACd,UAAU,GAAO;AAAA,MAClB,CAAA;AAAA,IACI;AAAA;AAEX,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { ReactNode } from 'react';
2
+ import { BudgetsCopy } from '../../../core/types/localization';
3
+ import { BudgetDetailsCopy } from '../../../core/types/localization/InsightsFeedCopy';
4
+ interface BudgetSummaryProps {
5
+ budgetsCopy: BudgetsCopy;
6
+ copy: BudgetDetailsCopy;
7
+ daysLeft?: number;
8
+ icon: ReactNode;
9
+ limit: number;
10
+ spent: number;
11
+ }
12
+ export declare const BudgetSummary: ({ budgetsCopy, copy, daysLeft, icon, limit, spent, }: BudgetSummaryProps) => import("react/jsx-runtime").JSX.Element;
13
+ export {};
@@ -0,0 +1,94 @@
1
+ import { buildDynamicCopy as h, buildPluralCopy as f } from "../../../core/utils/Localization.es.js";
2
+ import { formatCurrency as n } from "../../../core/utils/NumberFormatting.es.js";
3
+ import b from "../../components/ComponentBlocks/StatusIndicator.es.js";
4
+ import { calculateBudgetPercent as g, calculateBudgetTier as v, tierColor as y } from "./layout.es.js";
5
+ import i from "@mui/material/Stack";
6
+ import { Text as l } from "@mxenabled/mxui";
7
+ import { jsx as r, jsxs as e } from "react/jsx-runtime";
8
+ import p from "@mui/material/Box";
9
+ import S from "@mui/material/Alert";
10
+ var k = ({ budgetsCopy: c, copy: a, daysLeft: d, icon: s, limit: o, spent: t }) => {
11
+ const m = g(t, o), u = v(m), x = y(u), _ = d === void 0 ? /* @__PURE__ */ r(S, {
12
+ severity: "info",
13
+ children: a.previous_month_notice
14
+ }) : /* @__PURE__ */ r(l, {
15
+ color: "text.secondary",
16
+ variant: "body2",
17
+ children: f(a.days_left_until_end_of_month_one, a.days_left_until_end_of_month, d, String(d))
18
+ });
19
+ return o <= 0 ? /* @__PURE__ */ e(i, {
20
+ sx: { gap: 16 },
21
+ children: [/* @__PURE__ */ e(i, {
22
+ sx: {
23
+ alignItems: "center",
24
+ flexDirection: "row",
25
+ gap: 12
26
+ },
27
+ children: [/* @__PURE__ */ r(p, { children: s }), /* @__PURE__ */ e(i, { children: [/* @__PURE__ */ r(l, {
28
+ color: "text.secondary",
29
+ variant: "body2",
30
+ children: c.spent_label
31
+ }), /* @__PURE__ */ r(l, {
32
+ bold: !0,
33
+ component: "p",
34
+ variant: "h2",
35
+ children: n(t, "0,0.00")
36
+ })] })]
37
+ }), _]
38
+ }) : /* @__PURE__ */ e(i, {
39
+ sx: { gap: 16 },
40
+ children: [/* @__PURE__ */ r(p, {
41
+ "aria-label": h(a.total_out_of_limit_aria, n(t, "0,0.00"), n(o, "0,0.00")),
42
+ "data-tier": u ?? "none",
43
+ role: "group",
44
+ children: /* @__PURE__ */ r(b, {
45
+ amount: /* @__PURE__ */ e(i, {
46
+ sx: {
47
+ alignItems: "baseline",
48
+ flexDirection: "row",
49
+ gap: 4
50
+ },
51
+ children: [/* @__PURE__ */ r(l, {
52
+ bold: !0,
53
+ component: "p",
54
+ variant: "h2",
55
+ children: n(t, "0,0.00")
56
+ }), /* @__PURE__ */ e(l, {
57
+ color: "text.secondary",
58
+ variant: "body2",
59
+ children: ["/ ", n(o, "0,0.00")]
60
+ })]
61
+ }),
62
+ borderRadius: "8px",
63
+ completeColor: x,
64
+ icon: s,
65
+ label: /* @__PURE__ */ e(i, {
66
+ sx: {
67
+ alignItems: "center",
68
+ flexDirection: "row",
69
+ gap: 6
70
+ },
71
+ children: [/* @__PURE__ */ r(p, { sx: {
72
+ bgcolor: x,
73
+ borderRadius: "50%",
74
+ height: 8,
75
+ width: 8
76
+ } }), /* @__PURE__ */ r(l, {
77
+ color: "text.secondary",
78
+ variant: "body2",
79
+ children: c.spent_label
80
+ })]
81
+ }),
82
+ leftLabel: h(c.percent_spent, String(m)),
83
+ percentComplete: Math.min(100, m),
84
+ rightLabel: o > t ? h(a.remaining, n(o - t, "0,0.00")) : "",
85
+ sx: { p: 0 }
86
+ })
87
+ }), _]
88
+ });
89
+ };
90
+ export {
91
+ k as BudgetSummary
92
+ };
93
+
94
+ //# sourceMappingURL=BudgetSummary.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BudgetSummary.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/BudgetDetailsBlock/BudgetSummary.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\n\nimport Alert from '@mui/material/Alert'\nimport Box from '@mui/material/Box'\nimport Stack from '@mui/material/Stack'\n\nimport { Text } from '@mxenabled/mxui'\n\nimport { buildDynamicCopy, buildPluralCopy } from '../../../core/utils/Localization'\nimport { formatCurrency } from '../../../core/utils/NumberFormatting'\nimport type { BudgetsCopy } from '../../../core/types/localization'\nimport type { BudgetDetailsCopy } from '../../../core/types/localization/InsightsFeedCopy'\nimport StatusIndicator from '../../components/ComponentBlocks/StatusIndicator'\n\nimport { calculateBudgetPercent, calculateBudgetTier, tierColor } from './layout'\n\ninterface BudgetSummaryProps {\n budgetsCopy: BudgetsCopy\n copy: BudgetDetailsCopy\n daysLeft?: number\n icon: ReactNode\n limit: number\n spent: number\n}\n\nexport const BudgetSummary = ({\n budgetsCopy,\n copy,\n daysLeft,\n icon,\n limit,\n spent,\n}: BudgetSummaryProps) => {\n const percent = calculateBudgetPercent(spent, limit)\n const tier = calculateBudgetTier(percent)\n const color = tierColor(tier)\n const periodLine =\n daysLeft === undefined ? (\n <Alert severity=\"info\">{copy.previous_month_notice}</Alert>\n ) : (\n <Text color=\"text.secondary\" variant=\"body2\">\n {\n buildPluralCopy(\n copy.days_left_until_end_of_month_one,\n copy.days_left_until_end_of_month,\n daysLeft,\n String(daysLeft),\n ) as string\n }\n </Text>\n )\n\n if (limit <= 0) {\n return (\n <Stack sx={{ gap: 16 }}>\n <Stack sx={{ alignItems: 'center', flexDirection: 'row', gap: 12 }}>\n <Box>{icon}</Box>\n <Stack>\n <Text color=\"text.secondary\" variant=\"body2\">\n {budgetsCopy.spent_label}\n </Text>\n <Text bold={true} component=\"p\" variant=\"h2\">\n {formatCurrency(spent, '0,0.00')}\n </Text>\n </Stack>\n </Stack>\n {periodLine}\n </Stack>\n )\n }\n\n return (\n <Stack sx={{ gap: 16 }}>\n <Box\n aria-label={\n buildDynamicCopy(\n copy.total_out_of_limit_aria,\n formatCurrency(spent, '0,0.00'),\n formatCurrency(limit, '0,0.00'),\n ) as string\n }\n data-tier={tier ?? 'none'}\n role=\"group\"\n >\n <StatusIndicator\n amount={\n <Stack sx={{ alignItems: 'baseline', flexDirection: 'row', gap: 4 }}>\n <Text bold={true} component=\"p\" variant=\"h2\">\n {formatCurrency(spent, '0,0.00')}\n </Text>\n <Text color=\"text.secondary\" variant=\"body2\">\n / {formatCurrency(limit, '0,0.00')}\n </Text>\n </Stack>\n }\n borderRadius=\"8px\"\n completeColor={color}\n icon={icon}\n label={\n <Stack sx={{ alignItems: 'center', flexDirection: 'row', gap: 6 }}>\n <Box sx={{ bgcolor: color, borderRadius: '50%', height: 8, width: 8 }} />\n <Text color=\"text.secondary\" variant=\"body2\">\n {budgetsCopy.spent_label}\n </Text>\n </Stack>\n }\n leftLabel={buildDynamicCopy(budgetsCopy.percent_spent, String(percent)) as string}\n percentComplete={Math.min(100, percent)}\n rightLabel={\n limit > spent\n ? (buildDynamicCopy(\n copy.remaining,\n formatCurrency(limit - spent, '0,0.00'),\n ) as string)\n : ''\n }\n sx={{ p: 0 }}\n />\n </Box>\n {periodLine}\n </Stack>\n )\n}\n"],"mappings":";;;;;;;;;AAyBA,IAAa,IAAA,CAAiB,EAC5B,aAAA,GACA,MAAA,GACA,UAAA,GACA,MAAA,GACA,OAAA,GACA,OAAA,EAAA,MACwB;AACxB,QAAM,IAAU,EAAuB,GAAO,CAAK,GAC7C,IAAO,EAAoB,CAAO,GAClC,IAAQ,EAAU,CAAI,GACtB,IACJ,MAAa,SACX,gBAAA,EAAC,GAAD;AAAA,IAAO,UAAS;AAAA,IAAQ,UAAA,EAAK;AAAA,EAA6B,CAAA,IAE1D,gBAAA,EAAC,GAAD;AAAA,IAAM,OAAM;AAAA,IAAiB,SAAQ;AAAA,IAEjC,UAAA,EACE,EAAK,kCACL,EAAK,8BACL,GACA,OAAO,CAAQ,CACjB;AAAA,EAEE,CAAA;AAGV,SAAI,KAAS,IAET,gBAAA,EAAC,GAAD;AAAA,IAAO,IAAI,EAAE,KAAK,GAAG;AAAA,IAArB,UAAA,CACE,gBA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