Skip to content

A local-first personal finance app

Feature: Add a confirmation modal when users merge payees in /payees (#7188)

Asger Mogensene069312ac33c
diff --git a/packages/desktop-client/src/components/Modals.tsx b/packages/desktop-client/src/components/Modals.tsx
index 69448ba472..e767a25277 100644
--- a/packages/desktop-client/src/components/Modals.tsx
+++ b/packages/desktop-client/src/components/Modals.tsx
@@ -17,6 +17,7 @@ import { CategoryMenuModal } from './modals/CategoryMenuModal';
import { CloseAccountModal } from './modals/CloseAccountModal';
import { ConfirmCategoryDeleteModal } from './modals/ConfirmCategoryDeleteModal';
import { ConfirmDeleteModal } from './modals/ConfirmDeleteModal';
+import { ConfirmPayeesMergeModal } from './modals/ConfirmPayeesMergeModal';
import { ConfirmTransactionEditModal } from './modals/ConfirmTransactionEditModal';
import { ConfirmUnlinkAccountModal } from './modals/ConfirmUnlinkAccountModal';
import { ConvertToScheduleModal } from './modals/ConvertToScheduleModal';
@@ -140,6 +141,9 @@ export function Modals() {
case 'confirm-category-delete':
return <ConfirmCategoryDeleteModal key={key} {...modal.options} />;
+ case 'confirm-payees-merge':
+ return <ConfirmPayeesMergeModal key={key} {...modal.options} />;
+
case 'confirm-unlink-account':
return <ConfirmUnlinkAccountModal key={key} {...modal.options} />;
diff --git a/packages/desktop-client/src/components/modals/ConfirmPayeesMergeModal.tsx b/packages/desktop-client/src/components/modals/ConfirmPayeesMergeModal.tsx
new file mode 100644
index 0000000000..0babf29028
--- /dev/null
+++ b/packages/desktop-client/src/components/modals/ConfirmPayeesMergeModal.tsx
@@ -0,0 +1,118 @@
+import React from 'react';
+import { Trans, useTranslation } from 'react-i18next';
+
+import { Button } from '@actual-app/components/button';
+import { SvgArrowDown } from '@actual-app/components/icons/v1';
+import { Text } from '@actual-app/components/text';
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
+
+import { Information } from '@desktop-client/components/alerts';
+import {
+ Modal,
+ ModalButtons,
+ ModalHeader,
+} from '@desktop-client/components/common/Modal';
+import { usePayees } from '@desktop-client/hooks/usePayees';
+import type { Modal as ModalType } from '@desktop-client/modals/modalsSlice';
+
+const mergePayeeStyle = {
+ padding: 10,
+ border: 'solid',
+ borderWidth: 1,
+ borderRadius: 6,
+ borderColor: theme.tableBorder,
+ backgroundColor: theme.tableBackground,
+};
+
+const targetPayeeStyle = {
+ ...mergePayeeStyle,
+ backgroundColor: theme.tableRowBackgroundHighlight,
+};
+
+type ConfirmPayeesMergeModalProps = Extract<
+ ModalType,
+ { name: 'confirm-payees-merge' }
+>['options'];
+
+export function ConfirmPayeesMergeModal({
+ payeeIds,
+ targetPayeeId,
+ onConfirm,
+}: ConfirmPayeesMergeModalProps) {
+ const { t } = useTranslation();
+ const { data: allPayees = [] } = usePayees();
+
+ const mergePayees = allPayees.filter(p => payeeIds.includes(p.id));
+
+ const targetPayee = allPayees.find(p => p.id === targetPayeeId);
+
+ if (!targetPayee || mergePayees.length === 0) {
+ return null;
+ }
+
+ return (
+ <Modal name="confirm-payees-merge">
+ {({ state }) => (
+ <>
+ <ModalHeader title={t('Confirm Merge')} />
+
+ <View style={{ maxWidth: 500, marginTop: 20 }}>
+ <View
+ style={{
+ flexDirection: 'column',
+ alignItems: 'center',
+ justifyContent: 'center',
+ gap: 20,
+ }}
+ >
+ <View style={{ width: '100%', flexDirection: 'column', gap: 10 }}>
+ {mergePayees.map(payee => (
+ <View style={mergePayeeStyle} key={payee.id}>
+ <Text>{payee.name}</Text>
+ </View>
+ ))}
+ </View>
+ <SvgArrowDown width={20} height={20} />
+ <View style={{ width: '100%' }}>
+ <View style={targetPayeeStyle}>
+ <Text
+ style={{
+ fontWeight: 700,
+ color: theme.tableRowBackgroundHighlightText,
+ }}
+ >
+ {targetPayee.name}
+ </Text>
+ </View>
+ </View>
+ </View>
+
+ <Information style={{ marginTop: 20 }}>
+ <Trans>
+ Merging will delete the selected payee(s) and transfer any
+ associated rules to the target payee.
+ </Trans>
+ </Information>
+
+ <ModalButtons style={{ marginTop: 20 }} focusButton>
+ <Button style={{ marginRight: 10 }} onPress={() => state.close()}>
+ <Trans>Cancel</Trans>
+ </Button>
+ <Button
+ variant="primary"
+ style={{ marginRight: 10 }}
+ onPress={async () => {
+ onConfirm?.();
+ state.close();
+ }}
+ >
+ <Trans>Merge</Trans>
+ </Button>
+ </ModalButtons>
+ </View>
+ </>
+ )}
+ </Modal>
+ );
+}
diff --git a/packages/desktop-client/src/components/payees/ManagePayees.tsx b/packages/desktop-client/src/components/payees/ManagePayees.tsx
index 40bf490983..40e38d5748 100644
--- a/packages/desktop-client/src/components/payees/ManagePayees.tsx
+++ b/packages/desktop-client/src/components/payees/ManagePayees.tsx
@@ -191,9 +191,25 @@ export const ManagePayees = ({
async function onMerge() {
const ids = [...selected.items];
- await props.onMerge(ids);
+ if (ids.length < 2) return;
- selected.dispatch({ type: 'select-none' });
+ const targetPayeeId = ids[0];
+
+ dispatch(
+ pushModal({
+ modal: {
+ name: 'confirm-payees-merge',
+ options: {
+ payeeIds: ids.filter(id => id !== targetPayeeId),
+ targetPayeeId,
+ onConfirm: async () => {
+ await props.onMerge(ids);
+ selected.dispatch({ type: 'select-none' });
+ },
+ },
+ },
+ }),
+ );
}
const onChangeCategoryLearning = useCallback(() => {
diff --git a/packages/desktop-client/src/modals/modalsSlice.ts b/packages/desktop-client/src/modals/modalsSlice.ts
index a204f88c8b..7441412009 100644
--- a/packages/desktop-client/src/modals/modalsSlice.ts
+++ b/packages/desktop-client/src/modals/modalsSlice.ts
@@ -67,6 +67,14 @@ export type Modal =
group?: CategoryGroupEntity['id'];
};
}
+ | {
+ name: 'confirm-payees-merge';
+ options: {
+ payeeIds: string[];
+ targetPayeeId: string;
+ onConfirm: () => void;
+ };
+ }
| {
name: 'load-backup';
options: {
diff --git a/upcoming-release-notes/7188.md b/upcoming-release-notes/7188.md
new file mode 100644
index 0000000000..b7a25c11a8
--- /dev/null
+++ b/upcoming-release-notes/7188.md
@@ -0,0 +1,6 @@
+---
+category: Features
+authors: [AsgerMogensen]
+---
+
+Add a confirmation modal when users merge payees in /payees