@mx-cartographer/experiences 9.7.176 → 9.7.178

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 (26) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/dist/core/api/SettingsApi.d.ts +6 -4
  3. package/dist/core/api/SettingsApi.es.js.map +1 -1
  4. package/dist/core/stores/SettingsStore.d.ts +2 -4
  5. package/dist/core/stores/SettingsStore.es.js +13 -8
  6. package/dist/core/stores/SettingsStore.es.js.map +1 -1
  7. package/dist/core/types/User.d.ts +2 -0
  8. package/dist/core/types/localization/SettingsCopy.d.ts +2 -0
  9. package/dist/core/utils/Fetch.d.ts +3 -1
  10. package/dist/core/utils/Fetch.es.js +28 -21
  11. package/dist/core/utils/Fetch.es.js.map +1 -1
  12. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/AmountInputModalBlock.es.js +75 -74
  13. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/AmountInputModalBlock.es.js.map +1 -1
  14. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/CreateBudgetDialog.es.js +39 -43
  15. package/dist/insights-v2/actionBlocks/AmountInputModalBlock/CreateBudgetDialog.es.js.map +1 -1
  16. package/dist/insights-v2/actionBlocks/useBlockSave.d.ts +11 -0
  17. package/dist/insights-v2/actionBlocks/useBlockSave.es.js +29 -0
  18. package/dist/insights-v2/actionBlocks/useBlockSave.es.js.map +1 -0
  19. package/dist/settings/components/profile/ProfileTab.es.js +55 -52
  20. package/dist/settings/components/profile/ProfileTab.es.js.map +1 -1
  21. package/dist/settings/components/profile/actions/ResetPasswordAction.es.js +78 -61
  22. package/dist/settings/components/profile/actions/ResetPasswordAction.es.js.map +1 -1
  23. package/dist/settings/constants/Settings.d.ts +2 -0
  24. package/dist/settings/constants/Settings.es.js +13 -11
  25. package/dist/settings/constants/Settings.es.js.map +1 -1
  26. 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 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;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;AAA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;AAAA,IAClB,qBAAA,MAAA;AAA2B,MAAK,EAAW;AAAA;AAAA,IAC3C,uBAAuB;AAAA,IACvB,YAAY,EAAY;AAAA,IACxB,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,mBAAmB,KAAY,CAAC;AAAA,IAChC,aAAa,EAAW;AAAA,IACxB,eAAe,EAAQ,YAAY,EAAW,gBAAgB;AAAA,IAC9D,UACE,EAAQ,gBAAgB,EAAK,kBAC3B,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,IACzD,MAAM,EAAQ;AAAA,EACf,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 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,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zD,MAAM,EAAQ;AAAA,EACf,CAAA;AAEL,CAAC"}
@@ -1,62 +1,58 @@
1
- import { buildDynamicCopy as C } from "../../../core/utils/Localization.es.js";
2
- import { useCategoryStore as F, useGlobalCopyStore as I, useInsightsV2Store as L } from "../../../common/context/hooks.es.js";
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 k, formatCurrency as w } from "../../../core/utils/NumberFormatting.es.js";
5
- import { getLocalizedCategoryName as M } from "../../../core/utils/CategoryUtil.es.js";
6
- import O from "../../../common/components/CurrencyDialog.es.js";
7
- import { useBeatActions as P } from "../../beatActions.es.js";
8
- import { isPositiveAmount as j, resolveBudgetFacts as E } from "../BudgetDetailsBlock/layout.es.js";
9
- import { useCtaHandler as G } from "../../ctaActions/useCtaAction.es.js";
10
- import H from "../../components/shared/StatusSnackbar.es.js";
11
- import e from "react";
12
- import { observer as V } from "mobx-react-lite";
13
- import { jsx as l, jsxs as z } from "react/jsx-runtime";
14
- var ae = V(function({ beat: n }) {
15
- const { budgets: t, categories: b, common: r, insights_feed: h } = I(), S = F(), { closeActionDrawer: s } = L(), v = G(n, P()), A = n.insights_payload, { categoryGuid: m = "" } = E(n), x = T(A?.instance_slot?.data, "average_amount") ?? 0, d = S.categories.find(({ guid: o }) => o === m), g = d ? M(d, b) : "", [c, B] = e.useState(""), [D, p] = e.useState(!0), [N, f] = e.useState(!1), [a, i] = e.useState(null), u = e.useRef(!0);
16
- e.useEffect(() => (u.current = !0, () => {
17
- u.current = !1;
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(c)
25
- }, { onSuccess: ["refreshBeat"] });
26
- u.current && (f(!1), p(!1), i(o ? "created" : "failed"));
20
+ amount: Number(r)
21
+ }, { onSuccess: ["refreshBeat"] }));
22
+ e !== void 0 && (g(!1), c(e ? "created" : "failed"));
27
23
  };
28
- return /* @__PURE__ */ z(e.Fragment, { children: [/* @__PURE__ */ l(O, {
29
- closeAriaLabel: r.close_aria,
30
- content: C(t.create_budget_content, /* @__PURE__ */ l("strong", { children: g }, "category"), w(x, k.whole)),
31
- handleInputChange: B,
32
- handleModalClose: s,
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
- R();
30
+ k();
35
31
  },
36
- handleSecondaryAction: s,
37
- inputLabel: r.amount_text,
38
- inputValue: c,
39
- isOpen: D,
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: r.cancel_button,
38
+ secondaryText: o.cancel_button,
43
39
  title: t.dialog_create_budget_title
44
- }), /* @__PURE__ */ l(H, {
45
- actionText: a === "failed" ? h?.general?.try_again : void 0,
46
- closeAriaLabel: r.close_aria,
47
- message: y(a === "created" ? t.alert_budget_created : t.alert_merchant_budget_not_created),
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
- i(null), p(!0);
45
+ c(null), g(!0);
50
46
  },
51
47
  onClose: () => {
52
- i(null), s();
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
- ae as CreateBudgetDialog
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 [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\n return () => {\n isMounted.current = false\n }\n }, [])\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 (!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, 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":";;;;;;;;;;;;;AAuBA,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/E,CAAC,GAAQ,CAAA,IAA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AC,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"}
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/E,CAAC,GAAQ,CAAA,IAAa,EAAM,SAAS,EAAE,GACvC,CAAC,GAAQ,CAAA,IAAa,EAAM,SAAS,EAAI,GACzC,CAAC,GAAQ,CAAA,IAAa,EAAM,SAAwB,IAAI,GACxD,EAAE,UAAA,GAAU,MAAA,EAAA,IAAS,EAAa,GAElC,IAAA,CAAS,MAAiB,EAAiB,GAAM,CAAY,GAE7D,IAAY,EAAiB,CAAM,KAAK,CAAC,GAEzC,IAAe,YAAY;AAC/B,QAAI,CAAC,EAAiB,CAAM,EAAG;AAE/B,UAAM,IAAK,MAAM,EAAA,MACf,EACE,gBACA;AAAA,MAAE,cAAA;AAAA,MAAc,QAAQ,OAAO,CAAM;AAAA,IAAE,GACvC,EAAE,WAAW,CAAC,aAAa,EAAE,CAC/B,CACF;AACA,IAAI,MAAO,WAEX,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,EAAgB,KAAK,CACrD;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"}
@@ -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"}
@@ -1,24 +1,24 @@
1
- import { useAppConfig as E, useGlobalCopyStore as B, useSettingsStore as M, useUserStore as L } from "../../../common/context/hooks.es.js";
2
- import { useScreenSize as R } from "../../../common/hooks/useScreenSize.es.js";
3
- import z from "../../../common/components/dialog/Dialog.es.js";
4
- import I from "./actions/ResetPasswordAction.es.js";
5
- import N from "./actions/VerifyEmailAction.es.js";
6
- import $ from "./actions/VerifyPhoneAction.es.js";
1
+ import { useAppConfig as B, useGlobalCopyStore as M, useSettingsStore as R, useUserStore as L } from "../../../common/context/hooks.es.js";
2
+ import { useScreenSize as z } from "../../../common/hooks/useScreenSize.es.js";
3
+ import I from "../../../common/components/dialog/Dialog.es.js";
4
+ import N from "./actions/ResetPasswordAction.es.js";
5
+ import $ from "./actions/VerifyEmailAction.es.js";
6
+ import j from "./actions/VerifyPhoneAction.es.js";
7
7
  import p from "react";
8
- import { observer as j } from "mobx-react-lite";
8
+ import { observer as H } from "mobx-react-lite";
9
9
  import l from "@mui/material/Stack";
10
- import { H3 as H, P as J } from "@mxenabled/mxui";
11
- import O from "@mui/material/Button";
12
- import { Fragment as G, jsx as t, jsxs as i } from "react/jsx-runtime";
13
- import { alpha as b, useTheme as K } from "@mui/material/styles";
14
- import Y from "@mui/material/Box";
15
- import { getUnixTime as q } from "date-fns/getUnixTime";
10
+ import { H3 as J, P as O } from "@mxenabled/mxui";
11
+ import G from "@mui/material/Button";
12
+ import { Fragment as K, jsx as t, jsxs as i } from "react/jsx-runtime";
13
+ import { alpha as b, useTheme as Y } from "@mui/material/styles";
14
+ import q from "@mui/material/Box";
15
+ import { getUnixTime as Q } from "date-fns/getUnixTime";
16
16
  import d from "@mui/material/TextField";
17
- import { AdapterDateFns as Q } from "@mui/x-date-pickers/AdapterDateFns";
18
- import { DatePicker as W } from "@mui/x-date-pickers";
19
- import { LocalizationProvider as X } from "@mui/x-date-pickers/LocalizationProvider";
20
- var Z = ({ availableWidth: C, handleOnLeaveClick: u }) => {
21
- const f = K(), { common: w, settings: o } = B(), { isMobile: c } = R(C), { config: h } = E(), { updateUser: S } = M(), { user: r } = L(), [a, P] = p.useState({
17
+ import { AdapterDateFns as W } from "@mui/x-date-pickers/AdapterDateFns";
18
+ import { DatePicker as X } from "@mui/x-date-pickers";
19
+ import { LocalizationProvider as Z } from "@mui/x-date-pickers/LocalizationProvider";
20
+ var ee = ({ availableWidth: w, handleOnLeaveClick: f }) => {
21
+ const u = Y(), { common: S, settings: o } = M(), { isMobile: c } = z(w), { config: h } = B(), { updateUser: P } = R(), { user: r } = L(), [a, T] = p.useState({
22
22
  first_name: r.first_name,
23
23
  last_name: r.last_name,
24
24
  email: r.email,
@@ -26,9 +26,9 @@ var Z = ({ availableWidth: C, handleOnLeaveClick: u }) => {
26
26
  birthday: r.birthday,
27
27
  postal_code: r.postal_code,
28
28
  credit_score: r.credit_score
29
- }), [m, y] = p.useState(!1), [T, g] = p.useState(!1), _ = p.useRef(null), v = a.email && !r.email_is_verified && !m, x = a.phone && !r.phone_is_verified && !m;
29
+ }), [m, y] = p.useState(!1), [U, g] = p.useState(!1), _ = p.useRef(null), v = a.email && !r.email_is_verified && !m, x = a.phone && !r.phone_is_verified && !m, C = h.display_password_options_in_settings && r.has_password !== !1;
30
30
  p.useEffect(() => {
31
- if (u) {
31
+ if (f) {
32
32
  const e = (s) => {
33
33
  _.current && !_.current.contains(s.target) && m && g(!0);
34
34
  };
@@ -37,31 +37,31 @@ var Z = ({ availableWidth: C, handleOnLeaveClick: u }) => {
37
37
  };
38
38
  }
39
39
  }, [m]);
40
- const U = () => {
40
+ const V = () => {
41
41
  if (a.birthday) {
42
- const e = /* @__PURE__ */ new Date(a.birthday * 1e3), s = e.getUTCFullYear(), F = e.getUTCMonth(), A = e.getUTCDate();
43
- return new Date(s, F, A);
42
+ const e = /* @__PURE__ */ new Date(a.birthday * 1e3), s = e.getUTCFullYear(), A = e.getUTCMonth(), E = e.getUTCDate();
43
+ return new Date(s, A, E);
44
44
  }
45
- }, V = async () => {
46
- await S({
45
+ }, k = async () => {
46
+ await P({
47
47
  ...r,
48
48
  ...a
49
49
  }), y(!1);
50
- }, k = () => {
51
- g(!1), u && u();
52
50
  }, D = () => {
51
+ g(!1), f && f();
52
+ }, F = () => {
53
53
  g(!1);
54
54
  }, n = (e) => {
55
55
  const s = {
56
56
  ...a,
57
57
  ...e
58
58
  };
59
- P(s), y(JSON.stringify({
59
+ T(s), y(JSON.stringify({
60
60
  ...r,
61
61
  ...s
62
62
  }) !== JSON.stringify(r));
63
63
  };
64
- return /* @__PURE__ */ i(G, { children: [/* @__PURE__ */ i(Y, {
64
+ return /* @__PURE__ */ i(K, { children: [/* @__PURE__ */ i(q, {
65
65
  component: "form",
66
66
  ref: _,
67
67
  sx: {
@@ -70,8 +70,8 @@ var Z = ({ availableWidth: C, handleOnLeaveClick: u }) => {
70
70
  "& .MuiTextField-root, & .MuiPickersTextField-root": { flex: 1 }
71
71
  },
72
72
  children: [
73
- /* @__PURE__ */ t(H, { children: o.personal_details }),
74
- /* @__PURE__ */ t(J, {
73
+ /* @__PURE__ */ t(J, { children: o.personal_details }),
74
+ /* @__PURE__ */ t(O, {
75
75
  variant: "body1",
76
76
  children: o.update_information
77
77
  }),
@@ -104,7 +104,7 @@ var Z = ({ availableWidth: C, handleOnLeaveClick: u }) => {
104
104
  defaultValue: a.email,
105
105
  label: o.email_address,
106
106
  onChange: (e) => n({ email: e.target.value })
107
- }), v && /* @__PURE__ */ t(N, {})]
107
+ }), v && /* @__PURE__ */ t($, {})]
108
108
  }), h.display_sms_edit_field_in_settings && /* @__PURE__ */ i(l, {
109
109
  sx: {
110
110
  flex: 1,
@@ -115,36 +115,36 @@ var Z = ({ availableWidth: C, handleOnLeaveClick: u }) => {
115
115
  label: o.mobile_number,
116
116
  onChange: (e) => n({ phone: e.target.value }),
117
117
  type: "tel"
118
- }), x && /* @__PURE__ */ t($, {})]
118
+ }), x && /* @__PURE__ */ t(j, {})]
119
119
  })]
120
120
  }),
121
121
  /* @__PURE__ */ i(l, {
122
122
  direction: c ? "column" : "row",
123
123
  spacing: 24,
124
124
  sx: { mb: 24 },
125
- children: [/* @__PURE__ */ t(X, {
126
- dateAdapter: Q,
127
- children: /* @__PURE__ */ t(W, {
125
+ children: [/* @__PURE__ */ t(Z, {
126
+ dateAdapter: W,
127
+ children: /* @__PURE__ */ t(X, {
128
128
  label: o.birthdate,
129
- onChange: (e) => n({ birthday: q(e) }),
129
+ onChange: (e) => n({ birthday: Q(e) }),
130
130
  slotProps: {
131
131
  nextIconButton: { sx: {
132
132
  color: "primary.main",
133
- "&:hover": { backgroundColor: b(f.palette.primary.light, 0.1) }
133
+ "&:hover": { backgroundColor: b(u.palette.primary.light, 0.1) }
134
134
  } },
135
135
  previousIconButton: { sx: {
136
136
  color: "primary.main",
137
- "&:hover": { backgroundColor: b(f.palette.primary.light, 0.1) }
137
+ "&:hover": { backgroundColor: b(u.palette.primary.light, 0.1) }
138
138
  } }
139
139
  },
140
140
  sx: {
141
141
  width: "100%",
142
142
  "& .MuiIconButton-edgeEnd": {
143
143
  color: "primary.main",
144
- "&:hover": { backgroundColor: b(f.palette.primary.light, 0.1) }
144
+ "&:hover": { backgroundColor: b(u.palette.primary.light, 0.1) }
145
145
  }
146
146
  },
147
- value: U()
147
+ value: V()
148
148
  })
149
149
  }), /* @__PURE__ */ t(d, {
150
150
  defaultValue: a.postal_code,
@@ -158,28 +158,31 @@ var Z = ({ availableWidth: C, handleOnLeaveClick: u }) => {
158
158
  label: o.credit_score,
159
159
  onChange: (e) => n({ credit_score: Number(e.target.value) })
160
160
  }),
161
- h.display_password_options_in_settings && /* @__PURE__ */ t(I, {}),
162
- /* @__PURE__ */ t(O, {
161
+ C && /* @__PURE__ */ t(N, {}),
162
+ /* @__PURE__ */ t(G, {
163
163
  disabled: !m,
164
- onClick: V,
165
- sx: { width: c ? "100%" : 124 },
164
+ onClick: k,
165
+ sx: {
166
+ mt: C ? 0 : 24,
167
+ width: c ? "100%" : 124
168
+ },
166
169
  variant: "contained",
167
- children: w.save_button
170
+ children: S.save_button
168
171
  })
169
172
  ] })
170
173
  ]
171
- }), /* @__PURE__ */ t(z, {
174
+ }), /* @__PURE__ */ t(I, {
172
175
  copy: { title: o.discard_changes },
173
- isOpen: T,
174
- onClose: D,
175
- onSecondaryAction: k,
176
+ isOpen: U,
177
+ onClose: F,
178
+ onSecondaryAction: D,
176
179
  primaryText: o.keep_editing,
177
180
  secondaryText: o.leave,
178
181
  children: o.discard_changes_message
179
182
  })] });
180
- }, ye = j(Z);
183
+ }, ve = H(ee);
181
184
  export {
182
- ye as default
185
+ ve as default
183
186
  };
184
187
 
185
188
  //# sourceMappingURL=ProfileTab.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ProfileTab.es.js","names":[],"sources":["../../../../src/settings/components/profile/ProfileTab.tsx"],"sourcesContent":["import React from 'react'\nimport { observer } from 'mobx-react-lite'\nimport { getUnixTime } from 'date-fns/getUnixTime'\n\nimport { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns'\nimport { DatePicker } from '@mui/x-date-pickers'\nimport { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'\n\nimport { alpha, useTheme } from '@mui/material/styles'\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Stack from '@mui/material/Stack'\nimport TextField from '@mui/material/TextField'\n\nimport { H3, P } from '@mxenabled/mxui'\n\nimport {\n useAppConfig,\n useGlobalCopyStore,\n useScreenSize,\n useSettingsStore,\n useUserStore,\n Dialog,\n} from '../../../common'\nimport { type EditableUser } from '../../../core'\nimport ResetPasswordAction from './actions/ResetPasswordAction'\nimport VerifyEmailAction from './actions/VerifyEmailAction'\nimport VerifyPhoneAction from './actions/VerifyPhoneAction'\n\ninterface ProfileFormProps {\n availableWidth?: number\n handleOnLeaveClick?: () => void\n}\n\ntype UserInput = {\n [U in keyof EditableUser]: EditableUser[U]\n}\n\nconst ProfileForm: React.FC<ProfileFormProps> = ({ availableWidth, handleOnLeaveClick }) => {\n const theme = useTheme()\n const { common: commonCopy, settings: settingsCopy } = useGlobalCopyStore()\n const { isMobile } = useScreenSize(availableWidth)\n const { config } = useAppConfig()\n const { updateUser } = useSettingsStore()\n const { user } = useUserStore()\n\n const [modifiedUser, setModifiedUser] = React.useState<EditableUser>({\n first_name: user.first_name,\n last_name: user.last_name,\n email: user.email,\n phone: user.phone,\n birthday: user.birthday,\n postal_code: user.postal_code,\n credit_score: user.credit_score,\n })\n const [hasUnsavedChanges, setHasUnsavedChanges] = React.useState(false)\n const [showLeaveDialog, setShowLeaveDialog] = React.useState(false)\n const boxRef = React.useRef<HTMLDivElement>(null)\n\n const showVerifyEmail = modifiedUser.email && !user.email_is_verified && !hasUnsavedChanges\n const showVerifyPhone = modifiedUser.phone && !user.phone_is_verified && !hasUnsavedChanges\n\n React.useEffect(() => {\n if (handleOnLeaveClick) {\n const handleClickOutside = (event: MouseEvent) => {\n if (boxRef.current && !boxRef.current.contains(event.target as Node) && hasUnsavedChanges) {\n setShowLeaveDialog(true)\n }\n }\n\n document.addEventListener('mousedown', handleClickOutside)\n return () => {\n document.removeEventListener('mousedown', handleClickOutside)\n }\n }\n return undefined\n }, [hasUnsavedChanges])\n\n // eslint-disable-next-line consistent-return\n const formatReadableBirthday = () => {\n if (modifiedUser.birthday) {\n const utc = new Date(modifiedUser.birthday * 1000)\n const year = utc.getUTCFullYear()\n const month = utc.getUTCMonth()\n const day = utc.getUTCDate()\n return new Date(year, month, day)\n }\n }\n\n const handleSave = async () => {\n await updateUser({ ...user, ...modifiedUser })\n setHasUnsavedChanges(false)\n }\n\n const handleLeaveDialog = () => {\n setShowLeaveDialog(false)\n\n if (handleOnLeaveClick) {\n handleOnLeaveClick()\n }\n }\n\n const handleKeepEditing = () => {\n setShowLeaveDialog(false)\n }\n\n const handleInput = (update: UserInput) => {\n const changedUser = {\n ...modifiedUser,\n ...update,\n }\n setModifiedUser(changedUser)\n setHasUnsavedChanges(JSON.stringify({ ...user, ...changedUser }) !== JSON.stringify(user))\n }\n\n return (\n <>\n <Box\n component=\"form\"\n ref={boxRef}\n sx={{\n backgroundColor: 'background.paper',\n p: 24,\n '& .MuiTextField-root, & .MuiPickersTextField-root': {\n flex: 1,\n },\n }}\n >\n <H3>{settingsCopy.personal_details}</H3>\n <P variant=\"body1\">{settingsCopy.update_information}</P>\n <Stack direction={isMobile ? 'column' : 'row'} spacing={24} sx={{ mb: 24, pt: 24 }}>\n <TextField\n defaultValue={modifiedUser.first_name}\n label={settingsCopy.first_name}\n onChange={(e) => handleInput({ first_name: e.target.value })}\n />\n <TextField\n defaultValue={modifiedUser.last_name}\n label={settingsCopy.last_name}\n onChange={(e) => handleInput({ last_name: e.target.value })}\n />\n </Stack>\n <Stack direction={isMobile ? 'column' : 'row'}>\n {config.display_email_edit_field_in_settings && (\n <Stack sx={{ flex: 1, mb: showVerifyEmail ? 20 : 24, mr: isMobile ? 0 : 24 }}>\n <TextField\n defaultValue={modifiedUser.email}\n label={settingsCopy.email_address}\n onChange={(e) => handleInput({ email: e.target.value })}\n />\n {showVerifyEmail && <VerifyEmailAction />}\n </Stack>\n )}\n {config.display_sms_edit_field_in_settings && (\n <Stack sx={{ flex: 1, mb: showVerifyPhone ? 20 : 24 }}>\n <TextField\n defaultValue={modifiedUser.phone}\n label={settingsCopy.mobile_number}\n onChange={(e) => handleInput({ phone: e.target.value })}\n type=\"tel\"\n />\n {showVerifyPhone && <VerifyPhoneAction />}\n </Stack>\n )}\n </Stack>\n <Stack direction={isMobile ? 'column' : 'row'} spacing={24} sx={{ mb: 24 }}>\n <LocalizationProvider dateAdapter={AdapterDateFns}>\n <DatePicker\n label={settingsCopy.birthdate}\n onChange={(value) => handleInput({ birthday: getUnixTime(value as Date) })}\n slotProps={{\n nextIconButton: {\n sx: {\n color: 'primary.main',\n '&:hover': { backgroundColor: alpha(theme.palette.primary.light, 0.1) },\n },\n },\n previousIconButton: {\n sx: {\n color: 'primary.main',\n '&:hover': { backgroundColor: alpha(theme.palette.primary.light, 0.1) },\n },\n },\n }}\n sx={{\n width: '100%',\n '& .MuiIconButton-edgeEnd': {\n color: 'primary.main',\n '&:hover': { backgroundColor: alpha(theme.palette.primary.light, 0.1) },\n },\n }}\n value={formatReadableBirthday()}\n />\n </LocalizationProvider>\n <TextField\n defaultValue={modifiedUser.postal_code}\n label={settingsCopy.zip_code}\n onChange={(e) => handleInput({ postal_code: e.target.value })}\n />\n </Stack>\n <Stack>\n <TextField\n defaultValue={modifiedUser.credit_score}\n label={settingsCopy.credit_score}\n onChange={(e) => handleInput({ credit_score: Number(e.target.value) })}\n />\n {config.display_password_options_in_settings && <ResetPasswordAction />}\n <Button\n disabled={!hasUnsavedChanges}\n onClick={handleSave}\n sx={{ width: isMobile ? '100%' : 124 }}\n variant=\"contained\"\n >\n {commonCopy.save_button}\n </Button>\n </Stack>\n </Box>\n <Dialog\n copy={{ title: settingsCopy.discard_changes }}\n isOpen={showLeaveDialog}\n onClose={handleKeepEditing}\n onSecondaryAction={handleLeaveDialog}\n primaryText={settingsCopy.keep_editing}\n secondaryText={settingsCopy.leave}\n >\n {settingsCopy.discard_changes_message}\n </Dialog>\n </>\n )\n}\n\nexport default observer(ProfileForm)\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsCA,IAAM,IAAA,CAA2C,EAAE,gBAAA,GAA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OAAO,IAAW,SAAS,IAAI;AAAA,UACrC,SAAQ;AAAA,UAEP,UAAA,EAAW;AAAA,QACN,CAAA;AAAA,MACH,EAAA,CAAA;AAAA,IACJ;AAAA,EACL,CAAA,GAAA,gBAAA,EAAC,GAAD;AAAA,IACE,MAAM,EAAE,OAAO,EAAa,gBAAgB;AAAA,IAC5C,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,mBAAmB;AAAA,IACnB,aAAa,EAAa;AAAA,IAC1B,eAAe,EAAa;AAAA,IAE3B,UAAA,EAAa;AAAA,EACR,CAAA,CACR,EAAA,CAAA;AAEN,GAEA,KAAe,EAAS,CAAW"}
1
+ {"version":3,"file":"ProfileTab.es.js","names":[],"sources":["../../../../src/settings/components/profile/ProfileTab.tsx"],"sourcesContent":["import React from 'react'\nimport { observer } from 'mobx-react-lite'\nimport { getUnixTime } from 'date-fns/getUnixTime'\n\nimport { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns'\nimport { DatePicker } from '@mui/x-date-pickers'\nimport { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'\n\nimport { alpha, useTheme } from '@mui/material/styles'\nimport Box from '@mui/material/Box'\nimport Button from '@mui/material/Button'\nimport Stack from '@mui/material/Stack'\nimport TextField from '@mui/material/TextField'\n\nimport { H3, P } from '@mxenabled/mxui'\n\nimport {\n useAppConfig,\n useGlobalCopyStore,\n useScreenSize,\n useSettingsStore,\n useUserStore,\n Dialog,\n} from '../../../common'\nimport { type EditableUser } from '../../../core'\nimport ResetPasswordAction from './actions/ResetPasswordAction'\nimport VerifyEmailAction from './actions/VerifyEmailAction'\nimport VerifyPhoneAction from './actions/VerifyPhoneAction'\n\ninterface ProfileFormProps {\n availableWidth?: number\n handleOnLeaveClick?: () => void\n}\n\ntype UserInput = {\n [U in keyof EditableUser]: EditableUser[U]\n}\n\nconst ProfileForm: React.FC<ProfileFormProps> = ({ availableWidth, handleOnLeaveClick }) => {\n const theme = useTheme()\n const { common: commonCopy, settings: settingsCopy } = useGlobalCopyStore()\n const { isMobile } = useScreenSize(availableWidth)\n const { config } = useAppConfig()\n const { updateUser } = useSettingsStore()\n const { user } = useUserStore()\n\n const [modifiedUser, setModifiedUser] = React.useState<EditableUser>({\n first_name: user.first_name,\n last_name: user.last_name,\n email: user.email,\n phone: user.phone,\n birthday: user.birthday,\n postal_code: user.postal_code,\n credit_score: user.credit_score,\n })\n const [hasUnsavedChanges, setHasUnsavedChanges] = React.useState(false)\n const [showLeaveDialog, setShowLeaveDialog] = React.useState(false)\n const boxRef = React.useRef<HTMLDivElement>(null)\n\n const showVerifyEmail = modifiedUser.email && !user.email_is_verified && !hasUnsavedChanges\n const showVerifyPhone = modifiedUser.phone && !user.phone_is_verified && !hasUnsavedChanges\n // Hidden only when the server says there is no password; a missing has_password shows it.\n const showResetPassword =\n config.display_password_options_in_settings && user.has_password !== false\n\n React.useEffect(() => {\n if (handleOnLeaveClick) {\n const handleClickOutside = (event: MouseEvent) => {\n if (boxRef.current && !boxRef.current.contains(event.target as Node) && hasUnsavedChanges) {\n setShowLeaveDialog(true)\n }\n }\n\n document.addEventListener('mousedown', handleClickOutside)\n return () => {\n document.removeEventListener('mousedown', handleClickOutside)\n }\n }\n return undefined\n }, [hasUnsavedChanges])\n\n // eslint-disable-next-line consistent-return\n const formatReadableBirthday = () => {\n if (modifiedUser.birthday) {\n const utc = new Date(modifiedUser.birthday * 1000)\n const year = utc.getUTCFullYear()\n const month = utc.getUTCMonth()\n const day = utc.getUTCDate()\n return new Date(year, month, day)\n }\n }\n\n const handleSave = async () => {\n await updateUser({ ...user, ...modifiedUser })\n setHasUnsavedChanges(false)\n }\n\n const handleLeaveDialog = () => {\n setShowLeaveDialog(false)\n\n if (handleOnLeaveClick) {\n handleOnLeaveClick()\n }\n }\n\n const handleKeepEditing = () => {\n setShowLeaveDialog(false)\n }\n\n const handleInput = (update: UserInput) => {\n const changedUser = {\n ...modifiedUser,\n ...update,\n }\n setModifiedUser(changedUser)\n setHasUnsavedChanges(JSON.stringify({ ...user, ...changedUser }) !== JSON.stringify(user))\n }\n\n return (\n <>\n <Box\n component=\"form\"\n ref={boxRef}\n sx={{\n backgroundColor: 'background.paper',\n p: 24,\n '& .MuiTextField-root, & .MuiPickersTextField-root': {\n flex: 1,\n },\n }}\n >\n <H3>{settingsCopy.personal_details}</H3>\n <P variant=\"body1\">{settingsCopy.update_information}</P>\n <Stack direction={isMobile ? 'column' : 'row'} spacing={24} sx={{ mb: 24, pt: 24 }}>\n <TextField\n defaultValue={modifiedUser.first_name}\n label={settingsCopy.first_name}\n onChange={(e) => handleInput({ first_name: e.target.value })}\n />\n <TextField\n defaultValue={modifiedUser.last_name}\n label={settingsCopy.last_name}\n onChange={(e) => handleInput({ last_name: e.target.value })}\n />\n </Stack>\n <Stack direction={isMobile ? 'column' : 'row'}>\n {config.display_email_edit_field_in_settings && (\n <Stack sx={{ flex: 1, mb: showVerifyEmail ? 20 : 24, mr: isMobile ? 0 : 24 }}>\n <TextField\n defaultValue={modifiedUser.email}\n label={settingsCopy.email_address}\n onChange={(e) => handleInput({ email: e.target.value })}\n />\n {showVerifyEmail && <VerifyEmailAction />}\n </Stack>\n )}\n {config.display_sms_edit_field_in_settings && (\n <Stack sx={{ flex: 1, mb: showVerifyPhone ? 20 : 24 }}>\n <TextField\n defaultValue={modifiedUser.phone}\n label={settingsCopy.mobile_number}\n onChange={(e) => handleInput({ phone: e.target.value })}\n type=\"tel\"\n />\n {showVerifyPhone && <VerifyPhoneAction />}\n </Stack>\n )}\n </Stack>\n <Stack direction={isMobile ? 'column' : 'row'} spacing={24} sx={{ mb: 24 }}>\n <LocalizationProvider dateAdapter={AdapterDateFns}>\n <DatePicker\n label={settingsCopy.birthdate}\n onChange={(value) => handleInput({ birthday: getUnixTime(value as Date) })}\n slotProps={{\n nextIconButton: {\n sx: {\n color: 'primary.main',\n '&:hover': { backgroundColor: alpha(theme.palette.primary.light, 0.1) },\n },\n },\n previousIconButton: {\n sx: {\n color: 'primary.main',\n '&:hover': { backgroundColor: alpha(theme.palette.primary.light, 0.1) },\n },\n },\n }}\n sx={{\n width: '100%',\n '& .MuiIconButton-edgeEnd': {\n color: 'primary.main',\n '&:hover': { backgroundColor: alpha(theme.palette.primary.light, 0.1) },\n },\n }}\n value={formatReadableBirthday()}\n />\n </LocalizationProvider>\n <TextField\n defaultValue={modifiedUser.postal_code}\n label={settingsCopy.zip_code}\n onChange={(e) => handleInput({ postal_code: e.target.value })}\n />\n </Stack>\n <Stack>\n <TextField\n defaultValue={modifiedUser.credit_score}\n label={settingsCopy.credit_score}\n onChange={(e) => handleInput({ credit_score: Number(e.target.value) })}\n />\n {showResetPassword && <ResetPasswordAction />}\n <Button\n disabled={!hasUnsavedChanges}\n onClick={handleSave}\n // Reset Password normally separates Credit Score from Save; keep the gap without it.\n sx={{ mt: showResetPassword ? 0 : 24, width: isMobile ? '100%' : 124 }}\n variant=\"contained\"\n >\n {commonCopy.save_button}\n </Button>\n </Stack>\n </Box>\n <Dialog\n copy={{ title: settingsCopy.discard_changes }}\n isOpen={showLeaveDialog}\n onClose={handleKeepEditing}\n onSecondaryAction={handleLeaveDialog}\n primaryText={settingsCopy.keep_editing}\n secondaryText={settingsCopy.leave}\n >\n {settingsCopy.discard_changes_message}\n </Dialog>\n </>\n )\n}\n\nexport default observer(ProfileForm)\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsCA,IAAM,KAAA,CAA2C,EAAE,gBAAA,GAAgB,oBAAA,EAAA,MAAyB;AAC1F,QAAM,IAAQ,EAAS,GACjB,EAAE,QAAQ,GAAY,UAAU,EAAA,IAAiB,EAAmB,GACpE,EAAE,UAAA,EAAA,IAAa,EAAc,CAAc,GAC3C,EAAE,QAAA,EAAA,IAAW,EAAa,GAC1B,EAAE,YAAA,EAAA,IAAe,EAAiB,GAClC,EAAE,MAAA,EAAA,IAAS,EAAa,GAExB,CAAC,GAAc,CAAA,IAAmB,EAAM,SAAuB;AAAA,IACnE,YAAY,EAAK;AAAA,IACjB,WAAW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