@mx-cartographer/experiences 9.7.176 → 9.7.177
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.
- package/CHANGELOG.md +5 -1
- package/dist/insights-v2/actionBlocks/AmountInputModalBlock/AmountInputModalBlock.es.js +75 -74
- package/dist/insights-v2/actionBlocks/AmountInputModalBlock/AmountInputModalBlock.es.js.map +1 -1
- package/dist/insights-v2/actionBlocks/AmountInputModalBlock/CreateBudgetDialog.es.js +39 -43
- package/dist/insights-v2/actionBlocks/AmountInputModalBlock/CreateBudgetDialog.es.js.map +1 -1
- package/dist/insights-v2/actionBlocks/useBlockSave.d.ts +11 -0
- package/dist/insights-v2/actionBlocks/useBlockSave.es.js +29 -0
- package/dist/insights-v2/actionBlocks/useBlockSave.es.js.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
## [9.7.177] - 11-17-2026
|
|
2
|
+
|
|
3
|
+
- **CHANGED** - Insights 2.0 block dialogs (Amount Input, Create Budget) save through one shared hook; no visible change (WEC-2262)
|
|
4
|
+
|
|
1
5
|
## [9.7.176] - 11-17-2026
|
|
2
6
|
|
|
3
|
-
-
|
|
7
|
+
- **FIXED** - goal amount validation in the goals widget (WELL-178)
|
|
4
8
|
|
|
5
9
|
## [9.7.175] - 11-17-2026
|
|
6
10
|
|
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
import { buildDynamicCopy as
|
|
2
|
-
import
|
|
3
|
-
import { useCategoryStore as
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { useBeatActions as
|
|
7
|
-
import { useCtaHandler as
|
|
8
|
-
import { useAnalyticsEvent as
|
|
9
|
-
import { useOpenedCta as
|
|
1
|
+
import { buildDynamicCopy as Q } from "../../../core/utils/Localization.es.js";
|
|
2
|
+
import X from "../../../common/utils/AccountDisplayName.es.js";
|
|
3
|
+
import { useCategoryStore as Y, useGlobalCopyStore as w, useInsightsV2Store as B, useSettingsStore as Z, useUserStore as oo } from "../../../common/context/hooks.es.js";
|
|
4
|
+
import E from "../../../common/components/Loader.es.js";
|
|
5
|
+
import eo from "../../../common/components/CurrencyDialog.es.js";
|
|
6
|
+
import { useBeatActions as to } from "../../beatActions.es.js";
|
|
7
|
+
import { useCtaHandler as io } from "../../ctaActions/useCtaAction.es.js";
|
|
8
|
+
import { useAnalyticsEvent as no } from "../../analytics/useAnalyticsEvent.es.js";
|
|
9
|
+
import { useOpenedCta as ro } from "../useOpenedCta.es.js";
|
|
10
|
+
import { useBlockSave as so } from "../useBlockSave.es.js";
|
|
10
11
|
import { CreateBudgetDialog as ao } from "./CreateBudgetDialog.es.js";
|
|
11
|
-
import { AMOUNT_SETTINGS as co, CREATE_BUDGET_VARIANT as lo, findLowBalanceProfile as uo, isAmountInputVariant as
|
|
12
|
-
import
|
|
13
|
-
import { observer as
|
|
14
|
-
import
|
|
15
|
-
import { H3 as fo, InstitutionLogo as
|
|
16
|
-
import { Icon as
|
|
17
|
-
import { jsx as e, jsxs as
|
|
12
|
+
import { AMOUNT_SETTINGS as co, CREATE_BUDGET_VARIANT as lo, findLowBalanceProfile as uo, isAmountInputVariant as L, resolveAmountInputVariant as mo, toInputValue as po } from "./layout.es.js";
|
|
13
|
+
import c from "react";
|
|
14
|
+
import { observer as k } from "mobx-react-lite";
|
|
15
|
+
import N from "@mui/material/Stack";
|
|
16
|
+
import { H3 as fo, InstitutionLogo as yo, Text as T } from "@mxenabled/mxui";
|
|
17
|
+
import { Icon as go } from "@mxenabled/mx-icons";
|
|
18
|
+
import { jsx as e, jsxs as V } from "react/jsx-runtime";
|
|
18
19
|
import ho from "@mui/material/Dialog";
|
|
19
|
-
import
|
|
20
|
-
var
|
|
21
|
-
const
|
|
20
|
+
import vo from "@mui/material/IconButton";
|
|
21
|
+
var _ = ({ children: y, closeAriaLabel: i, heading: n, onClose: t }) => {
|
|
22
|
+
const r = c.useId();
|
|
22
23
|
return /* @__PURE__ */ e(ho, {
|
|
23
|
-
"aria-labelledby": n ?
|
|
24
|
+
"aria-labelledby": n ? r : void 0,
|
|
24
25
|
maxWidth: "xs",
|
|
25
26
|
onClose: t,
|
|
26
27
|
open: !0,
|
|
27
|
-
sx: { "& .MuiDialog-paper": { borderRadius: (
|
|
28
|
-
children: /* @__PURE__ */
|
|
28
|
+
sx: { "& .MuiDialog-paper": { borderRadius: (a) => `${a.shape.borderRadius}px` } },
|
|
29
|
+
children: /* @__PURE__ */ V(N, {
|
|
29
30
|
sx: {
|
|
30
31
|
gap: 12,
|
|
31
32
|
p: 24,
|
|
@@ -33,10 +34,10 @@ var C = ({ children: g, closeAriaLabel: i, heading: n, onClose: t }) => {
|
|
|
33
34
|
},
|
|
34
35
|
children: [
|
|
35
36
|
n && /* @__PURE__ */ e(fo, {
|
|
36
|
-
id:
|
|
37
|
+
id: r,
|
|
37
38
|
children: n
|
|
38
39
|
}),
|
|
39
|
-
/* @__PURE__ */ e(
|
|
40
|
+
/* @__PURE__ */ e(vo, {
|
|
40
41
|
"aria-label": i || "Close",
|
|
41
42
|
onClick: t,
|
|
42
43
|
sx: {
|
|
@@ -44,104 +45,104 @@ var C = ({ children: g, closeAriaLabel: i, heading: n, onClose: t }) => {
|
|
|
44
45
|
right: 8,
|
|
45
46
|
top: 18
|
|
46
47
|
},
|
|
47
|
-
children: /* @__PURE__ */ e(
|
|
48
|
+
children: /* @__PURE__ */ e(go, {
|
|
48
49
|
name: "close",
|
|
49
50
|
sx: { color: "action.active" }
|
|
50
51
|
})
|
|
51
52
|
}),
|
|
52
|
-
|
|
53
|
+
y
|
|
53
54
|
]
|
|
54
55
|
})
|
|
55
56
|
});
|
|
56
|
-
},
|
|
57
|
-
const { common: n } =
|
|
58
|
-
return
|
|
59
|
-
d && !
|
|
60
|
-
}, [
|
|
57
|
+
}, Fo = k(function({ beat: i }) {
|
|
58
|
+
const { common: n } = w(), { closeActionDrawer: t } = B(), r = Y(), a = ro(i), [l] = c.useState(() => mo(a)), d = l === lo;
|
|
59
|
+
return c.useEffect(() => {
|
|
60
|
+
d && !r.categoriesLoaded && r.loadCategories();
|
|
61
|
+
}, [r, d]), d ? r.categoriesLoaded ? /* @__PURE__ */ e(ao, { beat: i }) : /* @__PURE__ */ e(_, {
|
|
61
62
|
closeAriaLabel: n?.close_aria,
|
|
62
63
|
onClose: t,
|
|
63
|
-
children: /* @__PURE__ */ e(
|
|
64
|
-
}) : /* @__PURE__ */ e(
|
|
64
|
+
children: /* @__PURE__ */ e(E, {})
|
|
65
|
+
}) : /* @__PURE__ */ e(_o, {
|
|
65
66
|
beat: i,
|
|
66
67
|
variant: l
|
|
67
68
|
});
|
|
68
|
-
}),
|
|
69
|
-
const { common: t, insights_feed:
|
|
69
|
+
}), _o = k(function({ beat: i, variant: n }) {
|
|
70
|
+
const { common: t, insights_feed: r } = w(), { closeActionDrawer: a } = B(), l = Z(), { userInsightProfile: d } = oo(), M = io(i, to()), C = no(), u = r?.amount_input_modal, o = L(n) ? co[n] : void 0, m = !!o?.needsNotificationProfiles, g = {
|
|
70
71
|
insightProfile: d,
|
|
71
72
|
lowBalanceProfile: m ? uo(l.notificationProfiles, i.primary_account_guid) : void 0
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
p.current = !1;
|
|
75
|
-
}), []), r.useEffect(() => {
|
|
73
|
+
}, S = o?.read(g), [R, $] = c.useState(m), { isMounted: G, isSaving: F, save: H } = so();
|
|
74
|
+
c.useEffect(() => {
|
|
76
75
|
m && l.loadNotificationProfiles().finally(() => {
|
|
77
|
-
|
|
76
|
+
G.current && $(!1);
|
|
78
77
|
});
|
|
79
78
|
}, [m, l]);
|
|
80
|
-
const [O, U] =
|
|
81
|
-
if (
|
|
79
|
+
const [O, U] = c.useState(null), [j, h] = c.useState(!1), p = O ?? po(S);
|
|
80
|
+
if (R) return /* @__PURE__ */ e(_, {
|
|
82
81
|
closeAriaLabel: t?.close_aria,
|
|
83
|
-
onClose:
|
|
84
|
-
children: /* @__PURE__ */ e(
|
|
82
|
+
onClose: a,
|
|
83
|
+
children: /* @__PURE__ */ e(E, {})
|
|
85
84
|
});
|
|
86
|
-
const
|
|
87
|
-
if (!u || !o || !
|
|
88
|
-
return console.warn(`amount_input_modal_block: ${u ? o ?
|
|
85
|
+
const s = L(n) ? u?.[n] : void 0, A = o ? u?.[o.errorKey] : void 0, b = !!s?.title && !!s.description && !!s.input_label && !!A && !!u?.save_error && !!t?.save_button && (!o?.hasCancel || !!t.cancel_button) && !!t.close_aria, z = !!o?.hasSource(g);
|
|
86
|
+
if (!u || !o || !s || !b || !z)
|
|
87
|
+
return console.warn(`amount_input_modal_block: ${u ? o ? b ? m ? "no low-balance profile for the account" : "user insight profile not set by the host" : `copy incomplete for "${n}"` : `unknown variant "${n}"` : "copy namespace missing"}`), /* @__PURE__ */ e(_, {
|
|
89
88
|
closeAriaLabel: t?.close_aria,
|
|
90
89
|
heading: t?.error_heading,
|
|
91
|
-
onClose:
|
|
92
|
-
children: /* @__PURE__ */ e(
|
|
90
|
+
onClose: a,
|
|
91
|
+
children: /* @__PURE__ */ e(T, { children: t?.error_message })
|
|
93
92
|
});
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
}, { inputSelected:
|
|
97
|
-
if (!
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
const I = () => {
|
|
94
|
+
C(o.analytics.cancel), a();
|
|
95
|
+
}, { inputSelected: x } = o.analytics, D = o.hasEditCopy && !!S, P = i.primary_account ? X(i.primary_account) : "", v = o.isValid(p), K = p !== "" && !v, W = async () => {
|
|
96
|
+
if (!v) return;
|
|
97
|
+
const f = await H(() => {
|
|
98
|
+
h(!1);
|
|
99
|
+
const [q, J] = o.save(Number(p), g);
|
|
100
|
+
return M(q, J, { analytics: o.analytics.save });
|
|
101
|
+
});
|
|
102
|
+
f !== void 0 && (f ? a() : h(!0));
|
|
102
103
|
};
|
|
103
|
-
return /* @__PURE__ */ e(
|
|
104
|
+
return /* @__PURE__ */ e(eo, {
|
|
104
105
|
closeAriaLabel: t.close_aria,
|
|
105
|
-
content:
|
|
106
|
-
errorText: K ?
|
|
107
|
-
handleInputChange: (
|
|
108
|
-
U(
|
|
106
|
+
content: Q(D && s.description_edit || s.description, /* @__PURE__ */ e("strong", { children: P }, "account")),
|
|
107
|
+
errorText: K ? A : j ? u.save_error : void 0,
|
|
108
|
+
handleInputChange: (f) => {
|
|
109
|
+
U(f), h(!1);
|
|
109
110
|
},
|
|
110
|
-
handleInputClick:
|
|
111
|
-
handleModalClose:
|
|
111
|
+
handleInputClick: x ? () => C(x) : void 0,
|
|
112
|
+
handleModalClose: I,
|
|
112
113
|
handlePrimaryAction: () => {
|
|
113
114
|
W();
|
|
114
115
|
},
|
|
115
|
-
handleSecondaryAction:
|
|
116
|
-
inputLabel:
|
|
117
|
-
inputValue:
|
|
116
|
+
handleSecondaryAction: I,
|
|
117
|
+
inputLabel: s.input_label,
|
|
118
|
+
inputValue: p,
|
|
118
119
|
isOpen: !0,
|
|
119
|
-
isPrimaryDisabled:
|
|
120
|
+
isPrimaryDisabled: F || !v,
|
|
120
121
|
primaryText: t.save_button,
|
|
121
122
|
secondaryText: o.hasCancel ? t.cancel_button : void 0,
|
|
122
|
-
subtitle: o.showsAccount && i.primary_account ? /* @__PURE__ */
|
|
123
|
+
subtitle: o.showsAccount && i.primary_account ? /* @__PURE__ */ V(N, {
|
|
123
124
|
sx: {
|
|
124
125
|
alignItems: "center",
|
|
125
126
|
flexDirection: "row",
|
|
126
127
|
gap: 8
|
|
127
128
|
},
|
|
128
|
-
children: [/* @__PURE__ */ e(
|
|
129
|
+
children: [/* @__PURE__ */ e(yo, {
|
|
129
130
|
alt: "",
|
|
130
131
|
institutionGuid: i.primary_account.institution_guid ?? "",
|
|
131
132
|
size: 16
|
|
132
|
-
}), /* @__PURE__ */ e(
|
|
133
|
+
}), /* @__PURE__ */ e(T, {
|
|
133
134
|
color: "text.secondary",
|
|
134
135
|
uppercase: !0,
|
|
135
136
|
variant: "body2",
|
|
136
|
-
children:
|
|
137
|
+
children: P
|
|
137
138
|
})]
|
|
138
139
|
}) : void 0,
|
|
139
|
-
title:
|
|
140
|
+
title: D && s.title_edit || s.title,
|
|
140
141
|
unit: o.unit
|
|
141
142
|
});
|
|
142
143
|
});
|
|
143
144
|
export {
|
|
144
|
-
|
|
145
|
+
Fo as AmountInputModalBlock
|
|
145
146
|
};
|
|
146
147
|
|
|
147
148
|
//# sourceMappingURL=AmountInputModalBlock.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AmountInputModalBlock.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/AmountInputModalBlock/AmountInputModalBlock.tsx"],"sourcesContent":["import React from 'react'\n\nimport Stack from '@mui/material/Stack'\n\nimport MuiDialog from '@mui/material/Dialog'\nimport IconButton from '@mui/material/IconButton'\n\nimport { Icon } from '@mxenabled/mx-icons'\nimport { H3, InstitutionLogo, Text } from '@mxenabled/mxui'\nimport { observer } from 'mobx-react-lite'\n\nimport {\n CurrencyDialog,\n Loader,\n buildDynamicCopy,\n useCategoryStore,\n useGlobalCopyStore,\n useInsightsV2Store,\n useSettingsStore,\n useUserStore,\n} from '../../../common'\nimport getAccountDisplayName from '../../../common/utils/AccountDisplayName'\nimport { useAnalyticsEvent } from '../../analytics'\nimport { useBeatActions } from '../../beatActions'\nimport { useCtaHandler } from '../../ctaActions'\nimport type { ActionBlockProps } from '../../mappings/blocks'\nimport { useOpenedCta } from '../useOpenedCta'\n\nimport { CreateBudgetDialog } from './CreateBudgetDialog'\nimport {\n AMOUNT_SETTINGS,\n CREATE_BUDGET_VARIANT,\n findLowBalanceProfile,\n isAmountInputVariant,\n resolveAmountInputVariant,\n toInputValue,\n} from './layout'\n\n/** Dialog frame for the formless states: loading and a non-retriable problem. */\nconst StatusDialog = ({\n children,\n closeAriaLabel,\n heading,\n onClose,\n}: React.PropsWithChildren<{ closeAriaLabel?: string; heading?: string; onClose: () => void }>) => {\n const headingId = React.useId()\n\n return (\n <MuiDialog\n aria-labelledby={heading ? headingId : undefined}\n maxWidth=\"xs\"\n onClose={onClose}\n open={true}\n // Same 4px theme radius as CurrencyDialog, so the loading/error states match the form.\n sx={{ '& .MuiDialog-paper': { borderRadius: (theme) => `${theme.shape.borderRadius}px` } }}\n >\n <Stack sx={{ gap: 12, p: 24, position: 'relative' }}>\n {heading && <H3 id={headingId}>{heading}</H3>}\n <IconButton\n aria-label={closeAriaLabel || 'Close'}\n onClick={onClose}\n sx={{ position: 'absolute', right: 8, top: 18 }}\n >\n <Icon name=\"close\" sx={{ color: 'action.active' }} />\n </IconButton>\n {children}\n </Stack>\n </MuiDialog>\n )\n}\n\n/** `amount_input_modal_block`: one amount or percentage setting in a modal, picked by the CTA variant. */\nexport const AmountInputModalBlock = observer(function AmountInputModalBlock({\n beat,\n}: ActionBlockProps) {\n const { common: commonCopy } = useGlobalCopyStore()\n const { closeActionDrawer } = useInsightsV2Store()\n const categoryStore = useCategoryStore()\n const openedCta = useOpenedCta(beat)\n // Read once on open: a refreshed beat must not swap the dialog under its snackbar.\n const [variant] = React.useState(() => resolveAmountInputVariant(openedCta))\n const isCreateBudget = variant === CREATE_BUDGET_VARIANT\n\n // The create dialog names the category, so it waits for the category store.\n React.useEffect(() => {\n if (isCreateBudget && !categoryStore.categoriesLoaded) void categoryStore.loadCategories()\n }, [categoryStore, isCreateBudget])\n\n if (!isCreateBudget) return <AmountSettingDialog beat={beat} variant={variant} />\n\n return categoryStore.categoriesLoaded ? (\n <CreateBudgetDialog beat={beat} />\n ) : (\n <StatusDialog closeAriaLabel={commonCopy?.close_aria} onClose={closeActionDrawer}>\n <Loader />\n </StatusDialog>\n )\n})\n\n/** One amount or percentage setting, per its `AMOUNT_SETTINGS` entry (`AMOUNT_INPUT_VARIANTS`). */\nconst AmountSettingDialog = observer(function AmountSettingDialog({\n beat,\n variant,\n}: ActionBlockProps & { variant?: string }) {\n const { common: commonCopy, insights_feed: insightsFeedCopy } = useGlobalCopyStore()\n const { closeActionDrawer } = useInsightsV2Store()\n const settingsStore = useSettingsStore()\n const { userInsightProfile } = useUserStore()\n const runHandler = useCtaHandler(beat, useBeatActions())\n const fireAnalyticsEvent = useAnalyticsEvent()\n\n const copy = insightsFeedCopy?.amount_input_modal\n const setting = isAmountInputVariant(variant) ? AMOUNT_SETTINGS[variant] : undefined\n const needsNotificationProfiles = !!setting?.needsNotificationProfiles\n\n const sources = {\n insightProfile: userInsightProfile,\n lowBalanceProfile: needsNotificationProfiles\n ? findLowBalanceProfile(settingsStore.notificationProfiles, beat.primary_account_guid)\n : undefined,\n }\n const savedAmount = setting?.read(sources)\n\n // Mounting is the open, so profiles reload here and the threshold prefills as saved now.\n const [isLoadingProfiles, setIsLoadingProfiles] = React.useState(needsNotificationProfiles)\n // False once unmounted: a save that resolves after the user closed the dialog must not close\n // (or update) whatever action session is open by then.\n const isMounted = React.useRef(true)\n\n React.useEffect(() => {\n isMounted.current = true\n\n return () => {\n isMounted.current = false\n }\n }, [])\n\n React.useEffect(() => {\n if (!needsNotificationProfiles) return\n\n void settingsStore.loadNotificationProfiles().finally(() => {\n if (isMounted.current) setIsLoadingProfiles(false)\n })\n }, [needsNotificationProfiles, settingsStore])\n\n // `null` until the user types: the field shows the saved amount until then.\n const [typed, setTyped] = React.useState<string | null>(null)\n const [isSaving, setIsSaving] = React.useState(false)\n const [saveFailed, setSaveFailed] = React.useState(false)\n\n const value = typed ?? toInputValue(savedAmount)\n\n if (isLoadingProfiles) {\n return (\n <StatusDialog closeAriaLabel={commonCopy?.close_aria} onClose={closeActionDrawer}>\n <Loader />\n </StatusDialog>\n )\n }\n\n // Copy ships separately (see the doc's Rollout order), so check every string the form renders:\n // a partial ship falls to the error dialog instead of throwing mid-render.\n const variantCopy = isAmountInputVariant(variant) ? copy?.[variant] : undefined\n const errorCopy = setting ? copy?.[setting.errorKey] : undefined\n const hasCopy =\n !!variantCopy?.title &&\n !!variantCopy.description &&\n !!variantCopy.input_label &&\n !!errorCopy &&\n !!copy?.save_error &&\n !!commonCopy?.save_button &&\n (!setting?.hasCancel || !!commonCopy.cancel_button) &&\n !!commonCopy.close_aria\n const hasProfile = !!setting?.hasSource(sources)\n\n if (!copy || !setting || !variantCopy || !hasCopy || !hasProfile) {\n // One message to the user; distinct warnings so a rollout problem can be traced to its cause.\n console.warn(\n `amount_input_modal_block: ${\n !copy\n ? 'copy namespace missing'\n : !setting\n ? `unknown variant \"${variant}\"`\n : !hasCopy\n ? `copy incomplete for \"${variant}\"`\n : needsNotificationProfiles\n ? 'no low-balance profile for the account'\n : 'user insight profile not set by the host'\n }`,\n )\n\n return (\n <StatusDialog\n closeAriaLabel={commonCopy?.close_aria}\n heading={commonCopy?.error_heading}\n onClose={closeActionDrawer}\n >\n <Text>{commonCopy?.error_message}</Text>\n </StatusDialog>\n )\n }\n\n // Trigger 4 — user dismissed without saving (close icon, Cancel button, backdrop). Pulse\n // parity: EditThreshold.js close button / EditSafetyNet.js cancel button.\n const handleDismiss = () => {\n fireAnalyticsEvent(setting.analytics.cancel)\n closeActionDrawer()\n }\n\n const { inputSelected } = setting.analytics\n const isEdit = setting.hasEditCopy && !!savedAmount\n const accountName = beat.primary_account ? getAccountDisplayName(beat.primary_account) : ''\n const isValid = setting.isValid(value)\n const isInvalid = value !== '' && !isValid\n\n const handleSave = async () => {\n // Guarded here too, not only by the disabled button: Enter submits the dialog's form directly.\n if (!isValid || isSaving) return\n\n const amount = Number(value)\n\n setIsSaving(true)\n setSaveFailed(false)\n\n // Trigger 2: save analytics ride the handler run, fired only on success.\n const [handler, params] = setting.save(amount, sources)\n const ok = await runHandler(handler, params, { analytics: setting.analytics.save })\n\n if (!isMounted.current) return\n\n setIsSaving(false)\n\n if (ok) closeActionDrawer()\n else setSaveFailed(true)\n }\n\n return (\n <CurrencyDialog\n closeAriaLabel={commonCopy.close_aria}\n // Only strings and the <strong> go in, so the result is renderable (the helper's type also\n // admits raw DOM nodes).\n content={\n buildDynamicCopy(\n (isEdit && variantCopy.description_edit) || variantCopy.description,\n <strong key=\"account\">{accountName}</strong>,\n ) as React.ReactNode\n }\n errorText={isInvalid ? errorCopy : saveFailed ? copy.save_error : undefined}\n handleInputChange={(next) => {\n setTyped(next)\n setSaveFailed(false)\n }}\n handleInputClick={inputSelected ? () => fireAnalyticsEvent(inputSelected) : undefined}\n handleModalClose={handleDismiss}\n handlePrimaryAction={() => void handleSave()}\n handleSecondaryAction={handleDismiss}\n inputLabel={variantCopy.input_label}\n inputValue={value}\n isOpen={true}\n isPrimaryDisabled={isSaving || !isValid}\n primaryText={commonCopy.save_button}\n secondaryText={setting.hasCancel ? commonCopy.cancel_button : undefined}\n subtitle={\n setting.showsAccount && beat.primary_account ? (\n <Stack sx={{ alignItems: 'center', flexDirection: 'row', gap: 8 }}>\n {/* Decorative: the account name is the visible text beside it. */}\n <InstitutionLogo\n alt=\"\"\n institutionGuid={beat.primary_account.institution_guid ?? ''}\n size={16}\n />\n <Text color=\"text.secondary\" uppercase={true} variant=\"body2\">\n {accountName}\n </Text>\n </Stack>\n ) : undefined\n }\n title={(isEdit && variantCopy.title_edit) || variantCopy.title}\n unit={setting.unit}\n />\n )\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuCA,IAAM,IAAA,CAAgB,EACpB,UAAA,GACA,gBAAA,GACA,SAAA,GACA,SAAA,EAAA,MACiG;AACjG,QAAM,IAAY,EAAM,MAAM;AAE9B,SACE,gBAAA,EAAC,IAAD;AAAA,IACE,mBAAiB,IAAU,IAAY;AAAA,IACvC,UAAS;AAAA,IACA,SAAA;AAAA,IACT,MAAM;AAAA,IAEN,IAAI,EAAE,sBAAsB,EAAE,cAAA,CAAe,MAAU,GAAG,EAAM,MAAM,YAAA,KAAiB,EAAE;AAAA,IAEzF,UAAA,gBAAA,EAAC,GAAD;AAAA,MAAO,IAAI;AAAA,QAAE,KAAK;AAAA,QAAI,GAAG;AAAA,QAAI,UAAU;AAAA,MAAW;AAAA,MAAlD,UAAA;AA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mountInputModalBlock/AmountInputModalBlock.tsx"],"sourcesContent":["import React from 'react'\n\nimport Stack from '@mui/material/Stack'\n\nimport MuiDialog from '@mui/material/Dialog'\nimport IconButton from '@mui/material/IconButton'\n\nimport { Icon } from '@mxenabled/mx-icons'\nimport { H3, InstitutionLogo, Text } from '@mxenabled/mxui'\nimport { observer } from 'mobx-react-lite'\n\nimport {\n CurrencyDialog,\n Loader,\n buildDynamicCopy,\n useCategoryStore,\n useGlobalCopyStore,\n useInsightsV2Store,\n useSettingsStore,\n useUserStore,\n} from '../../../common'\nimport getAccountDisplayName from '../../../common/utils/AccountDisplayName'\nimport { useAnalyticsEvent } from '../../analytics'\nimport { useBeatActions } from '../../beatActions'\nimport { useCtaHandler } from '../../ctaActions'\nimport type { ActionBlockProps } from '../../mappings/blocks'\nimport { useBlockSave } from '../useBlockSave'\nimport { useOpenedCta } from '../useOpenedCta'\n\nimport { CreateBudgetDialog } from './CreateBudgetDialog'\nimport {\n AMOUNT_SETTINGS,\n CREATE_BUDGET_VARIANT,\n findLowBalanceProfile,\n isAmountInputVariant,\n resolveAmountInputVariant,\n toInputValue,\n} from './layout'\n\n/** Dialog frame for the formless states: loading and a non-retriable problem. */\nconst StatusDialog = ({\n children,\n closeAriaLabel,\n heading,\n onClose,\n}: React.PropsWithChildren<{ closeAriaLabel?: string; heading?: string; onClose: () => void }>) => {\n const headingId = React.useId()\n\n return (\n <MuiDialog\n aria-labelledby={heading ? headingId : undefined}\n maxWidth=\"xs\"\n onClose={onClose}\n open={true}\n // Same 4px theme radius as CurrencyDialog, so the loading/error states match the form.\n sx={{ '& .MuiDialog-paper': { borderRadius: (theme) => `${theme.shape.borderRadius}px` } }}\n >\n <Stack sx={{ gap: 12, p: 24, position: 'relative' }}>\n {heading && <H3 id={headingId}>{heading}</H3>}\n <IconButton\n aria-label={closeAriaLabel || 'Close'}\n onClick={onClose}\n sx={{ position: 'absolute', right: 8, top: 18 }}\n >\n <Icon name=\"close\" sx={{ color: 'action.active' }} />\n </IconButton>\n {children}\n </Stack>\n </MuiDialog>\n )\n}\n\n/** `amount_input_modal_block`: one amount or percentage setting in a modal, picked by the CTA variant. */\nexport const AmountInputModalBlock = observer(function AmountInputModalBlock({\n beat,\n}: ActionBlockProps) {\n const { common: commonCopy } = useGlobalCopyStore()\n const { closeActionDrawer } = useInsightsV2Store()\n const categoryStore = useCategoryStore()\n const openedCta = useOpenedCta(beat)\n // Read once on open: a refreshed beat must not swap the dialog under its snackbar.\n const [variant] = React.useState(() => resolveAmountInputVariant(openedCta))\n const isCreateBudget = variant === CREATE_BUDGET_VARIANT\n\n // The create dialog names the category, so it waits for the category store.\n React.useEffect(() => {\n if (isCreateBudget && !categoryStore.categoriesLoaded) void categoryStore.loadCategories()\n }, [categoryStore, isCreateBudget])\n\n if (!isCreateBudget) return <AmountSettingDialog beat={beat} variant={variant} />\n\n return categoryStore.categoriesLoaded ? (\n <CreateBudgetDialog beat={beat} />\n ) : (\n <StatusDialog closeAriaLabel={commonCopy?.close_aria} onClose={closeActionDrawer}>\n <Loader />\n </StatusDialog>\n )\n})\n\n/** One amount or percentage setting, per its `AMOUNT_SETTINGS` entry (`AMOUNT_INPUT_VARIANTS`). */\nconst AmountSettingDialog = observer(function AmountSettingDialog({\n beat,\n variant,\n}: ActionBlockProps & { variant?: string }) {\n const { common: commonCopy, insights_feed: insightsFeedCopy } = useGlobalCopyStore()\n const { closeActionDrawer } = useInsightsV2Store()\n const settingsStore = useSettingsStore()\n const { userInsightProfile } = useUserStore()\n const runHandler = useCtaHandler(beat, useBeatActions())\n const fireAnalyticsEvent = useAnalyticsEvent()\n\n const copy = insightsFeedCopy?.amount_input_modal\n const setting = isAmountInputVariant(variant) ? AMOUNT_SETTINGS[variant] : undefined\n const needsNotificationProfiles = !!setting?.needsNotificationProfiles\n\n const sources = {\n insightProfile: userInsightProfile,\n lowBalanceProfile: needsNotificationProfiles\n ? findLowBalanceProfile(settingsStore.notificationProfiles, beat.primary_account_guid)\n : undefined,\n }\n const savedAmount = setting?.read(sources)\n\n // Mounting is the open, so profiles reload here and the threshold prefills as saved now.\n const [isLoadingProfiles, setIsLoadingProfiles] = React.useState(needsNotificationProfiles)\n const { isMounted, isSaving, save } = useBlockSave()\n\n React.useEffect(() => {\n if (!needsNotificationProfiles) return\n\n void settingsStore.loadNotificationProfiles().finally(() => {\n if (isMounted.current) setIsLoadingProfiles(false)\n })\n }, [needsNotificationProfiles, settingsStore])\n\n // `null` until the user types: the field shows the saved amount until then.\n const [typed, setTyped] = React.useState<string | null>(null)\n const [saveFailed, setSaveFailed] = React.useState(false)\n\n const value = typed ?? toInputValue(savedAmount)\n\n if (isLoadingProfiles) {\n return (\n <StatusDialog closeAriaLabel={commonCopy?.close_aria} onClose={closeActionDrawer}>\n <Loader />\n </StatusDialog>\n )\n }\n\n // Copy ships separately (see the doc's Rollout order), so check every string the form renders:\n // a partial ship falls to the error dialog instead of throwing mid-render.\n const variantCopy = isAmountInputVariant(variant) ? copy?.[variant] : undefined\n const errorCopy = setting ? copy?.[setting.errorKey] : undefined\n const hasCopy =\n !!variantCopy?.title &&\n !!variantCopy.description &&\n !!variantCopy.input_label &&\n !!errorCopy &&\n !!copy?.save_error &&\n !!commonCopy?.save_button &&\n (!setting?.hasCancel || !!commonCopy.cancel_button) &&\n !!commonCopy.close_aria\n const hasProfile = !!setting?.hasSource(sources)\n\n if (!copy || !setting || !variantCopy || !hasCopy || !hasProfile) {\n // One message to the user; distinct warnings so a rollout problem can be traced to its cause.\n console.warn(\n `amount_input_modal_block: ${\n !copy\n ? 'copy namespace missing'\n : !setting\n ? `unknown variant \"${variant}\"`\n : !hasCopy\n ? `copy incomplete for \"${variant}\"`\n : needsNotificationProfiles\n ? 'no low-balance profile for the account'\n : 'user insight profile not set by the host'\n }`,\n )\n\n return (\n <StatusDialog\n closeAriaLabel={commonCopy?.close_aria}\n heading={commonCopy?.error_heading}\n onClose={closeActionDrawer}\n >\n <Text>{commonCopy?.error_message}</Text>\n </StatusDialog>\n )\n }\n\n // Trigger 4 — user dismissed without saving (close icon, Cancel button, backdrop). Pulse\n // parity: EditThreshold.js close button / EditSafetyNet.js cancel button.\n const handleDismiss = () => {\n fireAnalyticsEvent(setting.analytics.cancel)\n closeActionDrawer()\n }\n\n const { inputSelected } = setting.analytics\n const isEdit = setting.hasEditCopy && !!savedAmount\n const accountName = beat.primary_account ? getAccountDisplayName(beat.primary_account) : ''\n const isValid = setting.isValid(value)\n const isInvalid = value !== '' && !isValid\n\n const handleSave = async () => {\n // Enter submits the form directly, bypassing the disabled button.\n if (!isValid) return\n\n // Trigger 2: save analytics ride the handler run, fired only on success.\n const ok = await save(() => {\n setSaveFailed(false)\n const [handler, params] = setting.save(Number(value), sources)\n return runHandler(handler, params, { analytics: setting.analytics.save })\n })\n if (ok === undefined) return\n\n if (ok) closeActionDrawer()\n else setSaveFailed(true)\n }\n\n return (\n <CurrencyDialog\n closeAriaLabel={commonCopy.close_aria}\n // Only strings and the <strong> go in, so the result is renderable (the helper's type also\n // admits raw DOM nodes).\n content={\n buildDynamicCopy(\n (isEdit && variantCopy.description_edit) || variantCopy.description,\n <strong key=\"account\">{accountName}</strong>,\n ) as React.ReactNode\n }\n errorText={isInvalid ? errorCopy : saveFailed ? copy.save_error : undefined}\n handleInputChange={(next) => {\n setTyped(next)\n setSaveFailed(false)\n }}\n handleInputClick={inputSelected ? () => fireAnalyticsEvent(inputSelected) : undefined}\n handleModalClose={handleDismiss}\n handlePrimaryAction={() => void handleSave()}\n handleSecondaryAction={handleDismiss}\n inputLabel={variantCopy.input_label}\n inputValue={value}\n isOpen={true}\n isPrimaryDisabled={isSaving || !isValid}\n primaryText={commonCopy.save_button}\n secondaryText={setting.hasCancel ? commonCopy.cancel_button : undefined}\n subtitle={\n setting.showsAccount && beat.primary_account ? (\n <Stack sx={{ alignItems: 'center', flexDirection: 'row', gap: 8 }}>\n {/* Decorative: the account name is the visible text beside it. */}\n <InstitutionLogo\n alt=\"\"\n institutionGuid={beat.primary_account.institution_guid ?? ''}\n size={16}\n />\n <Text color=\"text.secondary\" uppercase={true} variant=\"body2\">\n {accountName}\n </Text>\n </Stack>\n ) : undefined\n }\n title={(isEdit && variantCopy.title_edit) || variantCopy.title}\n unit={setting.unit}\n />\n )\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwCA,IAAM,IAAA,CAAgB,EACpB,UAAA,GACA,gBAAA,GACA,SAAA,GACA,SAAA,EAAA,MACiG;AACjG,QAAM,IAAY,EAAM,MAAM;AAE9B,SACE,gBAAA,EAAC,IAAD;AAAA,IACE,mBAAiB,IAAU,IAAY;AAAA,IACvC,UAAS;AAAA,IACA,SAAA;AAAA,IACT,MAAM;AAAA,IAEN,IAAI,EAAE,sBAAsB,EAAE,cAAA,CAAe,MAAU,GAAG,EAAM,MAAM,YAAA,KAAiB,EAAE;AAAA,IAEzF,UAAA,gBAAA,EAAC,GAAD;AAAA,MAAO,IAAI;AAAA,QAAE,KAAK;AAAA,QAAI,GAAG;AAAA,QAAI,UAAU;AAAA,MAAW;AAAA,MAAlD,UAAA;AAAA,QACG,KAAW,gBAAA,EAAC,IAAD;AAAA,UAAI,IAAI;AAAA,UAAY,UAAA;AAAA,QAAY,CAAA;AAAA,QAC5C,gBAAA,EAAC,IAAD;AAAA,UACE,cAAY,KAAkB;AAAA,UAC9B,SAAS;AAAA,UACT,IAAI;AAAA,YAAE,UAAU;AAAA,YAAY,OAAO;AAAA,YAAG,KAAK;AAAA,UAAG;AAAA,UAE9C,UAAA,gBAAA,EAAC,IAAD;AAAA,YAAM,MAAK;AAAA,YAAQ,IAAI,EAAE,OAAO,gBAAgB;AAAA,UAAI,CAAA;AAAA,QAC1C,CAAA;AAAA,QACX;AAAA,MACI;AAAA;EACE,CAAA;AAEf,GAGa,KAAwB,EAAS,SAA+B,EAC3E,MAAA,EAAA,GACmB;AACnB,QAAM,EAAE,QAAQ,EAAA,IAAe,EAAmB,GAC5C,EAAE,mBAAA,EAAA,IAAsB,EAAmB,GAC3C,IAAgB,EAA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,YAAY;AAAA,QAAU,eAAe;AAAA,QAAO,KAAK;AAAA,MAAE;AAAA,MAAhE,UAAA,CAEE,gBAAA,EAAC,IAAD;AAAA,QACE,KAAI;AAAA,QACJ,iBAAiB,EAAK,gBAAgB,oBAAoB;AAAA,QAC1D,MAAM;AAAA,MACP,CAAA,GACD,gBAAA,EAAC,GAAD;AAAA,QAAM,OAAM;AAAA,QAAiB,WAAW;AAAA,QAAM,SAAQ;AAAA,QACnD,UAAA;AAAA,MACG,CAAA,CACD;AAAA,IACL,CAAA,IAAA;AAAA,IAEN,OAAQ,KAAU,EAAY,cAAe,EAAY;AAAA,IACzD,MAAM,EAAQ;AAAA,EACf,CAAA;AAEL,CAAC"}
|
|
@@ -1,62 +1,58 @@
|
|
|
1
|
-
import { buildDynamicCopy as
|
|
2
|
-
import { useCategoryStore as F, useGlobalCopyStore as
|
|
1
|
+
import { buildDynamicCopy as y } from "../../../core/utils/Localization.es.js";
|
|
2
|
+
import { useCategoryStore as F, useGlobalCopyStore as L, useInsightsV2Store as R } from "../../../common/context/hooks.es.js";
|
|
3
3
|
import { slot as T } from "../../../core/types/Insights.es.js";
|
|
4
|
-
import { CURRENCY_FORMAT as
|
|
5
|
-
import { getLocalizedCategoryName as
|
|
6
|
-
import
|
|
7
|
-
import { useBeatActions as
|
|
8
|
-
import { isPositiveAmount as
|
|
9
|
-
import { useCtaHandler as
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const y = (o) => C(o, g), _ = j(c) && !N, R = async () => {
|
|
20
|
-
if (!_) return;
|
|
21
|
-
f(!0);
|
|
22
|
-
const o = await v("createBudget", {
|
|
4
|
+
import { CURRENCY_FORMAT as w, formatCurrency as I } from "../../../core/utils/NumberFormatting.es.js";
|
|
5
|
+
import { getLocalizedCategoryName as O } from "../../../core/utils/CategoryUtil.es.js";
|
|
6
|
+
import P from "../../../common/components/CurrencyDialog.es.js";
|
|
7
|
+
import { useBeatActions as j } from "../../beatActions.es.js";
|
|
8
|
+
import { isPositiveAmount as f, resolveBudgetFacts as G } from "../BudgetDetailsBlock/layout.es.js";
|
|
9
|
+
import { useCtaHandler as H } from "../../ctaActions/useCtaAction.es.js";
|
|
10
|
+
import M from "../../components/shared/StatusSnackbar.es.js";
|
|
11
|
+
import { useBlockSave as V } from "../useBlockSave.es.js";
|
|
12
|
+
import n from "react";
|
|
13
|
+
import { observer as z } from "mobx-react-lite";
|
|
14
|
+
import { jsx as l, jsxs as E } from "react/jsx-runtime";
|
|
15
|
+
var ne = z(function({ beat: s }) {
|
|
16
|
+
const { budgets: t, categories: _, common: o, insights_feed: C } = L(), b = F(), { closeActionDrawer: i } = R(), h = H(s, j()), v = s.insights_payload, { categoryGuid: m = "" } = G(s), S = T(v?.instance_slot?.data, "average_amount") ?? 0, u = b.categories.find(({ guid: e }) => e === m), d = u ? O(u, _) : "", [r, A] = n.useState(""), [x, g] = n.useState(!0), [a, c] = n.useState(null), { isSaving: B, save: D } = V(), p = (e) => y(e, d), N = f(r) && !B, k = async () => {
|
|
17
|
+
if (!f(r)) return;
|
|
18
|
+
const e = await D(() => h("createBudget", {
|
|
23
19
|
categoryGuid: m,
|
|
24
|
-
amount: Number(
|
|
25
|
-
}, { onSuccess: ["refreshBeat"] });
|
|
26
|
-
|
|
20
|
+
amount: Number(r)
|
|
21
|
+
}, { onSuccess: ["refreshBeat"] }));
|
|
22
|
+
e !== void 0 && (g(!1), c(e ? "created" : "failed"));
|
|
27
23
|
};
|
|
28
|
-
return /* @__PURE__ */
|
|
29
|
-
closeAriaLabel:
|
|
30
|
-
content:
|
|
31
|
-
handleInputChange:
|
|
32
|
-
handleModalClose:
|
|
24
|
+
return /* @__PURE__ */ E(n.Fragment, { children: [/* @__PURE__ */ l(P, {
|
|
25
|
+
closeAriaLabel: o.close_aria,
|
|
26
|
+
content: y(t.create_budget_content, /* @__PURE__ */ l("strong", { children: d }, "category"), I(S, w.whole)),
|
|
27
|
+
handleInputChange: A,
|
|
28
|
+
handleModalClose: i,
|
|
33
29
|
handlePrimaryAction: () => {
|
|
34
|
-
|
|
30
|
+
k();
|
|
35
31
|
},
|
|
36
|
-
handleSecondaryAction:
|
|
37
|
-
inputLabel:
|
|
38
|
-
inputValue:
|
|
39
|
-
isOpen:
|
|
40
|
-
isPrimaryDisabled: !
|
|
32
|
+
handleSecondaryAction: i,
|
|
33
|
+
inputLabel: o.amount_text,
|
|
34
|
+
inputValue: r,
|
|
35
|
+
isOpen: x,
|
|
36
|
+
isPrimaryDisabled: !N,
|
|
41
37
|
primaryText: t.dialog_primary_button_text,
|
|
42
|
-
secondaryText:
|
|
38
|
+
secondaryText: o.cancel_button,
|
|
43
39
|
title: t.dialog_create_budget_title
|
|
44
|
-
}), /* @__PURE__ */ l(
|
|
45
|
-
actionText: a === "failed" ?
|
|
46
|
-
closeAriaLabel:
|
|
47
|
-
message:
|
|
40
|
+
}), /* @__PURE__ */ l(M, {
|
|
41
|
+
actionText: a === "failed" ? C?.general?.try_again : void 0,
|
|
42
|
+
closeAriaLabel: o.close_aria,
|
|
43
|
+
message: p(a === "created" ? t.alert_budget_created : t.alert_merchant_budget_not_created),
|
|
48
44
|
onActionClick: () => {
|
|
49
|
-
|
|
45
|
+
c(null), g(!0);
|
|
50
46
|
},
|
|
51
47
|
onClose: () => {
|
|
52
|
-
|
|
48
|
+
c(null), i();
|
|
53
49
|
},
|
|
54
50
|
open: !!a,
|
|
55
51
|
severity: a === "created" ? "success" : "error"
|
|
56
52
|
})] });
|
|
57
53
|
});
|
|
58
54
|
export {
|
|
59
|
-
|
|
55
|
+
ne as CreateBudgetDialog
|
|
60
56
|
};
|
|
61
57
|
|
|
62
58
|
//# sourceMappingURL=CreateBudgetDialog.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreateBudgetDialog.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/AmountInputModalBlock/CreateBudgetDialog.tsx"],"sourcesContent":["import React from 'react'\n\nimport { observer } from 'mobx-react-lite'\n\nimport {\n CurrencyDialog,\n buildDynamicCopy,\n useCategoryStore,\n useGlobalCopyStore,\n useInsightsV2Store,\n} from '../../../common'\nimport { slot } from '../../../core/types/Insights'\nimport { getLocalizedCategoryName } from '../../../core/utils/CategoryUtil'\nimport { CURRENCY_FORMAT, formatCurrency } from '../../../core/utils/NumberFormatting'\nimport StatusSnackbar from '../../components/shared/StatusSnackbar'\nimport { useBeatActions } from '../../beatActions'\nimport { useCtaHandler } from '../../ctaActions'\nimport type { ActionBlockProps } from '../../mappings/blocks'\nimport { isPositiveAmount, resolveBudgetFacts } from '../BudgetDetailsBlock/layout'\n\ntype Notice = 'created' | 'failed'\n\n/** The \"Create a Budget\" dialog (mounted once categories load): creates the budget, refreshes the beat, shows the result. */\nexport const CreateBudgetDialog = observer(function CreateBudgetDialog({ beat }: ActionBlockProps) {\n const {\n budgets: budgetsCopy,\n categories: categoriesCopy,\n common: commonCopy,\n insights_feed: insightsFeedCopy,\n } = useGlobalCopyStore()\n const categoryStore = useCategoryStore()\n const { closeActionDrawer } = useInsightsV2Store()\n const runHandler = useCtaHandler(beat, useBeatActions())\n\n const payload = beat.insights_payload\n const { categoryGuid = '' } = resolveBudgetFacts(beat)\n const averageAmount = slot<number>(payload?.instance_slot?.data, 'average_amount') ?? 0\n const category = categoryStore.categories.find(({ guid }) => guid === categoryGuid)\n const categoryName = category ? getLocalizedCategoryName(category, categoriesCopy) : ''\n\n const [amount, setAmount] = React.useState('')\n const [isOpen, setIsOpen] = React.useState(true)\n const [
|
|
1
|
+
{"version":3,"file":"CreateBudgetDialog.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/AmountInputModalBlock/CreateBudgetDialog.tsx"],"sourcesContent":["import React from 'react'\n\nimport { observer } from 'mobx-react-lite'\n\nimport {\n CurrencyDialog,\n buildDynamicCopy,\n useCategoryStore,\n useGlobalCopyStore,\n useInsightsV2Store,\n} from '../../../common'\nimport { slot } from '../../../core/types/Insights'\nimport { getLocalizedCategoryName } from '../../../core/utils/CategoryUtil'\nimport { CURRENCY_FORMAT, formatCurrency } from '../../../core/utils/NumberFormatting'\nimport StatusSnackbar from '../../components/shared/StatusSnackbar'\nimport { useBeatActions } from '../../beatActions'\nimport { useCtaHandler } from '../../ctaActions'\nimport type { ActionBlockProps } from '../../mappings/blocks'\nimport { isPositiveAmount, resolveBudgetFacts } from '../BudgetDetailsBlock/layout'\nimport { useBlockSave } from '../useBlockSave'\n\ntype Notice = 'created' | 'failed'\n\n/** The \"Create a Budget\" dialog (mounted once categories load): creates the budget, refreshes the beat, shows the result. */\nexport const CreateBudgetDialog = observer(function CreateBudgetDialog({ beat }: ActionBlockProps) {\n const {\n budgets: budgetsCopy,\n categories: categoriesCopy,\n common: commonCopy,\n insights_feed: insightsFeedCopy,\n } = useGlobalCopyStore()\n const categoryStore = useCategoryStore()\n const { closeActionDrawer } = useInsightsV2Store()\n const runHandler = useCtaHandler(beat, useBeatActions())\n\n const payload = beat.insights_payload\n const { categoryGuid = '' } = resolveBudgetFacts(beat)\n const averageAmount = slot<number>(payload?.instance_slot?.data, 'average_amount') ?? 0\n const category = categoryStore.categories.find(({ guid }) => guid === categoryGuid)\n const categoryName = category ? getLocalizedCategoryName(category, categoriesCopy) : ''\n\n const [amount, setAmount] = React.useState('')\n const [isOpen, setIsOpen] = React.useState(true)\n const [notice, setNotice] = React.useState<Notice | null>(null)\n const { isSaving, save } = useBlockSave()\n\n const named = (copy: string) => buildDynamicCopy(copy, categoryName) as string\n\n const canCreate = isPositiveAmount(amount) && !isSaving\n\n const handleCreate = async () => {\n if (!isPositiveAmount(amount)) return\n\n const ok = await save(() =>\n runHandler(\n 'createBudget',\n { categoryGuid, amount: Number(amount) },\n { onSuccess: ['refreshBeat'] },\n ),\n )\n if (ok === undefined) return\n\n setIsOpen(false)\n setNotice(ok ? 'created' : 'failed')\n }\n\n return (\n <React.Fragment>\n <CurrencyDialog\n closeAriaLabel={commonCopy.close_aria}\n content={\n buildDynamicCopy(\n budgetsCopy.create_budget_content,\n <strong key=\"category\">{categoryName}</strong>,\n formatCurrency(averageAmount, CURRENCY_FORMAT.whole),\n ) as React.ReactNode\n }\n handleInputChange={setAmount}\n handleModalClose={closeActionDrawer}\n handlePrimaryAction={() => void handleCreate()}\n handleSecondaryAction={closeActionDrawer}\n inputLabel={commonCopy.amount_text}\n inputValue={amount}\n isOpen={isOpen}\n isPrimaryDisabled={!canCreate}\n primaryText={budgetsCopy.dialog_primary_button_text}\n secondaryText={commonCopy.cancel_button}\n title={budgetsCopy.dialog_create_budget_title}\n />\n <StatusSnackbar\n actionText={notice === 'failed' ? insightsFeedCopy?.general?.try_again : undefined}\n closeAriaLabel={commonCopy.close_aria}\n message={\n notice === 'created'\n ? named(budgetsCopy.alert_budget_created)\n : named(budgetsCopy.alert_merchant_budget_not_created)\n }\n onActionClick={() => {\n setNotice(null)\n setIsOpen(true)\n }}\n onClose={() => {\n setNotice(null)\n closeActionDrawer()\n }}\n open={Boolean(notice)}\n severity={notice === 'created' ? 'success' : 'error'}\n />\n </React.Fragment>\n )\n})\n"],"mappings":";;;;;;;;;;;;;;AAwBA,IAAa,KAAqB,EAAS,SAA4B,EAAE,MAAA,EAAA,GAA0B;AACjG,QAAM,EACJ,SAAS,GACT,YAAY,GACZ,QAAQ,GACR,eAAe,EAAA,IACb,EAAmB,GACjB,IAAgB,EAAiB,GACjC,EAAE,mBAAA,EAAA,IAAsB,EAAmB,GAC3C,IAAa,EAAc,GAAM,EAAe,CAAC,GAEjD,IAAU,EAAK,kBACf,EAAE,cAAA,IAAe,GAAA,IAAO,EAAmB,CAAI,GAC/C,IAAgB,EAAa,GAAS,eAAe,MAAM,gBAAgB,KAAK,GAChF,IAAW,EAAc,WAAW,KAAA,CAAM,EAAE,MAAA,EAAA,MAAW,MAAS,CAAY,GAC5E,IAAe,IAAW,EAAyB,GAAU,CAAc,IAAI,IAE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,EAAY,iCADoB;AAAA,IAG5C,eAAA,MAAqB;AACnB,MAAA,EAAU,IAAI,GACd,EAAU,EAAI;AAAA,IAChB;AAAA,IACA,SAAA,MAAe;AACb,MAAA,EAAU,IAAI,GACd,EAAkB;AAAA,IACpB;AAAA,IACA,MAAM,EAAQ;AAAA,IACd,UAAU,MAAW,YAAY,YAAY;AAAA,EAC9C,CAAA,CACa,EAAA,CAAA;AAEpB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A block dialog's save: one at a time, resolving `run`'s result (`false` if it throws; `run`
|
|
4
|
+
* reports its own errors) or `undefined` if a save is running or the dialog closed first.
|
|
5
|
+
* `isMounted` is for the dialog's other async work.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useBlockSave: () => {
|
|
8
|
+
isMounted: React.RefObject<boolean>;
|
|
9
|
+
isSaving: boolean;
|
|
10
|
+
save: (run: () => Promise<boolean>) => Promise<boolean | undefined>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import e from "react";
|
|
2
|
+
var f = () => {
|
|
3
|
+
const [a, u] = e.useState(!1), r = e.useRef(!0), t = e.useRef(!1);
|
|
4
|
+
return e.useEffect(() => (r.current = !0, () => {
|
|
5
|
+
r.current = !1;
|
|
6
|
+
}), []), {
|
|
7
|
+
isMounted: r,
|
|
8
|
+
isSaving: a,
|
|
9
|
+
save: e.useCallback(async (n) => {
|
|
10
|
+
if (t.current) return;
|
|
11
|
+
t.current = !0, u(!0);
|
|
12
|
+
let s = !1;
|
|
13
|
+
try {
|
|
14
|
+
s = await n();
|
|
15
|
+
} catch {
|
|
16
|
+
s = !1;
|
|
17
|
+
} finally {
|
|
18
|
+
t.current = !1;
|
|
19
|
+
}
|
|
20
|
+
if (r.current)
|
|
21
|
+
return u(!1), s;
|
|
22
|
+
}, [])
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
f as useBlockSave
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=useBlockSave.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBlockSave.es.js","names":[],"sources":["../../../src/insights-v2/actionBlocks/useBlockSave.ts"],"sourcesContent":["import React from 'react'\n\n/**\n * A block dialog's save: one at a time, resolving `run`'s result (`false` if it throws; `run`\n * reports its own errors) or `undefined` if a save is running or the dialog closed first.\n * `isMounted` is for the dialog's other async work.\n */\nexport const useBlockSave = () => {\n const [isSaving, setIsSaving] = React.useState(false)\n const isMounted = React.useRef(true)\n const inFlight = React.useRef(false)\n\n React.useEffect(() => {\n isMounted.current = true\n\n return () => {\n isMounted.current = false\n }\n }, [])\n\n const save = React.useCallback(\n async (run: () => Promise<boolean>): Promise<boolean | undefined> => {\n if (inFlight.current) return undefined\n\n inFlight.current = true\n setIsSaving(true)\n let ok = false\n try {\n ok = await run()\n } catch {\n ok = false\n } finally {\n inFlight.current = false\n }\n if (!isMounted.current) return undefined\n\n setIsSaving(false)\n return ok\n },\n [],\n )\n\n return { isMounted, isSaving, save }\n}\n"],"mappings":";AAOA,IAAa,IAAA,MAAqB;AAChC,QAAM,CAAC,GAAU,CAAA,IAAe,EAAM,SAAS,EAAK,GAC9C,IAAY,EAAM,OAAO,EAAI,GAC7B,IAAW,EAAM,OAAO,EAAK;AAEnC,SAAA,EAAM,UAAA,OACJ,EAAU,UAAU,IAEpB,MAAa;AACX,IAAA,EAAU,UAAU;AAAA,EACtB,IACC,CAAC,CAAC,GAwBE;AAAA,IAAE,WAAA;AAAA,IAAW,UAAA;AAAA,IAAU,MAtBjB,EAAM,YACjB,OAAO,MAA8D;AACnE,UAAI,EAAS,QAAS;AAEtB,MAAA,EAAS,UAAU,IACnB,EAAY,EAAI;AAChB,UAAI,IAAK;AACT,UAAI;AACF,QAAA,IAAK,MAAM,EAAI;AAAA,MACjB,QAAQ;AACN,QAAA,IAAK;AAAA,MACP,UAAA;AACE,QAAA,EAAS,UAAU;AAAA,MACrB;AACA,UAAK,EAAU;AAEf,eAAA,EAAY,EAAK,GACV;AAAA,IACT,GACA,CAAC,CAG2B;AAAA,EAAK;AACrC"}
|