@mx-cartographer/experiences 9.7.97 → 9.7.99-alpha-ram-cs-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/core/types/Insights.d.ts +26 -119
  3. package/dist/core/types/Insights.es.js.map +1 -1
  4. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/AmountInputModalBlock.d.ts +2 -7
  5. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/AmountInputModalBlock.es.js +79 -72
  6. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/AmountInputModalBlock.es.js.map +1 -1
  7. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/CreateBudgetDialog.d.ts +5 -0
  8. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/CreateBudgetDialog.es.js +61 -0
  9. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/CreateBudgetDialog.es.js.map +1 -0
  10. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/layout.d.ts +2 -6
  11. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/layout.es.js +13 -12
  12. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/layout.es.js.map +1 -1
  13. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/BudgetDetailsBlock.es.js +166 -113
  14. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/BudgetDetailsBlock.es.js.map +1 -1
  15. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/BudgetSummary.es.js +4 -4
  16. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/layout.d.ts +5 -1
  17. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/layout.es.js +39 -26
  18. package/dist/insights-v2/actionBlocks/BudgetDetailsBlock/layout.es.js.map +1 -1
  19. package/dist/insights-v2/actionBlocks/TransactionHistoryBlock/TransactionDrillDown.es.js +42 -55
  20. package/dist/insights-v2/actionBlocks/TransactionHistoryBlock/TransactionDrillDown.es.js.map +1 -1
  21. package/dist/insights-v2/actionBlocks/TransactionListBlock/layout.d.ts +8 -6
  22. package/dist/insights-v2/actionBlocks/TransactionListBlock/layout.es.js +23 -17
  23. package/dist/insights-v2/actionBlocks/TransactionListBlock/layout.es.js.map +1 -1
  24. package/dist/insights-v2/actionBlocks/util.d.ts +2 -11
  25. package/dist/insights-v2/actionBlocks/util.es.js +14 -7
  26. package/dist/insights-v2/actionBlocks/util.es.js.map +1 -1
  27. package/dist/insights-v2/analytics/analyticsEventsConfig.d.ts +16 -0
  28. package/dist/insights-v2/analytics/analyticsEventsConfig.es.js +19 -2
  29. package/dist/insights-v2/analytics/analyticsEventsConfig.es.js.map +1 -1
  30. package/dist/insights-v2/blocks/ChartBlocks/BarchartBlock/BarchartBlock.es.js +30 -29
  31. package/dist/insights-v2/blocks/ChartBlocks/BarchartBlock/BarchartBlock.es.js.map +1 -1
  32. package/dist/insights-v2/blocks/ChartBlocks/BarchartBlock/layout.d.ts +1 -0
  33. package/dist/insights-v2/blocks/ChartBlocks/BarchartBlock/layout.es.js +4 -3
  34. package/dist/insights-v2/blocks/ChartBlocks/BarchartBlock/layout.es.js.map +1 -1
  35. package/dist/insights-v2/blocks/ComponentBlocks/AccountBlock/AccountBlock.es.js +1 -1
  36. package/dist/insights-v2/blocks/ComponentBlocks/AccountBlock/AccountBlock.es.js.map +1 -1
  37. package/dist/insights-v2/blocks/ComponentBlocks/AccountBlock/layout.es.js +1 -1
  38. package/dist/insights-v2/blocks/ComponentBlocks/AccountBlock/layout.es.js.map +1 -1
  39. package/dist/insights-v2/components/ExportCsvButton.d.ts +9 -0
  40. package/dist/insights-v2/components/ExportCsvButton.es.js +25 -0
  41. package/dist/insights-v2/components/ExportCsvButton.es.js.map +1 -0
  42. package/dist/insights-v2/components/Header.es.js +5 -2
  43. package/dist/insights-v2/components/Header.es.js.map +1 -1
  44. package/dist/insights-v2/mappings/blocks.es.js +151 -146
  45. package/dist/insights-v2/mappings/blocks.es.js.map +1 -1
  46. package/package.json +1 -1
@@ -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 useGlobalCopyStore,\n useInsightsV2Store,\n useSettingsStore,\n useUserStore,\n} from '../../../common'\nimport getAccountDisplayName from '../../../common/utils/AccountDisplayName'\nimport { ANALYTICS_EVENTS_CONFIG, useAnalyticsEvent } from '../../analytics'\nimport { useBeatActions } from '../../beatActions'\nimport { useCtaHandler } from '../../ctaActions'\nimport type { ActionBlockProps } from '../../mappings/blocks'\nimport { getDynamicCtaBasedOnTriggers } from '../util'\n\nimport {\n AMOUNT_INPUT_VARIANTS,\n findLowBalanceProfile,\n isAmountInputVariant,\n isWholeAmount,\n resolveAmountInputVariant,\n toInputValue,\n} from './layout'\n\n/**\n * The dialog frame for the states that have no form: loading, and a non-retriable problem. Named by\n * its heading and closable by button, Esc and backdrop, like the form dialog.\n */\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 >\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/**\n * `amount_input_modal_block`: one whole-dollar setting edited in a dialog (Figma 441:24913 and\n * 5402:34137). The CTA's variant picks what is edited:\n * - `low_balance_threshold`: the `threshold` on the beat account's low-balance alert profile;\n * - `safety_net`: `savings_opportunity_minimum_checking_account_balance` on the insight profile.\n *\n * Registered with `presentation: 'modal'`, so no drawer opens behind it; closing the dialog ends\n * the action-drawer session. `observer` is required: the starting values are read from stores.\n */\nexport const AmountInputModalBlock = observer(function AmountInputModalBlock({\n beat,\n}: ActionBlockProps) {\n const { common: commonCopy, insights_feed: insightsFeedCopy } = useGlobalCopyStore()\n const { actionDrawer, closeActionDrawer } = useInsightsV2Store()\n const settingsStore = useSettingsStore()\n const { userInsightProfile } = useUserStore()\n const runHandler = useCtaHandler(beat, useBeatActions())\n const fireAnalyticsEvent = useAnalyticsEvent()\n\n const { primary_cta, secondary_cta, in_description_cta } = beat.insights_payload ?? {}\n const cta = getDynamicCtaBasedOnTriggers(\n actionDrawer,\n primary_cta,\n secondary_cta,\n in_description_cta,\n )\n const variant = resolveAmountInputVariant(cta)\n const copy = insightsFeedCopy?.amount_input_modal\n const isLowBalance = variant === AMOUNT_INPUT_VARIANTS.LOW_BALANCE_THRESHOLD\n\n const lowBalanceProfile = isLowBalance\n ? findLowBalanceProfile(settingsStore.notificationProfiles, beat.primary_account_guid)\n : undefined\n const savedAmount = isLowBalance\n ? lowBalanceProfile?.threshold\n : userInsightProfile?.savings_opportunity_minimum_checking_account_balance\n\n // Mounted only while open (modal presentation), so mounting is the open: profiles are reloaded\n // here on each open, so the threshold prefills as saved now. `SettingsStore` swallows a failed\n // request, which leaves no profile for the account: the missing-profile error below covers it.\n const [isLoadingProfiles, setIsLoadingProfiles] = React.useState(isLowBalance)\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 (!isLowBalance) return\n\n void settingsStore.loadNotificationProfiles().finally(() => {\n if (isMounted.current) setIsLoadingProfiles(false)\n })\n }, [isLowBalance, 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 hasCopy =\n !!variantCopy?.title &&\n !!variantCopy.description &&\n !!variantCopy.input_label &&\n !!copy?.whole_number_error &&\n !!copy.save_error &&\n !!commonCopy?.save_button &&\n // Cancel renders for the low-balance variant only.\n (!isLowBalance || !!commonCopy.cancel_button) &&\n !!commonCopy.close_aria\n const hasProfile = isLowBalance ? !!lowBalanceProfile : !!userInsightProfile\n\n if (!copy || !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 : !isAmountInputVariant(variant)\n ? `unknown variant \"${variant}\"`\n : !hasCopy\n ? `copy incomplete for \"${variant}\"`\n : isLowBalance\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(\n isLowBalance\n ? ANALYTICS_EVENTS_CONFIG.EDIT_INSIGHT_THRESHOLD_CANCELED\n : ANALYTICS_EVENTS_CONFIG.EDIT_SAFETY_NET_CANCEL,\n )\n closeActionDrawer()\n }\n\n const isEdit = !isLowBalance && !!savedAmount\n const accountName = beat.primary_account ? getAccountDisplayName(beat.primary_account) : ''\n const isValid = isWholeAmount(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 ok = isLowBalance\n ? await runHandler(\n 'updateNotificationProfileThreshold',\n { profileGuid: lowBalanceProfile?.guid, threshold: amount },\n { analytics: ANALYTICS_EVENTS_CONFIG.EDIT_INSIGHT_THRESHOLD_SAVE },\n )\n : await runHandler(\n 'updateUserInsightProfile',\n { fields: { savings_opportunity_minimum_checking_account_balance: amount } },\n { analytics: ANALYTICS_EVENTS_CONFIG.EDIT_SAFETY_NET_SAVE },\n )\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 ? copy.whole_number_error : saveFailed ? copy.save_error : undefined}\n handleInputChange={(next) => {\n setTyped(next)\n setSaveFailed(false)\n }}\n handleInputClick={\n // Pulse fires input-selected for the threshold dialog only (EditThreshold.js); the\n // safety-net dialog has no input event.\n isLowBalance\n ? () => fireAnalyticsEvent(ANALYTICS_EVENTS_CONFIG.EDIT_INSIGHT_THRESHOLD_INPUT_SELECTED)\n : undefined\n }\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={isLowBalance ? commonCopy.cancel_button : undefined}\n subtitle={\n isLowBalance && 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 />\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,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;AAA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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,EAC1D,CAAA;AAEL,CAAC"}
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 useGlobalCopyStore,\n useInsightsV2Store,\n useSettingsStore,\n useUserStore,\n} from '../../../common'\nimport getAccountDisplayName from '../../../common/utils/AccountDisplayName'\nimport { ANALYTICS_EVENTS_CONFIG, useAnalyticsEvent } from '../../analytics'\nimport { useBeatActions } from '../../beatActions'\nimport { useCtaHandler } from '../../ctaActions'\nimport type { ActionBlockProps } from '../../mappings/blocks'\nimport { getDynamicCtaBasedOnTriggers } from '../util'\n\nimport { CreateBudgetDialog } from './CreateBudgetDialog'\nimport {\n AMOUNT_INPUT_VARIANTS,\n CREATE_BUDGET_VARIANT,\n findLowBalanceProfile,\n isAmountInputVariant,\n isWholeAmount,\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 >\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/**\n * `amount_input_modal_block`: one whole-dollar setting in a modal, picked by the CTA variant\n * (low-balance threshold, safety net or create budget).\n */\nexport const AmountInputModalBlock = observer(function AmountInputModalBlock({\n beat,\n}: ActionBlockProps) {\n const { actionDrawer } = useInsightsV2Store()\n const { primary_cta, secondary_cta, in_description_cta } = beat.insights_payload ?? {}\n // Read once on open: a refreshed beat must not swap the dialog under its snackbar.\n const [variant] = React.useState(() =>\n resolveAmountInputVariant(\n getDynamicCtaBasedOnTriggers(actionDrawer, primary_cta, secondary_cta, in_description_cta),\n ),\n )\n\n return variant === CREATE_BUDGET_VARIANT ? (\n <CreateBudgetDialog beat={beat} />\n ) : (\n <AmountSettingDialog beat={beat} variant={variant} />\n )\n})\n\n/** The low-balance threshold and safety-net settings (the two `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 isLowBalance = variant === AMOUNT_INPUT_VARIANTS.LOW_BALANCE_THRESHOLD\n\n const lowBalanceProfile = isLowBalance\n ? findLowBalanceProfile(settingsStore.notificationProfiles, beat.primary_account_guid)\n : undefined\n const savedAmount = isLowBalance\n ? lowBalanceProfile?.threshold\n : userInsightProfile?.savings_opportunity_minimum_checking_account_balance\n\n // Mounting is the open, so profiles reload here and the threshold prefills as saved now.\n const [isLoadingProfiles, setIsLoadingProfiles] = React.useState(isLowBalance)\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 (!isLowBalance) return\n\n void settingsStore.loadNotificationProfiles().finally(() => {\n if (isMounted.current) setIsLoadingProfiles(false)\n })\n }, [isLowBalance, 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 hasCopy =\n !!variantCopy?.title &&\n !!variantCopy.description &&\n !!variantCopy.input_label &&\n !!copy?.whole_number_error &&\n !!copy.save_error &&\n !!commonCopy?.save_button &&\n // Cancel renders for the low-balance variant only.\n (!isLowBalance || !!commonCopy.cancel_button) &&\n !!commonCopy.close_aria\n const hasProfile = isLowBalance ? !!lowBalanceProfile : !!userInsightProfile\n\n if (!copy || !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 : !isAmountInputVariant(variant)\n ? `unknown variant \"${variant}\"`\n : !hasCopy\n ? `copy incomplete for \"${variant}\"`\n : isLowBalance\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(\n isLowBalance\n ? ANALYTICS_EVENTS_CONFIG.EDIT_INSIGHT_THRESHOLD_CANCELED\n : ANALYTICS_EVENTS_CONFIG.EDIT_SAFETY_NET_CANCEL,\n )\n closeActionDrawer()\n }\n\n const isEdit = !isLowBalance && !!savedAmount\n const accountName = beat.primary_account ? getAccountDisplayName(beat.primary_account) : ''\n const isValid = isWholeAmount(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 ok = isLowBalance\n ? await runHandler(\n 'updateNotificationProfileThreshold',\n { profileGuid: lowBalanceProfile?.guid, threshold: amount },\n { analytics: ANALYTICS_EVENTS_CONFIG.EDIT_INSIGHT_THRESHOLD_SAVE },\n )\n : await runHandler(\n 'updateUserInsightProfile',\n { fields: { savings_opportunity_minimum_checking_account_balance: amount } },\n { analytics: ANALYTICS_EVENTS_CONFIG.EDIT_SAFETY_NET_SAVE },\n )\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 ? copy.whole_number_error : saveFailed ? copy.save_error : undefined}\n handleInputChange={(next) => {\n setTyped(next)\n setSaveFailed(false)\n }}\n handleInputClick={\n // Pulse fires input-selected for the threshold dialog only (EditThreshold.js); the\n // safety-net dialog has no input event.\n isLowBalance\n ? () => fireAnalyticsEvent(ANALYTICS_EVENTS_CONFIG.EDIT_INSIGHT_THRESHOLD_INPUT_SELECTED)\n : undefined\n }\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={isLowBalance ? commonCopy.cancel_button : undefined}\n subtitle={\n isLowBalance && 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 />\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,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,E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uB;AAAA,IACvB,YAAY,EAAY;AAAA,IACxB,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,mBAAmB,KAAY,CAAC;AAAA,IAChC,aAAa,EAAW;AAAA,IACxB,eAAe,IAAe,EAAW,gBAAgB;AAAA,IACzD,UACE,KAAgB,EAAK,kBACnB,gBAAA,EAAC,GAAD;AAAA,MAAO,IAAI;AAAA,QAAE,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,EAC1D,CAAA;AAEL,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { ActionBlockProps } from '../../mappings/blocks';
2
+ /** Category Spending's "Create a Budget" dialog: creates the budget, refreshes the beat, shows the result. */
3
+ export declare const CreateBudgetDialog: (({ beat }: ActionBlockProps) => import("react/jsx-runtime").JSX.Element) & {
4
+ displayName: string;
5
+ };
@@ -0,0 +1,61 @@
1
+ import { buildDynamicCopy as h } from "../../../core/utils/Localization.es.js";
2
+ import { useCategoryStore as I, useGlobalCopyStore as N, useInsightsV2Store as k } from "../../../common/context/hooks.es.js";
3
+ import { slot as F } from "../../../core/types/Insights.es.js";
4
+ import { formatCurrency as P } from "../../../core/utils/NumberFormatting.es.js";
5
+ import T from "../../../common/components/CurrencyDialog.es.js";
6
+ import { useBeatActions as j } from "../../beatActions.es.js";
7
+ import { resolveBudgetFacts as w } from "../BudgetDetailsBlock/layout.es.js";
8
+ import { useCtaHandler as G } from "../../ctaActions/useCtaAction.es.js";
9
+ import H from "../../components/shared/StatusSnackbar.es.js";
10
+ import e from "react";
11
+ import { observer as M } from "mobx-react-lite";
12
+ import { jsx as m, jsxs as O } from "react/jsx-runtime";
13
+ var R = (s) => s !== "" && Number(s) > 0, $ = M(function({ beat: i }) {
14
+ const { budgets: t, common: a, insights_feed: S } = N(), o = I(), { closeActionDrawer: c } = k(), v = G(i, j()), g = i.insights_payload, { categoryGuid: f = "" } = w(i), A = F(g?.instance_slot?.data, "average_amount") ?? 0, p = o.categories.find(({ guid: r }) => r === f)?.name ?? g?.subtitle ?? "", [u, x] = e.useState(""), [B, y] = e.useState(!0), [D, _] = e.useState(!1), [n, l] = e.useState(null), d = e.useRef(!0);
15
+ e.useEffect(() => (d.current = !0, o.categoriesLoaded || o.loadCategories(), () => {
16
+ d.current = !1;
17
+ }), [o]);
18
+ const C = (r) => h(r, p), b = R(u) && !D && o.categoriesLoaded, L = async () => {
19
+ if (!b) return;
20
+ _(!0);
21
+ const r = await v("createBudget", {
22
+ categoryGuid: f,
23
+ amount: Number(u)
24
+ }, { onSuccess: ["refreshBeat"] });
25
+ d.current && (_(!1), y(!1), l(r ? "created" : "failed"));
26
+ };
27
+ return /* @__PURE__ */ O(e.Fragment, { children: [/* @__PURE__ */ m(T, {
28
+ closeAriaLabel: a.close_aria,
29
+ content: h(t.create_budget_content, /* @__PURE__ */ m("strong", { children: p }, "category"), P(A, "0,0")),
30
+ handleInputChange: x,
31
+ handleModalClose: c,
32
+ handlePrimaryAction: () => {
33
+ L();
34
+ },
35
+ handleSecondaryAction: c,
36
+ inputLabel: a.amount_text,
37
+ inputValue: u,
38
+ isOpen: B,
39
+ isPrimaryDisabled: !b,
40
+ primaryText: t.dialog_primary_button_text,
41
+ secondaryText: a.cancel_button,
42
+ title: t.dialog_create_budget_title
43
+ }), /* @__PURE__ */ m(H, {
44
+ actionText: n === "failed" ? S?.general?.try_again : void 0,
45
+ closeAriaLabel: a.close_aria,
46
+ message: C(n === "created" ? t.alert_budget_created : t.alert_merchant_budget_not_created),
47
+ onActionClick: () => {
48
+ l(null), y(!0);
49
+ },
50
+ onClose: () => {
51
+ l(null), c();
52
+ },
53
+ open: !!n,
54
+ severity: n === "created" ? "success" : "error"
55
+ })] });
56
+ });
57
+ export {
58
+ $ as CreateBudgetDialog
59
+ };
60
+
61
+ //# sourceMappingURL=CreateBudgetDialog.es.js.map
@@ -0,0 +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 formatCurrency,\n useCategoryStore,\n useGlobalCopyStore,\n useInsightsV2Store,\n} from '../../../common'\nimport { slot } from '../../../core/types/Insights'\nimport StatusSnackbar from '../../components/shared/StatusSnackbar'\nimport { useBeatActions } from '../../beatActions'\nimport { useCtaHandler } from '../../ctaActions'\nimport type { ActionBlockProps } from '../../mappings/blocks'\nimport { resolveBudgetFacts } from '../BudgetDetailsBlock/layout'\n\ntype Notice = 'created' | 'failed'\n\nconst isPositiveAmount = (value: string) => value !== '' && Number(value) > 0\n\n/** Category Spending's \"Create a Budget\" dialog: creates the budget, refreshes the beat, shows the result. */\nexport const CreateBudgetDialog = observer(function CreateBudgetDialog({ beat }: ActionBlockProps) {\n const {\n budgets: budgetsCopy,\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?.name ?? payload?.subtitle ?? ''\n\n const [amount, setAmount] = React.useState('')\n const [isOpen, setIsOpen] = React.useState(true)\n const [isSaving, setIsSaving] = React.useState(false)\n const [notice, setNotice] = React.useState<Notice | null>(null)\n const isMounted = React.useRef(true)\n\n React.useEffect(() => {\n isMounted.current = true\n // `createBudget` needs the category in the store.\n if (!categoryStore.categoriesLoaded) void categoryStore.loadCategories()\n\n return () => {\n isMounted.current = false\n }\n }, [categoryStore])\n\n const named = (copy: string) => buildDynamicCopy(copy, categoryName) as string\n\n const canCreate = isPositiveAmount(amount) && !isSaving && categoryStore.categoriesLoaded\n\n const handleCreate = async () => {\n if (!canCreate) return\n\n setIsSaving(true)\n const ok = await runHandler(\n 'createBudget',\n { categoryGuid, amount: Number(amount) },\n { onSuccess: ['refreshBeat'] },\n )\n if (!isMounted.current) return\n\n setIsSaving(false)\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, '0,0'),\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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IAAK,EAAU,YAEf,EAAY,EAAK,GACjB,EAAU,EAAK,GACf,EAAU,IAAK,YAAY,QAAQ;AAAA,EACrC;AAEA,SACE,gBAAA,EAAC,EAAM,UAAP,EAAA,UAAA,CACE,gBAAA,EAAC,GAAD;AAAA,IACE,gBAAgB,EAAW;AAAA,IAC3B,SACE,EACE,EAAY,uBACZ,gBAAA,EAAC,UAAD,EAAA,UAAwB,EAAqB,GAAjC,UAAiC,GAC7C,EAAe,GAAe,KAAK,CACrC;AAAA,IAEF,mBAAmB;AAAA,IACnB,kBAAkB;AAAA,IAClB,qBAAA,MAAA;AAA2B,MAAK,EAAa;AAAA;AAAA,IAC7C,uBAAuB;AAAA,IACvB,YAAY,EAAW;AAAA,IACvB,YAAY;AAAA,IACJ,QAAA;AAAA,IACR,mBAAmB,CAAC;AAAA,IACpB,aAAa,EAAY;AAAA,IACzB,eAAe,EAAW;AAAA,IAC1B,OAAO,EAAY;AAAA,EACpB,CAAA,GACD,gBAAA,EAAC,GAAD;AAAA,IACE,YAAY,MAAW,WAAW,GAAkB,SAAS,YAAY;AAAA,IACzE,gBAAgB,EAAW;AAAA,IAC3B,SAEM,EADJ,MAAW,YACD,EAAY,uBACZ,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"}
@@ -4,14 +4,10 @@ export declare const AMOUNT_INPUT_VARIANTS: {
4
4
  readonly LOW_BALANCE_THRESHOLD: "low_balance_threshold";
5
5
  readonly SAFETY_NET: "safety_net";
6
6
  };
7
+ export declare const CREATE_BUDGET_VARIANT = "create_budget";
7
8
  export type AmountInputVariant = (typeof AMOUNT_INPUT_VARIANTS)[keyof typeof AMOUNT_INPUT_VARIANTS];
8
9
  export declare const isAmountInputVariant: (variant?: string | null) => variant is AmountInputVariant;
9
- /**
10
- * The variant the modal edits, from the CTA that opened it. ditto drives the shared
11
- * `amount_input_modal_block` by an explicit CTA variant, but gives Savings Opportunity's safety-net
12
- * reminder a dedicated `safety_net_block` with no variant, so there the block name selects it. An
13
- * explicit variant always wins (so an unknown one still falls to the block's "unknown variant" path).
14
- */
10
+ /** The variant to edit: the CTA's, else `safety_net` for the dedicated `safety_net_block`. */
15
11
  export declare const resolveAmountInputVariant: (cta?: {
16
12
  block?: string | null;
17
13
  variant?: string | null;
@@ -1,19 +1,20 @@
1
- import { AccountNotificationTypes as i } from "../../../core/types/Notification.es.js";
2
- import { actionBlocksKey as a } from "../../mappings/actionBlocksKey.es.js";
3
- var o = {
1
+ import { AccountNotificationTypes as a } from "../../../core/types/Notification.es.js";
2
+ import { actionBlocksKey as o } from "../../mappings/actionBlocksKey.es.js";
3
+ var e = {
4
4
  LOW_BALANCE_THRESHOLD: "low_balance_threshold",
5
5
  SAFETY_NET: "safety_net"
6
- }, T = (t) => Object.values(o).includes(t ?? ""), u = (t) => {
6
+ }, T = "create_budget", u = (t) => Object.values(e).includes(t ?? ""), N = (t) => {
7
7
  if (t?.variant) return t.variant;
8
- if (t?.block === a.SAFETY_NET_ACTION_BLOCK) return o.SAFETY_NET;
9
- }, e = 1e9, N = (t) => /^\d+$/.test(t) && Number(t) >= 1 && Number(t) <= e, c = (t) => t ? String(Math.round(t)) : "", l = (t, n) => n ? t.find((r) => r.entity_guid === n && r.notification_type === i.AccountBalanceLow) : void 0;
8
+ if (t?.block === o.SAFETY_NET_ACTION_BLOCK) return e.SAFETY_NET;
9
+ }, i = 1e9, c = (t) => /^\d+$/.test(t) && Number(t) >= 1 && Number(t) <= i, v = (t) => t ? String(Math.round(t)) : "", E = (t, r) => r ? t.find((n) => n.entity_guid === r && n.notification_type === a.AccountBalanceLow) : void 0;
10
10
  export {
11
- o as AMOUNT_INPUT_VARIANTS,
12
- l as findLowBalanceProfile,
13
- T as isAmountInputVariant,
14
- N as isWholeAmount,
15
- u as resolveAmountInputVariant,
16
- c as toInputValue
11
+ e as AMOUNT_INPUT_VARIANTS,
12
+ T as CREATE_BUDGET_VARIANT,
13
+ E as findLowBalanceProfile,
14
+ u as isAmountInputVariant,
15
+ c as isWholeAmount,
16
+ N as resolveAmountInputVariant,
17
+ v as toInputValue
17
18
  };
18
19
 
19
20
  //# sourceMappingURL=layout.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"layout.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/AmountInputModalBlock/layout.ts"],"sourcesContent":["import type { NotificationProfile } from '../../../core'\nimport { AccountNotificationTypes } from '../../../core/types/Notification'\nimport { actionBlocksKey } from '../../mappings/actionBlocksKey'\n\n/** CTA variants `amount_input_modal_block` serves (ditto sets one on the beat's CTA). */\nexport const AMOUNT_INPUT_VARIANTS = {\n LOW_BALANCE_THRESHOLD: 'low_balance_threshold',\n SAFETY_NET: 'safety_net',\n} as const\n\nexport type AmountInputVariant = (typeof AMOUNT_INPUT_VARIANTS)[keyof typeof AMOUNT_INPUT_VARIANTS]\n\nexport const isAmountInputVariant = (variant?: string | null): variant is AmountInputVariant =>\n Object.values<string>(AMOUNT_INPUT_VARIANTS).includes(variant ?? '')\n\n/**\n * The variant the modal edits, from the CTA that opened it. ditto drives the shared\n * `amount_input_modal_block` by an explicit CTA variant, but gives Savings Opportunity's safety-net\n * reminder a dedicated `safety_net_block` with no variant, so there the block name selects it. An\n * explicit variant always wins (so an unknown one still falls to the block's \"unknown variant\" path).\n */\nexport const resolveAmountInputVariant = (cta?: {\n block?: string | null\n variant?: string | null\n}): string | undefined => {\n if (cta?.variant) return cta.variant\n if (cta?.block === actionBlocksKey.SAFETY_NET_ACTION_BLOCK) return AMOUNT_INPUT_VARIANTS.SAFETY_NET\n return undefined\n}\n\n/** Pulse v1's upper bound for a safety net; applied to both variants. */\nconst MAX_AMOUNT = 1_000_000_000\n\n/** Whole dollars from 1 to `MAX_AMOUNT`, as pulse v1 accepted for both settings. */\nexport const isWholeAmount = (value: string): boolean =>\n /^\\d+$/.test(value) && Number(value) >= 1 && Number(value) <= MAX_AMOUNT\n\n/** A saved amount as the field's starting text; nothing saved (or zero) starts empty. */\nexport const toInputValue = (amount?: number | null): string =>\n amount ? String(Math.round(amount)) : ''\n\n/** The account's low-balance alert profile, which holds the threshold (as pulse v1 looked it up). */\nexport const findLowBalanceProfile = (\n profiles: NotificationProfile[],\n accountGuid?: string | null,\n): NotificationProfile | undefined =>\n accountGuid\n ? profiles.find(\n (profile) =>\n profile.entity_guid === accountGuid &&\n profile.notification_type === AccountNotificationTypes.AccountBalanceLow,\n )\n : undefined\n"],"mappings":";;AAKA,IAAa,IAAwB;AAAA,EACnC,uBAAuB;AAAA,EACvB,YAAY;AACd,GAIa,IAAA,CAAwB,MACnC,OAAO,OAAe,CAAqB,EAAE,SAAS,KAAW,EAAE,GAQxD,IAAA,CAA6B,MAGhB;AACxB,MAAI,GAAK,QAAS,QAAO,EAAI;AAC7B,MAAI,GAAK,UAAU,EAAgB,wBAAyB,QAAO,EAAsB;AAE3F,GAGM,IAAa,KAGN,IAAA,CAAiB,MAC5B,QAAQ,KAAK,CAAK,KAAK,OAAO,CAAK,KAAK,KAAK,OAAO,CAAK,KAAK,GAGnD,IAAA,CAAgB,MAC3B,IAAS,OAAO,KAAK,MAAM,CAAM,CAAC,IAAI,IAG3B,IAAA,CACX,GACA,MAEA,IACI,EAAS,KAAA,CACN,MACC,EAAQ,gBAAgB,KACxB,EAAQ,sBAAsB,EAAyB,iBAC3D,IACA"}
1
+ {"version":3,"file":"layout.es.js","names":[],"sources":["../../../../src/insights-v2/actionBlocks/AmountInputModalBlock/layout.ts"],"sourcesContent":["import type { NotificationProfile } from '../../../core'\nimport { AccountNotificationTypes } from '../../../core/types/Notification'\nimport { actionBlocksKey } from '../../mappings/actionBlocksKey'\n\n/** CTA variants `amount_input_modal_block` serves (ditto sets one on the beat's CTA). */\nexport const AMOUNT_INPUT_VARIANTS = {\n LOW_BALANCE_THRESHOLD: 'low_balance_threshold',\n SAFETY_NET: 'safety_net',\n} as const\n\nexport const CREATE_BUDGET_VARIANT = 'create_budget'\n\nexport type AmountInputVariant = (typeof AMOUNT_INPUT_VARIANTS)[keyof typeof AMOUNT_INPUT_VARIANTS]\n\nexport const isAmountInputVariant = (variant?: string | null): variant is AmountInputVariant =>\n Object.values<string>(AMOUNT_INPUT_VARIANTS).includes(variant ?? '')\n\n/** The variant to edit: the CTA's, else `safety_net` for the dedicated `safety_net_block`. */\nexport const resolveAmountInputVariant = (cta?: {\n block?: string | null\n variant?: string | null\n}): string | undefined => {\n if (cta?.variant) return cta.variant\n if (cta?.block === actionBlocksKey.SAFETY_NET_ACTION_BLOCK)\n return AMOUNT_INPUT_VARIANTS.SAFETY_NET\n return undefined\n}\n\n/** Pulse v1's upper bound for a safety net; applied to both variants. */\nconst MAX_AMOUNT = 1_000_000_000\n\n/** Whole dollars from 1 to `MAX_AMOUNT`, as pulse v1 accepted for both settings. */\nexport const isWholeAmount = (value: string): boolean =>\n /^\\d+$/.test(value) && Number(value) >= 1 && Number(value) <= MAX_AMOUNT\n\n/** A saved amount as the field's starting text; nothing saved (or zero) starts empty. */\nexport const toInputValue = (amount?: number | null): string =>\n amount ? String(Math.round(amount)) : ''\n\n/** The account's low-balance alert profile, which holds the threshold (as pulse v1 looked it up). */\nexport const findLowBalanceProfile = (\n profiles: NotificationProfile[],\n accountGuid?: string | null,\n): NotificationProfile | undefined =>\n accountGuid\n ? profiles.find(\n (profile) =>\n profile.entity_guid === accountGuid &&\n profile.notification_type === AccountNotificationTypes.AccountBalanceLow,\n )\n : undefined\n"],"mappings":";;AAKA,IAAa,IAAwB;AAAA,EACnC,uBAAuB;AAAA,EACvB,YAAY;AACd,GAEa,IAAwB,iBAIxB,IAAA,CAAwB,MACnC,OAAO,OAAe,CAAqB,EAAE,SAAS,KAAW,EAAE,GAGxD,IAAA,CAA6B,MAGhB;AACxB,MAAI,GAAK,QAAS,QAAO,EAAI;AAC7B,MAAI,GAAK,UAAU,EAAgB,wBACjC,QAAO,EAAsB;AAEjC,GAGM,IAAa,KAGN,IAAA,CAAiB,MAC5B,QAAQ,KAAK,CAAK,KAAK,OAAO,CAAK,KAAK,KAAK,OAAO,CAAK,KAAK,GAGnD,IAAA,CAAgB,MAC3B,IAAS,OAAO,KAAK,MAAM,CAAM,CAAC,IAAI,IAG3B,IAAA,CACX,GACA,MAEA,IACI,EAAS,KAAA,CACN,MACC,EAAQ,gBAAgB,KACxB,EAAQ,sBAAsB,EAAyB,iBAC3D,IACA"}
@@ -1,130 +1,160 @@
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, {
1
+ import { buildDynamicCopy as W } from "../../../core/utils/Localization.es.js";
2
+ import { DATE_FORMATS_INTL as ae, formatDate as ie } from "../../../core/constants/DateFormats.es.js";
3
+ import { useBudgetsStore as ne, useCategoryStore as se, useGlobalCopyStore as de, useGlobalStore as ce, useTransactionStore as le } from "../../../common/context/hooks.es.js";
4
+ import { getCategoryColor as Y } from "../../../core/utils/CategoryUtil.es.js";
5
+ import ue from "../../../common/components/Loader.es.js";
6
+ import me from "../../../common/components/CurrencyDialog.es.js";
7
+ import ge from "../../../transactions/components/shared/TransactionList.es.js";
8
+ import { budgetMonthOf as _e, budgetTransactionFilter as fe, daysLeftInBudgetMonth as ye, resolveBudgetFacts as pe } from "./layout.es.js";
9
+ import { ANALYTICS_EVENTS_CONFIG as x } from "../../analytics/analyticsEventsConfig.es.js";
10
+ import { useAnalyticsEvent as he } from "../../analytics/useAnalyticsEvent.es.js";
11
+ import be from "../../components/shared/StatusSnackbar.es.js";
12
+ import { ExportCsvButton as Te } from "../../components/ExportCsvButton.es.js";
13
+ import { BudgetSummary as Be } from "./BudgetSummary.es.js";
14
+ import { useEffect as xe, useRef as Ce, useState as C } from "react";
15
+ import { observer as De } from "mobx-react-lite";
16
+ import D from "@mui/material/Stack";
17
+ import { CategoryIcon as Ee, MerchantLogo as Se, Text as M } from "@mxenabled/mxui";
18
+ import w from "@mui/material/Button";
19
+ import { jsx as r, jsxs as F } from "react/jsx-runtime";
20
+ import { alpha as ve, useTheme as Ge } from "@mui/material/styles";
21
+ import Le from "@mui/material/Box";
22
+ import ke from "@mui/material/Skeleton";
23
+ var et = De(function({ beat: g }) {
24
+ const I = Ge(), { copyStore: H, emitUpdate: $ } = ce(), { budgets: e, common: l, insights_feed: N } = de(), i = ne(), u = se(), f = le(), y = he(), [q, J] = C(!1), [a, E] = C(null), [p, h] = C(""), [s, _] = C(null), S = Ce(!1), O = N?.budget_details, { categories: K } = u, Q = i.isDataLoaded && u.categoriesLoaded;
25
+ if (xe(() => {
26
+ Promise.allSettled([i.isDataLoaded || i.loadBudgets(), u.categoriesLoaded || u.loadCategories()]).then(() => J(!(i.isDataLoaded && u.categoriesLoaded))), f.isTransactionDataLoaded || f.loadMissingTransactionData();
27
+ }, [
28
+ i,
29
+ u,
30
+ f
31
+ ]), !H.isInitialized) return /* @__PURE__ */ r(ue, {});
32
+ if (!O) return /* @__PURE__ */ r(D, {
23
33
  sx: { p: 24 },
24
- children: /* @__PURE__ */ r(z, { children: s?.error_message })
34
+ children: /* @__PURE__ */ r(M, { children: l?.error_message })
25
35
  });
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, {
36
+ const o = pe(g), b = o.categoryGuid ? K.find(({ guid: t }) => t === o.categoryGuid) : void 0, d = o.categoryGuid ? i.budgets.find(({ category_guid: t }) => t === o.categoryGuid) : void 0, c = !o.categoryGuid && o.merchantGuid ? i.getMerchantBudgetByMerchantGuid(o.merchantGuid) : void 0, U = b?.name ?? c?.merchant_name ?? g.payload?.merchant_name ?? "", j = d?.amount ?? c?.amount ?? o.budgeted ?? 0, X = o.spent ?? d?.transaction_total ?? c?.transaction_total ?? 0, Z = o.categoryGuid ? /* @__PURE__ */ r(Ee, {
27
37
  categoryGuid: o.categoryGuid,
28
38
  size: 44,
29
39
  sx: {
30
- bgcolor: le(j(o.categoryGuid, L), 0.15),
31
- border: `1px solid ${j(o.categoryGuid, L)}`,
40
+ bgcolor: ve(Y(o.categoryGuid, I), 0.15),
41
+ border: `1px solid ${Y(o.categoryGuid, I)}`,
32
42
  color: "text.primary"
33
43
  }
34
- }) : /* @__PURE__ */ r(ce, {
44
+ }) : /* @__PURE__ */ r(Se, {
35
45
  categoryGuid: "",
36
46
  merchantGuid: o.merchantGuid ?? "",
37
47
  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) {
48
+ }), R = _e(g), T = f.detailedTransactions.filter(fe(o, R)), v = (t) => {
49
+ t === "delete" && y(x.BUDGET_DELETE_START), h(t === "edit" ? String(j) : ""), E(t);
50
+ }, z = () => {
51
+ E(null), h("");
52
+ }, P = () => {
53
+ a === "delete" && y(x.BUDGET_DELETE_CANCEL), z();
54
+ }, n = (t) => W(t, U), B = (t) => n({
55
+ create: e.alert_merchant_budget_not_created,
56
+ edit: e.error_alert_edit_merchant_budget,
57
+ delete: e.error_alert_delete_merchant_budget
58
+ }[t]), ee = async (t, m) => {
59
+ if (c) {
44
60
  if (t === "delete") {
45
- const { isSuccess: S } = await a.deleteMerchantBudget(d.guid);
61
+ const { isSuccess: A } = await i.deleteMerchantBudget(c.guid);
46
62
  return {
47
- ok: S,
48
- success: c(e.success_alert_delete_merchant_budget),
49
- failure: c(e.error_alert_delete_merchant_budget)
63
+ ok: A,
64
+ success: n(e.success_alert_delete_merchant_budget),
65
+ failure: n(e.error_alert_delete_merchant_budget)
50
66
  };
51
67
  }
52
- const { isSuccess: G } = await a.updateMerchantBudget({
53
- ...d,
54
- amount: u
68
+ const { isSuccess: k } = await i.updateMerchantBudget({
69
+ ...c,
70
+ amount: m
55
71
  });
56
72
  return {
57
- ok: G,
58
- success: c(e.success_alert_edit_merchant_budget),
59
- failure: c(e.error_alert_edit_merchant_budget)
73
+ ok: k,
74
+ success: n(e.success_alert_edit_merchant_budget),
75
+ failure: n(e.error_alert_edit_merchant_budget)
60
76
  };
61
77
  }
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
78
+ return t === "delete" && d ? {
79
+ ok: await i.deleteBudget(d.guid),
80
+ success: n(e.alert_budget_deleted),
81
+ failure: B(t)
82
+ } : t === "edit" && d ? {
83
+ ok: await i.updateBudget({
84
+ ...d,
85
+ amount: m
69
86
  }),
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)
87
+ success: n(e.alert_budget_updated),
88
+ failure: B(t)
89
+ } : t === "create" && b ? {
90
+ ok: await i.addBudget(b, m),
91
+ success: n(e.alert_budget_created),
92
+ failure: B(t)
74
93
  } : {
75
94
  ok: !1,
76
95
  success: ""
77
96
  };
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
+ }, te = async () => {
98
+ if (S.current || !a) return;
99
+ const t = Number(p);
100
+ if (a !== "delete" && !(Number.isFinite(t) && t > 0)) return;
101
+ S.current = !0;
102
+ const m = {
103
+ action: a,
104
+ amount: p
105
+ };
106
+ try {
107
+ const { ok: k, success: A, failure: oe } = await ee(a, t);
108
+ k ? ($({ staleBeatGuid: g.guid }), a === "edit" && y({
109
+ ...x.BUDGET_EDIT_SAVE,
110
+ value: p
111
+ }), a === "delete" && y(x.BUDGET_DELETE_END), _({
112
+ message: A,
113
+ severity: "success"
114
+ })) : _({
115
+ message: oe ?? l.error_message,
116
+ severity: "error",
117
+ retry: m
118
+ });
119
+ } catch {
120
+ _({
121
+ message: B(a),
122
+ severity: "error",
123
+ retry: m
124
+ });
125
+ } finally {
126
+ S.current = !1, z();
97
127
  }
98
- }, F = !!(n ?? d), K = E ? /* @__PURE__ */ r(z, {
128
+ }, V = !!(d ?? c), re = q ? /* @__PURE__ */ r(M, {
99
129
  color: "text.secondary",
100
130
  variant: "body2",
101
- children: s.error_message
102
- }) : V ? F ? /* @__PURE__ */ P(v, {
131
+ children: l.error_message
132
+ }) : Q ? V ? /* @__PURE__ */ F(D, {
103
133
  sx: {
104
134
  flexDirection: "row",
105
135
  gap: 12
106
136
  },
107
- children: [/* @__PURE__ */ r(k, {
137
+ children: [/* @__PURE__ */ r(w, {
108
138
  fullWidth: !0,
109
- onClick: () => b("edit"),
139
+ onClick: () => v("edit"),
110
140
  variant: "outlined",
111
141
  children: e.details_edit_button
112
- }), /* @__PURE__ */ r(k, {
142
+ }), /* @__PURE__ */ r(w, {
113
143
  color: "error",
114
144
  fullWidth: !0,
115
- onClick: () => b("delete"),
145
+ onClick: () => v("delete"),
116
146
  variant: "outlined",
117
147
  children: e.details_delete_button
118
148
  })]
119
- }) : !F && m ? /* @__PURE__ */ r(k, {
149
+ }) : !V && b ? /* @__PURE__ */ r(w, {
120
150
  fullWidth: !0,
121
- onClick: () => b("create"),
151
+ onClick: () => v("create"),
122
152
  variant: "contained",
123
153
  children: e.dialog_primary_button_text
124
- }) : null : /* @__PURE__ */ r(me, {
154
+ }) : null : /* @__PURE__ */ r(ke, {
125
155
  height: 40,
126
156
  variant: "rounded"
127
- }), x = i === "delete", C = {
157
+ }), G = a === "delete", L = {
128
158
  create: {
129
159
  content: e.add_description_bottom,
130
160
  primaryText: e.dialog_primary_button_text,
@@ -141,52 +171,75 @@ var we = ne(function({ beat: _ }) {
141
171
  title: e.delete_title
142
172
  }
143
173
  };
144
- return /* @__PURE__ */ P(v, {
174
+ return /* @__PURE__ */ F(D, {
145
175
  sx: {
146
176
  bgcolor: "background.paper",
147
177
  gap: 24,
148
178
  p: 24
149
179
  },
150
180
  children: [
151
- /* @__PURE__ */ r(ae, {
181
+ /* @__PURE__ */ F(D, {
182
+ sx: {
183
+ alignItems: "center",
184
+ flexDirection: "row",
185
+ justifyContent: "space-between"
186
+ },
187
+ children: [/* @__PURE__ */ r(M, {
188
+ bold: !0,
189
+ variant: "body1",
190
+ children: ie(R, ae.MONTH_YEAR)
191
+ }), T.length > 0 && /* @__PURE__ */ r(Te, { transactions: T })]
192
+ }),
193
+ /* @__PURE__ */ r(Be, {
152
194
  budgetsCopy: e,
153
- copy: w,
154
- daysLeft: oe(_),
155
- icon: q,
156
- limit: A,
157
- spent: $
195
+ copy: O,
196
+ daysLeft: ye(g),
197
+ icon: Z,
198
+ limit: j,
199
+ spent: X
158
200
  }),
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,
201
+ re,
202
+ a && /* @__PURE__ */ r(me, {
203
+ closeAriaLabel: l.close_aria,
204
+ content: W(L[a].content, /* @__PURE__ */ r("b", { children: U })),
205
+ handleInputChange: h,
206
+ handleModalClose: P,
165
207
  handlePrimaryAction: () => {
166
- J();
208
+ te();
167
209
  },
168
- handleSecondaryAction: B,
169
- inputLabel: x ? void 0 : e.add_label,
170
- inputValue: T,
210
+ handleSecondaryAction: P,
211
+ inputLabel: G ? void 0 : e.add_label,
212
+ inputValue: p,
171
213
  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
214
+ primaryColor: G ? "error" : "primary",
215
+ primaryText: L[a].primaryText,
216
+ secondaryColor: G ? "inherit" : "primary",
217
+ secondaryText: l.cancel_button,
218
+ title: L[a].title
177
219
  }),
178
- /* @__PURE__ */ r(te, {
179
- closeAriaLabel: s.close_aria,
180
- message: y?.message ?? "",
181
- onClose: () => f(null),
182
- open: !!y,
183
- severity: y?.severity
220
+ T.length > 0 && /* @__PURE__ */ r(Le, {
221
+ sx: {
222
+ bgcolor: "background.default",
223
+ mx: -24
224
+ },
225
+ children: /* @__PURE__ */ r(ge, { transaction: T })
226
+ }),
227
+ /* @__PURE__ */ r(be, {
228
+ actionText: s?.retry ? N?.general?.try_again : void 0,
229
+ closeAriaLabel: l.close_aria,
230
+ message: s?.message ?? "",
231
+ onActionClick: () => {
232
+ s?.retry && (h(s.retry.amount), E(s.retry.action), _(null));
233
+ },
234
+ onClose: () => _(null),
235
+ open: !!s,
236
+ severity: s?.severity
184
237
  })
185
238
  ]
186
239
  });
187
240
  });
188
241
  export {
189
- we as BudgetDetailsBlock
242
+ et as BudgetDetailsBlock
190
243
  };
191
244
 
192
245
  //# sourceMappingURL=BudgetDetailsBlock.es.js.map