Skip to content

A local-first personal finance app

[Redux] Move payee states from queriesSlice to payeesSlice (#5592)

Joel Jeremy Marquez92e43bc3b599
diff --git a/packages/desktop-client/src/accounts/accountsSlice.ts b/packages/desktop-client/src/accounts/accountsSlice.ts
index 564ee754f6..a5f77b754a 100644
--- a/packages/desktop-client/src/accounts/accountsSlice.ts
+++ b/packages/desktop-client/src/accounts/accountsSlice.ts
@@ -15,10 +15,8 @@ import {
import { resetApp } from '@desktop-client/app/appSlice';
import { addNotification } from '@desktop-client/notifications/notificationsSlice';
-import {
- markPayeesDirty,
- setNewTransactions,
-} from '@desktop-client/queries/queriesSlice';
+import { markPayeesDirty } from '@desktop-client/payees/payeesSlice';
+import { setNewTransactions } from '@desktop-client/queries/queriesSlice';
import { createAppAsyncThunk } from '@desktop-client/redux';
import { type AppDispatch } from '@desktop-client/redux/store';
diff --git a/packages/desktop-client/src/components/ManageRules.tsx b/packages/desktop-client/src/components/ManageRules.tsx
index 5414821a8a..765f176d0d 100644
--- a/packages/desktop-client/src/components/ManageRules.tsx
+++ b/packages/desktop-client/src/components/ManageRules.tsx
@@ -38,7 +38,7 @@ import {
SelectedProvider,
} from '@desktop-client/hooks/useSelected';
import { pushModal } from '@desktop-client/modals/modalsSlice';
-import { getPayees } from '@desktop-client/queries/queriesSlice';
+import { getPayees } from '@desktop-client/payees/payeesSlice';
import { useDispatch } from '@desktop-client/redux';
export type FilterData = {
diff --git a/packages/desktop-client/src/components/accounts/Account.tsx b/packages/desktop-client/src/components/accounts/Account.tsx
index bb1cc751b8..2e13bf44ad 100644
--- a/packages/desktop-client/src/components/accounts/Account.tsx
+++ b/packages/desktop-client/src/components/accounts/Account.tsx
@@ -78,17 +78,14 @@ import {
replaceModal,
} from '@desktop-client/modals/modalsSlice';
import { addNotification } from '@desktop-client/notifications/notificationsSlice';
+import { createPayee, getPayees } from '@desktop-client/payees/payeesSlice';
import * as queries from '@desktop-client/queries';
import { aqlQuery } from '@desktop-client/queries/aqlQuery';
import {
pagedQuery,
type PagedQuery,
} from '@desktop-client/queries/pagedQuery';
-import {
- createPayee,
- getPayees,
- updateNewTransactions,
-} from '@desktop-client/queries/queriesSlice';
+import { updateNewTransactions } from '@desktop-client/queries/queriesSlice';
import { useSelector, useDispatch } from '@desktop-client/redux';
import { type AppDispatch } from '@desktop-client/redux/store';
diff --git a/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx
index b05f79386b..54b8f76539 100644
--- a/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx
+++ b/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx
@@ -37,7 +37,7 @@ import { useCommonPayees, usePayees } from '@desktop-client/hooks/usePayees';
import {
createPayee,
getActivePayees,
-} from '@desktop-client/queries/queriesSlice';
+} from '@desktop-client/payees/payeesSlice';
import { useDispatch } from '@desktop-client/redux';
export type PayeeAutocompleteItem = PayeeEntity;
diff --git a/packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx b/packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx
index 1c816b2e5f..e40c00e58b 100644
--- a/packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx
+++ b/packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx
@@ -40,10 +40,10 @@ import {
import { useCategories } from '@desktop-client/hooks/useCategories';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
import { useSyncedPrefs } from '@desktop-client/hooks/useSyncedPrefs';
+import { reloadPayees } from '@desktop-client/payees/payeesSlice';
import {
importPreviewTransactions,
importTransactions,
- reloadPayees,
} from '@desktop-client/queries/queriesSlice';
import { useDispatch } from '@desktop-client/redux';
diff --git a/packages/desktop-client/src/components/payees/ManagePayeesWithData.tsx b/packages/desktop-client/src/components/payees/ManagePayeesWithData.tsx
index 8f4abcbd8c..d57bc089c6 100644
--- a/packages/desktop-client/src/components/payees/ManagePayeesWithData.tsx
+++ b/packages/desktop-client/src/components/payees/ManagePayeesWithData.tsx
@@ -10,7 +10,7 @@ import { ManagePayees } from './ManagePayees';
import { usePayees } from '@desktop-client/hooks/usePayees';
import { pushModal } from '@desktop-client/modals/modalsSlice';
-import { getPayees, reloadPayees } from '@desktop-client/queries/queriesSlice';
+import { getPayees, reloadPayees } from '@desktop-client/payees/payeesSlice';
import { useDispatch } from '@desktop-client/redux';
type ManagePayeesWithDataProps = {
diff --git a/packages/desktop-client/src/components/rules/RuleEditor.tsx b/packages/desktop-client/src/components/rules/RuleEditor.tsx
index 7fd47396c7..e1fc504ac1 100644
--- a/packages/desktop-client/src/components/rules/RuleEditor.tsx
+++ b/packages/desktop-client/src/components/rules/RuleEditor.tsx
@@ -74,8 +74,8 @@ import {
useSelected,
SelectedProvider,
} from '@desktop-client/hooks/useSelected';
+import { getPayees } from '@desktop-client/payees/payeesSlice';
import { aqlQuery } from '@desktop-client/queries/aqlQuery';
-import { getPayees } from '@desktop-client/queries/queriesSlice';
import { useDispatch } from '@desktop-client/redux';
import { enableUndo, disableUndo } from '@desktop-client/undo';
diff --git a/packages/desktop-client/src/components/rules/ScheduleValue.tsx b/packages/desktop-client/src/components/rules/ScheduleValue.tsx
index 1a3c56e706..dc8bce6a89 100644
--- a/packages/desktop-client/src/components/rules/ScheduleValue.tsx
+++ b/packages/desktop-client/src/components/rules/ScheduleValue.tsx
@@ -12,7 +12,7 @@ import { Value } from './Value';
import { usePayees } from '@desktop-client/hooks/usePayees';
import { useSchedules } from '@desktop-client/hooks/useSchedules';
-import { getPayeesById } from '@desktop-client/queries/queriesSlice';
+import { getPayeesById } from '@desktop-client/payees/payeesSlice';
type ScheduleValueProps = {
value: ScheduleEntity;
diff --git a/packages/desktop-client/src/components/schedules/ScheduleDetails.tsx b/packages/desktop-client/src/components/schedules/ScheduleDetails.tsx
index 0e9bcd7d40..198bb9d806 100644
--- a/packages/desktop-client/src/components/schedules/ScheduleDetails.tsx
+++ b/packages/desktop-client/src/components/schedules/ScheduleDetails.tsx
@@ -54,9 +54,9 @@ import {
type Modal as ModalType,
pushModal,
} from '@desktop-client/modals/modalsSlice';
+import { getPayeesById } from '@desktop-client/payees/payeesSlice';
import { aqlQuery } from '@desktop-client/queries/aqlQuery';
import { liveQuery } from '@desktop-client/queries/liveQuery';
-import { getPayeesById } from '@desktop-client/queries/queriesSlice';
import { useDispatch } from '@desktop-client/redux';
type Fields = {
diff --git a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
index 6448bbc13e..1ce84d9d94 100644
--- a/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
+++ b/packages/desktop-client/src/components/transactions/TransactionsTable.tsx
@@ -126,10 +126,8 @@ import {
import { pushModal } from '@desktop-client/modals/modalsSlice';
import { NotesTagFormatter } from '@desktop-client/notes/NotesTagFormatter';
import { addNotification } from '@desktop-client/notifications/notificationsSlice';
-import {
- getPayeesById,
- getCategoriesById,
-} from '@desktop-client/queries/queriesSlice';
+import { getPayeesById } from '@desktop-client/payees/payeesSlice';
+import { getCategoriesById } from '@desktop-client/queries/queriesSlice';
import { useDispatch } from '@desktop-client/redux';
type TransactionHeaderProps = {
diff --git a/packages/desktop-client/src/global-events.ts b/packages/desktop-client/src/global-events.ts
index cf119dd88f..81e3a30903 100644
--- a/packages/desktop-client/src/global-events.ts
+++ b/packages/desktop-client/src/global-events.ts
@@ -10,8 +10,9 @@ import {
addGenericErrorNotification,
addNotification,
} from './notifications/notificationsSlice';
+import { reloadPayees } from './payees/payeesSlice';
import { loadPrefs } from './prefs/prefsSlice';
-import { reloadCategories, reloadPayees } from './queries/queriesSlice';
+import { reloadCategories } from './queries/queriesSlice';
import { type AppStore } from './redux/store';
import * as syncEvents from './sync-events';
diff --git a/packages/desktop-client/src/hooks/usePayees.ts b/packages/desktop-client/src/hooks/usePayees.ts
index 90c6e42a17..ddb3e7e47a 100644
--- a/packages/desktop-client/src/hooks/usePayees.ts
+++ b/packages/desktop-client/src/hooks/usePayees.ts
@@ -2,17 +2,14 @@ import { useEffect } from 'react';
import { useInitialMount } from './useInitialMount';
-import {
- getCommonPayees,
- getPayees,
-} from '@desktop-client/queries/queriesSlice';
+import { getCommonPayees, getPayees } from '@desktop-client/payees/payeesSlice';
import { useSelector, useDispatch } from '@desktop-client/redux';
export function useCommonPayees() {
const dispatch = useDispatch();
const isInitialMount = useInitialMount();
const isCommonPayeesDirty = useSelector(
- state => state.queries.isCommonPayeesDirty,
+ state => state.payees.isCommonPayeesDirty,
);
useEffect(() => {
@@ -21,13 +18,13 @@ export function useCommonPayees() {
}
}, [dispatch, isInitialMount, isCommonPayeesDirty]);
- return useSelector(state => state.queries.commonPayees);
+ return useSelector(state => state.payees.commonPayees);
}
export function usePayees() {
const dispatch = useDispatch();
const isInitialMount = useInitialMount();
- const isPayeesDirty = useSelector(state => state.queries.isPayeesDirty);
+ const isPayeesDirty = useSelector(state => state.payees.isPayeesDirty);
useEffect(() => {
if (isInitialMount || isPayeesDirty) {
@@ -35,5 +32,5 @@ export function usePayees() {
}
}, [dispatch, isInitialMount, isPayeesDirty]);
- return useSelector(state => state.queries.payees);
+ return useSelector(state => state.payees.payees);
}
diff --git a/packages/desktop-client/src/payees/payeesSlice.ts b/packages/desktop-client/src/payees/payeesSlice.ts
new file mode 100644
index 0000000000..8436f6cda6
--- /dev/null
+++ b/packages/desktop-client/src/payees/payeesSlice.ts
@@ -0,0 +1,214 @@
+import { createSlice } from '@reduxjs/toolkit';
+import memoizeOne from 'memoize-one';
+
+import { send } from 'loot-core/platform/client/fetch';
+import { groupById } from 'loot-core/shared/util';
+import { type AccountEntity, type PayeeEntity } from 'loot-core/types/models';
+
+import { getAccountsById } from '@desktop-client/accounts/accountsSlice';
+import { resetApp } from '@desktop-client/app/appSlice';
+import { createAppAsyncThunk } from '@desktop-client/redux';
+
+const sliceName = 'payees';
+
+type PayeesState = {
+ commonPayees: PayeeEntity[];
+ isCommonPayeesLoading: boolean;
+ isCommonPayeesLoaded: boolean;
+ isCommonPayeesDirty: boolean;
+ payees: PayeeEntity[];
+ isPayeesLoading: boolean;
+ isPayeesLoaded: boolean;
+ isPayeesDirty: boolean;
+};
+
+const initialState: PayeesState = {
+ commonPayees: [],
+ isCommonPayeesLoading: false,
+ isCommonPayeesLoaded: false,
+ isCommonPayeesDirty: false,
+ payees: [],
+ isPayeesLoading: false,
+ isPayeesLoaded: false,
+ isPayeesDirty: false,
+};
+
+const payeesSlice = createSlice({
+ name: sliceName,
+ initialState,
+ reducers: {
+ markPayeesDirty(state) {
+ _markPayeesDirty(state);
+ },
+ },
+ extraReducers: builder => {
+ builder.addCase(resetApp, () => initialState);
+
+ builder.addCase(createPayee.fulfilled, _markPayeesDirty);
+
+ builder.addCase(reloadCommonPayees.fulfilled, (state, action) => {
+ _loadCommonPayees(state, action.payload);
+ });
+
+ builder.addCase(reloadCommonPayees.rejected, state => {
+ state.isCommonPayeesLoading = false;
+ });
+
+ builder.addCase(reloadCommonPayees.pending, state => {
+ state.isCommonPayeesLoading = true;
+ });
+
+ builder.addCase(getCommonPayees.fulfilled, (state, action) => {
+ _loadCommonPayees(state, action.payload);
+ });
+
+ builder.addCase(getCommonPayees.rejected, state => {
+ state.isCommonPayeesLoading = false;
+ });
+
+ builder.addCase(getCommonPayees.pending, state => {
+ state.isCommonPayeesLoading = true;
+ });
+
+ builder.addCase(reloadPayees.fulfilled, (state, action) => {
+ _loadPayees(state, action.payload);
+ });
+
+ builder.addCase(reloadPayees.rejected, state => {
+ state.isPayeesLoading = false;
+ });
+
+ builder.addCase(reloadPayees.pending, state => {
+ state.isPayeesLoading = true;
+ });
+
+ builder.addCase(getPayees.fulfilled, (state, action) => {
+ _loadPayees(state, action.payload);
+ });
+
+ builder.addCase(getPayees.rejected, state => {
+ state.isPayeesLoading = false;
+ });
+
+ builder.addCase(getPayees.pending, state => {
+ state.isPayeesLoading = true;
+ });
+ },
+});
+
+type CreatePayeePayload = {
+ name: PayeeEntity['name'];
+};
+
+export const createPayee = createAppAsyncThunk(
+ `${sliceName}/createPayee`,
+ async ({ name }: CreatePayeePayload) => {
+ const id: PayeeEntity['id'] = await send('payee-create', {
+ name: name.trim(),
+ });
+ return id;
+ },
+);
+
+export const getCommonPayees = createAppAsyncThunk(
+ `${sliceName}/getCommonPayees`,
+ async () => {
+ const payees: PayeeEntity[] = await send('common-payees-get');
+ return payees;
+ },
+ {
+ condition: (_, { getState }) => {
+ const { payees } = getState();
+ return (
+ !payees.isCommonPayeesLoading &&
+ (payees.isCommonPayeesDirty || !payees.isCommonPayeesLoaded)
+ );
+ },
+ },
+);
+
+export const reloadCommonPayees = createAppAsyncThunk(
+ `${sliceName}/reloadCommonPayees`,
+ async () => {
+ const payees: PayeeEntity[] = await send('common-payees-get');
+ return payees;
+ },
+);
+
+export const getPayees = createAppAsyncThunk(
+ `${sliceName}/getPayees`,
+ async () => {
+ const payees: PayeeEntity[] = await send('payees-get');
+ return payees;
+ },
+ {
+ condition: (_, { getState }) => {
+ const { payees } = getState();
+ return (
+ !payees.isPayeesLoading &&
+ (payees.isPayeesDirty || !payees.isPayeesLoaded)
+ );
+ },
+ },
+);
+
+export const reloadPayees = createAppAsyncThunk(
+ `${sliceName}/reloadPayees`,
+ async () => {
+ const payees: PayeeEntity[] = await send('payees-get');
+ return payees;
+ },
+);
+
+export const getActivePayees = memoizeOne(
+ (payees: PayeeEntity[], accounts: AccountEntity[]) => {
+ const accountsById = getAccountsById(accounts);
+
+ return payees.filter(payee => {
+ if (payee.transfer_acct) {
+ const account = accountsById[payee.transfer_acct];
+ return account != null && !account.closed;
+ }
+ return true;
+ });
+ },
+);
+
+export const getPayeesById = memoizeOne(
+ (payees: PayeeEntity[] | null | undefined) => groupById(payees),
+);
+
+export const { name, reducer, getInitialState } = payeesSlice;
+
+export const actions = {
+ ...payeesSlice.actions,
+ createPayee,
+ getCommonPayees,
+ reloadCommonPayees,
+ getPayees,
+ reloadPayees,
+};
+
+export const { markPayeesDirty } = payeesSlice.actions;
+
+function _loadCommonPayees(
+ state: PayeesState,
+ commonPayees: PayeesState['commonPayees'],
+) {
+ state.commonPayees = commonPayees;
+ state.isCommonPayeesLoading = false;
+ state.isCommonPayeesLoaded = true;
+ state.isCommonPayeesDirty = false;
+}
+
+function _loadPayees(state: PayeesState, payees: PayeesState['payees']) {
+ state.payees = payees;
+ state.isPayeesLoading = false;
+ state.isPayeesLoaded = true;
+ state.isPayeesDirty = false;
+}
+
+function _markPayeesDirty(state: PayeesState) {
+ state.isCommonPayeesDirty = true;
+ state.isPayeesDirty = true;
+}
diff --git a/packages/desktop-client/src/queries/queriesSlice.ts b/packages/desktop-client/src/queries/queriesSlice.ts
index e94badc742..27158e2822 100644
--- a/packages/desktop-client/src/queries/queriesSlice.ts
+++ b/packages/desktop-client/src/queries/queriesSlice.ts
@@ -4,20 +4,14 @@ import { t } from 'i18next';
import memoizeOne from 'memoize-one';
import { send } from 'loot-core/platform/client/fetch';
-import { groupById } from 'loot-core/shared/util';
import {
type CategoryEntity,
type CategoryGroupEntity,
type TransactionEntity,
- type AccountEntity,
- type PayeeEntity,
type Tag,
} from 'loot-core/types/models';
-import {
- getAccountsById,
- markUpdatedAccounts,
-} from '@desktop-client/accounts/accountsSlice';
+import { markUpdatedAccounts } from '@desktop-client/accounts/accountsSlice';
import { resetApp } from '@desktop-client/app/appSlice';
import {
addGenericErrorNotification,
@@ -40,14 +34,6 @@ type QueriesState = {
isCategoriesLoading: boolean;
isCategoriesLoaded: boolean;
isCategoriesDirty: boolean;
- commonPayees: PayeeEntity[];
- isCommonPayeesLoading: boolean;
- isCommonPayeesLoaded: boolean;
- isCommonPayeesDirty: boolean;
- payees: PayeeEntity[];
- isPayeesLoading: boolean;
- isPayeesLoaded: boolean;
- isPayeesDirty: boolean;
tags: Tag[];
isTagsLoading: boolean;
isTagsLoaded: boolean;
@@ -65,14 +51,6 @@ const initialState: QueriesState = {
isCategoriesLoading: false,
isCategoriesLoaded: false,
isCategoriesDirty: false,
- commonPayees: [],
- isCommonPayeesLoading: false,
- isCommonPayeesLoaded: false,
- isCommonPayeesDirty: false,
- payees: [],
- isPayeesLoading: false,
- isPayeesLoaded: false,
- isPayeesDirty: false,
tags: [],
isTagsLoading: false,
isTagsLoaded: false,
@@ -128,9 +106,6 @@ const queriesSlice = createSlice({
markCategoriesDirty(state) {
_markCategoriesDirty(state);
},
- markPayeesDirty(state) {
- _markPayeesDirty(state);
- },
markTagsDirty(state) {
_markTagsDirty(state);
},
@@ -171,58 +146,6 @@ const queriesSlice = createSlice({
state.isCategoriesLoading = true;
});
- // Payees
-
- builder.addCase(createPayee.fulfilled, _markPayeesDirty);
-
- builder.addCase(reloadCommonPayees.fulfilled, (state, action) => {
- _loadCommonPayees(state, action.payload);
- });
-
- builder.addCase(reloadCommonPayees.rejected, state => {
- state.isCommonPayeesLoading = false;
- });
-
- builder.addCase(reloadCommonPayees.pending, state => {
- state.isCommonPayeesLoading = true;
- });
-
- builder.addCase(getCommonPayees.fulfilled, (state, action) => {
- _loadCommonPayees(state, action.payload);
- });
-
- builder.addCase(getCommonPayees.rejected, state => {
- state.isCommonPayeesLoading = false;
- });
-
- builder.addCase(getCommonPayees.pending, state => {
- state.isCommonPayeesLoading = true;
- });
-
- builder.addCase(reloadPayees.fulfilled, (state, action) => {
- _loadPayees(state, action.payload);
- });
-
- builder.addCase(reloadPayees.rejected, state => {
- state.isPayeesLoading = false;
- });
-
- builder.addCase(reloadPayees.pending, state => {
- state.isPayeesLoading = true;
- });
-
- builder.addCase(getPayees.fulfilled, (state, action) => {
- _loadPayees(state, action.payload);
- });
-
- builder.addCase(getPayees.rejected, state => {
- state.isPayeesLoading = false;
- });
-
- builder.addCase(getPayees.pending, state => {
- state.isPayeesLoading = true;
- });
-
// App
builder.addCase(resetApp, () => initialState);
@@ -426,72 +349,6 @@ export const reloadCategories = createAppAsyncThunk(
},
);
-// Payee actions
-
-type CreatePayeePayload = {
- name: PayeeEntity['name'];
-};
-
-export const createPayee = createAppAsyncThunk(
- `${sliceName}/createPayee`,
- async ({ name }: CreatePayeePayload) => {
- const id: PayeeEntity['id'] = await send('payee-create', {
- name: name.trim(),
- });
- return id;
- },
-);
-
-export const getCommonPayees = createAppAsyncThunk(
- `${sliceName}/getCommonPayees`,
- async () => {
- const payees: PayeeEntity[] = await send('common-payees-get');
- return payees;
- },
- {
- condition: (_, { getState }) => {
- const { queries } = getState();
- return (
- !queries.isCommonPayeesLoading &&
- (queries.isCommonPayeesDirty || !queries.isCommonPayeesLoaded)
- );
- },
- },
-);
-
-export const reloadCommonPayees = createAppAsyncThunk(
- `${sliceName}/reloadCommonPayees`,
- async () => {
- const payees: PayeeEntity[] = await send('common-payees-get');
- return payees;
- },
-);
-
-export const getPayees = createAppAsyncThunk(
- `${sliceName}/getPayees`,
- async () => {
- const payees: PayeeEntity[] = await send('payees-get');
- return payees;
- },
- {
- condition: (_, { getState }) => {
- const { queries } = getState();
- return (
- !queries.isPayeesLoading &&
- (queries.isPayeesDirty || !queries.isPayeesLoaded)
- );
- },
- },
-);
-
-export const reloadPayees = createAppAsyncThunk(
- `${sliceName}/reloadPayees`,
- async () => {
- const payees: PayeeEntity[] = await send('payees-get');
- return payees;
- },
-);
-
export const getTags = createAppAsyncThunk(
`${sliceName}/getTags`,
async () => {
@@ -966,23 +823,6 @@ export const importTransactions = createAppAsyncThunk(
// Helper functions
-export const getActivePayees = memoizeOne(
- (payees: PayeeEntity[], accounts: AccountEntity[]) => {
- const accountsById = getAccountsById(accounts);
-
- return payees.filter(payee => {
- if (payee.transfer_acct) {
- const account = accountsById[payee.transfer_acct];
- return account != null && !account.closed;
- }
- return true;
- });
- },
-);
-
-export const getPayeesById = memoizeOne(
- (payees: PayeeEntity[] | null | undefined) => groupById(payees),
-);
export const getCategoriesById = memoizeOne(
(categoryGroups: CategoryGroupEntity[] | null | undefined) => {
const res: { [id: CategoryGroupEntity['id']]: CategoryEntity } = {};
@@ -1000,11 +840,6 @@ export const getCategoriesById = memoizeOne(
export const { name, reducer, getInitialState } = queriesSlice;
export const actions = {
...queriesSlice.actions,
- createPayee,
- getCommonPayees,
- reloadCommonPayees,
- getPayees,
- reloadPayees,
importPreviewTransactions,
importTransactions,
applyBudgetAction,
@@ -1031,7 +866,6 @@ export const {
updateNewTransactions,
setLastTransaction,
markCategoriesDirty,
- markPayeesDirty,
markTagsDirty,
} = queriesSlice.actions;
@@ -1049,28 +883,6 @@ function _markCategoriesDirty(state: QueriesState) {
state.isCategoriesDirty = true;
}
-function _loadCommonPayees(
- state: QueriesState,
- commonPayees: QueriesState['commonPayees'],
-) {
- state.commonPayees = commonPayees;
- state.isCommonPayeesLoading = false;
- state.isCommonPayeesLoaded = true;
- state.isCommonPayeesDirty = false;
-}
-
-function _loadPayees(state: QueriesState, payees: QueriesState['payees']) {
- state.payees = payees;
- state.isPayeesLoading = false;
- state.isPayeesLoaded = true;
- state.isPayeesDirty = false;
-}
-
-function _markPayeesDirty(state: QueriesState) {
- state.isCommonPayeesDirty = true;
- state.isPayeesDirty = true;
-}
-
function _loadTags(state: QueriesState, tags: QueriesState['tags']) {
state.tags = tags;
state.isTagsLoading = false;
diff --git a/packages/desktop-client/src/redux/mock.tsx b/packages/desktop-client/src/redux/mock.tsx
index 055e40d595..93cf515a86 100644
--- a/packages/desktop-client/src/redux/mock.tsx
+++ b/packages/desktop-client/src/redux/mock.tsx
@@ -25,6 +25,10 @@ import {
name as notificationsSliceName,
reducer as notificationsSliceReducer,
} from '@desktop-client/notifications/notificationsSlice';
+import {
+ name as payeesSliceName,
+ reducer as payeesSliceReducer,
+} from '@desktop-client/payees/payeesSlice';
import {
name as prefsSliceName,
reducer as prefsSliceReducer,
@@ -44,6 +48,7 @@ const appReducer = combineReducers({
[budgetsSliceName]: budgetsSliceReducer,
[modalsSliceName]: modalsSliceReducer,
[notificationsSliceName]: notificationsSliceReducer,
+ [payeesSliceName]: payeesSliceReducer,
[prefsSliceName]: prefsSliceReducer,
[queriesSliceName]: queriesSliceReducer,
[usersSliceName]: usersSliceReducer,
diff --git a/packages/desktop-client/src/redux/store.ts b/packages/desktop-client/src/redux/store.ts
index d305d345ed..198edb4f83 100644
--- a/packages/desktop-client/src/redux/store.ts
+++ b/packages/desktop-client/src/redux/store.ts
@@ -26,6 +26,10 @@ import {
reducer as notificationsSliceReducer,
addNotification,
} from '@desktop-client/notifications/notificationsSlice';
+import {
+ name as payeesSliceName,
+ reducer as payeesSliceReducer,
+} from '@desktop-client/payees/payeesSlice';
import {
name as prefsSliceName,
reducer as prefsSliceReducer,
@@ -45,6 +49,7 @@ const rootReducer = combineReducers({
[budgetsSliceName]: budgetsSliceReducer,
[modalsSliceName]: modalsSliceReducer,
[notificationsSliceName]: notificationsSliceReducer,
+ [payeesSliceName]: payeesSliceReducer,
[prefsSliceName]: prefsSliceReducer,
[queriesSliceName]: queriesSliceReducer,
[usersSliceName]: usersSliceReducer,
diff --git a/packages/desktop-client/src/sync-events.ts b/packages/desktop-client/src/sync-events.ts
index 3fd1767d36..41233dc850 100644
--- a/packages/desktop-client/src/sync-events.ts
+++ b/packages/desktop-client/src/sync-events.ts
@@ -11,8 +11,9 @@ import {
addNotification,
type Notification,
} from './notifications/notificationsSlice';
+import { reloadPayees } from './payees/payeesSlice';
import { loadPrefs } from './prefs/prefsSlice';
-import { reloadCategories, reloadPayees } from './queries/queriesSlice';
+import { reloadCategories } from './queries/queriesSlice';
import { type AppStore } from './redux/store';
import { signOut } from './users/usersSlice';
diff --git a/upcoming-release-notes/5592.md b/upcoming-release-notes/5592.md
new file mode 100644
index 0000000000..ac88a8d9be
--- /dev/null
+++ b/upcoming-release-notes/5592.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [joel-jeremy]
+---
+
+[Redux] Move payee states from queriesSlice to payeesSlice