diff --git a/packages/desktop-client/src/components/modals/SelectLinkedAccountsModal.jsx b/packages/desktop-client/src/components/modals/SelectLinkedAccountsModal.jsx index 18bc02e618..4a5edbc0ed 100644 --- a/packages/desktop-client/src/components/modals/SelectLinkedAccountsModal.jsx +++ b/packages/desktop-client/src/components/modals/SelectLinkedAccountsModal.jsx @@ -1,12 +1,12 @@ import React, { useState } from 'react'; import { useTranslation, Trans } from 'react-i18next'; -import { closeModal } from 'loot-core/client/actions'; import { linkAccount, linkAccountSimpleFin, unlinkAccount, } from 'loot-core/client/accounts/accountSlice'; +import { closeModal } from 'loot-core/client/actions'; import { useAccounts } from '../../hooks/useAccounts'; import { useAppDispatch } from '../../redux'; diff --git a/packages/loot-core/src/client/accounts/accountSlice.ts b/packages/loot-core/src/client/accounts/accountSlice.ts index cf51c13ef8..8b00916886 100644 --- a/packages/loot-core/src/client/accounts/accountSlice.ts +++ b/packages/loot-core/src/client/accounts/accountSlice.ts @@ -4,12 +4,8 @@ import { type PayloadAction, } from '@reduxjs/toolkit'; -import { - type AccountEntity, - type TransactionEntity, -} from '../../types/models'; - import { send } from '../../platform/client/fetch'; +import { type AccountEntity, type TransactionEntity } from '../../types/models'; import { addNotification, getAccounts, getPayees } from '../actions'; import * as constants from '../constants'; import { type AppDispatch, type RootState } from '../store'; @@ -39,7 +35,9 @@ type MarkAccountSuccessPayload = { }; type AccountState = { - failedAccounts: { [key: AccountEntity['id']]: { type: string; code: string } }; + failedAccounts: { + [key: AccountEntity['id']]: { type: string; code: string }; + }; accountsSyncing: Array; }; diff --git a/packages/loot-core/src/client/actions/account.ts b/packages/loot-core/src/client/actions/account.ts deleted file mode 100644 index 5d9f8bb6ab..0000000000 --- a/packages/loot-core/src/client/actions/account.ts +++ /dev/null @@ -1,106 +0,0 @@ -// @ts-strict-ignore -import { send } from '../../platform/client/fetch'; -import * as constants from '../constants'; -import type { - MarkAccountReadAction, - SetLastTransactionAction, - UpdateNewTransactionsAction, -} from '../state-types/queries'; -import { type AppDispatch } from '../store'; - -import { addNotification } from './notifications'; - -// Remember the last transaction manually added to the system -export function setLastTransaction( - transaction: SetLastTransactionAction['transaction'], -): SetLastTransactionAction { - return { - type: constants.SET_LAST_TRANSACTION, - transaction, - }; -} - -export function parseTransactions(filepath, options) { - return async () => { - return await send('transactions-parse-file', { - filepath, - options, - }); - }; -} - -export function importPreviewTransactions(id: string, transactions) { - return async (dispatch: AppDispatch): Promise => { - const { errors = [], updatedPreview } = await send('transactions-import', { - accountId: id, - transactions, - isPreview: true, - }); - - errors.forEach(error => { - dispatch( - addNotification({ - type: 'error', - message: error.message, - }), - ); - }); - - return updatedPreview; - }; -} - -export function importTransactions(id: string, transactions, reconcile = true) { - return async (dispatch: AppDispatch): Promise => { - if (!reconcile) { - await send('api/transactions-add', { - accountId: id, - transactions, - }); - - return true; - } - - const { - errors = [], - added, - updated, - } = await send('transactions-import', { - accountId: id, - transactions, - isPreview: false, - }); - - errors.forEach(error => { - dispatch( - addNotification({ - type: 'error', - message: error.message, - }), - ); - }); - - dispatch({ - type: constants.SET_NEW_TRANSACTIONS, - newTransactions: added, - matchedTransactions: updated, - updatedAccounts: added.length > 0 ? [id] : [], - }); - - return added.length > 0 || updated.length > 0; - }; -} - -export function updateNewTransactions(changedId): UpdateNewTransactionsAction { - return { - type: constants.UPDATE_NEW_TRANSACTIONS, - changedId, - }; -} - -export function markAccountRead(accountId): MarkAccountReadAction { - return { - type: constants.MARK_ACCOUNT_READ, - accountId, - }; -} diff --git a/packages/loot-core/src/client/actions/index.ts b/packages/loot-core/src/client/actions/index.ts index ec9bda79e1..ef2b435b02 100644 --- a/packages/loot-core/src/client/actions/index.ts +++ b/packages/loot-core/src/client/actions/index.ts @@ -1,5 +1,4 @@ export * from './queries'; -export * from './account'; export * from './modals'; export * from './notifications'; export * from './prefs'; diff --git a/packages/loot-core/src/client/actions/queries.ts b/packages/loot-core/src/client/actions/queries.ts index caa316b824..3d972584c5 100644 --- a/packages/loot-core/src/client/actions/queries.ts +++ b/packages/loot-core/src/client/actions/queries.ts @@ -5,6 +5,11 @@ import throttle from 'throttleit'; import { send } from '../../platform/client/fetch'; import { type AccountEntity } from '../../types/models'; import * as constants from '../constants'; +import { + type MarkAccountReadAction, + type SetLastTransactionAction, + type UpdateNewTransactionsAction, +} from '../state-types/queries'; import { type AppDispatch, type GetRootState } from '../store'; import { pushModal } from './modals'; @@ -368,6 +373,101 @@ export function forceCloseAccount(accountId) { return closeAccount(accountId, null, null, true); } +// Remember the last transaction manually added to the system +export function setLastTransaction( + transaction: SetLastTransactionAction['transaction'], +): SetLastTransactionAction { + return { + type: constants.SET_LAST_TRANSACTION, + transaction, + }; +} + +export function parseTransactions(filepath, options) { + return async () => { + return await send('transactions-parse-file', { + filepath, + options, + }); + }; +} + +export function importPreviewTransactions(id: string, transactions) { + return async (dispatch: AppDispatch): Promise => { + const { errors = [], updatedPreview } = await send('transactions-import', { + accountId: id, + transactions, + isPreview: true, + }); + + errors.forEach(error => { + dispatch( + addNotification({ + type: 'error', + message: error.message, + }), + ); + }); + + return updatedPreview; + }; +} + +export function importTransactions(id: string, transactions, reconcile = true) { + return async (dispatch: AppDispatch): Promise => { + if (!reconcile) { + await send('api/transactions-add', { + accountId: id, + transactions, + }); + + return true; + } + + const { + errors = [], + added, + updated, + } = await send('transactions-import', { + accountId: id, + transactions, + isPreview: false, + }); + + errors.forEach(error => { + dispatch( + addNotification({ + type: 'error', + message: error.message, + }), + ); + }); + + dispatch({ + type: constants.SET_NEW_TRANSACTIONS, + newTransactions: added, + matchedTransactions: updated, + updatedAccounts: added.length > 0 ? [id] : [], + }); + + return added.length > 0 || updated.length > 0; + }; +} + +export function updateNewTransactions(changedId): UpdateNewTransactionsAction { + return { + type: constants.UPDATE_NEW_TRANSACTIONS, + changedId, + }; +} + +export function markAccountRead(accountId): MarkAccountReadAction { + return { + type: constants.MARK_ACCOUNT_READ, + accountId, + }; +} + const _undo = throttle(() => send('undo'), 100); const _redo = throttle(() => send('redo'), 100);