A local-first personal finance app
[Redux Toolkit Migration] notificationsSlice (#4126)
Joel Jeremy Marquezc2cb61eb7082
diff --git a/packages/desktop-client/src/components/App.tsx b/packages/desktop-client/src/components/App.tsxindex 459a706216..4e5079773c 100644--- a/packages/desktop-client/src/components/App.tsx+++ b/packages/desktop-client/src/components/App.tsx@@ -14,13 +14,10 @@ import { BrowserRouter } from 'react-router-dom';import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';-import {- addNotification,- loadGlobalPrefs,- signOut,-} from 'loot-core/client/actions';+import { loadGlobalPrefs, signOut } from 'loot-core/client/actions';import { setAppState, sync } from 'loot-core/client/app/appSlice';import { closeBudget, loadBudget } from 'loot-core/client/budgets/budgetsSlice';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import * as Platform from 'loot-core/client/platform';import { SpreadsheetProvider } from 'loot-core/client/SpreadsheetProvider';import { init as initConnection, send } from 'loot-core/platform/client/fetch';@@ -139,14 +136,16 @@ function AppInner() {if (userData?.tokenExpired) {dispatch(addNotification({- type: 'error',- id: 'login-expired',- title: t('Login expired'),- sticky: true,- message: t('Login expired, please log in again.'),- button: {- title: t('Go to log in'),- action: () => dispatch(signOut()),+ notification: {+ type: 'error',+ id: 'login-expired',+ title: t('Login expired'),+ sticky: true,+ message: t('Login expired, please log in again.'),+ button: {+ title: t('Go to log in'),+ action: () => dispatch(signOut()),+ },},}),);diff --git a/packages/desktop-client/src/components/FinancesApp.tsx b/packages/desktop-client/src/components/FinancesApp.tsxindex 156cc95cf0..071ce50330 100644--- a/packages/desktop-client/src/components/FinancesApp.tsx+++ b/packages/desktop-client/src/components/FinancesApp.tsx@@ -11,8 +11,8 @@ import {import { View } from '@actual-app/components/view';-import { addNotification } from 'loot-core/client/actions';import { sync } from 'loot-core/client/app/appSlice';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import * as undo from 'loot-core/platform/client/undo';import { ProtectedRoute } from '../auth/ProtectedRoute';@@ -113,15 +113,19 @@ export function FinancesApp() {await global.Actual.waitForUpdateReadyForDownload();dispatch(addNotification({- type: 'message',- title: t('A new version of Actual is available!'),- message: t('Click the button below to reload and apply the update.'),- sticky: true,- id: 'update-reload-notification',- button: {- title: t('Update now'),- action: async () => {- await global.Actual.applyAppUpdate();+ notification: {+ type: 'message',+ title: t('A new version of Actual is available!'),+ message: t(+ 'Click the button below to reload and apply the update.',+ ),+ sticky: true,+ id: 'update-reload-notification',+ button: {+ title: t('Update now'),+ action: async () => {+ await global.Actual.applyAppUpdate();+ },},},}),@@ -139,22 +143,24 @@ export function FinancesApp() {if (isOutdated && lastUsedVersion !== latestVersion) {dispatch(addNotification({- type: 'message',- title: t('A new version of Actual is available!'),- message: t(- 'Version {{latestVersion}} of Actual was recently released.',- { latestVersion },- ),- sticky: true,- id: 'update-notification',- button: {- title: t('Open changelog'),- action: () => {- window.open('https://actualbudget.org/docs/releases');+ notification: {+ type: 'message',+ title: t('A new version of Actual is available!'),+ message: t(+ 'Version {{latestVersion}} of Actual was recently released.',+ { latestVersion },+ ),+ sticky: true,+ id: 'update-notification',+ button: {+ title: t('Open changelog'),+ action: () => {+ window.open('https://actualbudget.org/docs/releases');+ },+ },+ onClose: () => {+ setLastUsedVersion(latestVersion);},- },- onClose: () => {- setLastUsedVersion(latestVersion);},}),);diff --git a/packages/desktop-client/src/components/Notifications.tsx b/packages/desktop-client/src/components/Notifications.tsxindex 53524f4eaf..faa6cb002a 100644--- a/packages/desktop-client/src/components/Notifications.tsx+++ b/packages/desktop-client/src/components/Notifications.tsx@@ -15,8 +15,10 @@ import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';import { css } from '@emotion/css';-import { removeNotification } from 'loot-core/client/actions';-import type { NotificationWithId } from 'loot-core/client/state-types/notifications';+import {+ removeNotification,+ type NotificationWithId,+} from 'loot-core/client/notifications/notificationsSlice';import { AnimatedLoading } from '../icons/AnimatedLoading';import { SvgDelete } from '../icons/v0';@@ -288,7 +290,7 @@ export function Notifications({ style }: { style?: CSSProperties }) {if (note.onClose) {note.onClose();}- dispatch(removeNotification(note.id));+ dispatch(removeNotification({ id: note.id }));}}/>))}diff --git a/packages/desktop-client/src/components/ServerContext.tsx b/packages/desktop-client/src/components/ServerContext.tsxindex e25f2a0969..aaa92a0576 100644--- a/packages/desktop-client/src/components/ServerContext.tsx+++ b/packages/desktop-client/src/components/ServerContext.tsx@@ -9,10 +9,12 @@ import React, {import { t } from 'i18next';-import { addNotification } from 'loot-core/client/actions';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import { type Handlers } from 'loot-core/types/handlers';+import { useDispatch } from '../redux';+type LoginMethods = {method: string;displayName: string;@@ -84,6 +86,7 @@ export const useSetLoginMethods = () =>useContext(ServerContext).setLoginMethods;export function ServerProvider({ children }: { children: ReactNode }) {+ const dispatch = useDispatch();const [serverURL, setServerURL] = useState('');const [version, setVersion] = useState('');const [multiuserEnabled, setMultiuserEnabled] = useState(false);@@ -108,11 +111,15 @@ export function ServerProvider({ children }: { children: ReactNode }) {const data: Awaited<ReturnType<Handlers['subscribe-get-login-methods']>> =await send('subscribe-get-login-methods');if ('error' in data) {- addNotification({- type: 'error',- title: t('Failed to refresh login methods'),- message: data.error ?? t('Unknown'),- });+ dispatch(+ addNotification({+ notification: {+ type: 'error',+ title: t('Failed to refresh login methods'),+ message: data.error ?? t('Unknown'),+ },+ }),+ );setAvailableLoginMethods([]);} else if (data.methods) {setAvailableLoginMethods(data.methods);@@ -120,7 +127,7 @@ export function ServerProvider({ children }: { children: ReactNode }) {setAvailableLoginMethods([]);}}- }, [serverURL]);+ }, [dispatch, serverURL]);useEffect(() => {if (serverURL) {diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsxindex a2eef55e14..2f9eb452f6 100644--- a/packages/desktop-client/src/components/accounts/Account.tsx+++ b/packages/desktop-client/src/components/accounts/Account.tsx@@ -18,7 +18,6 @@ import { t } from 'i18next';import { v4 as uuidv4 } from 'uuid';import { unlinkAccount } from 'loot-core/client/accounts/accountsSlice';-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 {@@ -30,6 +29,7 @@ import {pushModal,replaceModal,} from 'loot-core/client/modals/modalsSlice';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import * as queries from 'loot-core/client/queries';import {createPayee,@@ -767,8 +767,10 @@ class AccountInternal extends PureComponent<console.error('Error applying rules:', error);this.props.dispatch(addNotification({- type: 'error',- message: 'Failed to apply rules to transactions',+ notification: {+ type: 'error',+ message: 'Failed to apply rules to transactions',+ },}),);} finally {diff --git a/packages/desktop-client/src/components/admin/UserAccess/UserAccess.tsx b/packages/desktop-client/src/components/admin/UserAccess/UserAccess.tsxindex 296e4ff66a..973b7cb148 100644--- a/packages/desktop-client/src/components/admin/UserAccess/UserAccess.tsx+++ b/packages/desktop-client/src/components/admin/UserAccess/UserAccess.tsx@@ -14,8 +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 } from 'loot-core/client/actions';import { pushModal } from 'loot-core/client/modals/modalsSlice';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';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';@@ -44,7 +44,7 @@ function UserAccessContent({setLoading,}: ManageUserAccessContentProps) {const { t } = useTranslation();-+ const dispatch = useDispatch();const [allAccess, setAllAccess] = useState([]);const [page, setPage] = useState(0);const [filter, setFilter] = useState('');@@ -86,13 +86,17 @@ function UserAccessContent({};if ('error' in data) {- addNotification({- type: 'error',- id: 'error',- title: t('Error getting available users'),- sticky: true,- message: data.error,- });+ dispatch(+ addNotification({+ notification: {+ type: 'error',+ id: 'error',+ title: t('Error getting available users'),+ sticky: true,+ message: data.error,+ },+ }),+ );return [];}@@ -105,7 +109,7 @@ function UserAccessContent({setAllAccess(loadedAccess);return loadedAccess;- }, [cloudFileId, setLoading, t]);+ }, [cloudFileId, dispatch, setLoading, t]);const loadOwner = useCallback(async () => {const file = (await send('get-user-file-info', cloudFileId as string)) ?? {diff --git a/packages/desktop-client/src/components/admin/UserAccess/UserAccessRow.tsx b/packages/desktop-client/src/components/admin/UserAccess/UserAccessRow.tsxindex 88eca07c9a..069a0dd125 100644--- a/packages/desktop-client/src/components/admin/UserAccess/UserAccessRow.tsx+++ b/packages/desktop-client/src/components/admin/UserAccess/UserAccessRow.tsx@@ -4,7 +4,8 @@ import { useTranslation } from 'react-i18next';import { View } from '@actual-app/components/view';-import { addNotification, signOut } from 'loot-core/client/actions';+import { signOut } from 'loot-core/client/actions';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import { getUserAccessErrors } from 'loot-core/shared/errors';import { type UserAvailable } from 'loot-core/types/models';@@ -52,12 +53,14 @@ export const UserAccessRow = memo(if (someDeletionsFailed) {dispatch(addNotification({- type: 'error',- title: t('Access Revocation Incomplete'),- message: t(- 'Some access permissions were not revoked successfully.',- ),- sticky: true,+ notification: {+ type: 'error',+ title: t('Access Revocation Incomplete'),+ message: t(+ 'Some access permissions were not revoked successfully.',+ ),+ sticky: true,+ },}),);}@@ -69,15 +72,17 @@ export const UserAccessRow = memo(if (error === 'token-expired') {dispatch(addNotification({- type: 'error',- id: 'login-expired',- title: t('Login expired'),- sticky: true,- message: getUserAccessErrors(error),- button: {- title: t('Go to login'),- action: () => {- dispatch(signOut());+ notification: {+ type: 'error',+ id: 'login-expired',+ title: t('Login expired'),+ sticky: true,+ message: getUserAccessErrors(error),+ button: {+ title: t('Go to login'),+ action: () => {+ dispatch(signOut());+ },},},}),@@ -85,10 +90,12 @@ export const UserAccessRow = memo(} else {dispatch(addNotification({- type: 'error',- title: t('Something happened while editing access'),- sticky: true,- message: getUserAccessErrors(error),+ notification: {+ type: 'error',+ title: t('Something happened while editing access'),+ sticky: true,+ message: getUserAccessErrors(error),+ },}),);}diff --git a/packages/desktop-client/src/components/admin/UserDirectory/UserDirectory.tsx b/packages/desktop-client/src/components/admin/UserDirectory/UserDirectory.tsxindex 76a9fee3ee..98982445f0 100644--- a/packages/desktop-client/src/components/admin/UserDirectory/UserDirectory.tsx+++ b/packages/desktop-client/src/components/admin/UserDirectory/UserDirectory.tsx@@ -15,8 +15,9 @@ import { Stack } from '@actual-app/components/stack';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { addNotification, signOut } from 'loot-core/client/actions';+import { signOut } from 'loot-core/client/actions';import { pushModal } from 'loot-core/client/modals/modalsSlice';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import * as undo from 'loot-core/platform/client/undo';import {@@ -123,11 +124,13 @@ function UserDirectoryContent({if ('error' in loadedUsers) {dispatch(addNotification({- type: 'error',- id: 'error',- title: t('Error getting users'),- sticky: true,- message: getUserDirectoryErrors(loadedUsers.error),+ notification: {+ type: 'error',+ id: 'error',+ title: t('Error getting users'),+ sticky: true,+ message: getUserDirectoryErrors(loadedUsers.error),+ },}),);setLoading(false);@@ -166,24 +169,28 @@ function UserDirectoryContent({if (error === 'token-expired') {dispatch(addNotification({- type: 'error',- id: 'login-expired',- title: t('Login expired'),- sticky: true,- message: getUserDirectoryErrors(error),- button: {- title: t('Go to login'),- action: () => dispatch(signOut()),+ notification: {+ type: 'error',+ id: 'login-expired',+ title: t('Login expired'),+ sticky: true,+ message: getUserDirectoryErrors(error),+ button: {+ title: t('Go to login'),+ action: () => dispatch(signOut()),+ },},}),);} else {dispatch(addNotification({- type: 'error',- title: t('Something happened while deleting users'),- sticky: true,- message: getUserDirectoryErrors(error),+ notification: {+ type: 'error',+ title: t('Something happened while deleting users'),+ sticky: true,+ message: getUserDirectoryErrors(error),+ },}),);}diff --git a/packages/desktop-client/src/components/budget/index.tsx b/packages/desktop-client/src/components/budget/index.tsxindex a3e7c54ec0..040ea5cb69 100644--- a/packages/desktop-client/src/components/budget/index.tsx+++ b/packages/desktop-client/src/components/budget/index.tsx@@ -5,8 +5,8 @@ import { useTranslation } from 'react-i18next';import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';-import { addNotification } from 'loot-core/client/actions';import { pushModal } from 'loot-core/client/modals/modalsSlice';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import {applyBudgetAction,createCategory,@@ -148,11 +148,13 @@ function BudgetInner(props: BudgetInnerProps) {const categoryNameAlreadyExistsNotification = name => {dispatch(addNotification({- type: 'error',- message: t(- 'Category “{{name}}” already exists in group (it may be hidden)',- { name },- ),+ notification: {+ type: 'error',+ message: t(+ 'Category “{{name}}” already exists in group (it may be hidden)',+ { name },+ ),+ },}),);};diff --git a/packages/desktop-client/src/components/manager/subscribe/OpenIdForm.tsx b/packages/desktop-client/src/components/manager/subscribe/OpenIdForm.tsxindex 173ebb3541..2b2572bbf0 100644--- a/packages/desktop-client/src/components/manager/subscribe/OpenIdForm.tsx+++ b/packages/desktop-client/src/components/manager/subscribe/OpenIdForm.tsx@@ -9,11 +9,12 @@ import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { addNotification } from 'loot-core/client/actions';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import { type Handlers } from 'loot-core/types/handlers';import { type OpenIdConfig } from 'loot-core/types/models/openid';+import { useDispatch } from '../../../redux';import { theme } from '../../../style';import { Input } from '../../common/Input';import { Link } from '../../common/Link';@@ -51,7 +52,7 @@ export function OpenIdForm({loadData,}: OpenIdFormProps) {const { t } = useTranslation();-+ const dispatch = useDispatch();const [issuer, setIssuer] = useState('');const [clientId, setClientId] = useState('');const [clientSecret, setClientSecret] = useState('');@@ -73,13 +74,17 @@ export function OpenIdForm({if (!config) return;if ('error' in config) {- addNotification({- type: 'error',- id: 'error',- title: t('Error getting OpenID config'),- sticky: true,- message: config.error,- });+ dispatch(+ addNotification({+ notification: {+ type: 'error',+ id: 'error',+ title: t('Error getting OpenID config'),+ sticky: true,+ message: config.error,+ },+ }),+ );} else if ('openId' in config) {setProviderName(config?.openId?.selectedProvider ?? 'other');setIssuer(config?.openId?.issuer ?? '');@@ -89,7 +94,7 @@ export function OpenIdForm({},);}- }, [loadData, t]);+ }, [dispatch, loadData, t]);const handleProviderChange = (provider: OpenIdProviderOption) => {if (provider) {diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsxindex 5294f85055..4e4a1dc410 100644--- a/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionList.tsx@@ -20,7 +20,7 @@ import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { setNotificationInset } from 'loot-core/client/actions';+import { setNotificationInset } from 'loot-core/client/notifications/notificationsSlice';import { validForTransfer } from 'loot-core/client/transfer';import * as monthUtils from 'loot-core/shared/months';import { isPreviewId } from 'loot-core/shared/transactions';@@ -300,7 +300,9 @@ function SelectedTransactionsFloatingActionBar({const dispatch = useDispatch();useEffect(() => {- dispatch(setNotificationInset({ bottom: NOTIFICATION_BOTTOM_INSET }));+ dispatch(+ setNotificationInset({ inset: { bottom: NOTIFICATION_BOTTOM_INSET } }),+ );return () => {dispatch(setNotificationInset(null));};diff --git a/packages/desktop-client/src/components/modals/CreateAccountModal.tsx b/packages/desktop-client/src/components/modals/CreateAccountModal.tsxindex a395736d1a..ca757808e2 100644--- a/packages/desktop-client/src/components/modals/CreateAccountModal.tsx+++ b/packages/desktop-client/src/components/modals/CreateAccountModal.tsx@@ -10,11 +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 } from 'loot-core/client/actions';import {type Modal as ModalType,pushModal,} from 'loot-core/client/modals/modalsSlice';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import { useAuth } from '../../auth/AuthProvider';@@ -198,10 +198,12 @@ export function CreateAccountModal({} catch (err) {console.error(err);addNotification({- type: 'error',- title: t('Error when trying to contact Pluggy.ai'),- message: (err as Error).message,- timeout: 5000,+ notification: {+ type: 'error',+ title: t('Error when trying to contact Pluggy.ai'),+ message: (err as Error).message,+ timeout: 5000,+ },});dispatch(pushModal({diff --git a/packages/desktop-client/src/components/modals/EditAccess.tsx b/packages/desktop-client/src/components/modals/EditAccess.tsxindex bec438003b..2c56cda0b5 100644--- a/packages/desktop-client/src/components/modals/EditAccess.tsx+++ b/packages/desktop-client/src/components/modals/EditAccess.tsx@@ -7,11 +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, signOut } from 'loot-core/client/actions';+import { signOut } from 'loot-core/client/actions';import {type Modal as ModalType,popModal,} from 'loot-core/client/modals/modalsSlice';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import { getUserAccessErrors } from 'loot-core/shared/errors';@@ -68,15 +69,17 @@ export function EditUserAccess({if (error === 'token-expired') {dispatch(addNotification({- type: 'error',- id: 'login-expired',- title: t('Login expired'),- sticky: true,- message: getUserAccessErrors(error),- button: {- title: t('Go to login'),- action: () => {- dispatch(signOut());+ notification: {+ type: 'error',+ id: 'login-expired',+ title: t('Login expired'),+ sticky: true,+ message: getUserAccessErrors(error),+ button: {+ title: t('Go to login'),+ action: () => {+ dispatch(signOut());+ },},},}),diff --git a/packages/desktop-client/src/components/modals/EditUser.tsx b/packages/desktop-client/src/components/modals/EditUser.tsxindex 632396fed6..458f1f48ba 100644--- a/packages/desktop-client/src/components/modals/EditUser.tsx+++ b/packages/desktop-client/src/components/modals/EditUser.tsx@@ -7,11 +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, signOut } from 'loot-core/client/actions';+import { signOut } from 'loot-core/client/actions';import {type Modal as ModalType,popModal,} from 'loot-core/client/modals/modalsSlice';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import {type NewUserEntity,@@ -89,15 +90,17 @@ function useSaveUser() {if (error === 'token-expired') {dispatch(addNotification({- type: 'error',- id: 'login-expired',- title: t('Login expired'),- sticky: true,- message: getUserDirectoryErrors(error),- button: {- title: t('Go to login'),- action: () => {- dispatch(signOut());+ notification: {+ type: 'error',+ id: 'login-expired',+ title: t('Login expired'),+ sticky: true,+ message: getUserDirectoryErrors(error),+ button: {+ title: t('Go to login'),+ action: () => {+ dispatch(signOut());+ },},},}),diff --git a/packages/desktop-client/src/components/modals/TransferOwnership.tsx b/packages/desktop-client/src/components/modals/TransferOwnership.tsxindex 3a2924994d..ac075b9bd6 100644--- a/packages/desktop-client/src/components/modals/TransferOwnership.tsx+++ b/packages/desktop-client/src/components/modals/TransferOwnership.tsx@@ -7,12 +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 } 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 { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import { getUserAccessErrors } from 'loot-core/shared/errors';import { type Budget } from 'loot-core/types/budget';@@ -57,12 +57,14 @@ export function TransferOwnership({} else if ('error' in data) {dispatch(addNotification({- type: 'error',- title: t('Error getting users'),- message: t(- 'Failed to complete ownership transfer. Please try again.',- ),- sticky: true,+ notification: {+ type: 'error',+ title: t('Error getting users'),+ message: t(+ 'Failed to complete ownership transfer. Please try again.',+ ),+ sticky: true,+ },}),);} else {@@ -196,12 +198,14 @@ export function TransferOwnership({} catch (error) {dispatch(addNotification({- type: 'error',- title: t('Failed to transfer ownership'),- message: t(- 'Failed to complete ownership transfer. Please try again.',- ),- sticky: true,+ notification: {+ type: 'error',+ title: t('Failed to transfer ownership'),+ message: t(+ 'Failed to complete ownership transfer. Please try again.',+ ),+ sticky: true,+ },}),);setIsTransferring(false);diff --git a/packages/desktop-client/src/components/modals/manager/ConfirmChangeDocumentDir.tsx b/packages/desktop-client/src/components/modals/manager/ConfirmChangeDocumentDir.tsxindex 1ff4529be6..73a99bab52 100644--- a/packages/desktop-client/src/components/modals/manager/ConfirmChangeDocumentDir.tsx+++ b/packages/desktop-client/src/components/modals/manager/ConfirmChangeDocumentDir.tsx@@ -6,7 +6,7 @@ import { styles } from '@actual-app/components/styles';import { Text } from '@actual-app/components/text';import { View } from '@actual-app/components/view';-import { addNotification } from 'loot-core/client/actions';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { useGlobalPref } from '../../../hooks/useGlobalPref';import { useDispatch } from '../../../redux';@@ -76,8 +76,10 @@ export function ConfirmChangeDocumentDirModal({dispatch(addNotification({- type: 'message',- message: t('Actual’s data directory successfully changed.'),+ notification: {+ type: 'message',+ message: t('Actual’s data directory successfully changed.'),+ },}),);close();diff --git a/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx b/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsxindex 193eb65719..aefdf429a0 100644--- a/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx+++ b/packages/desktop-client/src/components/modals/manager/DuplicateFileModal.tsx@@ -8,9 +8,9 @@ import { InlineField } from '@actual-app/components/inline-field';import { Text } from '@actual-app/components/text';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 { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import { useDispatch } from '../../../redux';@@ -88,8 +88,10 @@ export function DuplicateFileModal({);dispatch(addNotification({- type: 'message',- message: t('Duplicate file “{{newName}}” created.', { newName }),+ notification: {+ type: 'message',+ message: t('Duplicate file “{{newName}}” created.', { newName }),+ },}),);if (onComplete) onComplete({ status: 'success' });@@ -99,8 +101,10 @@ export function DuplicateFileModal({else console.error('Failed to duplicate budget file:', e);dispatch(addNotification({- type: 'error',- message: t('Failed to duplicate budget file.'),+ notification: {+ type: 'error',+ message: t('Failed to duplicate budget file.'),+ },}),);} finally {diff --git a/packages/desktop-client/src/components/reports/Overview.tsx b/packages/desktop-client/src/components/reports/Overview.tsxindex d92a4cabe6..ef8f4e09e1 100644--- a/packages/desktop-client/src/components/reports/Overview.tsx+++ b/packages/desktop-client/src/components/reports/Overview.tsx@@ -10,9 +10,12 @@ import { Menu } from '@actual-app/components/menu';import { Popover } from '@actual-app/components/popover';import { View } from '@actual-app/components/view';-import { addNotification, removeNotification } from 'loot-core/client/actions';import { useDashboard } from 'loot-core/client/data-hooks/dashboard';import { useReports } from 'loot-core/client/data-hooks/reports';+import {+ addNotification,+ removeNotification,+} from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import {type CustomReportWidget,@@ -92,7 +95,7 @@ export function Overview() {const layout = baseLayout;const closeNotifications = () => {- dispatch(removeNotification('import'));+ dispatch(removeNotification({ id: 'import' }));};// Close import notifications when doing "undo" operation@@ -110,15 +113,17 @@ export function Overview() {const onDispatchSucessNotification = (message: string) => {dispatch(addNotification({- id: 'import',- type: 'message',- sticky: true,- timeout: 30_000, // 30s- message,- messageActions: {- undo: () => {- closeNotifications();- undo();+ notification: {+ id: 'import',+ type: 'message',+ sticky: true,+ timeout: 30_000, // 30s+ message,+ messageActions: {+ undo: () => {+ closeNotifications();+ undo();+ },},},}),@@ -217,10 +222,12 @@ export function Overview() {if (!openFileDialog) {dispatch(addNotification({- type: 'error',- message: t(- 'Fatal error occurred: unable to open import file dialog.',- ),+ notification: {+ type: 'error',+ message: t(+ 'Fatal error occurred: unable to open import file dialog.',+ ),+ },}),);return;@@ -246,9 +253,11 @@ export function Overview() {case 'json-parse-error':dispatch(addNotification({- id: 'import',- type: 'error',- message: t('Failed parsing the imported JSON.'),+ notification: {+ id: 'import',+ type: 'error',+ message: t('Failed parsing the imported JSON.'),+ },}),);break;@@ -256,9 +265,11 @@ export function Overview() {case 'validation-error':dispatch(addNotification({- id: 'import',- type: 'error',- message: res.message,+ notification: {+ id: 'import',+ type: 'error',+ message: res.message,+ },}),);break;@@ -266,9 +277,11 @@ export function Overview() {default:dispatch(addNotification({- id: 'import',- type: 'error',- message: t('Failed importing the dashboard file.'),+ notification: {+ id: 'import',+ type: 'error',+ message: t('Failed importing the dashboard file.'),+ },}),);break;diff --git a/packages/desktop-client/src/components/reports/reports/Calendar.tsx b/packages/desktop-client/src/components/reports/reports/Calendar.tsxindex 9ff6988463..5394a5efbd 100644--- a/packages/desktop-client/src/components/reports/reports/Calendar.tsx+++ b/packages/desktop-client/src/components/reports/reports/Calendar.tsx@@ -17,10 +17,10 @@ import { css } from '@emotion/css';import { useDrag } from '@use-gesture/react';import { format, parseISO } from 'date-fns';-import { addNotification } from 'loot-core/client/actions';import { SchedulesProvider } from 'loot-core/client/data-hooks/schedules';import { useTransactions } from 'loot-core/client/data-hooks/transactions';import { useWidget } from 'loot-core/client/data-hooks/widget';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import * as monthUtils from 'loot-core/shared/months';import { q, type Query } from 'loot-core/shared/query';@@ -330,15 +330,19 @@ function CalendarInner({ widget, parameters }: CalendarInnerProps) {});dispatch(addNotification({- type: 'message',- message: t('Dashboard widget successfully saved.'),+ notification: {+ type: 'message',+ message: t('Dashboard widget successfully saved.'),+ },}),);} catch (error) {dispatch(addNotification({- type: 'error',- message: t('Failed to save dashboard widget.'),+ notification: {+ type: 'error',+ message: t('Failed to save dashboard widget.'),+ },}),);console.error('Error saving widget:', error);diff --git a/packages/desktop-client/src/components/reports/reports/CashFlow.tsx b/packages/desktop-client/src/components/reports/reports/CashFlow.tsxindex 77ba93ebc9..b49bbb8573 100644--- a/packages/desktop-client/src/components/reports/reports/CashFlow.tsx+++ b/packages/desktop-client/src/components/reports/reports/CashFlow.tsx@@ -11,8 +11,8 @@ import { theme } from '@actual-app/components/theme';import { View } from '@actual-app/components/view';import * as d from 'date-fns';-import { addNotification } from 'loot-core/client/actions';import { useWidget } from 'loot-core/client/data-hooks/widget';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import * as monthUtils from 'loot-core/shared/months';import { integerToCurrency } from 'loot-core/shared/util';@@ -169,8 +169,10 @@ function CashFlowInner({ widget }: CashFlowInnerProps) {});dispatch(addNotification({- type: 'message',- message: t('Dashboard widget successfully saved.'),+ notification: {+ type: 'message',+ message: t('Dashboard widget successfully saved.'),+ },}),);}diff --git a/packages/desktop-client/src/components/reports/reports/CustomReportListCards.tsx b/packages/desktop-client/src/components/reports/reports/CustomReportListCards.tsxindex c2f0c1e5ec..5a397fd433 100644--- a/packages/desktop-client/src/components/reports/reports/CustomReportListCards.tsx+++ b/packages/desktop-client/src/components/reports/reports/CustomReportListCards.tsx@@ -6,7 +6,7 @@ import { Text } from '@actual-app/components/text';import { Tooltip } from '@actual-app/components/tooltip';import { View } from '@actual-app/components/view';-import { addNotification } from 'loot-core/client/actions';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { calculateHasWarning } from 'loot-core/client/reports';import { send, sendCatch } from 'loot-core/platform/client/fetch/index';import * as monthUtils from 'loot-core/shared/months';@@ -102,8 +102,10 @@ function CustomReportListCardsInner({if (response.error) {dispatch(addNotification({- type: 'error',- message: `Failed saving report name: ${response.error.message}`,+ notification: {+ type: 'error',+ message: `Failed saving report name: ${response.error.message}`,+ },}),);setNameMenuOpen(true);diff --git a/packages/desktop-client/src/components/reports/reports/NetWorth.tsx b/packages/desktop-client/src/components/reports/reports/NetWorth.tsxindex 05c8f429f4..dbb36e73cc 100644--- a/packages/desktop-client/src/components/reports/reports/NetWorth.tsx+++ b/packages/desktop-client/src/components/reports/reports/NetWorth.tsx@@ -8,8 +8,8 @@ import { styles } from '@actual-app/components/styles';import { View } from '@actual-app/components/view';import * as d from 'date-fns';-import { addNotification } from 'loot-core/client/actions';import { useWidget } from 'loot-core/client/data-hooks/widget';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import * as monthUtils from 'loot-core/shared/months';import { integerToCurrency } from 'loot-core/shared/util';@@ -149,8 +149,10 @@ function NetWorthInner({ widget }: NetWorthInnerProps) {});dispatch(addNotification({- type: 'message',- message: t('Dashboard widget successfully saved.'),+ notification: {+ type: 'message',+ message: t('Dashboard widget successfully saved.'),+ },}),);}diff --git a/packages/desktop-client/src/components/reports/reports/Spending.tsx b/packages/desktop-client/src/components/reports/reports/Spending.tsxindex 7ea6befb92..326ed9caeb 100644--- a/packages/desktop-client/src/components/reports/reports/Spending.tsx+++ b/packages/desktop-client/src/components/reports/reports/Spending.tsx@@ -14,8 +14,8 @@ import { Tooltip } from '@actual-app/components/tooltip';import { View } from '@actual-app/components/view';import * as d from 'date-fns';-import { addNotification } from 'loot-core/client/actions';import { useWidget } from 'loot-core/client/data-hooks/widget';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import * as monthUtils from 'loot-core/shared/months';import { amountToCurrency } from 'loot-core/shared/util';@@ -154,8 +154,10 @@ function SpendingInternal({ widget }: SpendingInternalProps) {});dispatch(addNotification({- type: 'message',- message: t('Dashboard widget successfully saved.'),+ notification: {+ type: 'message',+ message: t('Dashboard widget successfully saved.'),+ },}),);}diff --git a/packages/desktop-client/src/components/reports/reports/Summary.tsx b/packages/desktop-client/src/components/reports/reports/Summary.tsxindex c65b8708fd..781044375d 100644--- a/packages/desktop-client/src/components/reports/reports/Summary.tsx+++ b/packages/desktop-client/src/components/reports/reports/Summary.tsx@@ -14,8 +14,8 @@ import { theme } from '@actual-app/components/theme';import { View } from '@actual-app/components/view';import { parseISO } from 'date-fns';-import { addNotification } from 'loot-core/client/actions';import { useWidget } from 'loot-core/client/data-hooks/widget';+import { addNotification } from 'loot-core/client/notifications/notificationsSlice';import { send } from 'loot-core/platform/client/fetch';import * as monthUtils from 'loot-core/shared/months';import { amountToCurrency } from 'loot-core/shared/util';@@ -196,8 +196,10 @@ function SummaryInner({ widget }: SummaryInnerProps) {if (!widget) {dispatch(addNotification({- type: 'error',- message: t('Cannot save: No widget available.'),+ notification: {+ type: 'error',+ message: t('Cannot save: No widget available.'),+ },}),);return;@@ -224,8 +226,10 @@ function SummaryInner({ widget }: SummaryInnerProps) {if (!widget) {dispatch(addNotification({- type: 'error',- message: t('Cannot save: No widget available.'),+ notification: {+ type: 'error',+ message: t('Cannot save: No widget available.'),+ },}),);return;@@ -246,8 +250,10 @@ function SummaryInner({ widget }: SummaryInnerProps) {});dispatch(addNotification({- type: 'message',- message: t('Dashboard widget successfully saved.'),+ notification: {+ type: 'message',+ message: t('Dashboard widget successfully saved.'),+ },}),);}diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.jsx b/packages/desktop-client/src/components/transactions/TransactionsTable.jsxindex 88ee2e5250..dc35a15dee 100644--- a/packages/desktop-client/src/components/transactions/TransactionsTable.jsx+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.jsx@@ -25,9 +25,9 @@ import {isValid as isDateValid,} from 'date-fns';-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 { addNotification } from 'loot-core/client/notifications/notificationsSlice';import {getAccountsById,getPayeesById,@@ -2192,8 +2192,10 @@ export const TransactionTable = forwardRef((props, ref) => {if (newTransactions[0].account == null) {dispatch(addNotification({- type: 'error',- message: 'Account is a required field',+ notification: {+ type: 'error',+ message: 'Account is a required field',+ },}),);newNavigator.onEdit('temp', 'account');diff --git a/packages/desktop-client/src/global-events.ts b/packages/desktop-client/src/global-events.tsindex 4467783849..d1692ef3c0 100644--- a/packages/desktop-client/src/global-events.ts+++ b/packages/desktop-client/src/global-events.ts@@ -1,9 +1,5 @@// @ts-strict-ignore-import {- addGenericErrorNotification,- addNotification,- loadPrefs,-} from 'loot-core/client/actions';+import { loadPrefs } from 'loot-core/client/actions';import { setAppState } from 'loot-core/client/app/appSlice';import { closeBudgetUI } from 'loot-core/client/budgets/budgetsSlice';import {@@ -11,6 +7,10 @@ import {pushModal,replaceModal,} from 'loot-core/client/modals/modalsSlice';+import {+ addGenericErrorNotification,+ addNotification,+} from 'loot-core/client/notifications/notificationsSlice';import {getAccounts,getCategories,@@ -113,13 +113,15 @@ export function handleGlobalEvents(store: AppStore) {const unlistenFallbackWriteError = listen('fallback-write-error', () => {store.dispatch(addNotification({- type: 'error',- title: 'Unable to save changes',- sticky: true,- message:- 'This browser only supports using the app in one tab at a time, ' +- 'and another tab has opened the app. No changes will be saved ' +- 'from this tab; please close it and continue working in the other one.',+ notification: {+ type: 'error',+ title: 'Unable to save changes',+ sticky: true,+ message:+ 'This browser only supports using the app in one tab at a time, ' ++ 'and another tab has opened the app. No changes will be saved ' ++ 'from this tab; please close it and continue working in the other one.',+ },}),);});diff --git a/packages/desktop-client/src/hooks/useUndo.ts b/packages/desktop-client/src/hooks/useUndo.tsindex 0c6a1fd665..a1abfb4820 100644--- a/packages/desktop-client/src/hooks/useUndo.ts+++ b/packages/desktop-client/src/hooks/useUndo.ts@@ -1,7 +1,9 @@import { useCallback } from 'react';-import { addNotification } from 'loot-core/client/actions';-import { type Notification } from 'loot-core/client/state-types/notifications';+import {+ addNotification,+ type Notification,+} from 'loot-core/client/notifications/notificationsSlice';import { redo, undo } from 'loot-core/client/undo';import { useResponsive } from '../components/responsive/ResponsiveProvider';@@ -28,13 +30,15 @@ export function useUndo(): UndoActions {dispatch(addNotification({- type: 'message',- timeout,- button: {- title: 'Undo',- action: undo,+ notification: {+ type: 'message',+ timeout,+ button: {+ title: 'Undo',+ action: undo,+ },+ ...notification,},- ...notification,}),);},@@ -49,13 +53,15 @@ export function useUndo(): UndoActions {dispatch(addNotification({- type: 'message',- timeout,- button: {- title: 'Redo',- action: redo,+ notification: {+ type: 'message',+ timeout,+ button: {+ title: 'Redo',+ action: redo,+ },+ ...notification,},- ...notification,}),);},diff --git a/packages/desktop-client/src/index.tsx b/packages/desktop-client/src/index.tsxindex 8740e34607..fdcbf5cff2 100644--- a/packages/desktop-client/src/index.tsx+++ b/packages/desktop-client/src/index.tsx@@ -18,6 +18,7 @@ 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 notificationsSlice from 'loot-core/client/notifications/notificationsSlice';import * as queriesSlice from 'loot-core/client/queries/queriesSlice';import { runQuery } from 'loot-core/client/query-helpers';import { store } from 'loot-core/client/store';@@ -40,6 +41,7 @@ const boundActions = bindActionCreators(...appSlice.actions,...budgetsSlice.actions,...modalsSlice.actions,+ ...notificationsSlice.actions,...queriesSlice.actions,},store.dispatch,diff --git a/packages/loot-core/src/client/accounts/accountsSlice.ts b/packages/loot-core/src/client/accounts/accountsSlice.tsindex 322a78c5fb..71b6ea78d8 100644--- a/packages/loot-core/src/client/accounts/accountsSlice.ts+++ b/packages/loot-core/src/client/accounts/accountsSlice.ts@@ -9,7 +9,7 @@ import {type SyncServerSimpleFinAccount,type SyncServerPluggyAiAccount,} from '../../types/models';-import { addNotification } from '../actions';+import { addNotification } from '../notifications/notificationsSlice';import {getAccounts,getPayees,@@ -187,16 +187,20 @@ function handleSyncResponse(if ('type' in error && error.type === 'SyncError') {dispatch(addNotification({- type: 'error',- message: error.message,+ notification: {+ type: 'error',+ message: error.message,+ },}),);} else {dispatch(addNotification({- type: 'error',- message: error.message,- internal: 'internal' in error ? error.internal : undefined,+ notification: {+ type: 'error',+ message: error.message,+ internal: 'internal' in error ? error.internal : undefined,+ },}),);}diff --git a/packages/loot-core/src/client/actions/index.ts b/packages/loot-core/src/client/actions/index.tsindex b9e0e8b2fb..25ef30eedf 100644--- a/packages/loot-core/src/client/actions/index.ts+++ b/packages/loot-core/src/client/actions/index.ts@@ -1,3 +1,2 @@-export * from './notifications';export * from './prefs';export * from './user';diff --git a/packages/loot-core/src/client/actions/notifications.ts b/packages/loot-core/src/client/actions/notifications.tsdeleted file mode 100644index 2988ae464d..0000000000--- a/packages/loot-core/src/client/actions/notifications.ts+++ /dev/null@@ -1,48 +0,0 @@-import { t } from 'i18next';-import { v4 as uuidv4 } from 'uuid';--import * as constants from '../constants';-import type {- AddNotificationAction,- RemoveNotificationAction,- Notification,- SetNotificationInsetAction,-} from '../state-types/notifications';--export function addNotification(- notification: Notification,-): AddNotificationAction {- return {- type: constants.ADD_NOTIFICATION,- notification: {- ...notification,- id: notification.id || uuidv4(),- },- };-}--export function addGenericErrorNotification() {- return addNotification({- type: 'error',- message: t(- 'Something internally went wrong. You may want to restart the app if anything looks wrong. ' +- 'Please report this as a new issue on GitHub.',- ),- });-}--export function removeNotification(id: string): RemoveNotificationAction {- return {- type: constants.REMOVE_NOTIFICATION,- id,- };-}--export function setNotificationInset(- inset?: SetNotificationInsetAction['inset'] | null,-): SetNotificationInsetAction {- return {- type: constants.SET_NOTIFICATION_INSET,- inset: inset ? inset : {},- };-}diff --git a/packages/loot-core/src/client/notifications/notificationsSlice.ts b/packages/loot-core/src/client/notifications/notificationsSlice.tsnew file mode 100644index 0000000000..d171ec356f--- /dev/null+++ b/packages/loot-core/src/client/notifications/notificationsSlice.ts@@ -0,0 +1,106 @@+import { createSlice, type PayloadAction } from '@reduxjs/toolkit';+import { t } from 'i18next';+import { v4 as uuidv4 } from 'uuid';++const sliceName = 'notifications';++export type Notification = {+ id?: string | undefined;+ type?: 'message' | 'error' | 'warning' | undefined;+ pre?: string | undefined;+ title?: string | undefined;+ message: string;+ sticky?: boolean | undefined;+ timeout?: number | undefined;+ button?:+ | {+ title: string;+ action: () => void | Promise<void>;+ }+ | undefined;+ messageActions?: Record<string, () => void> | undefined;+ onClose?: (() => void) | undefined;+ internal?: string | undefined;+};+export type NotificationWithId = Notification & { id: string };++type NotificationsState = {+ notifications: NotificationWithId[];+ inset?: {+ bottom?: number;+ top?: number;+ right?: number;+ left?: number;+ };+};++const initialState: NotificationsState = {+ notifications: [],+ inset: {},+};++type AddNotificationPayload = {+ notification: Notification;+};+type RemoveNotificationPayload = {+ id: NotificationWithId['id'];+};+type SetNotificationInsetPayload = {+ inset: NotificationsState['inset'];+} | null;++const notificationsSlice = createSlice({+ name: sliceName,+ initialState,+ reducers: {+ addNotification(state, action: PayloadAction<AddNotificationPayload>) {+ const notification = {+ ...action.payload.notification,+ id: action.payload.notification.id || uuidv4(),+ };++ if (state.notifications.find(n => n.id === notification.id)) {+ return;+ }+ state.notifications = [...state.notifications, notification];+ },+ addGenericErrorNotification(state) {+ const notification: NotificationWithId = {+ id: uuidv4(),+ type: 'error',+ message: t(+ 'Something internally went wrong. You may want to restart the app if anything looks wrong. ' ++ 'Please report this as a new issue on GitHub.',+ ),+ };+ state.notifications = [...state.notifications, notification];+ },+ removeNotification(+ state,+ action: PayloadAction<RemoveNotificationPayload>,+ ) {+ state.notifications = state.notifications.filter(+ notif => notif.id !== action.payload.id,+ );+ },+ setNotificationInset(+ state,+ action: PayloadAction<SetNotificationInsetPayload>,+ ) {+ state.inset = action.payload?.inset ? action.payload.inset : {};+ },+ },+});++export const { name, reducer, getInitialState } = notificationsSlice;++export const actions = {+ ...notificationsSlice.actions,+};++export const {+ addGenericErrorNotification,+ addNotification,+ removeNotification,+ setNotificationInset,+} = actions;diff --git a/packages/loot-core/src/client/queries/queriesSlice.ts b/packages/loot-core/src/client/queries/queriesSlice.tsindex bef69556ce..8a9bd003ce 100644--- a/packages/loot-core/src/client/queries/queriesSlice.ts+++ b/packages/loot-core/src/client/queries/queriesSlice.ts@@ -12,7 +12,10 @@ import {type AccountEntity,type PayeeEntity,} from '../../types/models';-import { addGenericErrorNotification, addNotification } from '../actions';+import {+ addGenericErrorNotification,+ addNotification,+} from '../notifications/notificationsSlice';import { createAppAsyncThunk } from '../redux';const sliceName = 'queries';@@ -314,11 +317,13 @@ export const deleteCategory = createAppAsyncThunk(case 'category-type':dispatch(addNotification({- id: `${sliceName}/deleteCategory/transfer`,- type: 'error',- message: t(- 'A category must be transferred to another of the same type (expense or income)',- ),+ notification: {+ id: `${sliceName}/deleteCategory/transfer`,+ type: 'error',+ message: t(+ 'A category must be transferred to another of the same type (expense or income)',+ ),+ },}),);break;@@ -584,35 +589,43 @@ export const applyBudgetAction = createAppAsyncThunk(await send('budget/set-12month-avg', { month });break;case 'check-templates':- dispatch(addNotification(await send('budget/check-templates')));+ dispatch(+ addNotification({+ notification: await send('budget/check-templates'),+ }),+ );break;case 'apply-goal-template':dispatch(- addNotification(await send('budget/apply-goal-template', { month })),+ addNotification({+ notification: await send('budget/apply-goal-template', { month }),+ }),);break;case 'overwrite-goal-template':dispatch(- addNotification(- await send('budget/overwrite-goal-template', { month }),- ),+ addNotification({+ notification: await send('budget/overwrite-goal-template', {+ month,+ }),+ }),);break;case 'apply-single-category-template':dispatch(- addNotification(- await send('budget/apply-single-template', {+ addNotification({+ notification: await send('budget/apply-single-template', {month,category: args.category,}),- ),+ }),);break;case 'cleanup-goal-template':dispatch(- addNotification(- await send('budget/cleanup-goal-template', { month }),- ),+ addNotification({+ notification: await send('budget/cleanup-goal-template', { month }),+ }),);break;case 'hold':@@ -662,12 +675,12 @@ export const applyBudgetAction = createAppAsyncThunk(}case 'apply-multiple-templates':dispatch(- addNotification(- await send('budget/apply-multiple-templates', {+ addNotification({+ notification: await send('budget/apply-multiple-templates', {month,categoryIds: args.categories,}),- ),+ }),);break;case 'set-single-3-avg':@@ -725,8 +738,10 @@ export const importPreviewTransactions = createAppAsyncThunk(errors.forEach(error => {dispatch(addNotification({- type: 'error',- message: error.message,+ notification: {+ type: 'error',+ message: error.message,+ },}),);});@@ -769,8 +784,10 @@ export const importTransactions = createAppAsyncThunk(errors.forEach(error => {dispatch(addNotification({- type: 'error',- message: error.message,+ notification: {+ type: 'error',+ message: error.message,+ },}),);});diff --git a/packages/loot-core/src/client/reducers/index.ts b/packages/loot-core/src/client/reducers/index.tsindex 9793e164da..9b0ab97ac5 100644--- a/packages/loot-core/src/client/reducers/index.ts+++ b/packages/loot-core/src/client/reducers/index.ts@@ -1,9 +1,7 @@-import { update as notifications } from './notifications';import { update as prefs } from './prefs';import { update as user } from './user';export const reducers = {prefs,- notifications,user,};diff --git a/packages/loot-core/src/client/reducers/notifications.ts b/packages/loot-core/src/client/reducers/notifications.tsdeleted file mode 100644index a42efea911..0000000000--- a/packages/loot-core/src/client/reducers/notifications.ts+++ /dev/null@@ -1,39 +0,0 @@-// @ts-strict-ignore-import * as constants from '../constants';-import type { Action } from '../state-types';-import type { NotificationsState } from '../state-types/notifications';--export const initialState = {- notifications: [],- inset: {},-};--export function update(- state = initialState,- action: Action,-): NotificationsState {- switch (action.type) {- case constants.ADD_NOTIFICATION:- if (state.notifications.find(n => n.id === action.notification.id)) {- return state;- }-- return {- ...state,- notifications: [...state.notifications, action.notification],- };- case constants.REMOVE_NOTIFICATION:- return {- ...state,- notifications: state.notifications.filter(n => n.id !== action.id),- };- case constants.SET_NOTIFICATION_INSET:- return {- ...state,- inset: action.inset,- };- default:- }-- return state;-}diff --git a/packages/loot-core/src/client/shared-listeners.ts b/packages/loot-core/src/client/shared-listeners.tsindex a0bb46223d..c1dbd41d8b 100644--- a/packages/loot-core/src/client/shared-listeners.ts+++ b/packages/loot-core/src/client/shared-listeners.ts@@ -3,12 +3,15 @@ import { t } from 'i18next';import { listen, send } from '../platform/client/fetch';-import { addNotification, loadPrefs, signOut } from './actions';+import { loadPrefs, signOut } from './actions';import { resetSync, sync } from './app/appSlice';import { closeAndDownloadBudget, uploadBudget } from './budgets/budgetsSlice';import { pushModal } from './modals/modalsSlice';+import {+ addNotification,+ type Notification,+} from './notifications/notificationsSlice';import { getAccounts, getCategories, getPayees } from './queries/queriesSlice';-import type { Notification } from './state-types/notifications';import { type AppStore } from './store';export function listenForSyncEvent(store: AppStore) {@@ -17,10 +20,12 @@ export function listenForSyncEvent(store: AppStore) {if (type === 'unauthorized') {store.dispatch(addNotification({- type: 'warning',- message: 'Unable to authenticate with server',- sticky: true,- id: 'auth-issue',+ notification: {+ type: 'warning',+ message: 'Unable to authenticate with server',+ sticky: true,+ id: 'auth-issue',+ },}),);}@@ -41,9 +46,11 @@ export function listenForSyncEvent(store: AppStore) {store.dispatch(addNotification({- title: t('Syncing has been fixed!'),- message: t('Happy budgeting!'),- type: 'message',+ notification: {+ title: t('Syncing has been fixed!'),+ message: t('Happy budgeting!'),+ type: 'message',+ },}),);}@@ -354,7 +361,9 @@ export function listenForSyncEvent(store: AppStore) {}if (notif) {- store.dispatch(addNotification({ type: 'error', ...notif }));+ store.dispatch(+ addNotification({ notification: { type: 'error', ...notif } }),+ );}}});diff --git a/packages/loot-core/src/client/state-types/index.d.ts b/packages/loot-core/src/client/state-types/index.d.tsindex b92fa49456..61f4888196 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 { NotificationsActions, NotificationsState } from './notifications';import type { PrefsActions, PrefsState } from './prefs';import type { UserActions, UserState } from './user';@@ -8,14 +7,9 @@ export type CloseBudgetAction = {type: typeof constants.CLOSE_BUDGET;};-export type Action =- | NotificationsActions- | PrefsActions- | UserActions- | CloseBudgetAction;+export type Action = PrefsActions | UserActions | CloseBudgetAction;export type State = {- notifications: NotificationsState;prefs: PrefsState;user: UserState;};diff --git a/packages/loot-core/src/client/state-types/notifications.d.ts b/packages/loot-core/src/client/state-types/notifications.d.tsdeleted file mode 100644index 52423e6867..0000000000--- a/packages/loot-core/src/client/state-types/notifications.d.ts+++ /dev/null@@ -1,57 +0,0 @@-import type * as constants from '../constants';--export type Notification = {- id?: string | undefined;- // 'warning' is unhandled??- type?: 'message' | 'error' | 'warning';- pre?: string | undefined;- title?: string | undefined;- message: string;- sticky?: boolean | undefined;- timeout?: number | undefined;- button?:- | {- title: string;- action: () => void | Promise<void>;- }- | undefined;- messageActions?: Record<string, () => void> | undefined;- onClose?: (() => void) | undefined;- internal?: string | undefined;-};-type NotificationWithId = Notification & { id: string };--export type NotificationsState = {- notifications: NotificationWithId[];- inset?: {- bottom?: number;- top?: number;- right?: number;- left?: number;- };-};--type AddNotificationAction = {- type: typeof constants.ADD_NOTIFICATION;- notification: NotificationWithId;-};--type RemoveNotificationAction = {- type: typeof constants.REMOVE_NOTIFICATION;- id: string;-};--type SetNotificationInsetAction = {- type: typeof constants.SET_NOTIFICATION_INSET;- inset: {- bottom?: number;- top?: number;- right?: number;- left?: number;- };-};--export type NotificationsActions =- | AddNotificationAction- | RemoveNotificationAction- | SetNotificationInsetAction;diff --git a/packages/loot-core/src/client/store/index.ts b/packages/loot-core/src/client/store/index.tsindex 964e40fb79..4008c6c198 100644--- a/packages/loot-core/src/client/store/index.ts+++ b/packages/loot-core/src/client/store/index.ts@@ -10,7 +10,6 @@ import {reducer as accountsSliceReducer,getInitialState as getInitialAccountsState,} from '../accounts/accountsSlice';-import { addNotification } from '../actions';import {name as appSliceName,reducer as appSliceReducer,@@ -27,13 +26,18 @@ import {reducer as modalsSliceReducer,getInitialState as getInitialModalsState,} from '../modals/modalsSlice';+import {+ name as notificationsSliceName,+ reducer as notificationsSliceReducer,+ getInitialState as getInitialNotificationsState,+ addNotification,+} from '../notifications/notificationsSlice';import {name as queriesSliceName,reducer as queriesSliceReducer,getInitialState as getInitialQueriesState,} from '../queries/queriesSlice';import { reducers } from '../reducers';-import { initialState as initialNotificationsState } from '../reducers/notifications';import { initialState as initialPrefsState } from '../reducers/prefs';import { initialState as initialUserState } from '../reducers/user';@@ -43,6 +47,7 @@ const appReducer = combineReducers({[appSliceName]: appSliceReducer,[budgetsSliceName]: budgetsSliceReducer,[modalsSliceName]: modalsSliceReducer,+ [notificationsSliceName]: notificationsSliceReducer,[queriesSliceName]: queriesSliceReducer,});const rootReducer: typeof appReducer = (state, action) => {@@ -52,7 +57,7 @@ const rootReducer: typeof appReducer = (state, action) => {state = {account: getInitialAccountsState(),modals: getInitialModalsState(),- notifications: initialNotificationsState,+ notifications: getInitialNotificationsState(),queries: getInitialQueriesState(),budgets: state?.budgets || getInitialBudgetsState(),user: state?.user || initialUserState,@@ -79,9 +84,11 @@ notifyOnRejectedActionsMiddleware.startListening({console.error(action.error);dispatch(addNotification({- id: action.type,- type: 'error',- message: action.error.message || 'An unexpected error occurred.',+ notification: {+ id: action.type,+ type: 'error',+ message: action.error.message || 'An unexpected error occurred.',+ },}),);},diff --git a/packages/loot-core/src/client/store/mock.ts b/packages/loot-core/src/client/store/mock.tsindex a3c95da043..dcc5443acc 100644--- a/packages/loot-core/src/client/store/mock.ts+++ b/packages/loot-core/src/client/store/mock.ts@@ -16,6 +16,10 @@ import {name as modalsSliceName,reducer as modalsSliceReducer,} from '../modals/modalsSlice';+import {+ name as notificationsSliceName,+ reducer as notificationsSliceReducer,+} from '../notifications/notificationsSlice';import {name as queriesSliceName,reducer as queriesSliceReducer,@@ -30,6 +34,7 @@ const appReducer = combineReducers({[appSliceName]: appSliceReducer,[budgetsSliceName]: budgetsSliceReducer,[modalsSliceName]: modalsSliceReducer,+ [notificationsSliceName]: notificationsSliceReducer,[queriesSliceName]: queriesSliceReducer,});diff --git a/packages/loot-core/src/server/budget/cleanup-template.ts b/packages/loot-core/src/server/budget/cleanup-template.tsindex 30174657b2..b0dbc66535 100644--- a/packages/loot-core/src/server/budget/cleanup-template.ts+++ b/packages/loot-core/src/server/budget/cleanup-template.ts@@ -1,5 +1,5 @@// @ts-strict-ignore-import { Notification } from '../../client/state-types/notifications';+import { Notification } from '../../client/notifications/notificationsSlice';import * as monthUtils from '../../shared/months';import * as db from '../db';diff --git a/packages/loot-core/src/server/budget/goaltemplates.ts b/packages/loot-core/src/server/budget/goaltemplates.tsindex f137c6190a..5dacdfb01e 100644--- a/packages/loot-core/src/server/budget/goaltemplates.ts+++ b/packages/loot-core/src/server/budget/goaltemplates.ts@@ -1,5 +1,5 @@// @ts-strict-ignore-import { Notification } from '../../client/state-types/notifications';+import { Notification } from '../../client/notifications/notificationsSlice';import * as monthUtils from '../../shared/months';import { CategoryEntity } from '../../types/models';import * as db from '../db';diff --git a/packages/loot-core/src/server/budget/template-notes.ts b/packages/loot-core/src/server/budget/template-notes.tsindex e0243c7ed3..558ec4192a 100644--- a/packages/loot-core/src/server/budget/template-notes.ts+++ b/packages/loot-core/src/server/budget/template-notes.ts@@ -1,4 +1,4 @@-import { Notification } from '../../client/state-types/notifications';+import { Notification } from '../../client/notifications/notificationsSlice';import * as db from '../db';import { parse } from './goal-template.pegjs';diff --git a/packages/loot-core/src/server/budget/types/handlers.d.ts b/packages/loot-core/src/server/budget/types/handlers.d.tsindex 1c70706c9a..28da76d152 100644--- a/packages/loot-core/src/server/budget/types/handlers.d.ts+++ b/packages/loot-core/src/server/budget/types/handlers.d.ts@@ -1,4 +1,4 @@-import type { Notification } from '../../../client/state-types/notifications';+import type { Notification } from '../../../client/notifications/notificationsSlice';export interface BudgetHandlers {'budget/budget-amount': (arg: {diff --git a/upcoming-release-notes/4126.md b/upcoming-release-notes/4126.mdnew file mode 100644index 0000000000..33c04bde27--- /dev/null+++ b/upcoming-release-notes/4126.md@@ -0,0 +1,6 @@+---+category: Maintenance+authors: [joel-jeremy]+---++Phase 2 - Redux Toolkit Migration - notifications slice