A local-first personal finance app
[Redux Toolkit Migration] modalsSlice (#4119)
Joel Jeremy Marquez0f7a1e6b9750
diff --git a/packages/desktop-client/src/components/HelpMenu.tsx b/packages/desktop-client/src/components/HelpMenu.tsxindex 8b28ccafac..428c69c727 100644--- a/packages/desktop-client/src/components/HelpMenu.tsx+++ b/packages/desktop-client/src/components/HelpMenu.tsx@@ -9,7 +9,7 @@ import { Popover } from '@actual-app/components/popover';import { SpaceBetween } from '@actual-app/components/space-between';import { useToggle } from 'usehooks-ts';-import { pushModal } from 'loot-core/client/actions/modals';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { useFeatureFlag } from '../hooks/useFeatureFlag';import { SvgHelp } from '../icons/v2/Help';@@ -83,10 +83,10 @@ export const HelpMenu = () => {openDocsForCurrentPage();break;case 'keyboard-shortcuts':- dispatch(pushModal('keyboard-shortcuts'));+ dispatch(pushModal({ modal: { name: 'keyboard-shortcuts' } }));break;case 'goal-templates':- dispatch(pushModal('goal-templates'));+ dispatch(pushModal({ modal: { name: 'goal-templates' } }));break;}};diff --git a/packages/desktop-client/src/components/ManageRules.tsx b/packages/desktop-client/src/components/ManageRules.tsxindex 7e8e9aeabe..1442850229 100644--- a/packages/desktop-client/src/components/ManageRules.tsx+++ b/packages/desktop-client/src/components/ManageRules.tsx@@ -14,8 +14,8 @@ import { Stack } from '@actual-app/components/stack';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { pushModal } from 'loot-core/client/actions/modals';import { useSchedules } from 'loot-core/client/data-hooks/schedules';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { initiallyLoadPayees } from 'loot-core/client/queries/queriesSlice';import { send } from 'loot-core/platform/client/fetch';import * as undo from 'loot-core/platform/client/undo';@@ -184,7 +184,7 @@ export function ManageRules({}if (payeeId) {- undo.setUndoState('openModal', 'manage-rules');+ undo.setUndoState('openModal', { name: 'manage-rules', options: {} });}loadData();@@ -225,11 +225,16 @@ export function ManageRules({const onEditRule = useCallback(rule => {dispatch(- pushModal('edit-rule', {- rule,- onSave: async () => {- await loadRules();- setLoading(false);+ pushModal({+ modal: {+ name: 'edit-rule',+ options: {+ rule,+ onSave: async () => {+ await loadRules();+ setLoading(false);+ },+ },},}),);@@ -258,11 +263,16 @@ export function ManageRules({};dispatch(- pushModal('edit-rule', {- rule,- onSave: async () => {- await loadRules();- setLoading(false);+ pushModal({+ modal: {+ name: 'edit-rule',+ options: {+ rule,+ onSave: async () => {+ await loadRules();+ setLoading(false);+ },+ },},}),);diff --git a/packages/desktop-client/src/components/Modals.tsx b/packages/desktop-client/src/components/Modals.tsxindex ecd7ee692b..cb32f3e7c2 100644--- a/packages/desktop-client/src/components/Modals.tsx+++ b/packages/desktop-client/src/components/Modals.tsx@@ -1,9 +1,8 @@// @ts-strict-ignoreimport React, { useEffect } from 'react';-import { useTranslation } from 'react-i18next';import { useLocation } from 'react-router-dom';-import { closeModal } from 'loot-core/client/actions';+import { closeModal } from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import * as monthUtils from 'loot-core/shared/months';@@ -12,7 +11,6 @@ import { useModalState } from '../hooks/useModalState';import { useDispatch } from '../redux';import { EditSyncAccount } from './banksync/EditSyncAccount';-import { ModalTitle, ModalHeader } from './common/Modal';import { AccountAutocompleteModal } from './modals/AccountAutocompleteModal';import { AccountMenuModal } from './modals/AccountMenuModal';import { BudgetListModal } from './modals/BudgetListModal';@@ -56,6 +54,8 @@ import { ImportYNAB4Modal } from './modals/manager/ImportYNAB4Modal';import { ImportYNAB5Modal } from './modals/manager/ImportYNAB5Modal';import { ManageRulesModal } from './modals/ManageRulesModal';import { MergeUnusedPayeesModal } from './modals/MergeUnusedPayeesModal';+import { NewCategoryGroupModal } from './modals/NewCategoryGroupModal';+import { NewCategoryModal } from './modals/NewCategoryModal';import { NotesModal } from './modals/NotesModal';import { OpenIDEnableModal } from './modals/OpenIDEnableModal';import { OutOfSyncMigrationsModal } from './modals/OutOfSyncMigrationsModal';@@ -65,7 +65,6 @@ import { PluggyAiInitialiseModal } from './modals/PluggyAiInitialiseModal';import { ScheduledTransactionMenuModal } from './modals/ScheduledTransactionMenuModal';import { SelectLinkedAccountsModal } from './modals/SelectLinkedAccountsModal';import { SimpleFinInitialiseModal } from './modals/SimpleFinInitialiseModal';-import { SingleInputModal } from './modals/SingleInputModal';import { TrackingBalanceMenuModal } from './modals/TrackingBalanceMenuModal';import { TrackingBudgetMenuModal } from './modals/TrackingBudgetMenuModal';import { TrackingBudgetMonthMenuModal } from './modals/TrackingBudgetMonthMenuModal';@@ -92,10 +91,9 @@ export function Modals() {}}, [location]);- const { t } = useTranslation();-const modals = modalStack- .map(({ name, options }) => {+ .map(modal => {+ const { name } = modal;switch (name) {case 'goal-templates':return budgetId ? <GoalTemplateModal key={name} /> : null;@@ -105,13 +103,13 @@ export function Modals() {return budgetId ? <KeyboardShortcutModal key={name} /> : null;case 'import-transactions':- return <ImportTransactionsModal key={name} options={options} />;+ return <ImportTransactionsModal key={name} {...modal.options} />;case 'add-account':return (<CreateAccountModalkey={name}- upgradingAccountId={options?.upgradingAccountId}+ upgradingAccountId={modal.options.upgradingAccountId}/>);@@ -122,9 +120,9 @@ export function Modals() {return (<CloseAccountModalkey={name}- account={options.account}- balance={options.balance}- canDelete={options.canDelete}+ account={modal.options.account}+ balance={modal.options.balance}+ canDelete={modal.options.canDelete}/>);@@ -132,9 +130,9 @@ export function Modals() {return (<SelectLinkedAccountsModalkey={name}- externalAccounts={options.accounts}- requisitionId={options.requisitionId}- syncSource={options.syncSource}+ externalAccounts={modal.options.externalAccounts}+ requisitionId={modal.options.requisitionId}+ syncSource={modal.options.syncSource}/>);@@ -142,9 +140,9 @@ export function Modals() {return (<ConfirmCategoryDeleteModalkey={name}- category={options.category}- group={options.group}- onDelete={options.onDelete}+ category={modal.options.category}+ group={modal.options.group}+ onDelete={modal.options.onDelete}/>);@@ -152,8 +150,8 @@ export function Modals() {return (<ConfirmUnlinkAccountModalkey={name}- accountName={options.accountName}- onUnlink={options.onUnlink}+ accountName={modal.options.accountName}+ onUnlink={modal.options.onUnlink}/>);@@ -161,9 +159,9 @@ export function Modals() {return (<ConfirmTransactionEditModalkey={name}- onCancel={options.onCancel}- onConfirm={options.onConfirm}- confirmReason={options.confirmReason}+ onCancel={modal.options.onCancel}+ onConfirm={modal.options.onConfirm}+ confirmReason={modal.options.confirmReason}/>);@@ -171,8 +169,8 @@ export function Modals() {return (<ConfirmTransactionDeleteModalkey={name}- message={options.message}- onConfirm={options.onConfirm}+ message={modal.options.message}+ onConfirm={modal.options.onConfirm}/>);@@ -181,20 +179,22 @@ export function Modals() {<LoadBackupModalkey={name}watchUpdates- budgetId={options.budgetId}+ budgetId={modal.options.budgetId}backupDisabled={false}/>);case 'manage-rules':- return <ManageRulesModal key={name} payeeId={options?.payeeId} />;+ return (+ <ManageRulesModal key={name} payeeId={modal.options.payeeId} />+ );case 'edit-rule':return (<EditRuleModalkey={name}- defaultRule={options.rule}- onSave={options.onSave}+ rule={modal.options.rule}+ onSave={modal.options.onSave}/>);@@ -202,8 +202,8 @@ export function Modals() {return (<MergeUnusedPayeesModalkey={name}- payeeIds={options.payeeIds}- targetPayeeId={options.targetPayeeId}+ payeeIds={modal.options.payeeIds}+ targetPayeeId={modal.options.targetPayeeId}/>);@@ -211,7 +211,7 @@ export function Modals() {return (<GoCardlessInitialiseModalkey={name}- onSuccess={options.onSuccess}+ onSuccess={modal.options.onSuccess}/>);@@ -219,41 +219,56 @@ export function Modals() {return (<SimpleFinInitialiseModalkey={name}- onSuccess={options.onSuccess}+ onSuccess={modal.options.onSuccess}/>);case 'pluggyai-init':return (- <PluggyAiInitialiseModal key={name} onSuccess={options.onSuccess} />+ <PluggyAiInitialiseModal+ key={name}+ onSuccess={modal.options.onSuccess}+ />);case 'gocardless-external-msg':return (<GoCardlessExternalMsgModalkey={name}- onMoveExternal={options.onMoveExternal}+ onMoveExternal={modal.options.onMoveExternal}onClose={() => {- options.onClose?.();+ modal.options.onClose?.();send('gocardless-poll-web-token-stop');}}- onSuccess={options.onSuccess}+ onSuccess={modal.options.onSuccess}/>);case 'create-encryption-key':- return <CreateEncryptionKeyModal key={name} options={options} />;+ return (+ <CreateEncryptionKeyModal+ key={name}+ recreate={modal.options.recreate}+ />+ );case 'fix-encryption-key':- return <FixEncryptionKeyModal key={name} options={options} />;+ return (+ <FixEncryptionKeyModal+ key={name}+ cloudFileId={modal.options.cloudFileId}+ hasExistingKey={modal.options.hasExistingKey}+ onSuccess={modal.options.onSuccess}+ />+ );case 'edit-field':return (<EditFieldModalkey={name}- name={options.name}- onSubmit={options.onSubmit}- onClose={options.onClose}+ name={modal.options.name}+ onSubmit={modal.options.onSubmit}+ onClose={modal.options.onClose}/>);@@ -261,14 +276,11 @@ export function Modals() {return (<CategoryAutocompleteModalkey={name}- autocompleteProps={{- value: null,- onSelect: options.onSelect,- categoryGroups: options.categoryGroups,- showHiddenCategories: options.showHiddenCategories,- }}- month={options.month}- onClose={options.onClose}+ onSelect={modal.options.onSelect}+ categoryGroups={modal.options.categoryGroups}+ showHiddenCategories={modal.options.showHiddenCategories}+ month={modal.options.month}+ onClose={modal.options.onClose}/>);@@ -276,12 +288,9 @@ export function Modals() {return (<AccountAutocompleteModalkey={name}- autocompleteProps={{- value: null,- onSelect: options.onSelect,- includeClosedAccounts: options.includeClosedAccounts,- }}- onClose={options.onClose}+ onSelect={modal.options.onSelect}+ includeClosedAccounts={modal.options.includeClosedAccounts}+ onClose={modal.options.onClose}/>);@@ -289,11 +298,8 @@ export function Modals() {return (<PayeeAutocompleteModalkey={name}- autocompleteProps={{- value: null,- onSelect: options.onSelect,- }}- onClose={options.onClose}+ onSelect={modal.options.onSelect}+ onClose={modal.options.onClose}/>);@@ -302,44 +308,19 @@ export function Modals() {case 'new-category':return (- <SingleInputModal+ <NewCategoryModalkey={name}- name={name}- Header={props => (- <ModalHeader- {...props}- title={- <ModalTitle title={t('New Category')} shrinkOnOverflow />- }- />- )}- inputPlaceholder={t('Category name')}- buttonText={t('Add')}- onValidate={options.onValidate}- onSubmit={options.onSubmit}+ onValidate={modal.options.onValidate}+ onSubmit={modal.options.onSubmit}/>);case 'new-category-group':return (- <SingleInputModal+ <NewCategoryGroupModalkey={name}- name={name}- Header={props => (- <ModalHeader- {...props}- title={- <ModalTitle- title={t('New Category Group')}- shrinkOnOverflow- />- }- />- )}- inputPlaceholder={t('Category group name')}- buttonText={t('Add')}- onValidate={options.onValidate}- onSubmit={options.onSubmit}+ onValidate={modal.options.onValidate}+ onSubmit={modal.options.onSubmit}/>);@@ -347,27 +328,30 @@ export function Modals() {return (<NamespaceContext.Providerkey={name}- value={monthUtils.sheetForMonth(options.month)}+ value={monthUtils.sheetForMonth(modal.options.month)}><EnvelopeBudgetSummaryModalkey={name}- month={options.month}- onBudgetAction={options.onBudgetAction}+ month={modal.options.month}+ onBudgetAction={modal.options.onBudgetAction}/></NamespaceContext.Provider>);case 'tracking-budget-summary':return (- <TrackingBudgetSummaryModal key={name} month={options.month} />+ <TrackingBudgetSummaryModal+ key={name}+ month={modal.options.month}+ />);case 'schedule-edit':return (<ScheduleDetailskey={name}- id={options?.id || null}- transaction={options?.transaction || null}+ id={modal.options.id || null}+ transaction={modal.options.transaction || null}/>);@@ -375,10 +359,10 @@ export function Modals() {return (<ScheduleLinkkey={name}- transactionIds={options?.transactionIds}- getTransaction={options?.getTransaction}- accountName={options?.accountName}- onScheduleLinked={options?.onScheduleLinked}+ transactionIds={modal.options.transactionIds}+ getTransaction={modal.options.getTransaction}+ accountName={modal.options.accountName}+ onScheduleLinked={modal.options.onScheduleLinked}/>);@@ -392,18 +376,18 @@ export function Modals() {return <PostsOfflineNotification key={name} />;case 'synced-account-edit':- return <EditSyncAccount key={name} account={options.account} />;+ return <EditSyncAccount key={name} account={modal.options.account} />;case 'account-menu':return (<AccountMenuModalkey={name}- accountId={options.accountId}- onSave={options.onSave}- onEditNotes={options.onEditNotes}- onCloseAccount={options.onCloseAccount}- onReopenAccount={options.onReopenAccount}- onClose={options.onClose}+ accountId={modal.options.accountId}+ onSave={modal.options.onSave}+ onEditNotes={modal.options.onEditNotes}+ onCloseAccount={modal.options.onCloseAccount}+ onReopenAccount={modal.options.onReopenAccount}+ onClose={modal.options.onClose}/>);@@ -411,12 +395,12 @@ export function Modals() {return (<CategoryMenuModalkey={name}- categoryId={options.categoryId}- onSave={options.onSave}- onEditNotes={options.onEditNotes}- onDelete={options.onDelete}- onToggleVisibility={options.onToggleVisibility}- onClose={options.onClose}+ categoryId={modal.options.categoryId}+ onSave={modal.options.onSave}+ onEditNotes={modal.options.onEditNotes}+ onDelete={modal.options.onDelete}+ onToggleVisibility={modal.options.onToggleVisibility}+ onClose={modal.options.onClose}/>);@@ -424,14 +408,14 @@ export function Modals() {return (<NamespaceContext.Providerkey={name}- value={monthUtils.sheetForMonth(options.month)}+ value={monthUtils.sheetForMonth(modal.options.month)}><EnvelopeBudgetMenuModal- categoryId={options.categoryId}- onUpdateBudget={options.onUpdateBudget}- onCopyLastMonthAverage={options.onCopyLastMonthAverage}- onSetMonthsAverage={options.onSetMonthsAverage}- onApplyBudgetTemplate={options.onApplyBudgetTemplate}+ categoryId={modal.options.categoryId}+ onUpdateBudget={modal.options.onUpdateBudget}+ onCopyLastMonthAverage={modal.options.onCopyLastMonthAverage}+ onSetMonthsAverage={modal.options.onSetMonthsAverage}+ onApplyBudgetTemplate={modal.options.onApplyBudgetTemplate}/></NamespaceContext.Provider>);@@ -440,14 +424,14 @@ export function Modals() {return (<NamespaceContext.Providerkey={name}- value={monthUtils.sheetForMonth(options.month)}+ value={monthUtils.sheetForMonth(modal.options.month)}><TrackingBudgetMenuModal- categoryId={options.categoryId}- onUpdateBudget={options.onUpdateBudget}- onCopyLastMonthAverage={options.onCopyLastMonthAverage}- onSetMonthsAverage={options.onSetMonthsAverage}- onApplyBudgetTemplate={options.onApplyBudgetTemplate}+ categoryId={modal.options.categoryId}+ onUpdateBudget={modal.options.onUpdateBudget}+ onCopyLastMonthAverage={modal.options.onCopyLastMonthAverage}+ onSetMonthsAverage={modal.options.onSetMonthsAverage}+ onApplyBudgetTemplate={modal.options.onApplyBudgetTemplate}/></NamespaceContext.Provider>);@@ -456,14 +440,13 @@ export function Modals() {return (<CategoryGroupMenuModalkey={name}- groupId={options.groupId}- onSave={options.onSave}- onAddCategory={options.onAddCategory}- onEditNotes={options.onEditNotes}- onSaveNotes={options.onSaveNotes}- onDelete={options.onDelete}- onToggleVisibility={options.onToggleVisibility}- onClose={options.onClose}+ groupId={modal.options.groupId}+ onSave={modal.options.onSave}+ onAddCategory={modal.options.onAddCategory}+ onEditNotes={modal.options.onEditNotes}+ onDelete={modal.options.onDelete}+ onToggleVisibility={modal.options.onToggleVisibility}+ onClose={modal.options.onClose}/>);@@ -471,9 +454,9 @@ export function Modals() {return (<NotesModalkey={name}- id={options.id}- name={options.name}- onSave={options.onSave}+ id={modal.options.id}+ name={modal.options.name}+ onSave={modal.options.onSave}/>);@@ -481,13 +464,13 @@ export function Modals() {return (<NamespaceContext.Providerkey={name}- value={monthUtils.sheetForMonth(options.month)}+ value={monthUtils.sheetForMonth(modal.options.month)}><EnvelopeBalanceMenuModal- categoryId={options.categoryId}- onCarryover={options.onCarryover}- onTransfer={options.onTransfer}- onCover={options.onCover}+ categoryId={modal.options.categoryId}+ onCarryover={modal.options.onCarryover}+ onTransfer={modal.options.onTransfer}+ onCover={modal.options.onCover}/></NamespaceContext.Provider>);@@ -496,13 +479,13 @@ export function Modals() {return (<NamespaceContext.Providerkey={name}- value={monthUtils.sheetForMonth(options.month)}+ value={monthUtils.sheetForMonth(modal.options.month)}><EnvelopeToBudgetMenuModal- onTransfer={options.onTransfer}- onCover={options.onCover}- onHoldBuffer={options.onHoldBuffer}- onResetHoldBuffer={options.onResetHoldBuffer}+ onTransfer={modal.options.onTransfer}+ onCover={modal.options.onCover}+ onHoldBuffer={modal.options.onHoldBuffer}+ onResetHoldBuffer={modal.options.onResetHoldBuffer}/></NamespaceContext.Provider>);@@ -511,11 +494,11 @@ export function Modals() {return (<NamespaceContext.Providerkey={name}- value={monthUtils.sheetForMonth(options.month)}+ value={monthUtils.sheetForMonth(modal.options.month)}><HoldBufferModal- month={options.month}- onSubmit={options.onSubmit}+ month={modal.options.month}+ onSubmit={modal.options.onSubmit}/></NamespaceContext.Provider>);@@ -524,11 +507,11 @@ export function Modals() {return (<NamespaceContext.Providerkey={name}- value={monthUtils.sheetForMonth(options.month)}+ value={monthUtils.sheetForMonth(modal.options.month)}><TrackingBalanceMenuModal- categoryId={options.categoryId}- onCarryover={options.onCarryover}+ categoryId={modal.options.categoryId}+ onCarryover={modal.options.onCarryover}/></NamespaceContext.Provider>);@@ -537,12 +520,12 @@ export function Modals() {return (<TransferModalkey={name}- title={options.title}- categoryId={options.categoryId}- month={options.month}- amount={options.amount}- onSubmit={options.onSubmit}- showToBeBudgeted={options.showToBeBudgeted}+ title={modal.options.title}+ categoryId={modal.options.categoryId}+ month={modal.options.month}+ amount={modal.options.amount}+ onSubmit={modal.options.onSubmit}+ showToBeBudgeted={modal.options.showToBeBudgeted}/>);@@ -550,11 +533,11 @@ export function Modals() {return (<CoverModalkey={name}- title={options.title}- categoryId={options.categoryId}- month={options.month}- showToBeBudgeted={options.showToBeBudgeted}- onSubmit={options.onSubmit}+ title={modal.options.title}+ categoryId={modal.options.categoryId}+ month={modal.options.month}+ showToBeBudgeted={modal.options.showToBeBudgeted}+ onSubmit={modal.options.onSubmit}/>);@@ -562,10 +545,10 @@ export function Modals() {return (<ScheduledTransactionMenuModalkey={name}- transactionId={options.transactionId}- onPost={options.onPost}- onSkip={options.onSkip}- onComplete={options.onComplete}+ transactionId={modal.options.transactionId}+ onPost={modal.options.onPost}+ onSkip={modal.options.onSkip}+ onComplete={modal.options.onComplete}/>);@@ -573,9 +556,9 @@ export function Modals() {return (<BudgetPageMenuModalkey={name}- onAddCategoryGroup={options.onAddCategoryGroup}- onToggleHiddenCategories={options.onToggleHiddenCategories}- onSwitchBudgetFile={options.onSwitchBudgetFile}+ onAddCategoryGroup={modal.options.onAddCategoryGroup}+ onToggleHiddenCategories={modal.options.onToggleHiddenCategories}+ onSwitchBudgetFile={modal.options.onSwitchBudgetFile}/>);@@ -583,12 +566,12 @@ export function Modals() {return (<NamespaceContext.Providerkey={name}- value={monthUtils.sheetForMonth(options.month)}+ value={monthUtils.sheetForMonth(modal.options.month)}><EnvelopeBudgetMonthMenuModal- month={options.month}- onBudgetAction={options.onBudgetAction}- onEditNotes={options.onEditNotes}+ month={modal.options.month}+ onBudgetAction={modal.options.onBudgetAction}+ onEditNotes={modal.options.onEditNotes}/></NamespaceContext.Provider>);@@ -597,12 +580,12 @@ export function Modals() {return (<NamespaceContext.Providerkey={name}- value={monthUtils.sheetForMonth(options.month)}+ value={monthUtils.sheetForMonth(modal.options.month)}><TrackingBudgetMonthMenuModal- month={options.month}- onBudgetAction={options.onBudgetAction}- onEditNotes={options.onEditNotes}+ month={modal.options.month}+ onBudgetAction={modal.options.onBudgetAction}+ onEditNotes={modal.options.onEditNotes}/></NamespaceContext.Provider>);@@ -610,15 +593,15 @@ export function Modals() {case 'budget-list':return <BudgetListModal key={name} />;case 'delete-budget':- return <DeleteFileModal key={name} file={options.file} />;+ return <DeleteFileModal key={name} file={modal.options.file} />;case 'duplicate-budget':return (<DuplicateFileModalkey={name}- file={options.file}- managePage={options?.managePage}- loadBudget={options?.loadBudget}- onComplete={options?.onComplete}+ file={modal.options.file}+ managePage={modal.options.managePage}+ loadBudget={modal.options.loadBudget}+ onComplete={modal.options.onComplete}/>);case 'import':@@ -629,8 +612,8 @@ export function Modals() {return (<ConfirmChangeDocumentDirModalkey={name}- currentBudgetDirectory={options.currentBudgetDirectory}- newDirectory={options.newDirectory}+ currentBudgetDirectory={modal.options.currentBudgetDirectory}+ newDirectory={modal.options.newDirectory}/>);case 'import-ynab4':@@ -639,15 +622,7 @@ export function Modals() {return <ImportYNAB5Modal key={name} />;case 'import-actual':return <ImportActualModal key={name} />;- case 'manager-load-backup':- return (- <LoadBackupModal- key={name}- budgetId={options.budgetId}- backupDisabled={true}- watchUpdates={false}- />- );+case 'out-of-sync-migrations':return <OutOfSyncMigrationsModal key={name} />;@@ -655,8 +630,8 @@ export function Modals() {return (<EditUserAccesskey={name}- defaultUserAccess={options.access}- onSave={options.onSave}+ access={modal.options.access}+ onSave={modal.options.onSave}/>);@@ -664,19 +639,21 @@ export function Modals() {return (<EditUserFinanceAppkey={name}- defaultUser={options.user}- onSave={options.onSave}+ user={modal.options.user}+ onSave={modal.options.onSave}/>);case 'transfer-ownership':- return <TransferOwnership key={name} onSave={options.onSave} />;+ return <TransferOwnership key={name} onSave={modal.options.onSave} />;case 'enable-openid':- return <OpenIDEnableModal key={name} onSave={options.onSave} />;+ return <OpenIDEnableModal key={name} onSave={modal.options.onSave} />;case 'enable-password-auth':- return <PasswordEnableModal key={name} onSave={options.onSave} />;+ return (+ <PasswordEnableModal key={name} onSave={modal.options.onSave} />+ );default:throw new Error('Unknown modal');diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsxindex cb291091ac..a2eef55e14 100644--- a/packages/desktop-client/src/components/accounts/Account.tsx+++ b/packages/desktop-client/src/components/accounts/Account.tsx@@ -18,18 +18,18 @@ import { t } from 'i18next';import { v4 as uuidv4 } from 'uuid';import { unlinkAccount } from 'loot-core/client/accounts/accountsSlice';-import {- addNotification,- openAccountCloseModal,- pushModal,- replaceModal,-} from 'loot-core/client/actions';+import { addNotification } from 'loot-core/client/actions';import { syncAndDownload } from 'loot-core/client/app/appSlice';import { useFilters } from 'loot-core/client/data-hooks/filters';import {SchedulesProvider,accountSchedulesQuery,} from 'loot-core/client/data-hooks/schedules';+import {+ openAccountCloseModal,+ pushModal,+ replaceModal,+} from 'loot-core/client/modals/modalsSlice';import * as queries from 'loot-core/client/queries';import {createPayee,@@ -655,13 +655,18 @@ class AccountInternal extends PureComponent<if (res) {if (accountId && res?.length > 0) {this.props.dispatch(- pushModal('import-transactions', {- accountId,- filename: res[0],- onImported: (didChange: boolean) => {- if (didChange) {- this.fetchTransactions();- }+ pushModal({+ modal: {+ name: 'import-transactions',+ options: {+ accountId,+ filename: res[0],+ onImported: (didChange: boolean) => {+ if (didChange) {+ this.fetchTransactions();+ }+ },+ },},}),);@@ -823,23 +828,33 @@ class AccountInternal extends PureComponent<switch (item) {case 'link':this.props.dispatch(- pushModal('add-account', {- upgradingAccountId: accountId,+ pushModal({+ modal: {+ name: 'add-account',+ options: {+ upgradingAccountId: accountId,+ },+ },}),);break;case 'unlink':this.props.dispatch(- pushModal('confirm-unlink-account', {- accountName: account.name,- onUnlink: () => {- this.props.dispatch(unlinkAccount({ id: accountId }));+ pushModal({+ modal: {+ name: 'confirm-unlink-account',+ options: {+ accountName: account.name,+ onUnlink: () => {+ this.props.dispatch(unlinkAccount({ id: accountId }));+ },+ },},}),);break;case 'close':- this.props.dispatch(openAccountCloseModal(accountId));+ this.props.dispatch(openAccountCloseModal({ accountId }));break;case 'reopen':this.props.dispatch(reopenAccount({ id: accountId }));@@ -1245,11 +1260,16 @@ class AccountInternal extends PureComponent<const transactions = ungroupTransactions(data);if (transactions.length > 0) {this.props.dispatch(- pushModal('confirm-transaction-edit', {- onConfirm: () => {- onConfirm(ids);+ pushModal({+ modal: {+ name: 'confirm-transaction-edit',+ options: {+ onConfirm: () => {+ onConfirm(ids);+ },+ confirmReason,+ },},- confirmReason,}),);} else {@@ -1346,7 +1366,9 @@ class AccountInternal extends PureComponent<],} satisfies NewRuleEntity;- this.props.dispatch(pushModal('edit-rule', { rule }));+ this.props.dispatch(+ pushModal({ modal: { name: 'edit-rule', options: { rule } } }),+ );};onSetTransfer = async (ids: string[]) => {@@ -1845,7 +1867,11 @@ class AccountInternal extends PureComponent<showEmptyMessage ? (<EmptyMessageonAdd={() =>- this.props.dispatch(replaceModal('add-account'))+ this.props.dispatch(+ replaceModal({+ modal: { name: 'add-account', options: {} },+ }),+ )}/>) : !loading ? (diff --git a/packages/desktop-client/src/components/admin/UserAccess/UserAccess.tsx b/packages/desktop-client/src/components/admin/UserAccess/UserAccess.tsxindex 64996f470a..296e4ff66a 100644--- a/packages/desktop-client/src/components/admin/UserAccess/UserAccess.tsx+++ b/packages/desktop-client/src/components/admin/UserAccess/UserAccess.tsx@@ -14,7 +14,8 @@ import { Button } from '@actual-app/components/button';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { addNotification, pushModal } from 'loot-core/client/actions';+import { addNotification } from 'loot-core/client/actions';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import * as undo from 'loot-core/platform/client/undo';import { type Handlers } from 'loot-core/types/handlers';@@ -280,8 +281,13 @@ function LockToggle({ style, onToggleSave }: LockToggleProps) {aria-label="Menu"onPress={() =>dispatch(- pushModal('transfer-ownership', {- onSave: () => onToggleSave(),+ pushModal({+ modal: {+ name: 'transfer-ownership',+ options: {+ onSave: () => onToggleSave(),+ },+ },}),)}diff --git a/packages/desktop-client/src/components/admin/UserDirectory/UserDirectory.tsx b/packages/desktop-client/src/components/admin/UserDirectory/UserDirectory.tsxindex 7734107940..76a9fee3ee 100644--- a/packages/desktop-client/src/components/admin/UserDirectory/UserDirectory.tsx+++ b/packages/desktop-client/src/components/admin/UserDirectory/UserDirectory.tsx@@ -16,7 +16,7 @@ import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';import { addNotification, signOut } from 'loot-core/client/actions';-import { pushModal } from 'loot-core/client/actions/modals';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import * as undo from 'loot-core/platform/client/undo';import {@@ -204,11 +204,16 @@ function UserDirectoryContent({const onEditUser = useCallback(user => {dispatch(- pushModal('edit-user', {- user,- onSave: async () => {- await loadUsers();- setLoading(false);+ pushModal({+ modal: {+ name: 'edit-user',+ options: {+ user,+ onSave: async () => {+ await loadUsers();+ setLoading(false);+ },+ },},}),);@@ -225,11 +230,16 @@ function UserDirectoryContent({};dispatch(- pushModal('edit-user', {- user,- onSave: async () => {- await loadUsers();- setLoading(false);+ pushModal({+ modal: {+ name: 'edit-user',+ options: {+ user,+ onSave: async () => {+ await loadUsers();+ setLoading(false);+ },+ },},}),);diff --git a/packages/desktop-client/src/components/banksync/index.tsx b/packages/desktop-client/src/components/banksync/index.tsxindex 6eb1b8f3d2..4cd735e210 100644--- a/packages/desktop-client/src/components/banksync/index.tsx+++ b/packages/desktop-client/src/components/banksync/index.tsx@@ -4,7 +4,7 @@ import { Trans, useTranslation } from 'react-i18next';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { pushModal } from 'loot-core/src/client/actions/modals';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import {type BankSyncProviders,type AccountEntity,@@ -81,13 +81,25 @@ export function BankSync() {switch (action) {case 'edit':dispatch(- pushModal('synced-account-edit', {- account,+ pushModal({+ modal: {+ name: 'synced-account-edit',+ options: {+ account,+ },+ },}),);break;case 'link':- dispatch(pushModal('add-account', { upgradingAccountId: account.id }));+ dispatch(+ pushModal({+ modal: {+ name: 'add-account',+ options: { upgradingAccountId: account.id },+ },+ }),+ );break;default:break;diff --git a/packages/desktop-client/src/components/budget/goals/CategoryAutomationButton.tsx b/packages/desktop-client/src/components/budget/goals/CategoryAutomationButton.tsxindex 9aee1625b3..eef3b77930 100644--- a/packages/desktop-client/src/components/budget/goals/CategoryAutomationButton.tsx+++ b/packages/desktop-client/src/components/budget/goals/CategoryAutomationButton.tsx@@ -3,7 +3,7 @@ import React, { type CSSProperties } from 'react';import { Button } from '@actual-app/components/button';import { theme } from '@actual-app/components/theme';-import { pushModal } from 'loot-core/client/actions';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { type Template } from 'loot-core/server/budget/types/templates';import { useFeatureFlag } from '../../../hooks/useFeatureFlag';@@ -45,7 +45,7 @@ export function CategoryAutomationButton({...(hasAutomations && { display: 'flex !important' }),}}onPress={() => {- dispatch(pushModal('category-automations-edit'));+ dispatch(pushModal({ modal: { name: 'category-automations-edit' } }));}}><SvgChartPie style={{ width, height, flexShrink: 0 }} />diff --git a/packages/desktop-client/src/components/budget/index.tsx b/packages/desktop-client/src/components/budget/index.tsxindex e62b0de395..a3e7c54ec0 100644--- a/packages/desktop-client/src/components/budget/index.tsx+++ b/packages/desktop-client/src/components/budget/index.tsx@@ -5,7 +5,8 @@ import { useTranslation } from 'react-i18next';import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';-import { addNotification, pushModal } from 'loot-core/client/actions';+import { addNotification } from 'loot-core/client/actions';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import {applyBudgetAction,createCategory,@@ -191,12 +192,19 @@ function BudgetInner(props: BudgetInnerProps) {if (mustTransfer) {dispatch(- pushModal('confirm-category-delete', {- category: id,- onDelete: transferCategory => {- if (id !== transferCategory) {- dispatch(deleteCategory({ id, transferId: transferCategory }));- }+ pushModal({+ modal: {+ name: 'confirm-category-delete',+ options: {+ category: id,+ onDelete: transferCategory => {+ if (id !== transferCategory) {+ dispatch(+ deleteCategory({ id, transferId: transferCategory }),+ );+ }+ },+ },},}),);@@ -226,10 +234,15 @@ function BudgetInner(props: BudgetInnerProps) {if (mustTransfer) {dispatch(- pushModal('confirm-category-delete', {- group: id,- onDelete: transferCategory => {- dispatch(deleteGroup({ id, transferId: transferCategory }));+ pushModal({+ modal: {+ name: 'confirm-category-delete',+ options: {+ group: id,+ onDelete: transferCategory => {+ dispatch(deleteGroup({ id, transferId: transferCategory }));+ },+ },},}),);diff --git a/packages/desktop-client/src/components/manager/BudgetList.tsx b/packages/desktop-client/src/components/manager/BudgetList.tsxindex 754658fc85..9fab55ac19 100644--- a/packages/desktop-client/src/components/manager/BudgetList.tsx+++ b/packages/desktop-client/src/components/manager/BudgetList.tsx@@ -15,7 +15,7 @@ import { Text } from '@actual-app/components/text';import { Tooltip } from '@actual-app/components/tooltip';import { View } from '@actual-app/components/view';-import { getUserData, pushModal } from 'loot-core/client/actions';+import { getUserData } from 'loot-core/client/actions';import {closeAndDownloadBudget,closeAndLoadBudget,@@ -24,6 +24,7 @@ import {loadAllFiles,loadBudget,} from 'loot-core/client/budgets/budgetsSlice';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import {isElectron,isNonProductionEnvironment,@@ -591,7 +592,9 @@ export function BudgetList({ showHeader = true, quickSwitchMode = false }) {<BudgetListHeaderquickSwitchMode={quickSwitchMode}onRefresh={refresh}- onOpenSettings={() => dispatch(pushModal('files-settings'))}+ onOpenSettings={() =>+ dispatch(pushModal({ modal: { name: 'files-settings' } }))+ }/>)}<BudgetFiles@@ -600,11 +603,20 @@ export function BudgetList({ showHeader = true, quickSwitchMode = false }) {quickSwitchMode={quickSwitchMode}onSelect={onSelect}onDelete={(file: File) =>- dispatch(pushModal('delete-budget', { file }))+ dispatch(+ pushModal({ modal: { name: 'delete-budget', options: { file } } }),+ )}onDuplicate={(file: File) => {if (file && 'id' in file) {- dispatch(pushModal('duplicate-budget', { file, managePage: true }));+ dispatch(+ pushModal({+ modal: {+ name: 'duplicate-budget',+ options: { file, managePage: true },+ },+ }),+ );} else {console.error('Attempted to duplicate a cloud file - only local files are supported. Cloud file:',@@ -630,7 +642,7 @@ export function BudgetList({ showHeader = true, quickSwitchMode = false }) {color: theme.pageTextLight,}}onPress={() => {- dispatch(pushModal('import'));+ dispatch(pushModal({ modal: { name: 'import' } }));}}><Trans>Import file</Trans>diff --git a/packages/desktop-client/src/components/manager/WelcomeScreen.tsx b/packages/desktop-client/src/components/manager/WelcomeScreen.tsxindex a493e6cbda..f7ad15fcb3 100644--- a/packages/desktop-client/src/components/manager/WelcomeScreen.tsx+++ b/packages/desktop-client/src/components/manager/WelcomeScreen.tsx@@ -7,8 +7,8 @@ import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { pushModal } from 'loot-core/client/actions';import { createBudget } from 'loot-core/client/budgets/budgetsSlice';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { useDispatch } from '../../redux';import { theme } from '../../style';@@ -82,7 +82,9 @@ export function WelcomeScreen() {flexShrink: 0,}}>- <Button onPress={() => dispatch(pushModal('import'))}>+ <Button+ onPress={() => dispatch(pushModal({ modal: { name: 'import' } }))}+ >{t('Import my budget')}</Button><Viewdiff --git a/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx b/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsxindex c28ebc0032..dcdc939ddf 100644--- a/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx+++ b/packages/desktop-client/src/components/mobile/accounts/AccountTransactions.tsx@@ -12,11 +12,6 @@ import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import {- collapseModals,- openAccountCloseModal,- pushModal,-} from 'loot-core/client/actions';import { syncAndDownload } from 'loot-core/client/app/appSlice';import {accountSchedulesQuery,@@ -26,6 +21,11 @@ import {useTransactions,useTransactionsSearch,} from 'loot-core/client/data-hooks/transactions';+import {+ collapseModals,+ openAccountCloseModal,+ pushModal,+} from 'loot-core/client/modals/modalsSlice';import * as queries from 'loot-core/client/queries';import {markAccountRead,@@ -127,10 +127,15 @@ function AccountHeader({ account }: { readonly account: AccountEntity }) {const onEditNotes = useCallback((id: string) => {dispatch(- pushModal('notes', {- id: `account-${id}`,- name: account.name,- onSave: onSaveNotes,+ pushModal({+ modal: {+ name: 'notes',+ options: {+ id: `account-${id}`,+ name: account.name,+ onSave: onSaveNotes,+ },+ },}),);},@@ -138,7 +143,7 @@ function AccountHeader({ account }: { readonly account: AccountEntity }) {);const onCloseAccount = useCallback(() => {- dispatch(openAccountCloseModal(account.id));+ dispatch(openAccountCloseModal({ accountId: account.id }));}, [account.id, dispatch]);const onReopenAccount = useCallback(() => {@@ -147,12 +152,17 @@ function AccountHeader({ account }: { readonly account: AccountEntity }) {const onClick = useCallback(() => {dispatch(- pushModal('account-menu', {- accountId: account.id,- onSave,- onEditNotes,- onCloseAccount,- onReopenAccount,+ pushModal({+ modal: {+ name: 'account-menu',+ options: {+ accountId: account.id,+ onSave,+ onEditNotes,+ onCloseAccount,+ onReopenAccount,+ },+ },}),);}, [@@ -298,24 +308,41 @@ function TransactionListWithPreviews({navigate(`/transactions/${transaction.id}`);} else {dispatch(- pushModal('scheduled-transaction-menu', {- transactionId: transaction.id,- onPost: async transactionId => {- const parts = transactionId.split('/');- await send('schedule/post-transaction', { id: parts[1] });- dispatch(collapseModals('scheduled-transaction-menu'));- },- onSkip: async transactionId => {- const parts = transactionId.split('/');- await send('schedule/skip-next-date', { id: parts[1] });- dispatch(collapseModals('scheduled-transaction-menu'));- },- onComplete: async transactionId => {- const parts = transactionId.split('/');- await send('schedule/update', {- schedule: { id: parts[1], completed: true },- });- dispatch(collapseModals('scheduled-transaction-menu'));+ pushModal({+ modal: {+ name: 'scheduled-transaction-menu',+ options: {+ transactionId: transaction.id,+ onPost: async transactionId => {+ const parts = transactionId.split('/');+ await send('schedule/post-transaction', { id: parts[1] });+ dispatch(+ collapseModals({+ rootModalName: 'scheduled-transaction-menu',+ }),+ );+ },+ onSkip: async transactionId => {+ const parts = transactionId.split('/');+ await send('schedule/skip-next-date', { id: parts[1] });+ dispatch(+ collapseModals({+ rootModalName: 'scheduled-transaction-menu',+ }),+ );+ },+ onComplete: async transactionId => {+ const parts = transactionId.split('/');+ await send('schedule/update', {+ schedule: { id: parts[1], completed: true },+ });+ dispatch(+ collapseModals({+ rootModalName: 'scheduled-transaction-menu',+ }),+ );+ },+ },},}),);diff --git a/packages/desktop-client/src/components/mobile/accounts/Accounts.tsx b/packages/desktop-client/src/components/mobile/accounts/Accounts.tsxindex ae0b3b4ed6..8c72ef1ffa 100644--- a/packages/desktop-client/src/components/mobile/accounts/Accounts.tsx+++ b/packages/desktop-client/src/components/mobile/accounts/Accounts.tsx@@ -8,8 +8,8 @@ import { TextOneLine } from '@actual-app/components/text-one-line';import { View } from '@actual-app/components/view';import { css } from '@emotion/css';-import { replaceModal } from 'loot-core/client/actions';import { syncAndDownload } from 'loot-core/client/app/appSlice';+import { replaceModal } from 'loot-core/client/modals/modalsSlice';import * as queries from 'loot-core/client/queries';import { type AccountEntity } from 'loot-core/types/models';@@ -323,7 +323,7 @@ export function Accounts() {);const onAddAccount = useCallback(() => {- dispatch(replaceModal('add-account'));+ dispatch(replaceModal({ modal: { name: 'add-account', options: {} } }));}, [dispatch]);const onSync = useCallback(async () => {diff --git a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsxindex 7d95c695f7..48e888c5f3 100644--- a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx+++ b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx@@ -11,7 +11,7 @@ import { css } from '@emotion/css';import { AutoTextSize } from 'auto-text-size';import memoizeOne from 'memoize-one';-import { collapseModals, pushModal } from 'loot-core/client/actions';+import { collapseModals, pushModal } from 'loot-core/client/modals/modalsSlice';import {envelopeBudget,trackingBudget,@@ -242,50 +242,55 @@ function BudgetCell({const onOpenCategoryBudgetMenu = () => {dispatch(- pushModal(categoryBudgetMenuModal, {- categoryId: category.id,- month,- onUpdateBudget: amount => {- onBudgetAction(month, 'budget-amount', {- category: category.id,- amount,- });- showUndoNotification({- message: `${category.name} budget has been updated to ${integerToCurrency(amount)}.`,- });- },- onCopyLastMonthAverage: () => {- onBudgetAction(month, 'copy-single-last', {- category: category.id,- });- showUndoNotification({- message: `${category.name} budget has been set last to month’s budgeted amount.`,- });- },- onSetMonthsAverage: numberOfMonths => {- if (- numberOfMonths !== 3 &&- numberOfMonths !== 6 &&- numberOfMonths !== 12- ) {- return;- }+ pushModal({+ modal: {+ name: categoryBudgetMenuModal,+ options: {+ categoryId: category.id,+ month,+ onUpdateBudget: amount => {+ onBudgetAction(month, 'budget-amount', {+ category: category.id,+ amount,+ });+ showUndoNotification({+ message: `${category.name} budget has been updated to ${integerToCurrency(amount)}.`,+ });+ },+ onCopyLastMonthAverage: () => {+ onBudgetAction(month, 'copy-single-last', {+ category: category.id,+ });+ showUndoNotification({+ message: `${category.name} budget has been set last to month’s budgeted amount.`,+ });+ },+ onSetMonthsAverage: numberOfMonths => {+ if (+ numberOfMonths !== 3 &&+ numberOfMonths !== 6 &&+ numberOfMonths !== 12+ ) {+ return;+ }- onBudgetAction(month, `set-single-${numberOfMonths}-avg`, {- category: category.id,- });- showUndoNotification({- message: `${category.name} budget has been set to ${numberOfMonths === 12 ? 'yearly' : `${numberOfMonths} month`} average.`,- });- },- onApplyBudgetTemplate: () => {- onBudgetAction(month, 'apply-single-category-template', {- category: category.id,- });- showUndoNotification({- message: `${category.name} budget templates have been applied.`,- pre: categoryNotes,- });+ onBudgetAction(month, `set-single-${numberOfMonths}-avg`, {+ category: category.id,+ });+ showUndoNotification({+ message: `${category.name} budget has been set to ${numberOfMonths === 12 ? 'yearly' : `${numberOfMonths} month`} average.`,+ });+ },+ onApplyBudgetTemplate: () => {+ onBudgetAction(month, 'apply-single-category-template', {+ category: category.id,+ });+ showUndoNotification({+ message: `${category.name} budget templates have been applied.`,+ pre: categoryNotes,+ });+ },+ },},}),);@@ -423,7 +428,9 @@ const ExpenseCategory = memo(function ExpenseCategory({category: category.id,flag: carryover,});- dispatch(collapseModals(`${modalBudgetType}-balance-menu`));+ dispatch(+ collapseModals({ rootModalName: `${modalBudgetType}-balance-menu` }),+ );},[modalBudgetType, category.id, dispatch, month, onBudgetAction],);@@ -444,23 +451,32 @@ const ExpenseCategory = memo(function ExpenseCategory({const onTransfer = useCallback(() => {dispatch(- pushModal('transfer', {- title: category.name,- categoryId: category.id,- month,- amount: catBalance,- onSubmit: (amount, toCategoryId) => {- onBudgetAction(month, 'transfer-category', {- amount,- from: category.id,- to: toCategoryId,- });- dispatch(collapseModals(`${modalBudgetType}-balance-menu`));- showUndoNotification({- message: `Transferred ${integerToCurrency(amount)} from ${category.name} to ${categoriesById[toCategoryId].name}.`,- });+ pushModal({+ modal: {+ name: 'transfer',+ options: {+ title: category.name,+ categoryId: category.id,+ month,+ amount: catBalance,+ onSubmit: (amount, toCategoryId) => {+ onBudgetAction(month, 'transfer-category', {+ amount,+ from: category.id,+ to: toCategoryId,+ });+ dispatch(+ collapseModals({+ rootModalName: `${modalBudgetType}-balance-menu`,+ }),+ );+ showUndoNotification({+ message: `Transferred ${integerToCurrency(amount)} from ${category.name} to ${categoriesById[toCategoryId].name}.`,+ });+ },+ showToBeBudgeted: true,+ },},- showToBeBudgeted: true,}),);}, [@@ -477,25 +493,34 @@ const ExpenseCategory = memo(function ExpenseCategory({const onCover = useCallback(() => {dispatch(- pushModal('cover', {- title: category.name,- month,- categoryId: category.id,- onSubmit: fromCategoryId => {- onBudgetAction(month, 'cover-overspending', {- to: category.id,- from: fromCategoryId,- });- dispatch(collapseModals(`${modalBudgetType}-balance-menu`));- showUndoNotification({- message: t(- `Covered {{toCategoryName}} overspending from {{fromCategoryName}}.`,- {- toCategoryName: category.name,- fromCategoryName: categoriesById[fromCategoryId].name,- },- ),- });+ pushModal({+ modal: {+ name: 'cover',+ options: {+ title: category.name,+ month,+ categoryId: category.id,+ onSubmit: fromCategoryId => {+ onBudgetAction(month, 'cover-overspending', {+ to: category.id,+ from: fromCategoryId,+ });+ dispatch(+ collapseModals({+ rootModalName: `${modalBudgetType}-balance-menu`,+ }),+ );+ showUndoNotification({+ message: t(+ `Covered {{toCategoryName}} overspending from {{fromCategoryName}}.`,+ {+ toCategoryName: category.name,+ fromCategoryName: categoriesById[fromCategoryId].name,+ },+ ),+ });+ },+ },},}),);@@ -513,11 +538,16 @@ const ExpenseCategory = memo(function ExpenseCategory({const onOpenBalanceMenu = useCallback(() => {dispatch(- pushModal(`${modalBudgetType}-balance-menu`, {- categoryId: category.id,- month,- onCarryover,- ...(budgetType === 'rollover' && { onTransfer, onCover }),+ pushModal({+ modal: {+ name: `${modalBudgetType}-balance-menu`,+ options: {+ categoryId: category.id,+ month,+ onCarryover,+ ...(budgetType === 'rollover' && { onTransfer, onCover }),+ },+ },}),);}, [diff --git a/packages/desktop-client/src/components/mobile/budget/index.tsx b/packages/desktop-client/src/components/mobile/budget/index.tsxindex 498da1e1d4..41b3fd5781 100644--- a/packages/desktop-client/src/components/mobile/budget/index.tsx+++ b/packages/desktop-client/src/components/mobile/budget/index.tsx@@ -3,8 +3,8 @@ import React, { useCallback, useEffect, useState } from 'react';import { View } from '@actual-app/components/view';-import { collapseModals, pushModal } from 'loot-core/client/actions';import { sync } from 'loot-core/client/app/appSlice';+import { collapseModals, pushModal } from 'loot-core/client/modals/modalsSlice';import {applyBudgetAction,createCategory,@@ -79,15 +79,25 @@ export function Budget() {const onShowBudgetSummary = useCallback(() => {if (budgetType === 'report') {dispatch(- pushModal('tracking-budget-summary', {- month: startMonth,+ pushModal({+ modal: {+ name: 'tracking-budget-summary',+ options: {+ month: startMonth,+ },+ },}),);} else {dispatch(- pushModal('envelope-budget-summary', {- month: startMonth,- onBudgetAction,+ pushModal({+ modal: {+ name: 'envelope-budget-summary',+ options: {+ month: startMonth,+ onBudgetAction,+ },+ },}),);}@@ -95,11 +105,16 @@ export function Budget() {const onOpenNewCategoryGroupModal = useCallback(() => {dispatch(- pushModal('new-category-group', {- onValidate: name => (!name ? 'Name is required.' : null),- onSubmit: async name => {- dispatch(collapseModals('budget-page-menu'));- dispatch(createGroup({ name }));+ pushModal({+ modal: {+ name: 'new-category-group',+ options: {+ onValidate: name => (!name ? 'Name is required.' : null),+ onSubmit: async name => {+ dispatch(collapseModals({ rootModalName: 'budget-page-menu' }));+ dispatch(createGroup({ name }));+ },+ },},}),);@@ -108,13 +123,20 @@ export function Budget() {const onOpenNewCategoryModal = useCallback((groupId, isIncome) => {dispatch(- pushModal('new-category', {- onValidate: name => (!name ? 'Name is required.' : null),- onSubmit: async name => {- dispatch(collapseModals('category-group-menu'));- dispatch(- createCategory({ name, groupId, isIncome, isHidden: false }),- );+ pushModal({+ modal: {+ name: 'new-category',+ options: {+ onValidate: name => (!name ? 'Name is required.' : null),+ onSubmit: async name => {+ dispatch(+ collapseModals({ rootModalName: 'category-group-menu' }),+ );+ dispatch(+ createCategory({ name, groupId, isIncome, isHidden: false }),+ );+ },+ },},}),);@@ -147,18 +169,25 @@ export function Budget() {if (mustTransfer) {dispatch(- pushModal('confirm-category-delete', {- group: groupId,- onDelete: transferCategory => {- dispatch(collapseModals('category-group-menu'));- dispatch(- deleteGroup({ id: groupId, transferId: transferCategory }),- );+ pushModal({+ modal: {+ name: 'confirm-category-delete',+ options: {+ group: groupId,+ onDelete: transferCategory => {+ dispatch(+ collapseModals({ rootModalName: 'category-group-menu' }),+ );+ dispatch(+ deleteGroup({ id: groupId, transferId: transferCategory }),+ );+ },+ },},}),);} else {- dispatch(collapseModals('category-group-menu'));+ dispatch(collapseModals({ rootModalName: 'category-group-menu' }));dispatch(deleteGroup({ id: groupId }));}},@@ -172,7 +201,7 @@ export function Budget() {...group,hidden: !!!group.hidden,});- dispatch(collapseModals('category-group-menu'));+ dispatch(collapseModals({ rootModalName: 'category-group-menu' }));},[categoryGroups, dispatch, onSaveGroup],);@@ -192,23 +221,30 @@ export function Budget() {if (mustTransfer) {dispatch(- pushModal('confirm-category-delete', {- category: categoryId,- onDelete: transferCategory => {- if (categoryId !== transferCategory) {- dispatch(collapseModals('category-menu'));- dispatch(- deleteCategory({- id: categoryId,- transferId: transferCategory,- }),- );- }+ pushModal({+ modal: {+ name: 'confirm-category-delete',+ options: {+ category: categoryId,+ onDelete: transferCategory => {+ if (categoryId !== transferCategory) {+ dispatch(+ collapseModals({ rootModalName: 'category-menu' }),+ );+ dispatch(+ deleteCategory({+ id: categoryId,+ transferId: transferCategory,+ }),+ );+ }+ },+ },},}),);} else {- dispatch(collapseModals('category-menu'));+ dispatch(collapseModals({ rootModalName: 'category-menu' }));dispatch(deleteCategory({ id: categoryId }));}},@@ -222,7 +258,7 @@ export function Budget() {...category,hidden: !!!category.hidden,});- dispatch(collapseModals('category-menu'));+ dispatch(collapseModals({ rootModalName: 'category-menu' }));},[categories, dispatch, onSaveCategory],);@@ -340,10 +376,15 @@ export function Budget() {id => {const group = categoryGroups.find(g => g.id === id);dispatch(- pushModal('notes', {- id,- name: group.name,- onSave: onSaveNotes,+ pushModal({+ modal: {+ name: 'notes',+ options: {+ id,+ name: group.name,+ onSave: onSaveNotes,+ },+ },}),);},@@ -354,10 +395,15 @@ export function Budget() {id => {const category = categories.find(c => c.id === id);dispatch(- pushModal('notes', {- id,- name: category.name,- onSave: onSaveNotes,+ pushModal({+ modal: {+ name: 'notes',+ options: {+ id,+ name: category.name,+ onSave: onSaveNotes,+ },+ },}),);},@@ -368,13 +414,18 @@ export function Budget() {id => {const group = categoryGroups.find(g => g.id === id);dispatch(- pushModal('category-group-menu', {- groupId: group.id,- onSave: onSaveGroup,- onAddCategory: onOpenNewCategoryModal,- onEditNotes: onOpenCategoryGroupNotesModal,- onDelete: onDeleteGroup,- onToggleVisibility: onToggleGroupVisibility,+ pushModal({+ modal: {+ name: 'category-group-menu',+ options: {+ groupId: group.id,+ onSave: onSaveGroup,+ onAddCategory: onOpenNewCategoryModal,+ onEditNotes: onOpenCategoryGroupNotesModal,+ onDelete: onDeleteGroup,+ onToggleVisibility: onToggleGroupVisibility,+ },+ },}),);},@@ -393,20 +444,23 @@ export function Budget() {id => {const category = categories.find(c => c.id === id);dispatch(- pushModal('category-menu', {- categoryId: category.id,- onSave: onSaveCategory,- onEditNotes: onOpenCategoryNotesModal,- onDelete: onDeleteCategory,- onToggleVisibility: onToggleCategoryVisibility,- onBudgetAction,+ pushModal({+ modal: {+ name: 'category-menu',+ options: {+ categoryId: category.id,+ onSave: onSaveCategory,+ onEditNotes: onOpenCategoryNotesModal,+ onDelete: onDeleteCategory,+ onToggleVisibility: onToggleCategoryVisibility,+ },+ },}),);},[categories,dispatch,- onBudgetAction,onDeleteCategory,onOpenCategoryNotesModal,onSaveCategory,@@ -420,16 +474,21 @@ export function Budget() {const onToggleHiddenCategories = useCallback(() => {setShowHiddenCategoriesPref(!showHiddenCategories);- dispatch(collapseModals('budget-page-menu'));+ dispatch(collapseModals({ rootModalName: 'budget-page-menu' }));}, [dispatch, setShowHiddenCategoriesPref, showHiddenCategories]);const onOpenBudgetMonthNotesModal = useCallback(month => {dispatch(- pushModal('notes', {- id: `budget-${month}`,- name: monthUtils.format(month, 'MMMM ‘yy'),- onSave: onSaveNotes,+ pushModal({+ modal: {+ name: 'notes',+ options: {+ id: `budget-${month}`,+ name: monthUtils.format(month, 'MMMM ‘yy'),+ onSave: onSaveNotes,+ },+ },}),);},@@ -437,20 +496,22 @@ export function Budget() {);const onSwitchBudgetFile = useCallback(() => {- dispatch(pushModal('budget-list'));+ dispatch(pushModal({ modal: { name: 'budget-list' } }));}, [dispatch]);const onOpenBudgetMonthMenu = useCallback(month => {dispatch(- pushModal(- `${budgetType === 'report' ? 'tracking' : 'envelope'}-budget-month-menu`,- {- month,- onBudgetAction,- onEditNotes: onOpenBudgetMonthNotesModal,+ pushModal({+ modal: {+ name: `${budgetType === 'report' ? 'tracking' : 'envelope'}-budget-month-menu`,+ options: {+ month,+ onBudgetAction,+ onEditNotes: onOpenBudgetMonthNotesModal,+ },},- ),+ }),);},[budgetType, dispatch, onBudgetAction, onOpenBudgetMonthNotesModal],@@ -458,10 +519,15 @@ export function Budget() {const onOpenBudgetPageMenu = useCallback(() => {dispatch(- pushModal('budget-page-menu', {- onAddCategoryGroup: onOpenNewCategoryGroupModal,- onToggleHiddenCategories,- onSwitchBudgetFile,+ pushModal({+ modal: {+ name: 'budget-page-menu',+ options: {+ onAddCategoryGroup: onOpenNewCategoryGroupModal,+ onToggleHiddenCategories,+ onSwitchBudgetFile,+ },+ },}),);}, [diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsxindex e0f15d20db..e3ceef8a32 100644--- a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.jsx@@ -22,7 +22,7 @@ import {} from 'date-fns';import { UAParser } from 'ua-parser-js';-import { pushModal } from 'loot-core/client/actions';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { setLastTransaction } from 'loot-core/client/queries/queriesSlice';import { runQuery } from 'loot-core/client/query-helpers';import { send } from 'loot-core/platform/client/fetch';@@ -559,9 +559,14 @@ const TransactionEditInner = memo(function TransactionEditInner({// Should we bring that here as well? Or does the nature of the editing form// make this more appropriate?dispatch(- pushModal('confirm-transaction-edit', {- onConfirm: onConfirmSave,- confirmReason: 'editReconciled',+ pushModal({+ modal: {+ name: 'confirm-transaction-edit',+ options: {+ onConfirm: onConfirmSave,+ confirmReason: 'editReconciled',+ },+ },}),);} else {@@ -603,52 +608,76 @@ const TransactionEditInner = memo(function TransactionEditInner({switch (name) {case 'category':dispatch(- pushModal('category-autocomplete', {- categoryGroups,- month: monthUtils.monthFromDate(unserializedTransaction.date),- onSelect: categoryId => {- onUpdateInner(transactionToEdit, name, categoryId);- },- onClose: () => {- onClearActiveEdit();+ pushModal({+ modal: {+ name: 'category-autocomplete',+ options: {+ categoryGroups,+ month: monthUtils.monthFromDate(+ unserializedTransaction.date,+ ),+ onSelect: categoryId => {+ onUpdateInner(transactionToEdit, name, categoryId);+ },+ onClose: () => {+ onClearActiveEdit();+ },+ },},}),);break;case 'account':dispatch(- pushModal('account-autocomplete', {- onSelect: accountId => {- onUpdateInner(transactionToEdit, name, accountId);- },- onClose: () => {- onClearActiveEdit();+ pushModal({+ modal: {+ name: 'account-autocomplete',+ options: {+ onSelect: accountId => {+ onUpdateInner(transactionToEdit, name, accountId);+ },+ onClose: () => {+ onClearActiveEdit();+ },+ },},}),);break;case 'payee':dispatch(- pushModal('payee-autocomplete', {- onSelect: payeeId => {- onUpdateInner(transactionToEdit, name, payeeId);- },- onClose: () => {- onClearActiveEdit();+ pushModal({+ modal: {+ name: 'payee-autocomplete',+ options: {+ onSelect: payeeId => {+ onUpdateInner(transactionToEdit, name, payeeId);+ },+ onClose: () => {+ onClearActiveEdit();+ },+ },},}),);break;default:dispatch(- pushModal('edit-field', {- name,- month: monthUtils.monthFromDate(unserializedTransaction.date),- onSubmit: (name, value) => {- onUpdateInner(transactionToEdit, name, value);- },- onClose: () => {- onClearActiveEdit();+ pushModal({+ modal: {+ name: 'edit-field',+ options: {+ name,+ month: monthUtils.monthFromDate(+ unserializedTransaction.date,+ ),+ onSubmit: (name, value) => {+ onUpdateInner(transactionToEdit, name, value);+ },+ onClose: () => {+ onClearActiveEdit();+ },+ },},}),);@@ -674,17 +703,22 @@ const TransactionEditInner = memo(function TransactionEditInner({const onConfirmDelete = () => {dispatch(- pushModal('confirm-transaction-delete', {- onConfirm: () => {- onDelete(id);-- if (unserializedTransaction.id !== id) {- // Only a child transaction was deleted.- onClearActiveEdit();- return;- }-- navigate(-1);+ pushModal({+ modal: {+ name: 'confirm-transaction-delete',+ options: {+ onConfirm: () => {+ onDelete(id);++ if (unserializedTransaction.id !== id) {+ // Only a child transaction was deleted.+ onClearActiveEdit();+ return;+ }++ navigate(-1);+ },+ },},}),);@@ -692,9 +726,14 @@ const TransactionEditInner = memo(function TransactionEditInner({if (unserializedTransaction.reconciled) {dispatch(- pushModal('confirm-transaction-edit', {- onConfirm: onConfirmDelete,- confirmReason: 'deleteReconciled',+ pushModal({+ modal: {+ name: 'confirm-transaction-edit',+ options: {+ onConfirm: onConfirmDelete,+ confirmReason: 'deleteReconciled',+ },+ },}),);} else {diff --git a/packages/desktop-client/src/components/modals/AccountAutocompleteModal.tsx b/packages/desktop-client/src/components/modals/AccountAutocompleteModal.tsxindex bfb9a0691a..a3aa10db41 100644--- a/packages/desktop-client/src/components/modals/AccountAutocompleteModal.tsx+++ b/packages/desktop-client/src/components/modals/AccountAutocompleteModal.tsx@@ -1,8 +1,10 @@-import React, { type ComponentPropsWithoutRef } from 'react';+import React from 'react';import { useTranslation } from 'react-i18next';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';+import { theme } from '../../style';import { AccountAutocomplete } from '../autocomplete/AccountAutocomplete';import {@@ -14,13 +16,14 @@ import {import { SectionLabel } from '../forms';import { useResponsive } from '../responsive/ResponsiveProvider';-type AccountAutocompleteModalProps = {- autocompleteProps: ComponentPropsWithoutRef<typeof AccountAutocomplete>;- onClose: () => void;-};+type AccountAutocompleteModalProps = Extract<+ ModalType,+ { name: 'account-autocomplete' }+>['options'];export function AccountAutocompleteModal({- autocompleteProps,+ onSelect,+ includeClosedAccounts,onClose,}: AccountAutocompleteModalProps) {const { t } = useTranslation();@@ -79,7 +82,9 @@ export function AccountAutocompleteModal({closeOnBlur={false}onClose={close}{...defaultAutocompleteProps}- {...autocompleteProps}+ onSelect={onSelect}+ includeClosedAccounts={includeClosedAccounts}+ value={null}/></View></View>diff --git a/packages/desktop-client/src/components/modals/AccountMenuModal.tsx b/packages/desktop-client/src/components/modals/AccountMenuModal.tsxindex b36318ea86..5edbabb905 100644--- a/packages/desktop-client/src/components/modals/AccountMenuModal.tsx+++ b/packages/desktop-client/src/components/modals/AccountMenuModal.tsx@@ -13,6 +13,7 @@ import { Popover } from '@actual-app/components/popover';import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { type AccountEntity } from 'loot-core/types/models';import { useAccount } from '../../hooks/useAccount';@@ -30,14 +31,10 @@ import {import { Notes } from '../Notes';import { validateAccountName } from '../util/accountValidation';-type AccountMenuModalProps = {- accountId: string;- onSave: (account: AccountEntity) => void;- onCloseAccount: (accountId: string) => void;- onReopenAccount: (accountId: string) => void;- onEditNotes: (id: string) => void;- onClose?: () => void;-};+type AccountMenuModalProps = Extract<+ ModalType,+ { name: 'account-menu' }+>['options'];export function AccountMenuModal({accountId,diff --git a/packages/desktop-client/src/components/modals/BudgetPageMenuModal.tsx b/packages/desktop-client/src/components/modals/BudgetPageMenuModal.tsxindex 733076afda..5b080f15eb 100644--- a/packages/desktop-client/src/components/modals/BudgetPageMenuModal.tsx+++ b/packages/desktop-client/src/components/modals/BudgetPageMenuModal.tsx@@ -7,11 +7,16 @@ import { useTranslation } from 'react-i18next';import { Menu } from '@actual-app/components/menu';import { styles } from '@actual-app/components/styles';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';+import { useLocalPref } from '../../hooks/useLocalPref';import { theme } from '../../style';import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';-type BudgetPageMenuModalProps = ComponentPropsWithoutRef<typeof BudgetPageMenu>;+type BudgetPageMenuModalProps = Extract<+ ModalType,+ { name: 'budget-page-menu' }+>['options'];export function BudgetPageMenuModal({onAddCategoryGroup,diff --git a/packages/desktop-client/src/components/modals/CategoryAutocompleteModal.tsx b/packages/desktop-client/src/components/modals/CategoryAutocompleteModal.tsxindex 7ff32ed670..16d9b371e1 100644--- a/packages/desktop-client/src/components/modals/CategoryAutocompleteModal.tsx+++ b/packages/desktop-client/src/components/modals/CategoryAutocompleteModal.tsx@@ -1,8 +1,9 @@-import React, { type ComponentPropsWithoutRef } from 'react';+import React from 'react';import { useTranslation } from 'react-i18next';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import * as monthUtils from 'loot-core/shared/months';import { theme } from '../../style';@@ -17,15 +18,16 @@ import { SectionLabel } from '../forms';import { useResponsive } from '../responsive/ResponsiveProvider';import { NamespaceContext } from '../spreadsheet/NamespaceContext';-type CategoryAutocompleteModalProps = {- autocompleteProps: ComponentPropsWithoutRef<typeof CategoryAutocomplete>;- onClose: () => void;- month?: string;-};+type CategoryAutocompleteModalProps = Extract<+ ModalType,+ { name: 'category-autocomplete' }+>['options'];export function CategoryAutocompleteModal({- autocompleteProps,month,+ onSelect,+ categoryGroups,+ showHiddenCategories,onClose,}: CategoryAutocompleteModalProps) {const { t } = useTranslation();@@ -89,7 +91,10 @@ export function CategoryAutocompleteModal({showSplitOption={false}onClose={close}{...defaultAutocompleteProps}- {...autocompleteProps}+ onSelect={onSelect}+ categoryGroups={categoryGroups}+ showHiddenCategories={showHiddenCategories}+ value={null}/></NamespaceContext.Provider></View>diff --git a/packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsx b/packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsxindex f502a62f41..26ab06caf9 100644--- a/packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsx+++ b/packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsx@@ -13,7 +13,7 @@ import { Popover } from '@actual-app/components/popover';import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';-import { type CategoryGroupEntity } from 'loot-core/types/models';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { useCategories } from '../../hooks/useCategories';import { useNotes } from '../../hooks/useNotes';@@ -28,16 +28,10 @@ import {} from '../common/Modal';import { Notes } from '../Notes';-type CategoryGroupMenuModalProps = {- groupId: string;- onSave: (group: CategoryGroupEntity) => void;- onAddCategory: (groupId: string, isIncome: boolean) => void;- onEditNotes: (id: string) => void;- onSaveNotes: (id: string, notes: string) => void;- onDelete: (groupId: string) => void;- onToggleVisibility: (groupId: string) => void;- onClose?: () => void;-};+type CategoryGroupMenuModalProps = Extract<+ ModalType,+ { name: 'category-group-menu' }+>['options'];export function CategoryGroupMenuModal({groupId,diff --git a/packages/desktop-client/src/components/modals/CategoryMenuModal.tsx b/packages/desktop-client/src/components/modals/CategoryMenuModal.tsxindex 2a238c8c5c..55047c75c6 100644--- a/packages/desktop-client/src/components/modals/CategoryMenuModal.tsx+++ b/packages/desktop-client/src/components/modals/CategoryMenuModal.tsx@@ -8,7 +8,7 @@ import { Popover } from '@actual-app/components/popover';import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';-import { type CategoryEntity } from 'loot-core/types/models';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { useCategory } from '../../hooks/useCategory';import { useCategoryGroup } from '../../hooks/useCategoryGroup';@@ -24,14 +24,10 @@ import {} from '../common/Modal';import { Notes } from '../Notes';-type CategoryMenuModalProps = {- categoryId: string;- onSave: (category: CategoryEntity) => void;- onEditNotes: (categoryId: string) => void;- onDelete: (categoryId: string) => void;- onToggleVisibility: (categoryId: string) => void;- onClose?: () => void;-};+type CategoryMenuModalProps = Extract<+ ModalType,+ { name: 'category-menu' }+>['options'];export function CategoryMenuModal({categoryId,diff --git a/packages/desktop-client/src/components/modals/CloseAccountModal.tsx b/packages/desktop-client/src/components/modals/CloseAccountModal.tsxindex cc698bb636..3174e02736 100644--- a/packages/desktop-client/src/components/modals/CloseAccountModal.tsx+++ b/packages/desktop-client/src/components/modals/CloseAccountModal.tsx@@ -10,7 +10,10 @@ import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { pushModal } from 'loot-core/client/actions';+import {+ type Modal as ModalType,+ pushModal,+} from 'loot-core/client/modals/modalsSlice';import { closeAccount } from 'loot-core/client/queries/queriesSlice';import { integerToCurrency } from 'loot-core/shared/util';import { type AccountEntity } from 'loot-core/types/models';@@ -39,11 +42,10 @@ function needsCategory(return account.offbudget === 0 && isOffBudget;}-type CloseAccountModalProps = {- account: AccountEntity;- balance: number;- canDelete: boolean;-};+type CloseAccountModalProps = Extract<+ ModalType,+ { name: 'close-account' }+>['options'];export function CloseAccountModal({account,@@ -183,9 +185,14 @@ export function CloseAccountModal({},onClick: () => {dispatch(- pushModal('account-autocomplete', {- includeClosedAccounts: false,- onSelect: onSelectAccount,+ pushModal({+ modal: {+ name: 'account-autocomplete',+ options: {+ includeClosedAccounts: false,+ onSelect: onSelectAccount,+ },+ },}),);},@@ -223,10 +230,15 @@ export function CloseAccountModal({},onClick: () => {dispatch(- pushModal('category-autocomplete', {- categoryGroups,- showHiddenCategories: true,- onSelect: onSelectCategory,+ pushModal({+ modal: {+ name: 'category-autocomplete',+ options: {+ categoryGroups,+ showHiddenCategories: true,+ onSelect: onSelectCategory,+ },+ },}),);},diff --git a/packages/desktop-client/src/components/modals/ConfirmCategoryDeleteModal.tsx b/packages/desktop-client/src/components/modals/ConfirmCategoryDeleteModal.tsxindex 145366f626..618a28e6ad 100644--- a/packages/desktop-client/src/components/modals/ConfirmCategoryDeleteModal.tsx+++ b/packages/desktop-client/src/components/modals/ConfirmCategoryDeleteModal.tsx@@ -8,21 +8,22 @@ import { Text } from '@actual-app/components/text';import { theme } from '@actual-app/components/theme';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';+import { useCategories } from '../../hooks/useCategories';import { CategoryAutocomplete } from '../autocomplete/CategoryAutocomplete';import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';-type ConfirmCategoryDeleteProps = {- category: string;- group: string;- onDelete: (categoryId: string) => void;-};+type ConfirmCategoryDeleteModalProps = Extract<+ ModalType,+ { name: 'confirm-category-delete' }+>['options'];export function ConfirmCategoryDeleteModal({group: groupId,category: categoryId,onDelete,-}: ConfirmCategoryDeleteProps) {+}: ConfirmCategoryDeleteModalProps) {const { t } = useTranslation(); // Initialize translation hookconst [transferCategory, setTransferCategory] = useState<string | null>(null);const [error, setError] = useState<string | null>(null);diff --git a/packages/desktop-client/src/components/modals/ConfirmTransactionDeleteModal.tsx b/packages/desktop-client/src/components/modals/ConfirmTransactionDeleteModal.tsxindex 0acaea9cca..9766915f89 100644--- a/packages/desktop-client/src/components/modals/ConfirmTransactionDeleteModal.tsx+++ b/packages/desktop-client/src/components/modals/ConfirmTransactionDeleteModal.tsx@@ -7,18 +7,20 @@ import { Paragraph } from '@actual-app/components/paragraph';import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';+import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { useResponsive } from '../responsive/ResponsiveProvider';-type ConfirmTransactionDeleteProps = {- message?: string;- onConfirm: () => void;-};+type ConfirmTransactionDeleteModalProps = Extract<+ ModalType,+ { name: 'confirm-transaction-delete' }+>['options'];export function ConfirmTransactionDeleteModal({message = 'Are you sure you want to delete the transaction?',onConfirm,-}: ConfirmTransactionDeleteProps) {+}: ConfirmTransactionDeleteModalProps) {const { t } = useTranslation();const { isNarrowWidth } = useResponsive();const narrowButtonStyle = isNarrowWidthdiff --git a/packages/desktop-client/src/components/modals/ConfirmTransactionEditModal.tsx b/packages/desktop-client/src/components/modals/ConfirmTransactionEditModal.tsxindex 72af36bca5..3fbc8e8d4f 100644--- a/packages/desktop-client/src/components/modals/ConfirmTransactionEditModal.tsx+++ b/packages/desktop-client/src/components/modals/ConfirmTransactionEditModal.tsx@@ -7,19 +7,20 @@ import { Button } from '@actual-app/components/button';import { InitialFocus } from '@actual-app/components/initial-focus';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';+import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';-type ConfirmTransactionEditProps = {- onCancel?: () => void;- onConfirm: () => void;- confirmReason: string;-};+type ConfirmTransactionEditModalProps = Extract<+ ModalType,+ { name: 'confirm-transaction-edit' }+>['options'];export function ConfirmTransactionEditModal({onCancel,onConfirm,confirmReason,-}: ConfirmTransactionEditProps) {+}: ConfirmTransactionEditModalProps) {const { t } = useTranslation();return (diff --git a/packages/desktop-client/src/components/modals/ConfirmUnlinkAccountModal.tsx b/packages/desktop-client/src/components/modals/ConfirmUnlinkAccountModal.tsxindex a3ed1078ad..ab5062c779 100644--- a/packages/desktop-client/src/components/modals/ConfirmUnlinkAccountModal.tsx+++ b/packages/desktop-client/src/components/modals/ConfirmUnlinkAccountModal.tsx@@ -6,17 +6,19 @@ import { InitialFocus } from '@actual-app/components/initial-focus';import { Paragraph } from '@actual-app/components/paragraph';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';+import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';-type ConfirmUnlinkAccountProps = {- accountName: string;- onUnlink: () => void;-};+type ConfirmUnlinkAccountModalProps = Extract<+ ModalType,+ { name: 'confirm-unlink-account' }+>['options'];export function ConfirmUnlinkAccountModal({accountName,onUnlink,-}: ConfirmUnlinkAccountProps) {+}: ConfirmUnlinkAccountModalProps) {const { t } = useTranslation();return (diff --git a/packages/desktop-client/src/components/modals/CoverModal.tsx b/packages/desktop-client/src/components/modals/CoverModal.tsxindex 0c0de7ddc4..65511dcee2 100644--- a/packages/desktop-client/src/components/modals/CoverModal.tsx+++ b/packages/desktop-client/src/components/modals/CoverModal.tsx@@ -5,8 +5,10 @@ import { Button } from '@actual-app/components/button';import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';-import { pushModal } from 'loot-core/client/actions';-import { type CategoryEntity } from 'loot-core/types/models';+import {+ type Modal as ModalType,+ pushModal,+} from 'loot-core/client/modals/modalsSlice';import { useCategories } from '../../hooks/useCategories';import { useDispatch } from '../../redux';@@ -17,13 +19,7 @@ import {import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { FieldLabel, TapField } from '../mobile/MobileForms';-type CoverModalProps = {- title: string;- categoryId?: CategoryEntity['id'];- month: string;- showToBeBudgeted?: boolean;- onSubmit: (categoryId: CategoryEntity['id']) => void;-};+type CoverModalProps = Extract<ModalType, { name: 'cover' }>['options'];export function CoverModal({title,@@ -54,11 +50,16 @@ export function CoverModal({const onCategoryClick = useCallback(() => {dispatch(- pushModal('category-autocomplete', {- categoryGroups,- month,- onSelect: categoryId => {- setFromCategoryId(categoryId);+ pushModal({+ modal: {+ name: 'category-autocomplete',+ options: {+ categoryGroups,+ month,+ onSelect: categoryId => {+ setFromCategoryId(categoryId);+ },+ },},}),);diff --git a/packages/desktop-client/src/components/modals/CreateAccountModal.tsx b/packages/desktop-client/src/components/modals/CreateAccountModal.tsxindex f027847c53..a395736d1a 100644--- a/packages/desktop-client/src/components/modals/CreateAccountModal.tsx+++ b/packages/desktop-client/src/components/modals/CreateAccountModal.tsx@@ -10,7 +10,11 @@ import { Popover } from '@actual-app/components/popover';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { addNotification, pushModal } from 'loot-core/client/actions';+import { addNotification } from 'loot-core/client/actions';+import {+ type Modal as ModalType,+ pushModal,+} from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import { useAuth } from '../../auth/AuthProvider';@@ -29,11 +33,14 @@ import { Link } from '../common/Link';import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { useMultiuserEnabled } from '../ServerContext';-type CreateAccountProps = {- upgradingAccountId?: string;-};+type CreateAccountModalProps = Extract<+ ModalType,+ { name: 'add-account' }+>['options'];-export function CreateAccountModal({ upgradingAccountId }: CreateAccountProps) {+export function CreateAccountModal({+ upgradingAccountId,+}: CreateAccountModalProps) {const { t } = useTranslation();const isPluggyAiEnabled = useFeatureFlag('pluggyAiBankSync');@@ -108,16 +115,26 @@ export function CreateAccountModal({ upgradingAccountId }: CreateAccountProps) {}dispatch(- pushModal('select-linked-accounts', {- accounts: newAccounts,- syncSource: 'simpleFin',+ pushModal({+ modal: {+ name: 'select-linked-accounts',+ options: {+ externalAccounts: newAccounts,+ syncSource: 'simpleFin',+ },+ },}),);} catch (err) {console.error(err);dispatch(- pushModal('simplefin-init', {- onSuccess: () => setIsSimpleFinSetupComplete(true),+ pushModal({+ modal: {+ name: 'simplefin-init',+ options: {+ onSuccess: () => setIsSimpleFinSetupComplete(true),+ },+ },}),);}@@ -168,9 +185,14 @@ export function CreateAccountModal({ upgradingAccountId }: CreateAccountProps) {}dispatch(- pushModal('select-linked-accounts', {- accounts: newAccounts,- syncSource: 'pluggyai',+ pushModal({+ modal: {+ name: 'select-linked-accounts',+ options: {+ externalAccounts: newAccounts,+ syncSource: 'pluggyai',+ },+ },}),);} catch (err) {@@ -182,8 +204,13 @@ export function CreateAccountModal({ upgradingAccountId }: CreateAccountProps) {timeout: 5000,});dispatch(- pushModal('pluggyai-init', {- onSuccess: () => setIsPluggyAiSetupComplete(true),+ pushModal({+ modal: {+ name: 'pluggyai-init',+ options: {+ onSuccess: () => setIsPluggyAiSetupComplete(true),+ },+ },}),);}@@ -191,24 +218,39 @@ export function CreateAccountModal({ upgradingAccountId }: CreateAccountProps) {const onGoCardlessInit = () => {dispatch(- pushModal('gocardless-init', {- onSuccess: () => setIsGoCardlessSetupComplete(true),+ pushModal({+ modal: {+ name: 'gocardless-init',+ options: {+ onSuccess: () => setIsGoCardlessSetupComplete(true),+ },+ },}),);};const onSimpleFinInit = () => {dispatch(- pushModal('simplefin-init', {- onSuccess: () => setIsSimpleFinSetupComplete(true),+ pushModal({+ modal: {+ name: 'simplefin-init',+ options: {+ onSuccess: () => setIsSimpleFinSetupComplete(true),+ },+ },}),);};const onPluggyAiInit = () => {dispatch(- pushModal('pluggyai-init', {- onSuccess: () => setIsPluggyAiSetupComplete(true),+ pushModal({+ modal: {+ name: 'pluggyai-init',+ options: {+ onSuccess: () => setIsPluggyAiSetupComplete(true),+ },+ },}),);};@@ -261,7 +303,7 @@ export function CreateAccountModal({ upgradingAccountId }: CreateAccountProps) {};const onCreateLocalAccount = () => {- dispatch(pushModal('add-local-account'));+ dispatch(pushModal({ modal: { name: 'add-local-account' } }));};const { configuredGoCardless } = useGoCardlessStatus();diff --git a/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx b/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsxindex 8f58ba70a0..9e7abb77e4 100644--- a/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx+++ b/packages/desktop-client/src/components/modals/CreateEncryptionKeyModal.tsx@@ -14,6 +14,7 @@ import { css } from '@emotion/css';import { loadGlobalPrefs } from 'loot-core/client/actions';import { sync } from 'loot-core/client/app/appSlice';import { loadAllFiles } from 'loot-core/client/budgets/budgetsSlice';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import { getCreateKeyError } from 'loot-core/shared/errors';@@ -29,14 +30,13 @@ import {} from '../common/Modal';import { useResponsive } from '../responsive/ResponsiveProvider';-type CreateEncryptionKeyModalProps = {- options: {- recreate?: boolean;- };-};+type CreateEncryptionKeyModalProps = Extract<+ ModalType,+ { name: 'create-encryption-key' }+>['options'];export function CreateEncryptionKeyModal({- options = {},+ recreate,}: CreateEncryptionKeyModalProps) {const { t } = useTranslation();const [password, setPassword] = useState('');@@ -46,7 +46,7 @@ export function CreateEncryptionKeyModal({const { isNarrowWidth } = useResponsive();const dispatch = useDispatch();- const isRecreating = options.recreate;+ const isRecreating = recreate;async function onCreateKey(close: () => void) {if (password !== '' && !loading) {diff --git a/packages/desktop-client/src/components/modals/CreateLocalAccountModal.tsx b/packages/desktop-client/src/components/modals/CreateLocalAccountModal.tsxindex 7cf6ee4711..d0163d6231 100644--- a/packages/desktop-client/src/components/modals/CreateLocalAccountModal.tsx+++ b/packages/desktop-client/src/components/modals/CreateLocalAccountModal.tsx@@ -10,7 +10,7 @@ import { InlineField } from '@actual-app/components/inline-field';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { closeModal } from 'loot-core/client/actions';+import { closeModal } from 'loot-core/client/modals/modalsSlice';import { createAccount } from 'loot-core/client/queries/queriesSlice';import { toRelaxedNumber } from 'loot-core/shared/util';diff --git a/packages/desktop-client/src/components/modals/EditAccess.tsx b/packages/desktop-client/src/components/modals/EditAccess.tsxindex 197c8dd3c2..bec438003b 100644--- a/packages/desktop-client/src/components/modals/EditAccess.tsx+++ b/packages/desktop-client/src/components/modals/EditAccess.tsx@@ -7,10 +7,13 @@ import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { addNotification, popModal, signOut } from 'loot-core/client/actions';+import { addNotification, signOut } from 'loot-core/client/actions';+import {+ type Modal as ModalType,+ popModal,+} from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import { getUserAccessErrors } from 'loot-core/shared/errors';-import { type UserAccessEntity } from 'loot-core/types/models/userAccess';import { useDispatch } from '../../redux';import { theme } from '../../style';@@ -18,13 +21,13 @@ import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { Select } from '../common/Select';import { FormField, FormLabel } from '../forms';-type EditUserAccessProps = {- defaultUserAccess: UserAccessEntity;- onSave?: (userAccess: UserAccessEntity) => void;-};+type EditUserAccessProps = Extract<+ ModalType,+ { name: 'edit-access' }+>['options'];export function EditUserAccess({- defaultUserAccess,+ access: defaultUserAccess,onSave: originalOnSave,}: EditUserAccessProps) {const { t } = useTranslation();diff --git a/packages/desktop-client/src/components/modals/EditFieldModal.tsx b/packages/desktop-client/src/components/modals/EditFieldModal.tsxindex 526deca430..505c537e2e 100644--- a/packages/desktop-client/src/components/modals/EditFieldModal.tsx+++ b/packages/desktop-client/src/components/modals/EditFieldModal.tsx@@ -10,6 +10,7 @@ import { Button } from '@actual-app/components/button';import { View } from '@actual-app/components/view';import { parseISO, format as formatDate, parse as parseDate } from 'date-fns';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { currentDay, dayFromDate } from 'loot-core/shared/months';import { amountToInteger } from 'loot-core/shared/util';@@ -30,15 +31,10 @@ const itemStyle: CSSProperties = {type NoteAmendMode = 'replace' | 'prepend' | 'append';-type EditFieldModalProps = {- name: string;- onSubmit: (- name: string,- value: string | number,- mode?: NoteAmendMode,- ) => void;- onClose: () => void;-};+type EditFieldModalProps = Extract<+ ModalType,+ { name: 'edit-field' }+>['options'];export function EditFieldModal({name,diff --git a/packages/desktop-client/src/components/modals/EditRuleModal.jsx b/packages/desktop-client/src/components/modals/EditRuleModal.jsxindex 1296aeb7bb..8c8b2b7139 100644--- a/packages/desktop-client/src/components/modals/EditRuleModal.jsx+++ b/packages/desktop-client/src/components/modals/EditRuleModal.jsx@@ -756,7 +756,10 @@ const conditionFields = [['amount-outflow', mapField('amount', { outflow: true })],]);-export function EditRuleModal({ defaultRule, onSave: originalOnSave }) {+export function EditRuleModal({+ rule: defaultRule,+ onSave: originalOnSave = undefined,+}) {const { t } = useTranslation();const [conditions, setConditions] = useState(defaultRule.conditions.map(parse).map(c => ({ ...c, inputKey: uuid() })),diff --git a/packages/desktop-client/src/components/modals/EditUser.tsx b/packages/desktop-client/src/components/modals/EditUser.tsxindex 081e14b8af..632396fed6 100644--- a/packages/desktop-client/src/components/modals/EditUser.tsx+++ b/packages/desktop-client/src/components/modals/EditUser.tsx@@ -7,9 +7,17 @@ import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { addNotification, popModal, signOut } from 'loot-core/client/actions';+import { addNotification, signOut } from 'loot-core/client/actions';+import {+ type Modal as ModalType,+ popModal,+} from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';-import { PossibleRoles, type UserEntity } from 'loot-core/types/models/user';+import {+ type NewUserEntity,+ PossibleRoles,+ type UserEntity,+} from 'loot-core/types/models/user';import { useDispatch } from '../../redux';import { theme } from '../../style';@@ -19,20 +27,7 @@ import { Select } from '../common/Select';import { Checkbox, FormField, FormLabel } from '../forms';type User = UserEntity;--type EditUserProps = {- defaultUser: User;- onSave: (- method: 'user-add' | 'user-update',- user: User,- setError: (error: string) => void,- ) => Promise<void>;-};--type EditUserFinanceAppProps = {- defaultUser: User;- onSave: (user: User) => void;-};+type NewUser = NewUserEntity;function useGetUserDirectoryErrors() {const { t } = useTranslation();@@ -118,20 +113,25 @@ function useSaveUser() {return { saveUser };}+type EditUserFinanceAppProps = Extract<+ ModalType,+ { name: 'edit-user' }+>['options'];+export function EditUserFinanceApp({- defaultUser,+ user: defaultUser,onSave: originalOnSave,}: EditUserFinanceAppProps) {const { t } = useTranslation();const { saveUser } = useSaveUser();-+ const isExistingUser = 'id' in defaultUser && !!defaultUser.id;return (<Modal name="edit-user">{({ state: { close } }) => (<><ModalHeadertitle={- defaultUser.id+ isExistingUser? t('Edit user {{userName}}', {userName: defaultUser.displayName ?? defaultUser.userName,})@@ -154,9 +154,20 @@ export function EditUserFinanceApp({);}+type EditUserProps = {+ defaultUser: User | NewUser;+ onSave: (+ method: 'user-add' | 'user-update',+ user: User,+ setError: (error: string) => void,+ ) => Promise<void>;+};+function EditUser({ defaultUser, onSave: originalOnSave }: EditUserProps) {const { t } = useTranslation();const dispatch = useDispatch();+ const isExistingUser = 'id' in defaultUser && !!defaultUser.id;+ const isOwner = 'owner' in defaultUser && defaultUser.owner;const [userName, setUserName] = useState<string>(defaultUser.userName ?? '');const [displayName, setDisplayName] = useState<string>(@@ -177,13 +188,15 @@ function EditUser({ defaultUser, onSave: originalOnSave }: EditUserProps) {}const user: User = {...defaultUser,+ id: isExistingUser ? defaultUser.id : '',+ owner: isOwner,userName,displayName,enabled,role,};- const method = user.id ? 'user-update' : 'user-add';+ const method = isExistingUser ? 'user-update' : 'user-add';await originalOnSave(method, user, setError);}@@ -221,9 +234,9 @@ function EditUser({ defaultUser, onSave: originalOnSave }: EditUserProps) {<Checkboxid="enabled-field"checked={enabled}- disabled={defaultUser.owner}+ disabled={isOwner}style={{- color: defaultUser.owner ? theme.pageTextSubdued : 'inherit',+ color: isOwner ? theme.pageTextSubdued : 'inherit',}}onChange={() => setEnabled(!enabled)}/>@@ -232,7 +245,7 @@ function EditUser({ defaultUser, onSave: originalOnSave }: EditUserProps) {</label></View></Stack>- {defaultUser.owner && (+ {isOwner && (<labelstyle={{...styles.verySmallText,@@ -287,7 +300,7 @@ function EditUser({ defaultUser, onSave: originalOnSave }: EditUserProps) {<FormLabel title="Role" htmlFor="role-field" /><Selectid="role-field"- disabled={defaultUser.owner}+ disabled={isOwner}options={Object.entries(PossibleRoles)}value={role}onChange={newValue => setRole(newValue)}@@ -314,7 +327,7 @@ function EditUser({ defaultUser, onSave: originalOnSave }: EditUserProps) {<Trans>Cancel</Trans></Button><Button variant="primary" onPress={onSave}>- {defaultUser.id ? 'Save' : 'Add'}+ {isExistingUser ? 'Save' : 'Add'}</Button></Stack></>diff --git a/packages/desktop-client/src/components/modals/EnvelopeBalanceMenuModal.tsx b/packages/desktop-client/src/components/modals/EnvelopeBalanceMenuModal.tsxindex 6625973d8a..51ff6d5337 100644--- a/packages/desktop-client/src/components/modals/EnvelopeBalanceMenuModal.tsx+++ b/packages/desktop-client/src/components/modals/EnvelopeBalanceMenuModal.tsx@@ -1,13 +1,11 @@-import React, {- type ComponentPropsWithoutRef,- type CSSProperties,-} from 'react';+import React, { type CSSProperties } from 'react';import { useTranslation } from 'react-i18next';import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { envelopeBudget } from 'loot-core/client/queries';import { useCategory } from '../../hooks/useCategory';@@ -25,8 +23,9 @@ import {} from '../common/Modal';import { CellValueText } from '../spreadsheet/CellValue';-type EnvelopeBalanceMenuModalProps = ComponentPropsWithoutRef<- typeof BalanceMenu+type EnvelopeBalanceMenuModalProps = Omit<+ Extract<ModalType, { name: 'envelope-balance-menu' }>['options'],+ 'month'>;export function EnvelopeBalanceMenuModal({diff --git a/packages/desktop-client/src/components/modals/EnvelopeBudgetMenuModal.tsx b/packages/desktop-client/src/components/modals/EnvelopeBudgetMenuModal.tsxindex 4d32cce5f0..ce211d87a6 100644--- a/packages/desktop-client/src/components/modals/EnvelopeBudgetMenuModal.tsx+++ b/packages/desktop-client/src/components/modals/EnvelopeBudgetMenuModal.tsx@@ -1,15 +1,11 @@-import React, {- useState,- type ComponentPropsWithoutRef,- useEffect,- type CSSProperties,-} from 'react';+import React, { useState, useEffect, type CSSProperties } from 'react';import { useTranslation } from 'react-i18next';import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { envelopeBudget } from 'loot-core/client/queries';import { amountToInteger, integerToAmount } from 'loot-core/shared/util';@@ -25,12 +21,10 @@ import {} from '../common/Modal';import { FocusableAmountInput } from '../mobile/transactions/FocusableAmountInput';-type EnvelopeBudgetMenuModalProps = ComponentPropsWithoutRef<- typeof BudgetMenu-> & {- categoryId: string;- onUpdateBudget: (amount: number) => void;-};+type EnvelopeBudgetMenuModalProps = Omit<+ Extract<ModalType, { name: 'envelope-budget-menu' }>['options'],+ 'month'+>;export function EnvelopeBudgetMenuModal({categoryId,diff --git a/packages/desktop-client/src/components/modals/EnvelopeBudgetMonthMenuModal.tsx b/packages/desktop-client/src/components/modals/EnvelopeBudgetMonthMenuModal.tsxindex 932b58ee21..36d0d236f8 100644--- a/packages/desktop-client/src/components/modals/EnvelopeBudgetMonthMenuModal.tsx+++ b/packages/desktop-client/src/components/modals/EnvelopeBudgetMonthMenuModal.tsx@@ -7,6 +7,7 @@ import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';import { css } from '@emotion/css';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import * as monthUtils from 'loot-core/shared/months';import { useNotes } from '../../hooks/useNotes';@@ -18,11 +19,10 @@ import { BudgetMonthMenu } from '../budget/envelope/budgetsummary/BudgetMonthMenimport { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { Notes } from '../Notes';-type EnvelopeBudgetMonthMenuModalProps = {- month: string;- onBudgetAction: (month: string, action: string, arg?: unknown) => void;- onEditNotes: (month: string) => void;-};+type EnvelopeBudgetMonthMenuModalProps = Extract<+ ModalType,+ { name: 'envelope-budget-month-menu' }+>['options'];export function EnvelopeBudgetMonthMenuModal({month,diff --git a/packages/desktop-client/src/components/modals/EnvelopeBudgetSummaryModal.tsx b/packages/desktop-client/src/components/modals/EnvelopeBudgetSummaryModal.tsxindex f860b0950c..75fbc3dcee 100644--- a/packages/desktop-client/src/components/modals/EnvelopeBudgetSummaryModal.tsx+++ b/packages/desktop-client/src/components/modals/EnvelopeBudgetSummaryModal.tsx@@ -3,7 +3,11 @@ import { useTranslation } from 'react-i18next';import { styles } from '@actual-app/components/styles';-import { collapseModals, pushModal } from 'loot-core/client/actions';+import {+ collapseModals,+ type Modal as ModalType,+ pushModal,+} from 'loot-core/client/modals/modalsSlice';import { envelopeBudget } from 'loot-core/client/queries';import { format, sheetForMonth, prevMonth } from 'loot-core/shared/months';import { groupById, integerToCurrency } from 'loot-core/shared/util';@@ -17,10 +21,10 @@ import { useEnvelopeSheetValue } from '../budget/envelope/EnvelopeBudgetComponenimport { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { NamespaceContext } from '../spreadsheet/NamespaceContext';-type EnvelopeBudgetSummaryModalProps = {- onBudgetAction: (month: string, action: string, arg?: unknown) => void;- month: string;-};+type EnvelopeBudgetSummaryModalProps = Extract<+ ModalType,+ { name: 'envelope-budget-summary' }+>['options'];export function EnvelopeBudgetSummaryModal({month,@@ -42,23 +46,28 @@ export function EnvelopeBudgetSummaryModal({const openTransferAvailableModal = () => {dispatch(- pushModal('transfer', {- title: t('Transfer to category'),- month,- amount: sheetValue,- onSubmit: (amount, toCategoryId) => {- onBudgetAction(month, 'transfer-available', {- amount,+ pushModal({+ modal: {+ name: 'transfer',+ options: {+ title: t('Transfer to category'),month,- category: toCategoryId,- });- dispatch(collapseModals('transfer'));- showUndoNotification({- message: t('Transferred {{amount}} to {{categoryName}}', {- amount: integerToCurrency(amount),- categoryName: categoriesById[toCategoryId].name,- }),- });+ amount: sheetValue,+ onSubmit: (amount, toCategoryId) => {+ onBudgetAction(month, 'transfer-available', {+ amount,+ month,+ category: toCategoryId,+ });+ dispatch(collapseModals({ rootModalName: 'transfer' }));+ showUndoNotification({+ message: t('Transferred {{amount}} to {{categoryName}}', {+ amount: integerToCurrency(amount),+ categoryName: categoriesById[toCategoryId].name,+ }),+ });+ },+ },},}),);@@ -66,20 +75,25 @@ export function EnvelopeBudgetSummaryModal({const openCoverOverbudgetedModal = () => {dispatch(- pushModal('cover', {- title: t('Cover overbudgeted'),- month,- showToBeBudgeted: false,- onSubmit: categoryId => {- onBudgetAction(month, 'cover-overbudgeted', {- category: categoryId,- });- dispatch(collapseModals('cover'));- showUndoNotification({- message: t('Covered overbudgeted from {{categoryName}}', {- categoryName: categoriesById[categoryId].name,- }),- });+ pushModal({+ modal: {+ name: 'cover',+ options: {+ title: t('Cover overbudgeted'),+ month,+ showToBeBudgeted: false,+ onSubmit: categoryId => {+ onBudgetAction(month, 'cover-overbudgeted', {+ category: categoryId,+ });+ dispatch(collapseModals({ rootModalName: 'cover' }));+ showUndoNotification({+ message: t('Covered overbudgeted from {{categoryName}}', {+ categoryName: categoriesById[categoryId].name,+ }),+ });+ },+ },},}),);@@ -87,11 +101,16 @@ export function EnvelopeBudgetSummaryModal({const onHoldBuffer = () => {dispatch(- pushModal('hold-buffer', {- month,- onSubmit: amount => {- onBudgetAction(month, 'hold', { amount });- dispatch(collapseModals('hold-buffer'));+ pushModal({+ modal: {+ name: 'hold-buffer',+ options: {+ month,+ onSubmit: amount => {+ onBudgetAction(month, 'hold', { amount });+ dispatch(collapseModals({ rootModalName: 'hold-buffer' }));+ },+ },},}),);@@ -103,15 +122,20 @@ export function EnvelopeBudgetSummaryModal({const onClick = ({ close }: { close: () => void }) => {dispatch(- pushModal('envelope-summary-to-budget-menu', {- month,- onTransfer: openTransferAvailableModal,- onCover: openCoverOverbudgetedModal,- onResetHoldBuffer: () => {- onResetHoldBuffer();- close();+ pushModal({+ modal: {+ name: 'envelope-summary-to-budget-menu',+ options: {+ month,+ onTransfer: openTransferAvailableModal,+ onCover: openCoverOverbudgetedModal,+ onResetHoldBuffer: () => {+ onResetHoldBuffer();+ close();+ },+ onHoldBuffer,+ },},- onHoldBuffer,}),);};diff --git a/packages/desktop-client/src/components/modals/EnvelopeToBudgetMenuModal.tsx b/packages/desktop-client/src/components/modals/EnvelopeToBudgetMenuModal.tsxindex 43371ccaff..5f001699a1 100644--- a/packages/desktop-client/src/components/modals/EnvelopeToBudgetMenuModal.tsx+++ b/packages/desktop-client/src/components/modals/EnvelopeToBudgetMenuModal.tsx@@ -1,16 +1,16 @@-import React, {- type ComponentPropsWithoutRef,- type CSSProperties,-} from 'react';+import React, { type CSSProperties } from 'react';import { styles } from '@actual-app/components/styles';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';+import { theme } from '../../style';import { ToBudgetMenu } from '../budget/envelope/budgetsummary/ToBudgetMenu';import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';-type EnvelopeToBudgetMenuModalProps = ComponentPropsWithoutRef<- typeof ToBudgetMenu+type EnvelopeToBudgetMenuModalProps = Omit<+ Extract<ModalType, { name: 'envelope-summary-to-budget-menu' }>['options'],+ 'month'>;export function EnvelopeToBudgetMenuModal({diff --git a/packages/desktop-client/src/components/modals/FixEncryptionKeyModal.tsx b/packages/desktop-client/src/components/modals/FixEncryptionKeyModal.tsxindex 904e00ba2b..a891023e5c 100644--- a/packages/desktop-client/src/components/modals/FixEncryptionKeyModal.tsx+++ b/packages/desktop-client/src/components/modals/FixEncryptionKeyModal.tsx@@ -10,7 +10,7 @@ import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { type FinanceModals } from 'loot-core/client/state-types/modals';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import { getTestKeyError } from 'loot-core/shared/errors';@@ -25,15 +25,16 @@ import {} from '../common/Modal';import { useResponsive } from '../responsive/ResponsiveProvider';-type FixEncryptionKeyModalProps = {- options: FinanceModals['fix-encryption-key'];-};+type FixEncryptionKeyModalProps = Extract<+ ModalType,+ { name: 'fix-encryption-key' }+>['options'];export function FixEncryptionKeyModal({- options = {},+ cloudFileId,+ hasExistingKey,+ onSuccess,}: FixEncryptionKeyModalProps) {- const { hasExistingKey, cloudFileId, onSuccess } = options;-const { t } = useTranslation();const [password, setPassword] = useState('');const [error, setError] = useState('');diff --git a/packages/desktop-client/src/components/modals/GoCardlessExternalMsgModal.tsx b/packages/desktop-client/src/components/modals/GoCardlessExternalMsgModal.tsxindex c477d1178c..8b226ee413 100644--- a/packages/desktop-client/src/components/modals/GoCardlessExternalMsgModal.tsx+++ b/packages/desktop-client/src/components/modals/GoCardlessExternalMsgModal.tsx@@ -6,7 +6,10 @@ import { Button } from '@actual-app/components/button';import { Paragraph } from '@actual-app/components/paragraph';import { View } from '@actual-app/components/view';-import { pushModal } from 'loot-core/client/actions/modals';+import {+ type Modal as ModalType,+ pushModal,+} from 'loot-core/client/modals/modalsSlice';import { sendCatch } from 'loot-core/platform/client/fetch';import {type GoCardlessInstitution,@@ -73,19 +76,16 @@ function renderError(error: 'unknown' | 'timeout', t: (key: string) => string) {);}-type GoCardlessExternalMsgProps = {- onMoveExternal: (arg: {- institutionId: string;- }) => Promise<{ error?: 'unknown' | 'timeout'; data?: GoCardlessToken }>;- onSuccess: (data: GoCardlessToken) => Promise<void>;- onClose: () => void;-};+type GoCardlessExternalMsgModalProps = Extract<+ ModalType,+ { name: 'gocardless-external-msg' }+>['options'];export function GoCardlessExternalMsgModal({onMoveExternal,onSuccess,onClose,-}: GoCardlessExternalMsgProps) {+}: GoCardlessExternalMsgModalProps) {const { t } = useTranslation();const dispatch = useDispatch();@@ -115,7 +115,7 @@ export function GoCardlessExternalMsgModal({setWaiting('browser');const res = await onMoveExternal({ institutionId });- if (res.error) {+ if ('error' in res) {setError(res.error);setWaiting(null);return;@@ -134,8 +134,13 @@ export function GoCardlessExternalMsgModal({const onGoCardlessInit = () => {dispatch(- pushModal('gocardless-init', {- onSuccess: () => setIsGoCardlessSetupComplete(true),+ pushModal({+ modal: {+ name: 'gocardless-init',+ options: {+ onSuccess: () => setIsGoCardlessSetupComplete(true),+ },+ },}),);};diff --git a/packages/desktop-client/src/components/modals/GoCardlessInitialiseModal.tsx b/packages/desktop-client/src/components/modals/GoCardlessInitialiseModal.tsxindex 0bdd4761fd..4ba600e060 100644--- a/packages/desktop-client/src/components/modals/GoCardlessInitialiseModal.tsx+++ b/packages/desktop-client/src/components/modals/GoCardlessInitialiseModal.tsx@@ -7,6 +7,7 @@ import { InitialFocus } from '@actual-app/components/initial-focus';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import { getSecretsError } from 'loot-core/shared/errors';@@ -21,13 +22,14 @@ import {} from '../common/Modal';import { FormField, FormLabel } from '../forms';-type GoCardlessInitialiseProps = {- onSuccess: () => void;-};+type GoCardlessInitialiseModalProps = Extract<+ ModalType,+ { name: 'gocardless-init' }+>['options'];export const GoCardlessInitialiseModal = ({onSuccess,-}: GoCardlessInitialiseProps) => {+}: GoCardlessInitialiseModalProps) => {const { t } = useTranslation();const [secretId, setSecretId] = useState('');const [secretKey, setSecretKey] = useState('');diff --git a/packages/desktop-client/src/components/modals/HoldBufferModal.tsx b/packages/desktop-client/src/components/modals/HoldBufferModal.tsxindex c94b3a52c6..d60c25c182 100644--- a/packages/desktop-client/src/components/modals/HoldBufferModal.tsx+++ b/packages/desktop-client/src/components/modals/HoldBufferModal.tsx@@ -6,6 +6,7 @@ import { InitialFocus } from '@actual-app/components/initial-focus';import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { envelopeBudget } from 'loot-core/client/queries';import { useEnvelopeSheetValue } from '../budget/envelope/EnvelopeBudgetComponents';@@ -13,10 +14,10 @@ import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { FieldLabel } from '../mobile/MobileForms';import { AmountInput } from '../util/AmountInput';-type HoldBufferModalProps = {- month: string;- onSubmit: (amount: number) => void;-};+type HoldBufferModalProps = Extract<+ ModalType,+ { name: 'hold-buffer' }+>['options'];export function HoldBufferModal({ onSubmit }: HoldBufferModalProps) {const { t } = useTranslation(); // Initialize i18nextdiff --git a/packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx b/packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsxindex f44026d0bf..eba118bd8a 100644--- a/packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx+++ b/packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx@@ -141,7 +141,11 @@ function parseCategoryFields(trans, categories) {return match;}-export function ImportTransactionsModal({ options }) {+export function ImportTransactionsModal({+ filename: originalFileName,+ accountId,+ onImported,+}) {const { t } = useTranslation();const dateFormat = useDateFormat() || 'MM/dd/yyyy';const [prefs, savePrefs] = useSyncedPrefs();@@ -151,7 +155,7 @@ export function ImportTransactionsModal({ options }) {const [multiplierAmount, setMultiplierAmount] = useState('');const [loadingState, setLoadingState] = useState('parsing');const [error, setError] = useState(null);- const [filename, setFilename] = useState(options.filename);+ const [filename, setFilename] = useState(originalFileName);const [transactions, setTransactions] = useState([]);const [filetype, setFileType] = useState(null);const [fieldMappings, setFieldMappings] = useState(null);@@ -159,7 +163,6 @@ export function ImportTransactionsModal({ options }) {const [flipAmount, setFlipAmount] = useState(false);const [multiplierEnabled, setMultiplierEnabled] = useState(false);const [reconcile, setReconcile] = useState(true);- const { accountId, onImported } = options;// This cannot be set after parsing the file, because changing it// requires re-parsing the file. This is different from the other@@ -420,7 +423,7 @@ export function ImportTransactionsModal({ options }) {}useEffect(() => {- const fileType = getFileType(options.filename);+ const fileType = getFileType(originalFileName);const parseOptions = getParseOptions(fileType, {delimiter,hasHeaderRow,@@ -428,9 +431,9 @@ export function ImportTransactionsModal({ options }) {fallbackMissingPayeeToMemo,});- parse(options.filename, parseOptions);+ parse(originalFileName, parseOptions);}, [- options.filename,+ originalFileName,delimiter,hasHeaderRow,skipLines,diff --git a/packages/desktop-client/src/components/modals/LoadBackupModal.tsx b/packages/desktop-client/src/components/modals/LoadBackupModal.tsxindex 0d2af13245..11e413ff41 100644--- a/packages/desktop-client/src/components/modals/LoadBackupModal.tsx+++ b/packages/desktop-client/src/components/modals/LoadBackupModal.tsx@@ -8,7 +8,8 @@ import { theme } from '@actual-app/components/theme';import { View } from '@actual-app/components/view';import { loadBackup, makeBackup } from 'loot-core/client/budgets/budgetsSlice';-import { send, listen, unlisten } from 'loot-core/platform/client/fetch';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';+import { send, listen } from 'loot-core/platform/client/fetch';import { type Backup } from 'loot-core/server/backups';import { useMetadataPref } from '../../hooks/useMetadataPref';@@ -42,11 +43,10 @@ function BackupTable({ backups, onSelect }: BackupTableProps) {);}-type LoadBackupModalProps = {- budgetId: string;- watchUpdates: boolean;- backupDisabled: boolean;-};+type LoadBackupModalProps = Extract<+ ModalType,+ { name: 'load-backup' }+>['options'];export function LoadBackupModal({budgetId,@@ -59,13 +59,14 @@ export function LoadBackupModal({const budgetIdToLoad = budgetId ?? prefsBudgetId;useEffect(() => {- send('backups-get', { id: budgetIdToLoad }).then(setBackups);+ if (budgetIdToLoad) {+ send('backups-get', { id: budgetIdToLoad }).then(setBackups);+ }}, [budgetIdToLoad]);useEffect(() => {if (watchUpdates) {- listen('backups-updated', setBackups);- return () => unlisten('backups-updated');+ return listen('backups-updated', setBackups);}}, [watchUpdates]);@@ -106,14 +107,16 @@ export function LoadBackupModal({</Block><Buttonvariant="primary"- onPress={() =>- dispatch(- loadBackup({- budgetId: budgetIdToLoad,- backupId: latestBackup.id,- }),- )- }+ onPress={() => {+ if (budgetIdToLoad && latestBackup.id) {+ dispatch(+ loadBackup({+ budgetId: budgetIdToLoad,+ backupId: latestBackup.id,+ }),+ );+ }+ }}>{t('Revert to original version')}</Button>@@ -147,11 +150,13 @@ export function LoadBackupModal({) : (<BackupTablebackups={previousBackups}- onSelect={id =>- dispatch(- loadBackup({ budgetId: budgetIdToLoad, backupId: id }),- )- }+ onSelect={id => {+ if (budgetIdToLoad && id) {+ dispatch(+ loadBackup({ budgetId: budgetIdToLoad, backupId: id }),+ );+ }+ }}/>)}</View>diff --git a/packages/desktop-client/src/components/modals/ManageRulesModal.tsx b/packages/desktop-client/src/components/modals/ManageRulesModal.tsxindex 6d09774e87..dd57a5692e 100644--- a/packages/desktop-client/src/components/modals/ManageRulesModal.tsx+++ b/packages/desktop-client/src/components/modals/ManageRulesModal.tsx@@ -3,14 +3,16 @@ import React, { useState } from 'react';import { useTranslation } from 'react-i18next';import { useLocation } from 'react-router-dom';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { isNonProductionEnvironment } from 'loot-core/shared/environment';import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { ManageRules } from '../ManageRules';-type ManageRulesModalProps = {- payeeId?: string;-};+type ManageRulesModalProps = Extract<+ ModalType,+ { name: 'manage-rules' }+>['options'];export function ManageRulesModal({ payeeId }: ManageRulesModalProps) {const { t } = useTranslation();diff --git a/packages/desktop-client/src/components/modals/MergeUnusedPayeesModal.tsx b/packages/desktop-client/src/components/modals/MergeUnusedPayeesModal.tsxindex 33b79a8f88..7cccd52cc9 100644--- a/packages/desktop-client/src/components/modals/MergeUnusedPayeesModal.tsx+++ b/packages/desktop-client/src/components/modals/MergeUnusedPayeesModal.tsx@@ -6,7 +6,10 @@ import { Paragraph } from '@actual-app/components/paragraph';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { replaceModal } from 'loot-core/client/actions/modals';+import {+ type Modal as ModalType,+ replaceModal,+} from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import { type PayeeEntity } from 'loot-core/types/models';@@ -18,10 +21,10 @@ import { Modal, ModalButtons } from '../common/Modal';const highlightStyle = { color: theme.pageTextPositive };-type MergeUnusedPayeesModalProps = {- payeeIds: Array<PayeeEntity['id']>;- targetPayeeId: PayeeEntity['id'];-};+type MergeUnusedPayeesModalProps = Extract<+ ModalType,+ { name: 'merge-unused-payees' }+>['options'];export function MergeUnusedPayeesModal({payeeIds,@@ -82,7 +85,9 @@ export function MergeUnusedPayeesModal({if (ruleId) {const rule = await send('rule-get', { id: ruleId });- dispatch(replaceModal('edit-rule', { rule }));+ dispatch(+ replaceModal({ modal: { name: 'edit-rule', options: { rule } } }),+ );}},[onMerge, dispatch],diff --git a/packages/desktop-client/src/components/modals/NewCategoryGroupModal.tsx b/packages/desktop-client/src/components/modals/NewCategoryGroupModal.tsxnew file mode 100644index 0000000000..526f0268fd--- /dev/null+++ b/packages/desktop-client/src/components/modals/NewCategoryGroupModal.tsx@@ -0,0 +1,36 @@+import { useTranslation } from 'react-i18next';++import { type Modal } from 'loot-core/client/modals/modalsSlice';++import { ModalHeader, ModalTitle } from '../common/Modal';++import { SingleInputModal } from './SingleInputModal';++type NewCategoryGroupModalProps = Extract<+ Modal,+ { name: 'new-category-group' }+>['options'];++export function NewCategoryGroupModal({+ onValidate,+ onSubmit,+}: NewCategoryGroupModalProps) {+ const { t } = useTranslation();+ return (+ <SingleInputModal+ name="new-category-group"+ Header={props => (+ <ModalHeader+ {...props}+ title={+ <ModalTitle title={t('New Category Group')} shrinkOnOverflow />+ }+ />+ )}+ inputPlaceholder={t('Category group name')}+ buttonText={t('Add')}+ onValidate={onValidate}+ onSubmit={onSubmit}+ />+ );+}diff --git a/packages/desktop-client/src/components/modals/NewCategoryModal.tsx b/packages/desktop-client/src/components/modals/NewCategoryModal.tsxnew file mode 100644index 0000000000..4fce760621--- /dev/null+++ b/packages/desktop-client/src/components/modals/NewCategoryModal.tsx@@ -0,0 +1,34 @@+import { useTranslation } from 'react-i18next';++import { type Modal } from 'loot-core/client/modals/modalsSlice';++import { ModalHeader, ModalTitle } from '../common/Modal';++import { SingleInputModal } from './SingleInputModal';++type NewCategoryModalProps = Extract<+ Modal,+ { name: 'new-category' }+>['options'];++export function NewCategoryModal({+ onValidate,+ onSubmit,+}: NewCategoryModalProps) {+ const { t } = useTranslation();+ return (+ <SingleInputModal+ name="new-category"+ Header={props => (+ <ModalHeader+ {...props}+ title={<ModalTitle title={t('New Category')} shrinkOnOverflow />}+ />+ )}+ inputPlaceholder={t('Category name')}+ buttonText={t('Add')}+ onValidate={onValidate}+ onSubmit={onSubmit}+ />+ );+}diff --git a/packages/desktop-client/src/components/modals/NotesModal.tsx b/packages/desktop-client/src/components/modals/NotesModal.tsxindex de105976b6..59c120f5be 100644--- a/packages/desktop-client/src/components/modals/NotesModal.tsx+++ b/packages/desktop-client/src/components/modals/NotesModal.tsx@@ -5,16 +5,14 @@ import { useTranslation } from 'react-i18next';import { Button } from '@actual-app/components/button';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';+import { useNotes } from '../../hooks/useNotes';import { SvgCheck } from '../../icons/v2';import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { Notes } from '../Notes';-type NotesModalProps = {- id: string;- name: string;- onSave: (id: string, notes: string) => void;-};+type NotesModalProps = Extract<ModalType, { name: 'notes' }>['options'];export function NotesModal({ id, name, onSave }: NotesModalProps) {const { t } = useTranslation();diff --git a/packages/desktop-client/src/components/modals/OpenIDEnableModal.tsx b/packages/desktop-client/src/components/modals/OpenIDEnableModal.tsxindex 77b6edd266..a8b8112f97 100644--- a/packages/desktop-client/src/components/modals/OpenIDEnableModal.tsx+++ b/packages/desktop-client/src/components/modals/OpenIDEnableModal.tsx@@ -6,8 +6,11 @@ import { Label } from '@actual-app/components/label';import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';-import { popModal } from 'loot-core/client/actions';import { closeBudget } from 'loot-core/client/budgets/budgetsSlice';+import {+ type Modal as ModalType,+ popModal,+} from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import * as asyncStorage from 'loot-core/platform/server/asyncStorage';import { getOpenIdErrors } from 'loot-core/shared/errors';@@ -20,9 +23,10 @@ import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { OpenIdForm } from '../manager/subscribe/OpenIdForm';import { useRefreshLoginMethods } from '../ServerContext';-type OpenIDEnableModalProps = {- onSave?: () => void;-};+type OpenIDEnableModalProps = Extract<+ ModalType,+ { name: 'enable-openid' }+>['options'];export function OpenIDEnableModal({onSave: originalOnSave,diff --git a/packages/desktop-client/src/components/modals/PasswordEnableModal.tsx b/packages/desktop-client/src/components/modals/PasswordEnableModal.tsxindex 959bf22c52..e980784ad9 100644--- a/packages/desktop-client/src/components/modals/PasswordEnableModal.tsx+++ b/packages/desktop-client/src/components/modals/PasswordEnableModal.tsx@@ -6,8 +6,11 @@ import { Label } from '@actual-app/components/label';import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';-import { popModal } from 'loot-core/client/actions';import { closeBudget } from 'loot-core/client/budgets/budgetsSlice';+import {+ type Modal as ModalType,+ popModal,+} from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import * as asyncStorage from 'loot-core/platform/server/asyncStorage';@@ -26,9 +29,10 @@ import {useRefreshLoginMethods,} from '../ServerContext';-type PasswordEnableModalProps = {- onSave?: () => void;-};+type PasswordEnableModalProps = Extract<+ ModalType,+ { name: 'enable-password-auth' }+>['options'];export function PasswordEnableModal({onSave: originalOnSave,diff --git a/packages/desktop-client/src/components/modals/PayeeAutocompleteModal.tsx b/packages/desktop-client/src/components/modals/PayeeAutocompleteModal.tsxindex b2c85a98f4..8b5ae47cab 100644--- a/packages/desktop-client/src/components/modals/PayeeAutocompleteModal.tsx+++ b/packages/desktop-client/src/components/modals/PayeeAutocompleteModal.tsx@@ -1,6 +1,8 @@-import React, { type ComponentPropsWithoutRef } from 'react';+import React from 'react';import { useTranslation } from 'react-i18next';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';+import { useAccounts } from '../../hooks/useAccounts';import { useNavigate } from '../../hooks/useNavigate';import { usePayees } from '../../hooks/usePayees';@@ -14,13 +16,13 @@ import {} from '../common/Modal';import { useResponsive } from '../responsive/ResponsiveProvider';-type PayeeAutocompleteModalProps = {- autocompleteProps: ComponentPropsWithoutRef<typeof PayeeAutocomplete>;- onClose: () => void;-};+type PayeeAutocompleteModalProps = Extract<+ ModalType,+ { name: 'payee-autocomplete' }+>['options'];export function PayeeAutocompleteModal({- autocompleteProps,+ onSelect,onClose,}: PayeeAutocompleteModalProps) {const { t } = useTranslation();@@ -78,7 +80,8 @@ export function PayeeAutocompleteModal({showManagePayees={!isNarrowWidth}showMakeTransfer={!isNarrowWidth}{...defaultAutocompleteProps}- {...autocompleteProps}+ onSelect={onSelect}+ value={null}/></>)}diff --git a/packages/desktop-client/src/components/modals/PluggyAiInitialiseModal.tsx b/packages/desktop-client/src/components/modals/PluggyAiInitialiseModal.tsxindex 547f3b9b17..3f1ba5a9b6 100644--- a/packages/desktop-client/src/components/modals/PluggyAiInitialiseModal.tsx+++ b/packages/desktop-client/src/components/modals/PluggyAiInitialiseModal.tsx@@ -8,6 +8,7 @@ import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';import { getSecretsError } from 'loot-core/shared/errors';+import { type Modal as ModalType } from 'loot-core/src/client/modals/modalsSlice';import { send } from 'loot-core/src/platform/client/fetch';import { Error } from '../alerts';@@ -21,9 +22,10 @@ import {} from '../common/Modal';import { FormField, FormLabel } from '../forms';-type PluggyAiInitialiseProps = {- onSuccess: () => void;-};+type PluggyAiInitialiseProps = Extract<+ ModalType,+ { name: 'pluggyai-init' }+>['options'];export const PluggyAiInitialiseModal = ({onSuccess,diff --git a/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx b/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsxindex ec148781ab..622ab9199d 100644--- a/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx+++ b/packages/desktop-client/src/components/modals/ScheduledTransactionMenuModal.tsx@@ -11,6 +11,7 @@ import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';import { useSchedules } from 'loot-core/client/data-hooks/schedules';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { format } from 'loot-core/shared/months';import { q } from 'loot-core/shared/query';import {@@ -26,7 +27,10 @@ import {ModalTitle,} from '../common/Modal';-type ScheduledTransactionMenuModalProps = ScheduledTransactionMenuProps;+type ScheduledTransactionMenuModalProps = Extract<+ ModalType,+ { name: 'scheduled-transaction-menu' }+>['options'];export function ScheduledTransactionMenuModal({transactionId,diff --git a/packages/desktop-client/src/components/modals/SelectLinkedAccountsModal.jsx b/packages/desktop-client/src/components/modals/SelectLinkedAccountsModal.jsxindex f02fdf8939..ebc04e0fd4 100644--- a/packages/desktop-client/src/components/modals/SelectLinkedAccountsModal.jsx+++ b/packages/desktop-client/src/components/modals/SelectLinkedAccountsModal.jsx@@ -11,7 +11,7 @@ import {linkAccountSimpleFin,unlinkAccount,} from 'loot-core/client/accounts/accountsSlice';-import { closeModal } from 'loot-core/client/actions';+import { closeModal } from 'loot-core/client/modals/modalsSlice';import { useAccounts } from '../../hooks/useAccounts';import { useDispatch } from '../../redux';@@ -37,9 +37,9 @@ function useAddBudgetAccountOptions() {}export function SelectLinkedAccountsModal({- requisitionId,+ requisitionId = undefined,externalAccounts,- syncSource,+ syncSource = undefined,}) {externalAccounts.sort((a, b) => a.name.localeCompare(b.name));const { t } = useTranslation();diff --git a/packages/desktop-client/src/components/modals/SimpleFinInitialiseModal.tsx b/packages/desktop-client/src/components/modals/SimpleFinInitialiseModal.tsxindex c546066143..f635b6c29c 100644--- a/packages/desktop-client/src/components/modals/SimpleFinInitialiseModal.tsx+++ b/packages/desktop-client/src/components/modals/SimpleFinInitialiseModal.tsx@@ -6,6 +6,7 @@ import { ButtonWithLoading } from '@actual-app/components/button';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import { getSecretsError } from 'loot-core/shared/errors';@@ -20,13 +21,14 @@ import {} from '../common/Modal';import { FormField, FormLabel } from '../forms';-type SimpleFinInitialiseProps = {- onSuccess: () => void;-};+type SimpleFinInitialiseModalProps = Extract<+ ModalType,+ { name: 'simplefin-init' }+>['options'];export const SimpleFinInitialiseModal = ({onSuccess,-}: SimpleFinInitialiseProps) => {+}: SimpleFinInitialiseModalProps) => {const { t } = useTranslation();const [token, setToken] = useState('');const [isValid, setIsValid] = useState(true);diff --git a/packages/desktop-client/src/components/modals/SingleInputModal.tsx b/packages/desktop-client/src/components/modals/SingleInputModal.tsxindex e56fa50844..02dd3ce66b 100644--- a/packages/desktop-client/src/components/modals/SingleInputModal.tsx+++ b/packages/desktop-client/src/components/modals/SingleInputModal.tsx@@ -21,7 +21,7 @@ type SingleInputModalProps = {Header: ComponentType<ComponentPropsWithoutRef<typeof ModalHeader>>;buttonText: string;onSubmit: (value: string) => void;- onValidate?: (value: string) => string[];+ onValidate?: (value: string) => string | null;inputPlaceholder?: string;};diff --git a/packages/desktop-client/src/components/modals/TrackingBalanceMenuModal.tsx b/packages/desktop-client/src/components/modals/TrackingBalanceMenuModal.tsxindex 9d20517b6a..3dedcac117 100644--- a/packages/desktop-client/src/components/modals/TrackingBalanceMenuModal.tsx+++ b/packages/desktop-client/src/components/modals/TrackingBalanceMenuModal.tsx@@ -1,13 +1,11 @@-import React, {- type ComponentPropsWithoutRef,- type CSSProperties,-} from 'react';+import React, { type CSSProperties } from 'react';import { useTranslation } from 'react-i18next';import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { trackingBudget } from 'loot-core/client/queries';import { useCategory } from '../../hooks/useCategory';@@ -25,8 +23,9 @@ import {} from '../common/Modal';import { CellValueText } from '../spreadsheet/CellValue';-type TrackingBalanceMenuModalProps = ComponentPropsWithoutRef<- typeof BalanceMenu+type TrackingBalanceMenuModalProps = Omit<+ Extract<ModalType, { name: 'tracking-balance-menu' }>['options'],+ 'month'>;export function TrackingBalanceMenuModal({diff --git a/packages/desktop-client/src/components/modals/TrackingBudgetMenuModal.tsx b/packages/desktop-client/src/components/modals/TrackingBudgetMenuModal.tsxindex abceb5c7d4..561ba8c052 100644--- a/packages/desktop-client/src/components/modals/TrackingBudgetMenuModal.tsx+++ b/packages/desktop-client/src/components/modals/TrackingBudgetMenuModal.tsx@@ -1,15 +1,11 @@-import React, {- useState,- type ComponentPropsWithoutRef,- useEffect,- type CSSProperties,-} from 'react';+import React, { useState, useEffect, type CSSProperties } from 'react';import { useTranslation } from 'react-i18next';import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { trackingBudget } from 'loot-core/client/queries';import { amountToInteger, integerToAmount } from 'loot-core/shared/util';@@ -25,12 +21,10 @@ import {} from '../common/Modal';import { FocusableAmountInput } from '../mobile/transactions/FocusableAmountInput';-type TrackingBudgetMenuModalProps = ComponentPropsWithoutRef<- typeof BudgetMenu-> & {- categoryId: string;- onUpdateBudget: (amount: number) => void;-};+type TrackingBudgetMenuModalProps = Omit<+ Extract<ModalType, { name: 'tracking-budget-menu' }>['options'],+ 'month'+>;export function TrackingBudgetMenuModal({categoryId,diff --git a/packages/desktop-client/src/components/modals/TrackingBudgetMonthMenuModal.tsx b/packages/desktop-client/src/components/modals/TrackingBudgetMonthMenuModal.tsxindex f136a8ac43..fbd5b7978f 100644--- a/packages/desktop-client/src/components/modals/TrackingBudgetMonthMenuModal.tsx+++ b/packages/desktop-client/src/components/modals/TrackingBudgetMonthMenuModal.tsx@@ -7,6 +7,7 @@ import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';import { css } from '@emotion/css';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import * as monthUtils from 'loot-core/shared/months';import { useNotes } from '../../hooks/useNotes';@@ -18,11 +19,10 @@ import { BudgetMonthMenu } from '../budget/tracking/budgetsummary/BudgetMonthMenimport { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { Notes } from '../Notes';-type TrackingBudgetMonthMenuModalProps = {- month: string;- onBudgetAction: (month: string, action: string, arg?: unknown) => void;- onEditNotes: (month: string) => void;-};+type TrackingBudgetMonthMenuModalProps = Extract<+ ModalType,+ { name: 'tracking-budget-month-menu' }+>['options'];export function TrackingBudgetMonthMenuModal({month,diff --git a/packages/desktop-client/src/components/modals/TrackingBudgetSummaryModal.tsx b/packages/desktop-client/src/components/modals/TrackingBudgetSummaryModal.tsxindex 1c1b75237e..a58df062f4 100644--- a/packages/desktop-client/src/components/modals/TrackingBudgetSummaryModal.tsx+++ b/packages/desktop-client/src/components/modals/TrackingBudgetSummaryModal.tsx@@ -4,6 +4,7 @@ import { useTranslation } from 'react-i18next';import { Stack } from '@actual-app/components/stack';import { styles } from '@actual-app/components/styles';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { sheetForMonth } from 'loot-core/shared/months';import * as monthUtils from 'loot-core/shared/months';@@ -13,9 +14,10 @@ import { Saved } from '../budget/tracking/budgetsummary/Saved';import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { NamespaceContext } from '../spreadsheet/NamespaceContext';-type TrackingBudgetSummaryModalProps = {- month: string;-};+type TrackingBudgetSummaryModalProps = Extract<+ ModalType,+ { name: 'tracking-budget-summary' }+>['options'];export function TrackingBudgetSummaryModal({month,diff --git a/packages/desktop-client/src/components/modals/TransferModal.tsx b/packages/desktop-client/src/components/modals/TransferModal.tsxindex 8fdb02ba22..0c4f15c9b2 100644--- a/packages/desktop-client/src/components/modals/TransferModal.tsx+++ b/packages/desktop-client/src/components/modals/TransferModal.tsx@@ -6,8 +6,10 @@ import { InitialFocus } from '@actual-app/components/initial-focus';import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';-import { pushModal } from 'loot-core/client/actions';-import { type CategoryEntity } from 'loot-core/types/models';+import {+ type Modal as ModalType,+ pushModal,+} from 'loot-core/client/modals/modalsSlice';import { useCategories } from '../../hooks/useCategories';import { useDispatch } from '../../redux';@@ -19,14 +21,7 @@ import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { FieldLabel, TapField } from '../mobile/MobileForms';import { AmountInput } from '../util/AmountInput';-type TransferModalProps = {- title: string;- categoryId?: CategoryEntity['id'];- month: string;- amount: number;- showToBeBudgeted: boolean;- onSubmit: (amount: number, toCategoryId: CategoryEntity['id']) => void;-};+type TransferModalProps = Extract<ModalType, { name: 'transfer' }>['options'];export function TransferModal({title,@@ -60,12 +55,17 @@ export function TransferModal({const openCategoryModal = () => {dispatch(- pushModal('category-autocomplete', {- categoryGroups,- month,- showHiddenCategories: true,- onSelect: categoryId => {- setToCategoryId(categoryId);+ pushModal({+ modal: {+ name: 'category-autocomplete',+ options: {+ categoryGroups,+ month,+ showHiddenCategories: true,+ onSelect: categoryId => {+ setToCategoryId(categoryId);+ },+ },},}),);diff --git a/packages/desktop-client/src/components/modals/TransferOwnership.tsx b/packages/desktop-client/src/components/modals/TransferOwnership.tsxindex dc7ed9ea36..3a2924994d 100644--- a/packages/desktop-client/src/components/modals/TransferOwnership.tsx+++ b/packages/desktop-client/src/components/modals/TransferOwnership.tsx@@ -7,8 +7,12 @@ import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { addNotification, popModal } from 'loot-core/client/actions';+import { addNotification } from 'loot-core/client/actions';import { closeAndLoadBudget } from 'loot-core/client/budgets/budgetsSlice';+import {+ type Modal as ModalType,+ popModal,+} from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import { getUserAccessErrors } from 'loot-core/shared/errors';import { type Budget } from 'loot-core/types/budget';@@ -22,9 +26,10 @@ import { Modal, ModalCloseButton, ModalHeader } from '../common/Modal';import { Select } from '../common/Select';import { FormField, FormLabel } from '../forms';-type TransferOwnershipProps = {- onSave?: () => void;-};+type TransferOwnershipProps = Extract<+ ModalType,+ { name: 'transfer-ownership' }+>['options'];export function TransferOwnership({onSave: originalOnSave,diff --git a/packages/desktop-client/src/components/modals/manager/DeleteFileModal.tsx b/packages/desktop-client/src/components/modals/manager/DeleteFileModal.tsxindex 5390bf5b6f..6973f1d6b1 100644--- a/packages/desktop-client/src/components/modals/manager/DeleteFileModal.tsx+++ b/packages/desktop-client/src/components/modals/manager/DeleteFileModal.tsx@@ -6,17 +6,18 @@ import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';import { deleteBudget } from 'loot-core/client/budgets/budgetsSlice';-import { type File } from 'loot-core/types/file';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { useDispatch } from '../../../redux';import { theme } from '../../../style';import { Modal, ModalCloseButton, ModalHeader } from '../../common/Modal';-type DeleteFileProps = {- file: File;-};+type DeleteFileModalProps = Extract<+ ModalType,+ { name: 'delete-budget' }+>['options'];-export function DeleteFileModal({ file }: DeleteFileProps) {+export function DeleteFileModal({ file }: DeleteFileModalProps) {const { t } = useTranslation();// If the state is "broken" that means it was created by anotherdiff --git a/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx b/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsxindex f1d1644e5a..193eb65719 100644--- a/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx+++ b/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx@@ -10,8 +10,8 @@ import { View } from '@actual-app/components/view';import { addNotification } from 'loot-core/client/actions';import { duplicateBudget } from 'loot-core/client/budgets/budgetsSlice';+import { type Modal as ModalType } from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';-import { type File } from 'loot-core/types/file';import { useDispatch } from '../../../redux';import { theme } from '../../../style';@@ -23,22 +23,17 @@ import {ModalHeader,} from '../../common/Modal';-type DuplicateFileProps = {- file: File;- managePage?: boolean;- loadBudget?: 'none' | 'original' | 'copy';- onComplete?: (event: {- status: 'success' | 'failed' | 'canceled';- error?: object;- }) => void;-};+type DuplicateFileModalProps = Extract<+ ModalType,+ { name: 'duplicate-budget' }+>['options'];export function DuplicateFileModal({file,managePage,loadBudget = 'none',onComplete,-}: DuplicateFileProps) {+}: DuplicateFileModalProps) {const { t } = useTranslation();const fileEndingTranslation = ' - ' + t('copy');const [newName, setNewName] = useState(file.name + fileEndingTranslation);diff --git a/packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx b/packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsxindex 24f27121e3..c23079ea08 100644--- a/packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx+++ b/packages/desktop-client/src/components/modals/manager/FilesSettingsModal.tsx@@ -6,8 +6,8 @@ import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { pushModal } from 'loot-core/client/actions';import { loadAllFiles } from 'loot-core/client/budgets/budgetsSlice';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { useGlobalPref } from '../../../hooks/useGlobalPref';import { SvgPencil1 } from '../../../icons/v2';@@ -30,9 +30,14 @@ function FileLocationSettings() {setDirChanged(true);dispatch(- pushModal('confirm-change-document-dir', {- currentBudgetDirectory: documentDir,- newDirectory: chosenDirectory[0],+ pushModal({+ modal: {+ name: 'confirm-change-document-dir',+ options: {+ currentBudgetDirectory: documentDir,+ newDirectory: chosenDirectory[0],+ },+ },}),);}diff --git a/packages/desktop-client/src/components/modals/manager/ImportModal.tsx b/packages/desktop-client/src/components/modals/manager/ImportModal.tsxindex 661a893025..38dd3502c1 100644--- a/packages/desktop-client/src/components/modals/manager/ImportModal.tsx+++ b/packages/desktop-client/src/components/modals/manager/ImportModal.tsx@@ -8,7 +8,7 @@ import { Text } from '@actual-app/components/text';import { theme } from '@actual-app/components/theme';import { View } from '@actual-app/components/view';-import { pushModal } from 'loot-core/client/actions';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { useDispatch } from '../../../redux';import { Modal, ModalCloseButton, ModalHeader } from '../../common/Modal';@@ -31,13 +31,13 @@ export function ImportModal() {function onSelectType(type: 'ynab4' | 'ynab5' | 'actual') {switch (type) {case 'ynab4':- dispatch(pushModal('import-ynab4'));+ dispatch(pushModal({ modal: { name: 'import-ynab4' } }));break;case 'ynab5':- dispatch(pushModal('import-ynab5'));+ dispatch(pushModal({ modal: { name: 'import-ynab5' } }));break;case 'actual':- dispatch(pushModal('import-actual'));+ dispatch(pushModal({ modal: { name: 'import-actual' } }));break;default:}diff --git a/packages/desktop-client/src/components/payees/ManagePayees.tsx b/packages/desktop-client/src/components/payees/ManagePayees.tsxindex b94ed08dc9..d650c53a40 100644--- a/packages/desktop-client/src/components/payees/ManagePayees.tsx+++ b/packages/desktop-client/src/components/payees/ManagePayees.tsx@@ -12,7 +12,7 @@ import { Popover } from '@actual-app/components/popover';import { View } from '@actual-app/components/view';import memoizeOne from 'memoize-one';-import { pushModal } from 'loot-core/client/actions';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { getNormalisedString } from 'loot-core/shared/normalisation';import { type Diff, groupById } from 'loot-core/shared/util';import { type PayeeEntity } from 'loot-core/types/models';@@ -199,7 +199,7 @@ export const ManagePayees = ({}const onChangeCategoryLearning = useCallback(() => {- dispatch(pushModal('payee-category-learning'));+ dispatch(pushModal({ modal: { name: 'payee-category-learning' } }));}, [dispatch]);const buttonsDisabled = selected.items.size === 0;diff --git a/packages/desktop-client/src/components/payees/ManagePayeesWithData.tsx b/packages/desktop-client/src/components/payees/ManagePayeesWithData.tsxindex 3a16693220..dbb1d65cec 100644--- a/packages/desktop-client/src/components/payees/ManagePayeesWithData.tsx+++ b/packages/desktop-client/src/components/payees/ManagePayeesWithData.tsx@@ -1,6 +1,6 @@import React, { useState, useEffect, useCallback } from 'react';-import { pushModal } from 'loot-core/client/actions';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import {getPayees,initiallyLoadPayees,@@ -90,7 +90,9 @@ export function ManagePayeesWithData({}, [dispatch, refetchRuleCounts, refetchOrphanedPayees]);function onViewRules(id: PayeeEntity['id']) {- dispatch(pushModal('manage-rules', { payeeId: id }));+ dispatch(+ pushModal({ modal: { name: 'manage-rules', options: { payeeId: id } } }),+ );}function onCreateRule(id: PayeeEntity['id']) {@@ -114,7 +116,7 @@ export function ManagePayeesWithData({},],};- dispatch(pushModal('edit-rule', { rule }));+ dispatch(pushModal({ modal: { name: 'edit-rule', options: { rule } } }));}return (diff --git a/packages/desktop-client/src/components/schedules/PostsOfflineNotification.tsx b/packages/desktop-client/src/components/schedules/PostsOfflineNotification.tsxindex 97de4c8dc6..41b3e3c697 100644--- a/packages/desktop-client/src/components/schedules/PostsOfflineNotification.tsx+++ b/packages/desktop-client/src/components/schedules/PostsOfflineNotification.tsx@@ -7,7 +7,7 @@ import { Paragraph } from '@actual-app/components/paragraph';import { Stack } from '@actual-app/components/stack';import { Text } from '@actual-app/components/text';-import { popModal } from 'loot-core/client/actions';+import { popModal } from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import { type PayeeEntity } from 'loot-core/types/models';diff --git a/packages/desktop-client/src/components/schedules/ScheduleDetails.tsx b/packages/desktop-client/src/components/schedules/ScheduleDetails.tsxindex dce7afb46d..642549e127 100644--- a/packages/desktop-client/src/components/schedules/ScheduleDetails.tsx+++ b/packages/desktop-client/src/components/schedules/ScheduleDetails.tsx@@ -9,7 +9,10 @@ import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';import { t } from 'i18next';-import { pushModal } from 'loot-core/client/actions/modals';+import {+ type Modal as ModalType,+ pushModal,+} from 'loot-core/client/modals/modalsSlice';import { getPayeesById } from 'loot-core/client/queries/queriesSlice';import { runQuery, liveQuery } from 'loot-core/client/query-helpers';import { send, sendCatch } from 'loot-core/platform/client/fetch';@@ -100,10 +103,10 @@ function updateScheduleConditions(};}-type ScheduleDetailsProps = {- id: string;- transaction: TransactionEntity;-};+type ScheduleDetailsProps = Extract<+ ModalType,+ { name: 'schedule-edit' }+>['options'];export function ScheduleDetails({ id, transaction }: ScheduleDetailsProps) {const { t } = useTranslation();@@ -530,11 +533,16 @@ export function ScheduleDetails({ id, transaction }: ScheduleDetailsProps) {const rule = await send('rule-get', { id });globalDispatch(- pushModal('edit-rule', {- rule,- onSave: async () => {- const schedule = await loadSchedule();- dispatch({ type: 'set-schedule', schedule });+ pushModal({+ modal: {+ name: 'edit-rule',+ options: {+ rule,+ onSave: async () => {+ const schedule = await loadSchedule();+ dispatch({ type: 'set-schedule', schedule });+ },+ },},}),);diff --git a/packages/desktop-client/src/components/schedules/ScheduleLink.tsx b/packages/desktop-client/src/components/schedules/ScheduleLink.tsxindex ef030372d1..a74925129d 100644--- a/packages/desktop-client/src/components/schedules/ScheduleLink.tsx+++ b/packages/desktop-client/src/components/schedules/ScheduleLink.tsx@@ -7,14 +7,13 @@ import { InitialFocus } from '@actual-app/components/initial-focus';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { pushModal } from 'loot-core/client/actions';import { useSchedules } from 'loot-core/client/data-hooks/schedules';+import {+ type Modal as ModalType,+ pushModal,+} from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import { q } from 'loot-core/shared/query';-import {- type ScheduleEntity,- type TransactionEntity,-} from 'loot-core/types/models';import { SvgAdd } from '../../icons/v0';import { useDispatch } from '../../redux';@@ -23,17 +22,17 @@ import { Search } from '../common/Search';import { ROW_HEIGHT, SchedulesTable } from './SchedulesTable';+type ScheduleLinkProps = Extract<+ ModalType,+ { name: 'schedule-link' }+>['options'];+export function ScheduleLink({transactionIds: ids,getTransaction,accountName,onScheduleLinked,-}: {- transactionIds: string[];- getTransaction: (transactionId: string) => TransactionEntity;- accountName?: string;- onScheduleLinked?: (schedule: ScheduleEntity) => void;-}) {+}: ScheduleLinkProps) {const { t } = useTranslation();const dispatch = useDispatch();@@ -61,9 +60,14 @@ export function ScheduleLink({async function onCreate() {dispatch(- pushModal('schedule-edit', {- id: null,- transaction: getTransaction(ids[0]),+ pushModal({+ modal: {+ name: 'schedule-edit',+ options: {+ id: null,+ transaction: getTransaction(ids[0]),+ },+ },}),);}diff --git a/packages/desktop-client/src/components/schedules/index.tsx b/packages/desktop-client/src/components/schedules/index.tsxindex b45bfbc4c2..1dcc27ebb1 100644--- a/packages/desktop-client/src/components/schedules/index.tsx+++ b/packages/desktop-client/src/components/schedules/index.tsx@@ -4,8 +4,8 @@ import { Trans, useTranslation } from 'react-i18next';import { Button } from '@actual-app/components/button';import { View } from '@actual-app/components/view';-import { pushModal } from 'loot-core/client/actions';import { useSchedules } from 'loot-core/client/data-hooks/schedules';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import { q } from 'loot-core/shared/query';import { type ScheduleEntity } from 'loot-core/types/models';@@ -25,21 +25,23 @@ export function Schedules() {const onEdit = useCallback((id: ScheduleEntity['id']) => {- dispatch(pushModal('schedule-edit', { id }));+ dispatch(+ pushModal({ modal: { name: 'schedule-edit', options: { id } } }),+ );},[dispatch],);const onAdd = useCallback(() => {- dispatch(pushModal('schedule-edit'));+ dispatch(pushModal({ modal: { name: 'schedule-edit', options: {} } }));}, [dispatch]);const onDiscover = useCallback(() => {- dispatch(pushModal('schedules-discover'));+ dispatch(pushModal({ modal: { name: 'schedules-discover' } }));}, [dispatch]);const onChangeUpcomingLength = useCallback(() => {- dispatch(pushModal('schedules-upcoming-length'));+ dispatch(pushModal({ modal: { name: 'schedules-upcoming-length' } }));}, [dispatch]);const onAction = useCallback(diff --git a/packages/desktop-client/src/components/settings/AuthSettings.tsx b/packages/desktop-client/src/components/settings/AuthSettings.tsxindex c5f3ed3d51..eb37a58ee4 100644--- a/packages/desktop-client/src/components/settings/AuthSettings.tsx+++ b/packages/desktop-client/src/components/settings/AuthSettings.tsx@@ -5,7 +5,7 @@ import { Button } from '@actual-app/components/button';import { Label } from '@actual-app/components/label';import { Text } from '@actual-app/components/text';-import { pushModal } from 'loot-core/client/actions';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { useFeatureFlag } from '../../hooks/useFeatureFlag';import { useDispatch } from '../../redux';@@ -42,8 +42,13 @@ export function AuthSettings() {variant="normal"onPress={() =>dispatch(- pushModal('enable-openid', {- onSave: async () => {},+ pushModal({+ modal: {+ name: 'enable-openid',+ options: {+ onSave: async () => {},+ },+ },}),)}@@ -65,8 +70,13 @@ export function AuthSettings() {variant="normal"onPress={() =>dispatch(- pushModal('enable-password-auth', {- onSave: async () => {},+ pushModal({+ modal: {+ name: 'enable-password-auth',+ options: {+ onSave: async () => {},+ },+ },}),)}diff --git a/packages/desktop-client/src/components/settings/Encryption.tsx b/packages/desktop-client/src/components/settings/Encryption.tsxindex 91da20cdf3..7b2f8518d3 100644--- a/packages/desktop-client/src/components/settings/Encryption.tsx+++ b/packages/desktop-client/src/components/settings/Encryption.tsx@@ -4,7 +4,7 @@ import { Trans } from 'react-i18next';import { Button } from '@actual-app/components/button';import { Text } from '@actual-app/components/text';-import { pushModal } from 'loot-core/client/actions';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { useMetadataPref } from '../../hooks/useMetadataPref';import { useDispatch } from '../../redux';@@ -22,7 +22,11 @@ export function EncryptionSettings() {const missingCryptoAPI = !(window.crypto && crypto.subtle);function onChangeKey() {- dispatch(pushModal('create-encryption-key', { recreate: true }));+ dispatch(+ pushModal({+ modal: { name: 'create-encryption-key', options: { recreate: true } },+ }),+ );}return encryptKeyId ? (@@ -78,7 +82,15 @@ export function EncryptionSettings() {) : serverURL ? (<SettingprimaryAction={- <Button onPress={() => dispatch(pushModal('create-encryption-key'))}>+ <Button+ onPress={() =>+ dispatch(+ pushModal({+ modal: { name: 'create-encryption-key', options: {} },+ }),+ )+ }+ ><Trans>Enable encryption</Trans></Button>}diff --git a/packages/desktop-client/src/components/sidebar/Account.tsx b/packages/desktop-client/src/components/sidebar/Account.tsxindex 0c095ae16e..fd6de58ae1 100644--- a/packages/desktop-client/src/components/sidebar/Account.tsx+++ b/packages/desktop-client/src/components/sidebar/Account.tsx@@ -12,7 +12,7 @@ import { Tooltip } from '@actual-app/components/tooltip';import { View } from '@actual-app/components/view';import { css, cx } from '@emotion/css';-import { openAccountCloseModal } from 'loot-core/client/actions';+import { openAccountCloseModal } from 'loot-core/client/modals/modalsSlice';import * as Platform from 'loot-core/client/platform';import {reopenAccount,@@ -234,7 +234,9 @@ export function Account<FieldName extends SheetFields<'account'>>({onMenuSelect={type => {switch (type) {case 'close': {- dispatch(openAccountCloseModal(account.id));+ dispatch(+ openAccountCloseModal({ accountId: account.id }),+ );break;}case 'reopen': {diff --git a/packages/desktop-client/src/components/sidebar/Sidebar.tsx b/packages/desktop-client/src/components/sidebar/Sidebar.tsxindex 4d8c01f42c..db4ce920ae 100644--- a/packages/desktop-client/src/components/sidebar/Sidebar.tsx+++ b/packages/desktop-client/src/components/sidebar/Sidebar.tsx@@ -6,7 +6,7 @@ import { View } from '@actual-app/components/view';import { css } from '@emotion/css';import { Resizable } from 're-resizable';-import { replaceModal } from 'loot-core/client/actions';+import { replaceModal } from 'loot-core/client/modals/modalsSlice';import * as Platform from 'loot-core/client/platform';import { useGlobalPref } from '../../hooks/useGlobalPref';@@ -59,7 +59,7 @@ export function Sidebar() {};const onAddAccount = () => {- dispatch(replaceModal('add-account'));+ dispatch(replaceModal({ modal: { name: 'add-account', options: {} } }));};const containerRef = useResizeObserver<HTMLDivElement>(rect => {diff --git a/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx b/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsxindex 60fe4ea2f3..66034799af 100644--- a/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx+++ b/packages/desktop-client/src/components/transactions/SelectedTransactionsButton.tsx@@ -4,8 +4,8 @@ import { useTranslation } from 'react-i18next';import { Menu } from '@actual-app/components/menu';-import { pushModal } from 'loot-core/client/actions';import { useSchedules } from 'loot-core/client/data-hooks/schedules';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { validForTransfer } from 'loot-core/client/transfer';import { q } from 'loot-core/shared/query';import {@@ -200,7 +200,11 @@ export function SelectedTransactionsButton({}if (scheduleId) {- dispatch(pushModal('schedule-edit', { id: scheduleId }));+ dispatch(+ pushModal({+ modal: { name: 'schedule-edit', options: { id: scheduleId } },+ }),+ );}}diff --git a/packages/desktop-client/src/components/transactions/TransactionList.jsx b/packages/desktop-client/src/components/transactions/TransactionList.jsxindex c404ffbfdc..bcd3097d41 100644--- a/packages/desktop-client/src/components/transactions/TransactionList.jsx+++ b/packages/desktop-client/src/components/transactions/TransactionList.jsx@@ -1,6 +1,6 @@import React, { useRef, useCallback, useLayoutEffect } from 'react';-import { pushModal } from 'loot-core/client/actions';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { send } from 'loot-core/platform/client/fetch';import {splitTransaction,@@ -234,7 +234,11 @@ export function TransactionList({const onNavigateToSchedule = useCallback(scheduleId => {- dispatch(pushModal('schedule-edit', { id: scheduleId }));+ dispatch(+ pushModal({+ modal: { name: 'schedule-edit', options: { id: scheduleId } },+ }),+ );},[dispatch],);diff --git a/packages/desktop-client/src/components/transactions/TransactionMenu.tsx b/packages/desktop-client/src/components/transactions/TransactionMenu.tsxindex b25fa88ff7..e97261e61d 100644--- a/packages/desktop-client/src/components/transactions/TransactionMenu.tsx+++ b/packages/desktop-client/src/components/transactions/TransactionMenu.tsx@@ -3,8 +3,8 @@ import { useTranslation } from 'react-i18next';import { Menu } from '@actual-app/components/menu';-import { pushModal } from 'loot-core/client/actions';import { useSchedules } from 'loot-core/client/data-hooks/schedules';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { q } from 'loot-core/shared/query';import {scheduleIsRecurring,@@ -84,7 +84,11 @@ export function TransactionMenu({}if (scheduleId) {- dispatch(pushModal('schedule-edit', { id: scheduleId }));+ dispatch(+ pushModal({+ modal: { name: 'schedule-edit', options: { id: scheduleId } },+ }),+ );}}diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.jsx b/packages/desktop-client/src/components/transactions/TransactionsTable.jsxindex 8312f63b68..88ee2e5250 100644--- a/packages/desktop-client/src/components/transactions/TransactionsTable.jsx+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.jsx@@ -25,8 +25,9 @@ import {isValid as isDateValid,} from 'date-fns';-import { addNotification, pushModal } from 'loot-core/client/actions';+import { addNotification } from 'loot-core/client/actions';import { useCachedSchedules } from 'loot-core/client/data-hooks/schedules';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import {getAccountsById,getPayeesById,@@ -521,9 +522,14 @@ function PayeeCell({disabled={isPreview}onSelect={() =>dispatch(- pushModal('payee-autocomplete', {- onSelect: payeeId => {- onUpdate('payee', payeeId);+ pushModal({+ modal: {+ name: 'payee-autocomplete',+ options: {+ onSelect: payeeId => {+ onUpdate('payee', payeeId);+ },+ },},}),)@@ -858,15 +864,20 @@ const Transaction = memo(function Transaction({if (showReconciliationWarning === false) {setShowReconciliationWarning(true);dispatch(- pushModal('confirm-transaction-edit', {- onCancel: () => {- setShowReconciliationWarning(false);+ pushModal({+ modal: {+ name: 'confirm-transaction-edit',+ options: {+ onCancel: () => {+ setShowReconciliationWarning(false);+ },+ onConfirm: () => {+ setShowReconciliationWarning(false);+ onUpdateAfterConfirm(name, value);+ },+ confirmReason: 'editReconciled',+ },},- onConfirm: () => {- setShowReconciliationWarning(false);- onUpdateAfterConfirm(name, value);- },- confirmReason: 'editReconciled',}),);}@@ -878,11 +889,16 @@ const Transaction = memo(function Transaction({// Allow un-reconciling (unlocking) transactionsif (name === 'cleared' && transaction.reconciled) {dispatch(- pushModal('confirm-transaction-edit', {- onConfirm: () => {- onUpdateAfterConfirm('reconciled', false);+ pushModal({+ modal: {+ name: 'confirm-transaction-edit',+ options: {+ onConfirm: () => {+ onUpdateAfterConfirm('reconciled', false);+ },+ confirmReason: 'unlockReconciled',+ },},- confirmReason: 'unlockReconciled',}),);}diff --git a/packages/desktop-client/src/global-events.ts b/packages/desktop-client/src/global-events.tsindex 63938eadcb..4467783849 100644--- a/packages/desktop-client/src/global-events.ts+++ b/packages/desktop-client/src/global-events.ts@@ -2,13 +2,15 @@import {addGenericErrorNotification,addNotification,- closeModal,loadPrefs,- pushModal,- replaceModal,} from 'loot-core/client/actions';import { setAppState } from 'loot-core/client/app/appSlice';import { closeBudgetUI } from 'loot-core/client/budgets/budgetsSlice';+import {+ closeModal,+ pushModal,+ replaceModal,+} from 'loot-core/client/modals/modalsSlice';import {getAccounts,getCategories,@@ -29,16 +31,23 @@ export function handleGlobalEvents(store: AppStore) {({ orphanedIds, updatedPayeeIds }) => {// Right now, it prompts to merge into the first payeestore.dispatch(- pushModal('merge-unused-payees', {- payeeIds: orphanedIds,- targetPayeeId: updatedPayeeIds[0],+ pushModal({+ modal: {+ name: 'merge-unused-payees',+ options: {+ payeeIds: orphanedIds,+ targetPayeeId: updatedPayeeIds[0],+ },+ },}),);},);const unlistenSchedulesOffline = listen('schedules-offline', () => {- store.dispatch(pushModal('schedule-posts-offline-notification'));+ store.dispatch(+ pushModal({ modal: { name: 'schedule-posts-offline-notification' } }),+ );});const unlistenSync = sharedListeners.listenForSyncEvent(store);@@ -79,9 +88,9 @@ export function handleGlobalEvents(store: AppStore) {if (modalStack.length === 0 ||- modalStack[modalStack.length - 1].name !== tagged.openModal+ modalStack[modalStack.length - 1].name !== tagged.openModal.name) {- store.dispatch(replaceModal(tagged.openModal));+ store.dispatch(replaceModal({ modal: tagged.openModal }));}} else {store.dispatch(closeModal());diff --git a/packages/desktop-client/src/gocardless.ts b/packages/desktop-client/src/gocardless.tsindex 6cbb6b905d..8726156203 100644--- a/packages/desktop-client/src/gocardless.ts+++ b/packages/desktop-client/src/gocardless.ts@@ -1,4 +1,4 @@-import { pushModal } from 'loot-core/client/actions/modals';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { type AppDispatch } from 'loot-core/client/store';import { send } from 'loot-core/platform/client/fetch';import { type GoCardlessToken } from 'loot-core/types/models';@@ -14,24 +14,28 @@ function _authorize(},) {dispatch(- pushModal('gocardless-external-msg', {- onMoveExternal: async ({ institutionId }) => {- const resp = await send('gocardless-create-web-token', {- institutionId,- accessValidForDays: 90,- });+ pushModal({+ modal: {+ name: 'gocardless-external-msg',+ options: {+ onMoveExternal: async ({ institutionId }) => {+ const resp = await send('gocardless-create-web-token', {+ institutionId,+ accessValidForDays: 90,+ });- if ('error' in resp) return resp;- const { link, requisitionId } = resp;- window.Actual.openURLInBrowser(link);+ if ('error' in resp) return resp;+ const { link, requisitionId } = resp;+ window.Actual.openURLInBrowser(link);- return send('gocardless-poll-web-token', {- requisitionId,- });+ return send('gocardless-poll-web-token', {+ requisitionId,+ });+ },+ onClose,+ onSuccess,+ },},-- onClose,- onSuccess,}),);}@@ -40,10 +44,15 @@ export async function authorizeBank(dispatch: AppDispatch) {_authorize(dispatch, {onSuccess: async data => {dispatch(- pushModal('select-linked-accounts', {- accounts: data.accounts,- requisitionId: data.id,- syncSource: 'goCardless',+ pushModal({+ modal: {+ name: 'select-linked-accounts',+ options: {+ externalAccounts: data.accounts,+ requisitionId: data.id,+ syncSource: 'goCardless',+ },+ },}),);},diff --git a/packages/desktop-client/src/hooks/useModalState.ts b/packages/desktop-client/src/hooks/useModalState.tsindex 9b01288eea..b8ed3d608b 100644--- a/packages/desktop-client/src/hooks/useModalState.ts+++ b/packages/desktop-client/src/hooks/useModalState.ts@@ -1,7 +1,6 @@import { useCallback } from 'react';-import { popModal } from 'loot-core/client/actions';-import { type Modal } from 'loot-core/client/state-types/modals';+import { type Modal, popModal } from 'loot-core/client/modals/modalsSlice';import { useSelector, useDispatch } from '../redux';diff --git a/packages/desktop-client/src/hooks/useTransactionBatchActions.ts b/packages/desktop-client/src/hooks/useTransactionBatchActions.tsindex e78a12a4f4..0d42461d9a 100644--- a/packages/desktop-client/src/hooks/useTransactionBatchActions.ts+++ b/packages/desktop-client/src/hooks/useTransactionBatchActions.ts@@ -1,4 +1,4 @@-import { pushModal } from 'loot-core/client/actions';+import { pushModal } from 'loot-core/client/modals/modalsSlice';import { runQuery } from 'loot-core/client/query-helpers';import { validForTransfer } from 'loot-core/client/transfer';import { send } from 'loot-core/platform/client/fetch';@@ -154,16 +154,26 @@ export function useTransactionBatchActions() {const pushPayeeAutocompleteModal = () => {dispatch(- pushModal('payee-autocomplete', {- onSelect: payeeId => onChange(name, payeeId),+ pushModal({+ modal: {+ name: 'payee-autocomplete',+ options: {+ onSelect: payeeId => onChange(name, payeeId),+ },+ },}),);};const pushAccountAutocompleteModal = () => {dispatch(- pushModal('account-autocomplete', {- onSelect: accountId => onChange(name, accountId),+ pushModal({+ modal: {+ name: 'account-autocomplete',+ options: {+ onSelect: accountId => onChange(name, accountId),+ },+ },}),);};@@ -174,9 +184,14 @@ export function useTransactionBatchActions() {}dispatch(- pushModal('edit-field', {- name,- onSubmit: (name, value, mode) => onChange(name, value, mode),+ pushModal({+ modal: {+ name: 'edit-field',+ options: {+ name,+ onSubmit: (name, value, mode) => onChange(name, value, mode),+ },+ },}),);};@@ -192,9 +207,14 @@ export function useTransactionBatchActions() {t => monthUtils.monthFromDate(t.date) === transactionMonth,);dispatch(- pushModal('category-autocomplete', {- month: transactionsHaveSameMonth ? transactionMonth : undefined,- onSelect: categoryId => onChange(name, categoryId),+ pushModal({+ modal: {+ name: 'category-autocomplete',+ options: {+ month: transactionsHaveSameMonth ? transactionMonth : undefined,+ onSelect: categoryId => onChange(name, categoryId),+ },+ },}),);};@@ -208,17 +228,22 @@ export function useTransactionBatchActions() {const reconciledTransactions = transactions.filter(t => t.reconciled);if (reconciledTransactions.length > 0) {dispatch(- pushModal('confirm-transaction-edit', {- onConfirm: () => {- if (name === 'payee') {- pushPayeeAutocompleteModal();- } else if (name === 'account') {- pushAccountAutocompleteModal();- } else {- pushEditField();- }+ pushModal({+ modal: {+ name: 'confirm-transaction-edit',+ options: {+ onConfirm: () => {+ if (name === 'payee') {+ pushPayeeAutocompleteModal();+ } else if (name === 'account') {+ pushAccountAutocompleteModal();+ } else {+ pushEditField();+ }+ },+ confirmReason: 'batchEditWithReconciled',+ },},- confirmReason: 'batchEditWithReconciled',}),);return;@@ -282,58 +307,68 @@ export function useTransactionBatchActions() {const onBatchDelete = async ({ ids, onSuccess }: BatchDeleteProps) => {const onConfirmDelete = (ids: Array<TransactionEntity['id']>) => {dispatch(- pushModal('confirm-transaction-delete', {- message:- ids.length > 1- ? `Are you sure you want to delete these ${ids.length} transaction${ids.length > 1 ? 's' : ''}?`- : undefined,- onConfirm: async () => {- const { data } = await runQuery(- q('transactions')- .filter({ id: { $oneof: ids } })- .select('*')- .options({ splits: 'grouped' }),- );- let transactions = ungroupTransactions(data as TransactionEntity[]);-- const idSet = new Set(ids);- const changes: Diff<TransactionEntity> = {- added: [],- deleted: [],- updated: [],- };-- transactions.forEach(trans => {- const parentId = trans.parent_id;-- // First, check if we're actually deleting this transaction by- // checking `idSet`. Then, we don't need to do anything if it's- // a child transaction and the parent is already being deleted- if (!idSet.has(trans.id) || (parentId && idSet.has(parentId))) {- return;- }-- const { diff } = deleteTransaction(transactions, trans.id);-- // TODO: We need to keep an updated list of transactions so- // the logic in `updateTransaction`, particularly about- // updating split transactions, works. This isn't ideal and we- // should figure something else out- transactions = applyChanges<TransactionEntity>(- diff,- transactions,- );-- changes.deleted = diff.deleted- ? changes.deleted.concat(diff.deleted)- : diff.deleted;- changes.updated = diff.updated- ? changes.updated.concat(diff.updated)- : diff.updated;- });-- await send('transactions-batch-update', changes);- onSuccess?.(ids);+ pushModal({+ modal: {+ name: 'confirm-transaction-delete',+ options: {+ message:+ ids.length > 1+ ? `Are you sure you want to delete these ${ids.length} transaction${ids.length > 1 ? 's' : ''}?`+ : undefined,+ onConfirm: async () => {+ const { data } = await runQuery(+ q('transactions')+ .filter({ id: { $oneof: ids } })+ .select('*')+ .options({ splits: 'grouped' }),+ );+ let transactions = ungroupTransactions(+ data as TransactionEntity[],+ );++ const idSet = new Set(ids);+ const changes: Diff<TransactionEntity> = {+ added: [],+ deleted: [],+ updated: [],+ };++ transactions.forEach(trans => {+ const parentId = trans.parent_id;++ // First, check if we're actually deleting this transaction by+ // checking `idSet`. Then, we don't need to do anything if it's+ // a child transaction and the parent is already being deleted+ if (+ !idSet.has(trans.id) ||+ (parentId && idSet.has(parentId))+ ) {+ return;+ }++ const { diff } = deleteTransaction(transactions, trans.id);++ // TODO: We need to keep an updated list of transactions so+ // the logic in `updateTransaction`, particularly about+ // updating split transactions, works. This isn't ideal and we+ // should figure something else out+ transactions = applyChanges<TransactionEntity>(+ diff,+ transactions,+ );++ changes.deleted = diff.deleted+ ? changes.deleted.concat(diff.deleted)+ : diff.deleted;+ changes.updated = diff.updated+ ? changes.updated.concat(diff.updated)+ : diff.updated;+ });++ await send('transactions-batch-update', changes);+ onSuccess?.(ids);+ },+ },},}),);@@ -359,13 +394,18 @@ export function useTransactionBatchActions() {);dispatch(- pushModal('schedule-link', {- transactionIds: ids,- getTransaction: (id: TransactionEntity['id']) =>- transactions.find((t: TransactionEntity) => t.id === id),- accountName: account?.name ?? '',- onScheduleLinked: schedule => {- onSuccess?.(ids, schedule);+ pushModal({+ modal: {+ name: 'schedule-link',+ options: {+ transactionIds: ids,+ getTransaction: (id: TransactionEntity['id']) =>+ transactions.find((t: TransactionEntity) => t.id === id),+ accountName: account?.name ?? '',+ onScheduleLinked: schedule => {+ onSuccess?.(ids, schedule);+ },+ },},}),);@@ -398,11 +438,16 @@ export function useTransactionBatchActions() {const transactions = ungroupTransactions(data as TransactionEntity[]);if (transactions.length > 0) {dispatch(- pushModal('confirm-transaction-edit', {- onConfirm: () => {- onConfirm(ids);+ pushModal({+ modal: {+ name: 'confirm-transaction-edit',+ options: {+ onConfirm: () => {+ onConfirm(ids);+ },+ confirmReason,+ },},- confirmReason,}),);} else {diff --git a/packages/desktop-client/src/index.tsx b/packages/desktop-client/src/index.tsxindex a23d7fb1e3..8740e34607 100644--- a/packages/desktop-client/src/index.tsx+++ b/packages/desktop-client/src/index.tsx@@ -17,6 +17,7 @@ import * as accountsSlice from 'loot-core/client/accounts/accountsSlice';import * as actions from 'loot-core/client/actions';import * as appSlice from 'loot-core/client/app/appSlice';import * as budgetsSlice from 'loot-core/client/budgets/budgetsSlice';+import * as modalsSlice from 'loot-core/client/modals/modalsSlice';import * as queriesSlice from 'loot-core/client/queries/queriesSlice';import { runQuery } from 'loot-core/client/query-helpers';import { store } from 'loot-core/client/store';@@ -38,6 +39,7 @@ const boundActions = bindActionCreators(...accountsSlice.actions,...appSlice.actions,...budgetsSlice.actions,+ ...modalsSlice.actions,...queriesSlice.actions,},store.dispatch,diff --git a/packages/loot-core/src/client/actions/index.ts b/packages/loot-core/src/client/actions/index.tsindex 1fbc47c94a..b9e0e8b2fb 100644--- a/packages/loot-core/src/client/actions/index.ts+++ b/packages/loot-core/src/client/actions/index.ts@@ -1,4 +1,3 @@-export * from './modals';export * from './notifications';export * from './prefs';export * from './user';diff --git a/packages/loot-core/src/client/actions/modals.ts b/packages/loot-core/src/client/actions/modals.tsdeleted file mode 100644index e810a4bcb2..0000000000--- a/packages/loot-core/src/client/actions/modals.ts+++ /dev/null@@ -1,82 +0,0 @@-import { send } from '../../platform/client/fetch';-import { type AccountEntity } from '../../types/models';-import * as constants from '../constants';-import type {- OptionlessModal,- CloseModalAction,- PopModalAction,- PushModalAction,- ReplaceModalAction,- ModalWithOptions,- ModalType,- FinanceModals,- Modal,-} from '../state-types/modals';-import { type AppDispatch, type GetRootState } from '../store';--export function pushModal<M extends keyof ModalWithOptions>(- name: M,- options: ModalWithOptions[M],-): PushModalAction;-export function pushModal(name: OptionlessModal): PushModalAction;-export function pushModal<M extends ModalType>(- name: M,- options?: FinanceModals[M],-): PushModalAction;-export function pushModal<M extends ModalType>(- name: M,- options?: FinanceModals[M],-): PushModalAction {- const modal = { name, options };- return { type: constants.PUSH_MODAL, modal };-}--export function replaceModal<M extends keyof ModalWithOptions>(- name: M,- options: ModalWithOptions[M],-): ReplaceModalAction;-export function replaceModal(name: OptionlessModal): ReplaceModalAction;-export function replaceModal<M extends ModalType>(- name: M,- options?: FinanceModals[M],-): ReplaceModalAction {- const modal: Modal = { name, options };- return { type: constants.REPLACE_MODAL, modal };-}--export function popModal(): PopModalAction {- return { type: constants.POP_MODAL };-}--export function closeModal(): CloseModalAction {- return { type: constants.CLOSE_MODAL };-}--export function collapseModals(rootModalName: string) {- return { type: constants.COLLAPSE_MODALS, rootModalName };-}--export function openAccountCloseModal(accountId: AccountEntity['id']) {- return async (dispatch: AppDispatch, getState: GetRootState) => {- const {- balance,- numTransactions,- }: { balance: number; numTransactions: number } = await send(- 'account-properties',- {- id: accountId,- },- );- const account = getState().queries.accounts.find(- acct => acct.id === accountId,- );-- dispatch(- pushModal('close-account' as ModalType, {- account,- balance,- canDelete: numTransactions === 0,- }),- );- };-}diff --git a/packages/loot-core/src/client/actions/prefs.ts b/packages/loot-core/src/client/actions/prefs.tsindex a0034b0224..3744d037e8 100644--- a/packages/loot-core/src/client/actions/prefs.ts+++ b/packages/loot-core/src/client/actions/prefs.ts@@ -9,10 +9,9 @@ import {type SyncedPrefs,} from '../../types/prefs';import * as constants from '../constants';+import { closeModal } from '../modals/modalsSlice';import { type AppDispatch, type GetRootState } from '../store';-import { closeModal } from './modals';-export function loadPrefs() {return async (dispatch: AppDispatch, getState: GetRootState) => {const prefs = await send('load-prefs');diff --git a/packages/loot-core/src/client/app/appSlice.ts b/packages/loot-core/src/client/app/appSlice.tsindex 819027feb0..e93f0c2439 100644--- a/packages/loot-core/src/client/app/appSlice.ts+++ b/packages/loot-core/src/client/app/appSlice.ts@@ -3,8 +3,10 @@ import { createSlice, type PayloadAction } from '@reduxjs/toolkit';import { send } from '../../platform/client/fetch';import { getUploadError } from '../../shared/errors';import { type AccountEntity } from '../../types/models';+import { type AtLeastOne } from '../../types/util';import { syncAccounts } from '../accounts/accountsSlice';-import { loadPrefs, pushModal } from '../actions';+import { loadPrefs } from '../actions';+import { pushModal } from '../modals/modalsSlice';import { createAppAsyncThunk } from '../redux';const sliceName = 'app';@@ -49,15 +51,27 @@ export const resetSync = createAppAsyncThunk(error.reason === 'file-has-new-key') {dispatch(- pushModal('fix-encryption-key', {- onSuccess: () => {- // TODO: There won't be a loading indicator for this- dispatch(resetSync());+ pushModal({+ modal: {+ name: 'fix-encryption-key',+ options: {+ onSuccess: () => {+ // TODO: There won't be a loading indicator for this+ dispatch(resetSync());+ },+ },},}),);} else if (error.reason === 'encrypt-failure') {- dispatch(pushModal('create-encryption-key', { recreate: true }));+ dispatch(+ pushModal({+ modal: {+ name: 'create-encryption-key',+ options: { recreate: true },+ },+ }),+ );}} else {await dispatch(sync());@@ -117,7 +131,9 @@ export const syncAndDownload = createAppAsyncThunk(},);-type SetAppStatePayload = Partial<AppState>;+// Workaround for partial types in actions.+// https://github.com/reduxjs/redux-toolkit/issues/1423#issuecomment-902680573+type SetAppStatePayload = AtLeastOne<AppState>;const appSlice = createSlice({name: sliceName,diff --git a/packages/loot-core/src/client/budgets/budgetsSlice.ts b/packages/loot-core/src/client/budgets/budgetsSlice.tsindex 2ab08a9b5e..73a734c0c5 100644--- a/packages/loot-core/src/client/budgets/budgetsSlice.ts+++ b/packages/loot-core/src/client/budgets/budgetsSlice.ts@@ -7,9 +7,10 @@ import { getDownloadError, getSyncError } from '../../shared/errors';import { type Budget } from '../../types/budget';import { type File } from '../../types/file';import { type Handlers } from '../../types/handlers';-import { closeModal, loadGlobalPrefs, loadPrefs, pushModal } from '../actions';+import { loadGlobalPrefs, loadPrefs } from '../actions';import { setAppState } from '../app/appSlice';import * as constants from '../constants';+import { closeModal, pushModal } from '../modals/modalsSlice';import { createAppAsyncThunk } from '../redux';const sliceName = 'budgets';@@ -61,7 +62,9 @@ export const loadBudget = createAppAsyncThunk(if (error) {const message = getSyncError(error, id);if (error === 'out-of-sync-migrations') {- await dispatch(pushModal('out-of-sync-migrations'));+ await dispatch(+ pushModal({ modal: { name: 'out-of-sync-migrations' } }),+ );} else if (error === 'out-of-sync-data') {// confirm is not available on iOSif (typeof window.confirm !== 'undefined') {@@ -74,7 +77,9 @@ export const loadBudget = createAppAsyncThunk();if (showBackups) {- await dispatch(pushModal('load-backup', { budgetId: id }));+ await dispatch(+ pushModal({ modal: { name: 'load-backup', options: {} } }),+ );}} else {alert(message + ' ' + t('Make sure the app is up-to-date.'));@@ -266,9 +271,13 @@ export const uploadBudget = createAppAsyncThunk(},);+type CloseAndLoadBudgetPayload = {+ fileId: string;+};+export const closeAndLoadBudget = createAppAsyncThunk(`${sliceName}/closeAndLoadBudget`,- async ({ fileId }: { fileId: string }, { dispatch }) => {+ async ({ fileId }: CloseAndLoadBudgetPayload, { dispatch }) => {await dispatch(closeBudget());await dispatch(loadBudget({ id: fileId }));},@@ -318,7 +327,9 @@ export const downloadBudget = createAppAsyncThunk(},};- await dispatch(pushModal('fix-encryption-key', opts));+ await dispatch(+ pushModal({ modal: { name: 'fix-encryption-key', options: opts } }),+ );await dispatch(setAppState({ loadingText: null }));} else if (error.reason === 'file-exists') {alert(diff --git a/packages/loot-core/src/client/modals/modalsSlice.ts b/packages/loot-core/src/client/modals/modalsSlice.tsnew file mode 100644index 0000000000..57664ef55b--- /dev/null+++ b/packages/loot-core/src/client/modals/modalsSlice.ts@@ -0,0 +1,645 @@+import { createSlice, type PayloadAction } from '@reduxjs/toolkit';++import { send } from '../../platform/client/fetch';+import { type File } from '../../types/file';+import {+ type AccountEntity,+ type AccountSyncSource,+ type CategoryEntity,+ type CategoryGroupEntity,+ type GoCardlessToken,+ type NewRuleEntity,+ type RuleEntity,+ type ScheduleEntity,+ type TransactionEntity,+ type UserEntity,+ type UserAccessEntity,+ type NewUserEntity,+ type NoteEntity,+} from '../../types/models';+import { setAppState } from '../app/appSlice';+import { signOut } from '../budgets/budgetsSlice';+import { createAppAsyncThunk } from '../redux';++const sliceName = 'modals';++export type Modal =+ | {+ name: 'import-transactions';+ options: {+ accountId: string;+ filename: string;+ categories?: { list: CategoryEntity[]; grouped: CategoryGroupEntity[] };+ onImported: (didChange: boolean) => void;+ };+ }+ | {+ name: 'add-account';+ options: {+ upgradingAccountId?: string;+ };+ }+ | {+ name: 'add-local-account';+ }+ | {+ name: 'close-account';+ options: {+ account: AccountEntity;+ balance: number;+ canDelete: boolean;+ };+ }+ | {+ name: 'select-linked-accounts';+ options: {+ externalAccounts: unknown[];+ requisitionId?: string;+ upgradingAccountId?: string | undefined;+ syncSource?: AccountSyncSource;+ };+ }+ | {+ name: 'confirm-category-delete';+ options: {+ onDelete: (transferCategoryId: CategoryEntity['id']) => void;+ category?: CategoryEntity['id'];+ group?: CategoryGroupEntity['id'];+ };+ }+ | {+ name: 'load-backup';+ options: {+ budgetId?: string;+ watchUpdates?: boolean;+ backupDisabled?: boolean;+ };+ }+ | {+ name: 'manage-rules';+ options: { payeeId?: string };+ }+ | {+ name: 'edit-rule';+ options: {+ rule: RuleEntity | NewRuleEntity;+ onSave?: (rule: RuleEntity) => void;+ };+ }+ | {+ name: 'merge-unused-payees';+ options: {+ payeeIds: string[];+ targetPayeeId: string;+ };+ }+ | {+ name: 'gocardless-init';+ options: {+ onSuccess: () => void;+ };+ }+ | {+ name: 'simplefin-init';+ options: {+ onSuccess: () => void;+ };+ }+ | {+ name: 'pluggyai-init';+ options: {+ onSuccess: () => void;+ };+ }+ | {+ name: 'gocardless-external-msg';+ options: {+ onMoveExternal: (arg: {+ institutionId: string;+ }) => Promise<+ { error: 'unknown' | 'timeout' } | { data: GoCardlessToken }+ >;+ onClose?: (() => void) | undefined;+ onSuccess: (data: GoCardlessToken) => Promise<void>;+ };+ }+ | {+ name: 'delete-budget';+ options: { file: File };+ }+ | {+ name: 'duplicate-budget';+ options: {+ /** The budget file to be duplicated */+ file: File;+ /**+ * Indicates whether the duplication is initiated from the budget+ * management page. This may affect the behavior or UI of the+ * duplication process.+ */+ managePage?: boolean;+ /**+ * loadBudget indicates whether to open the 'original' budget, the+ * new duplicated 'copy' budget, or no budget ('none'). If 'none'+ * duplicate-budget stays on the same page.+ */+ loadBudget?: 'none' | 'original' | 'copy';+ /**+ * onComplete is called when the DuplicateFileModal is closed.+ * @param event the event object will pass back the status of the+ * duplicate process.+ * 'success' if the budget was duplicated.+ * 'failed' if the budget could not be duplicated. This will also+ * pass an error on the event object.+ * 'canceled' if the DuplicateFileModal was canceled.+ * @returns+ */+ onComplete?: (event: {+ status: 'success' | 'failed' | 'canceled';+ error?: Error;+ }) => void;+ };+ }+ | {+ name: 'import';+ }+ | {+ name: 'import-ynab4';+ }+ | {+ name: 'import-ynab5';+ }+ | {+ name: 'import-actual';+ }+ | {+ name: 'out-of-sync-migrations';+ }+ | {+ name: 'files-settings';+ }+ | {+ name: 'confirm-change-document-dir';+ options: {+ currentBudgetDirectory: string;+ newDirectory: string;+ };+ }+ | {+ name: 'create-encryption-key';+ options: { recreate?: boolean };+ }+ | {+ name: 'fix-encryption-key';+ options: {+ hasExistingKey?: boolean;+ cloudFileId?: string;+ onSuccess?: () => void;+ };+ }+ | {+ name: 'edit-field';+ options: {+ name: keyof Pick<TransactionEntity, 'date' | 'amount' | 'notes'>;+ onSubmit: (+ name: keyof Pick<TransactionEntity, 'date' | 'amount' | 'notes'>,+ value: string | number,+ mode?: 'prepend' | 'append' | 'replace' | null,+ ) => void;+ onClose?: () => void;+ };+ }+ | {+ name: 'category-autocomplete';+ options: {+ categoryGroups?: CategoryGroupEntity[];+ onSelect: (categoryId: string, categoryName: string) => void;+ month?: string | undefined;+ showHiddenCategories?: boolean;+ onClose?: () => void;+ };+ }+ | {+ name: 'account-autocomplete';+ options: {+ onSelect: (accountId: string, accountName: string) => void;+ includeClosedAccounts?: boolean;+ onClose?: () => void;+ };+ }+ | {+ name: 'payee-autocomplete';+ options: {+ onSelect: (payeeId: string) => void;+ onClose?: () => void;+ };+ }+ | {+ name: 'budget-summary';+ options: {+ month: string;+ };+ }+ | {+ name: 'schedule-edit';+ options: { id?: string; transaction?: TransactionEntity } | null;+ }+ | {+ name: 'schedule-link';+ options: {+ transactionIds: string[];+ getTransaction: (+ transactionId: TransactionEntity['id'],+ ) => TransactionEntity;+ accountName?: string;+ onScheduleLinked?: (schedule: ScheduleEntity) => void;+ };+ }+ | {+ name: 'schedules-discover';+ }+ | {+ name: 'schedule-posts-offline-notification';+ }+ | {+ name: 'synced-account-edit';+ options: {+ account: AccountEntity;+ };+ }+ | {+ name: 'account-menu';+ options: {+ accountId: AccountEntity['id'];+ onSave: (account: AccountEntity) => void;+ onCloseAccount: (accountId: AccountEntity['id']) => void;+ onReopenAccount: (accountId: AccountEntity['id']) => void;+ onEditNotes: (id: NoteEntity['id']) => void;+ onClose?: () => void;+ };+ }+ | {+ name: 'category-menu';+ options: {+ categoryId: CategoryEntity['id'];+ onSave: (category: CategoryEntity) => void;+ onEditNotes: (id: NoteEntity['id']) => void;+ onDelete: (categoryId: CategoryEntity['id']) => void;+ onToggleVisibility: (categoryId: CategoryEntity['id']) => void;+ onClose?: () => void;+ };+ }+ | {+ name: 'envelope-budget-menu';+ options: {+ categoryId: CategoryEntity['id'];+ month: string;+ onUpdateBudget: (amount: number) => void;+ onCopyLastMonthAverage: () => void;+ onSetMonthsAverage: (numberOfMonths: number) => void;+ onApplyBudgetTemplate: () => void;+ };+ }+ | {+ name: 'tracking-budget-menu';+ options: {+ categoryId: CategoryEntity['id'];+ month: string;+ onUpdateBudget: (amount: number) => void;+ onCopyLastMonthAverage: () => void;+ onSetMonthsAverage: (numberOfMonths: number) => void;+ onApplyBudgetTemplate: () => void;+ };+ }+ | {+ name: 'category-group-menu';+ options: {+ groupId: CategoryGroupEntity['id'];+ onSave: (group: CategoryGroupEntity) => void;+ onAddCategory: (+ groupId: CategoryGroupEntity['id'],+ isIncome: CategoryGroupEntity['is_income'],+ ) => void;+ onEditNotes: (id: NoteEntity['id']) => void;+ onDelete: (groupId: CategoryGroupEntity['id']) => void;+ onToggleVisibility: (groupId: CategoryGroupEntity['id']) => void;+ onClose?: () => void;+ };+ }+ | {+ name: 'notes';+ options: {+ id: NoteEntity['id'];+ name: string;+ onSave: (id: NoteEntity['id'], contents: string) => void;+ };+ }+ | {+ name: 'tracking-budget-summary';+ options: { month: string };+ }+ | {+ name: 'envelope-budget-summary';+ options: {+ month: string;+ onBudgetAction: (+ month: string,+ type: string,+ args?: unknown,+ ) => Promise<void>;+ };+ }+ | {+ name: 'new-category-group';+ options: {+ onValidate?: (value: string) => string | null;+ onSubmit: (value: string) => Promise<void>;+ };+ }+ | {+ name: 'new-category';+ options: {+ onValidate?: (value: string) => string | null;+ onSubmit: (value: string) => Promise<void>;+ };+ }+ | {+ name: 'envelope-balance-menu';+ options: {+ categoryId: CategoryEntity['id'];+ month: string;+ onCarryover: (carryover: boolean) => void;+ onTransfer: () => void;+ onCover: () => void;+ };+ }+ | {+ name: 'envelope-summary-to-budget-menu';+ options: {+ month: string;+ onTransfer: () => void;+ onCover: () => void;+ onHoldBuffer: () => void;+ onResetHoldBuffer: () => void;+ };+ }+ | {+ name: 'tracking-balance-menu';+ options: {+ categoryId: CategoryEntity['id'];+ month: string;+ onCarryover: (carryover: boolean) => void;+ };+ }+ | {+ name: 'transfer';+ options: {+ title: string;+ categoryId?: CategoryEntity['id'];+ month: string;+ amount: number;+ onSubmit: (amount: number, toCategoryId: CategoryEntity['id']) => void;+ showToBeBudgeted?: boolean;+ };+ }+ | {+ name: 'cover';+ options: {+ title: string;+ categoryId?: CategoryEntity['id'];+ month: string;+ showToBeBudgeted?: boolean;+ onSubmit: (fromCategoryId: CategoryEntity['id']) => void;+ };+ }+ | {+ name: 'hold-buffer';+ options: {+ month: string;+ onSubmit: (amount: number) => void;+ };+ }+ | {+ name: 'scheduled-transaction-menu';+ options: {+ transactionId: TransactionEntity['id'];+ onPost: (transactionId: TransactionEntity['id']) => void;+ onSkip: (transactionId: TransactionEntity['id']) => void;+ onComplete: (transactionId: TransactionEntity['id']) => void;+ };+ }+ | {+ name: 'budget-page-menu';+ options: {+ onAddCategoryGroup: () => void;+ onToggleHiddenCategories: () => void;+ onSwitchBudgetFile: () => void;+ };+ }+ | {+ name: 'envelope-budget-month-menu';+ options: {+ month: string;+ onBudgetAction: (month: string, action: string, arg?: unknown) => void;+ onEditNotes: (id: NoteEntity['id']) => void;+ };+ }+ | {+ name: 'tracking-budget-month-menu';+ options: {+ month: string;+ onBudgetAction: (month: string, action: string, arg?: unknown) => void;+ onEditNotes: (id: NoteEntity['id']) => void;+ };+ }+ | {+ name: 'budget-list';+ }+ | {+ name: 'confirm-transaction-edit';+ options: {+ onConfirm: () => void;+ onCancel?: () => void;+ confirmReason: string;+ };+ }+ | {+ name: 'confirm-transaction-delete';+ options: {+ message?: string | undefined;+ onConfirm: () => void;+ };+ }+ | {+ name: 'edit-user';+ options: {+ user: UserEntity | NewUserEntity;+ onSave: (user: UserEntity) => void;+ };+ }+ | {+ name: 'edit-access';+ options: {+ access: UserAccessEntity;+ onSave: (userAccess: UserAccessEntity) => void;+ };+ }+ | {+ name: 'transfer-ownership';+ options: {+ onSave: () => void;+ };+ }+ | {+ name: 'enable-openid';+ options: {+ onSave: () => void;+ };+ }+ | {+ name: 'enable-password-auth';+ options: {+ onSave: () => void;+ };+ }+ | {+ name: 'confirm-unlink-account';+ options: {+ accountName: string;+ onUnlink: () => void;+ };+ }+ | {+ name: 'keyboard-shortcuts';+ }+ | {+ name: 'goal-templates';+ }+ | {+ name: 'schedules-upcoming-length';+ }+ | {+ name: 'payee-category-learning';+ }+ | {+ name: 'category-automations-edit';+ };++type OpenAccountCloseModalPayload = {+ accountId: AccountEntity['id'];+};++export const openAccountCloseModal = createAppAsyncThunk(+ `${sliceName}/openAccountCloseModal`,+ async (+ { accountId }: OpenAccountCloseModalPayload,+ { dispatch, getState },+ ) => {+ const {+ balance,+ numTransactions,+ }: { balance: number; numTransactions: number } = await send(+ 'account-properties',+ {+ id: accountId,+ },+ );+ const account = getState().queries.accounts.find(+ acct => acct.id === accountId,+ );++ if (!account) {+ throw new Error(`Account with ID ${accountId} does not exist.`);+ }++ dispatch(+ pushModal({+ modal: {+ name: 'close-account',+ options: {+ account,+ balance,+ canDelete: numTransactions === 0,+ },+ },+ }),+ );+ },+);++type ModalsState = {+ modalStack: Modal[];+ isHidden: boolean;+};++const initialState: ModalsState = {+ modalStack: [],+ isHidden: false,+};++type PushModalPayload = {+ modal: Modal;+};++type ReplaceModalPayload = {+ modal: Modal;+};++type CollapseModalPayload = {+ rootModalName: Modal['name'];+};++const modalsSlice = createSlice({+ name: sliceName,+ initialState,+ reducers: {+ pushModal(state, action: PayloadAction<PushModalPayload>) {+ const modal = action.payload.modal;+ // special case: don't show the keyboard shortcuts modal if there's already a modal open+ if (+ modal.name.endsWith('keyboard-shortcuts') &&+ (state.modalStack.length > 0 ||+ window.document.querySelector(+ 'div[data-testid="filters-menu-tooltip"]',+ ) !== null)+ ) {+ return state;+ }+ state.modalStack = [...state.modalStack, modal];+ },+ replaceModal(state, action: PayloadAction<ReplaceModalPayload>) {+ const modal = action.payload.modal;+ state.modalStack = [modal];+ },+ popModal(state) {+ state.modalStack = state.modalStack.slice(0, -1);+ },+ closeModal(state) {+ state.modalStack = [];+ },+ collapseModals(state, action: PayloadAction<CollapseModalPayload>) {+ const idx = state.modalStack.findIndex(+ m => m.name === action.payload.rootModalName,+ );+ state.modalStack =+ idx < 0 ? state.modalStack : state.modalStack.slice(0, idx);+ },+ },+ extraReducers: builder => {+ builder+ .addCase(setAppState, (state, action) => {+ state.isHidden = action.payload.loadingText !== null;+ })+ .addCase(signOut, () => initialState);+ },+});++export const { name, reducer, getInitialState } = modalsSlice;++export const actions = {+ ...modalsSlice.actions,+ openAccountCloseModal,+};++export const { pushModal, closeModal, collapseModals, popModal, replaceModal } =+ actions;diff --git a/packages/loot-core/src/client/reducers/index.ts b/packages/loot-core/src/client/reducers/index.tsindex aaf67868ce..9793e164da 100644--- a/packages/loot-core/src/client/reducers/index.ts+++ b/packages/loot-core/src/client/reducers/index.ts@@ -1,11 +1,9 @@-import { update as modals } from './modals';import { update as notifications } from './notifications';import { update as prefs } from './prefs';import { update as user } from './user';export const reducers = {prefs,- modals,notifications,user,};diff --git a/packages/loot-core/src/client/reducers/modals.ts b/packages/loot-core/src/client/reducers/modals.tsdeleted file mode 100644index 6f0dac1ec0..0000000000--- a/packages/loot-core/src/client/reducers/modals.ts+++ /dev/null@@ -1,78 +0,0 @@-import * as constants from '../constants';-import type { Action } from '../state-types';-import type { ModalsState } from '../state-types/modals';--export const initialState: ModalsState = {- modalStack: [],- isHidden: false,-};--type ModalsAction =- | Action- // TODO. Temporary until we migrate to redux toolkit.- | {- type: 'app/setAppState';- payload: { loadingText: string | null };- }- // TODO: Temporary until we migrate to redux toolkit.- | {- type: 'budgets/signOut';- };--export function update(- state = initialState,- action: ModalsAction,-): ModalsState {- switch (action.type) {- case constants.PUSH_MODAL:- // special case: don't show the keyboard shortcuts modal if there's already a modal open- if (- action.modal.name.endsWith('keyboard-shortcuts') &&- (state.modalStack.length > 0 ||- window.document.querySelector(- 'div[data-testid="filters-menu-tooltip"]',- ) !== null)- ) {- return state;- }- return {- ...state,- modalStack: [...state.modalStack, action.modal],- };- case constants.REPLACE_MODAL:- return {- ...state,- modalStack: [action.modal],- };- case constants.POP_MODAL:- return { ...state, modalStack: state.modalStack.slice(0, -1) };- case constants.CLOSE_MODAL:- return {- ...state,- modalStack: [],- };- case constants.COLLAPSE_MODALS:- const idx = state.modalStack.findIndex(- m => m.name === action.rootModalName,- );- return {- ...state,- modalStack: idx < 0 ? state.modalStack : state.modalStack.slice(0, idx),- };- // TODO: Temporary until we migrate to redux toolkit.- case 'app/setAppState':- if (action.payload.loadingText) {- return {- ...state,- isHidden: action.payload.loadingText != null,- };- }- break;- // TODO: Temporary until we migrate to redux toolkit.- case 'budgets/signOut':- return initialState;- default:- }-- return state;-}diff --git a/packages/loot-core/src/client/redux.ts b/packages/loot-core/src/client/redux.tsnew file mode 100644index 0000000000..c78eb816f1--- /dev/null+++ b/packages/loot-core/src/client/redux.ts@@ -0,0 +1,8 @@+import { createAsyncThunk } from '@reduxjs/toolkit';++import { type AppDispatch, type RootState } from './store';++export const createAppAsyncThunk = createAsyncThunk.withTypes<{+ state: RootState;+ dispatch: AppDispatch;+}>();diff --git a/packages/loot-core/src/client/shared-listeners.ts b/packages/loot-core/src/client/shared-listeners.tsindex e2c5a841a4..a0bb46223d 100644--- a/packages/loot-core/src/client/shared-listeners.ts+++ b/packages/loot-core/src/client/shared-listeners.ts@@ -3,9 +3,10 @@ import { t } from 'i18next';import { listen, send } from '../platform/client/fetch';-import { addNotification, loadPrefs, pushModal, signOut } from './actions';+import { addNotification, loadPrefs, signOut } from './actions';import { resetSync, sync } from './app/appSlice';import { closeAndDownloadBudget, uploadBudget } from './budgets/budgetsSlice';+import { pushModal } from './modals/modalsSlice';import { getAccounts, getCategories, getPayees } from './queries/queriesSlice';import type { Notification } from './state-types/notifications';import { type AppStore } from './store';@@ -139,7 +140,12 @@ export function listenForSyncEvent(store: AppStore) {'Old encryption keys are not migrated. If using encryption, [reset encryption here](#makeKey).',),messageActions: {- makeKey: () => store.dispatch(pushModal('create-encryption-key')),+ makeKey: () =>+ store.dispatch(+ pushModal({+ modal: { name: 'create-encryption-key', options: {} },+ }),+ ),},sticky: true,id: 'old-file',@@ -167,7 +173,11 @@ export function listenForSyncEvent(store: AppStore) {button: {title: t('Reset key'),action: () => {- store.dispatch(pushModal('create-encryption-key'));+ store.dispatch(+ pushModal({+ modal: { name: 'create-encryption-key', options: {} },+ }),+ );},},};@@ -264,8 +274,13 @@ export function listenForSyncEvent(store: AppStore) {title: t('Create key'),action: () => {store.dispatch(- pushModal('fix-encryption-key', {- onSuccess: () => store.dispatch(sync()),+ pushModal({+ modal: {+ name: 'fix-encryption-key',+ options: {+ onSuccess: () => store.dispatch(sync()),+ },+ },}),);},@@ -283,7 +298,11 @@ export function listenForSyncEvent(store: AppStore) {button: {title: t('Reset key'),action: () => {- store.dispatch(pushModal('create-encryption-key'));+ store.dispatch(+ pushModal({+ modal: { name: 'create-encryption-key', options: {} },+ }),+ );},},};diff --git a/packages/loot-core/src/client/state-types/index.d.ts b/packages/loot-core/src/client/state-types/index.d.tsindex 6cb70748c0..b92fa49456 100644--- a/packages/loot-core/src/client/state-types/index.d.ts+++ b/packages/loot-core/src/client/state-types/index.d.ts@@ -1,6 +1,5 @@import type * as constants from '../constants';-import type { ModalsActions, ModalsState } from './modals';import type { NotificationsActions, NotificationsState } from './notifications';import type { PrefsActions, PrefsState } from './prefs';import type { UserActions, UserState } from './user';@@ -10,14 +9,12 @@ export type CloseBudgetAction = {};export type Action =- | ModalsActions| NotificationsActions| PrefsActions| UserActions| CloseBudgetAction;export type State = {- modals: ModalsState;notifications: NotificationsState;prefs: PrefsState;user: UserState;diff --git a/packages/loot-core/src/client/state-types/modals.d.ts b/packages/loot-core/src/client/state-types/modals.d.tsdeleted file mode 100644index 4a1ed5249e..0000000000--- a/packages/loot-core/src/client/state-types/modals.d.ts+++ /dev/null@@ -1,395 +0,0 @@-import { type File } from '../../types/file';-import type {- AccountEntity,- CategoryEntity,- CategoryGroupEntity,- GoCardlessToken,- ScheduleEntity,- TransactionEntity,-} from '../../types/models';-import type { NewRuleEntity, RuleEntity } from '../../types/models/rule';-import { type NewUserEntity, type UserEntity } from '../../types/models/user';-import { type UserAccessEntity } from '../../types/models/userAccess';-import type { EmptyObject, StripNever } from '../../types/util';-import type * as constants from '../constants';-export type ModalType = keyof FinanceModals;--export type OptionlessModal = {- [K in ModalType]: EmptyObject extends FinanceModals[K] ? K : never;-}[ModalType];--export type ModalWithOptions = StripNever<{- [K in ModalType]: keyof FinanceModals[K] extends never- ? never- : FinanceModals[K];-}>;--// There is a separate (overlapping!) set of modals for the management app. Fun!-type FinanceModals = {- 'import-transactions': {- accountId: string;- filename: string;- onImported: (didChange: boolean) => void;- };-- 'add-account': EmptyObject;- 'add-local-account': EmptyObject;- 'close-account': {- account: AccountEntity;- balance: number;- canDelete: boolean;- };- 'select-linked-accounts': {- accounts: unknown[];- requisitionId?: string;- upgradingAccountId?: string | undefined;- syncSource?: AccountSyncSource;- };-- 'confirm-category-delete': { onDelete: (categoryId: string) => void } & (- | { category: string }- | { group: string }- );-- 'load-backup': EmptyObject;-- 'manage-rules': { payeeId?: string };- 'edit-rule': {- rule: RuleEntity | NewRuleEntity;- onSave?: (rule: RuleEntity) => void;- };- 'merge-unused-payees': {- payeeIds: string[];- targetPayeeId: string;- };-- 'gocardless-init': {- onSuccess: () => void;- };- 'simplefin-init': {- onSuccess: () => void;- };- 'pluggyai-init': {- onSuccess: () => void;- };-- 'gocardless-external-msg': {- onMoveExternal: (arg: {- institutionId: string;- }) => Promise<{ error: string } | { data: unknown }>;- onClose?: (() => void) | undefined;- onSuccess: (data: GoCardlessToken) => Promise<void>;- };-- 'delete-budget': { file: File };-- 'duplicate-budget': {- /** The budget file to be duplicated */- file: File;- /**- * Indicates whether the duplication is initiated from the budget- * management page. This may affect the behavior or UI of the- * duplication process.- */- managePage?: boolean;- /**- * loadBudget indicates whether to open the 'original' budget, the- * new duplicated 'copy' budget, or no budget ('none'). If 'none'- * duplicate-budget stays on the same page.- */- loadBudget?: 'none' | 'original' | 'copy';- /**- * onComplete is called when the DuplicateFileModal is closed.- * @param event the event object will pass back the status of the- * duplicate process.- * 'success' if the budget was duplicated.- * 'failed' if the budget could not be duplicated. This will also- * pass an error on the event object.- * 'canceled' if the DuplicateFileModal was canceled.- * @returns- */- onComplete?: (event: {- status: 'success' | 'failed' | 'canceled';- error?: Error;- }) => void;- };-- import: null;-- 'import-ynab4': null;-- 'import-ynab5': null;-- 'import-actual': null;-- 'out-of-sync-migrations': null;-- 'files-settings': null;-- 'confirm-change-document-dir': {- currentBudgetDirectory: string;- newDirectory: string;- };-- 'create-encryption-key': { recreate?: boolean };- 'fix-encryption-key': {- hasExistingKey?: boolean;- cloudFileId?: string;- onSuccess?: () => void;- };-- 'edit-field': {- name: keyof Pick<TransactionEntity, 'date' | 'amount' | 'notes'>;- onSubmit: (- name: keyof Pick<TransactionEntity, 'date' | 'amount' | 'notes'>,- value: string | number,- mode?: 'prepend' | 'append' | 'replace' | null,- ) => void;- onClose?: () => void;- };-- 'category-autocomplete': {- categoryGroups?: CategoryGroupEntity[];- onSelect: (categoryId: string, categoryName: string) => void;- month?: string | undefined;- showHiddenCategories?: boolean;- onClose?: () => void;- };-- 'account-autocomplete': {- onSelect: (accountId: string, accountName: string) => void;- includeClosedAccounts?: boolean;- onClose?: () => void;- };-- 'payee-autocomplete': {- onSelect: (payeeId: string) => void;- onClose?: () => void;- };-- 'payee-category-learning': null;-- 'budget-summary': {- month: string;- };-- 'schedule-edit': { id: string; transaction?: TransactionEntity } | null;-- 'schedule-link': {- transactionIds: string[];- getTransaction: (- transactionId: TransactionEntity['id'],- ) => TransactionEntity;- accountName?: string;- onScheduleLinked?: (schedule: ScheduleEntity) => void;- };-- 'schedules-discover': null;-- 'schedules-upcoming-length': null;-- 'schedule-posts-offline-notification': null;-- 'synced-account-edit': {- account: AccountEntity;- };-- 'account-menu': {- accountId: string;- onSave: (account: AccountEntity) => void;- onCloseAccount: (accountId: string) => void;- onReopenAccount: (accountId: string) => void;- onEditNotes: (id: string) => void;- onClose?: () => void;- };- 'category-menu': {- categoryId: string;- onSave: (category: CategoryEntity) => void;- onEditNotes: (id: string) => void;- onDelete: (categoryId: string) => void;- onToggleVisibility: (categoryId: string) => void;- onBudgetAction: (month: string, action: string, args?: unknown) => void;- onClose?: () => void;- };- 'envelope-budget-menu': {- categoryId: string;- month: string;- onUpdateBudget: (amount: number) => void;- onCopyLastMonthAverage: () => void;- onSetMonthsAverage: (numberOfMonths: number) => void;- onApplyBudgetTemplate: () => void;- };- 'tracking-budget-menu': {- categoryId: string;- month: string;- onUpdateBudget: (amount: number) => void;- onCopyLastMonthAverage: () => void;- onSetMonthsAverage: (numberOfMonths: number) => void;- onApplyBudgetTemplate: () => void;- };- 'category-group-menu': {- groupId: string;- onSave: (group: CategoryGroupEntity) => void;- onAddCategory: (groupId: string, isIncome: boolean) => void;- onEditNotes: (id: string) => void;- onDelete: (groupId: string) => void;- onToggleVisibility: (groupId: string) => void;- onClose?: () => void;- };- notes: {- id: string;- name: string;- onSave: (id: string, notes: string) => void;- };- 'tracking-budget-summary': { month: string };- 'envelope-budget-summary': {- month: string;- onBudgetAction: (- month: string,- type: string,- args: unknown,- ) => Promise<void>;- };- 'new-category-group': {- onValidate?: (value: string) => string;- onSubmit: (value: string) => Promise<void>;- };- 'new-category': {- onValidate?: (value: string) => string;- onSubmit: (value: string) => Promise<void>;- };- 'envelope-balance-menu': {- categoryId: string;- month: string;- onCarryover: (carryover: boolean) => void;- onTransfer: () => void;- onCover: () => void;- };- 'envelope-summary-to-budget-menu': {- month: string;- onTransfer: () => void;- onCover: () => void;- onHoldBuffer: () => void;- onResetHoldBuffer: () => void;- };- 'tracking-balance-menu': {- categoryId: string;- month: string;- onCarryover: (carryover: boolean) => void;- };- transfer: {- title: string;- categoryId?: CategoryEntity['id'];- month: string;- amount: number;- onSubmit: (amount: number, toCategoryId: string) => void;- showToBeBudgeted?: boolean;- };- cover: {- title: string;- categoryId?: CategoryEntity['id'];- month: string;- showToBeBudgeted?: boolean;- onSubmit: (fromCategoryId: string) => void;- };- 'hold-buffer': {- month: string;- onSubmit: (amount: number) => void;- };- 'scheduled-transaction-menu': {- transactionId: string;- onPost: (transactionId: string) => void;- onSkip: (transactionId: string) => void;- onComplete: (transactionId: string) => void;- };- 'budget-page-menu': {- onAddCategoryGroup: () => void;- onToggleHiddenCategories: () => void;- onSwitchBudgetFile: () => void;- };- 'envelope-budget-month-menu': {- month: string;- onBudgetAction: (month: string, action: string, arg?: unknown) => void;- onEditNotes: (month: string) => void;- };- 'tracking-budget-month-menu': {- month: string;- onBudgetAction: (month: string, action: string, arg?: unknown) => void;- onEditNotes: (month: string) => void;- };- 'budget-list';- 'confirm-transaction-edit': {- onConfirm: () => void;- onCancel?: () => void;- confirmReason: string;- };- 'confirm-transaction-delete': {- message?: string | undefined;- onConfirm: () => void;- };- 'edit-user': {- user: UserEntity | NewUserEntity;- onSave: (rule: UserEntity) => void;- };- 'edit-access': {- access: UserAccessEntity | NewUserAccessEntity;- onSave: (rule: UserEntity) => void;- };- 'transfer-ownership': {- onSave: () => void;- };- 'enable-openid': {- onSave: () => void;- };- 'enable-password-auth': {- onSave: () => void;- };- 'confirm-unlink-account': {- accountName: string;- onUnlink: () => void;- };- 'keyboard-shortcuts': EmptyObject;- 'goal-templates': EmptyObject;- 'category-automations-edit': EmptyObject;-};--export type PushModalAction = {- type: typeof constants.PUSH_MODAL;- modal: Modal;-};--export type ReplaceModalAction = {- type: typeof constants.REPLACE_MODAL;- modal: Modal;-};--export type PopModalAction = {- type: typeof constants.POP_MODAL;-};--export type CloseModalAction = {- type: typeof constants.CLOSE_MODAL;-};--export type CollapseModalsAction = {- type: typeof constants.COLLAPSE_MODALS;- rootModalName: string;-};--export type ModalsActions =- | PushModalAction- | ReplaceModalAction- | PopModalAction- | CloseModalAction- | CollapseModalsAction;--export type ModalsState = {- modalStack: Modal[];- isHidden: boolean;-};--type Modal = {- name: string;- // eslint-disable-next-line @typescript-eslint/no-explicit-any- options?: any;-};diff --git a/packages/loot-core/src/client/store/index.ts b/packages/loot-core/src/client/store/index.tsindex 95523b362b..964e40fb79 100644--- a/packages/loot-core/src/client/store/index.ts+++ b/packages/loot-core/src/client/store/index.ts@@ -22,13 +22,17 @@ import {getInitialState as getInitialBudgetsState,} from '../budgets/budgetsSlice';import * as constants from '../constants';+import {+ name as modalsSliceName,+ reducer as modalsSliceReducer,+ getInitialState as getInitialModalsState,+} from '../modals/modalsSlice';import {name as queriesSliceName,reducer as queriesSliceReducer,getInitialState as getInitialQueriesState,} from '../queries/queriesSlice';import { reducers } from '../reducers';-import { initialState as initialModalsState } from '../reducers/modals';import { initialState as initialNotificationsState } from '../reducers/notifications';import { initialState as initialPrefsState } from '../reducers/prefs';import { initialState as initialUserState } from '../reducers/user';@@ -38,6 +42,7 @@ const appReducer = combineReducers({[accountsSliceName]: accountsSliceReducer,[appSliceName]: appSliceReducer,[budgetsSliceName]: budgetsSliceReducer,+ [modalsSliceName]: modalsSliceReducer,[queriesSliceName]: queriesSliceReducer,});const rootReducer: typeof appReducer = (state, action) => {@@ -46,7 +51,7 @@ const rootReducer: typeof appReducer = (state, action) => {// blows away everything elsestate = {account: getInitialAccountsState(),- modals: initialModalsState,+ modals: getInitialModalsState(),notifications: initialNotificationsState,queries: getInitialQueriesState(),budgets: state?.budgets || getInitialBudgetsState(),diff --git a/packages/loot-core/src/client/store/mock.ts b/packages/loot-core/src/client/store/mock.tsindex 318ee26637..a3c95da043 100644--- a/packages/loot-core/src/client/store/mock.ts+++ b/packages/loot-core/src/client/store/mock.ts@@ -12,6 +12,10 @@ import {name as budgetsSliceName,reducer as budgetsSliceReducer,} from '../budgets/budgetsSlice';+import {+ name as modalsSliceName,+ reducer as modalsSliceReducer,+} from '../modals/modalsSlice';import {name as queriesSliceName,reducer as queriesSliceReducer,@@ -25,6 +29,7 @@ const appReducer = combineReducers({[accountsSliceName]: accountsSliceReducer,[appSliceName]: appSliceReducer,[budgetsSliceName]: budgetsSliceReducer,+ [modalsSliceName]: modalsSliceReducer,[queriesSliceName]: queriesSliceReducer,});diff --git a/packages/loot-core/src/platform/client/undo/index.d.ts b/packages/loot-core/src/platform/client/undo/index.d.tsindex 759474e48b..63f1043690 100644--- a/packages/loot-core/src/platform/client/undo/index.d.ts+++ b/packages/loot-core/src/platform/client/undo/index.d.ts@@ -1,12 +1,9 @@-import { OptionlessModal } from '../../../client/state-types/modals';+import { Modal } from '../../../client/modals/modalsSlice';import { UndoState as ServerUndoState } from '../../../server/undo';export type UndoState = {url: string | null;- // Right now, only the payees page uses this. It's only being set to- // `manage-rules` which is an optionless modal. Do we want to also- // support modals with options?- openModal: OptionlessModal | null;+ openModal: Modal | null;selectedItems: {name: string;items: Set<string>;diff --git a/packages/loot-core/src/types/models/account.d.ts b/packages/loot-core/src/types/models/account.d.tsindex 3542fd1710..86b934f5b4 100644--- a/packages/loot-core/src/types/models/account.d.ts+++ b/packages/loot-core/src/types/models/account.d.ts@@ -22,4 +22,4 @@ type _SyncFields<T> = {last_sync: T extends true ? string : null;};-export type AccountSyncSource = 'simpleFin' | 'goCardless';+export type AccountSyncSource = 'simpleFin' | 'goCardless' | 'pluggyai';diff --git a/packages/loot-core/src/types/models/index.d.ts b/packages/loot-core/src/types/models/index.d.tsindex f96b1b31ed..82dc4d9d63 100644--- a/packages/loot-core/src/types/models/index.d.ts+++ b/packages/loot-core/src/types/models/index.d.ts@@ -15,3 +15,4 @@ export type * from './transaction';export type * from './transaction-filter';export type * from './user';export type * from './bank';+export type * from './userAccess';diff --git a/packages/loot-core/src/types/util.d.ts b/packages/loot-core/src/types/util.d.tsindex 48e7fefd07..1a86bf365b 100644--- a/packages/loot-core/src/types/util.d.ts+++ b/packages/loot-core/src/types/util.d.ts@@ -14,3 +14,10 @@ export type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;// see https://github.com/i18next/react-i18next/issues/1483// eslint-disable-next-line @typescript-eslint/no-explicit-anyexport type TransObjectLiteral = any;++export type AtLeastOne<T extends Record<string, unknown>> =+ keyof T extends infer K+ ? K extends string+ ? Pick<T, K & keyof T> & Partial<T>+ : never+ : never;diff --git a/upcoming-release-notes/4119.md b/upcoming-release-notes/4119.mdnew file mode 100644index 0000000000..0db924a035--- /dev/null+++ b/upcoming-release-notes/4119.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [joel-jeremy]+---++Phase 2 - Redux Toolkit Migration - modals slice