A local-first personal finance app
Enhance mobile rules with undo notifications for save and delete actions (#5906)
Matiss Janis Aboltins7a3794295fd3
diff --git a/packages/desktop-client/src/components/mobile/rules/MobileRuleEditPage.tsx b/packages/desktop-client/src/components/mobile/rules/MobileRuleEditPage.tsxindex bae4830d71..c61794fe0b 100644--- a/packages/desktop-client/src/components/mobile/rules/MobileRuleEditPage.tsx+++ b/packages/desktop-client/src/components/mobile/rules/MobileRuleEditPage.tsx@@ -15,6 +15,7 @@ import { MobilePageHeader, Page } from '@desktop-client/components/Page';import { RuleEditor } from '@desktop-client/components/rules/RuleEditor';import { useNavigate } from '@desktop-client/hooks/useNavigate';import { useSchedules } from '@desktop-client/hooks/useSchedules';+import { useUndo } from '@desktop-client/hooks/useUndo';import { pushModal } from '@desktop-client/modals/modalsSlice';import { addNotification } from '@desktop-client/notifications/notificationsSlice';import { useDispatch } from '@desktop-client/redux';@@ -25,6 +26,7 @@ export function MobileRuleEditPage() {const { id } = useParams<{ id?: string }>();const location = useLocation();const dispatch = useDispatch();+ const { showUndoNotification } = useUndo();const [rule, setRule] = useState<RuleEntity | null>(null);const [isLoading, setIsLoading] = useState(false);@@ -92,6 +94,11 @@ export function MobileRuleEditPage() {};const handleSave = () => {+ if (rule?.id) {+ showUndoNotification({+ message: t('Rule saved successfully'),+ });+ }// Navigate back to rules listnavigate('/rules');};@@ -115,14 +122,9 @@ export function MobileRuleEditPage() {onConfirm: async () => {try {await send('rule-delete', id);- dispatch(- addNotification({- notification: {- type: 'message',- message: t('Rule deleted successfully'),- },- }),- );+ showUndoNotification({+ message: t('Rule deleted successfully'),+ });navigate('/rules');} catch (error) {console.error('Failed to delete rule:', error);diff --git a/packages/loot-core/src/server/rules/app.ts b/packages/loot-core/src/server/rules/app.tsindex 7c2d2e2baa..c99dc44358 100644--- a/packages/loot-core/src/server/rules/app.ts+++ b/packages/loot-core/src/server/rules/app.ts@@ -86,8 +86,8 @@ export const app = createApp<RulesHandlers>();app.method('rule-validate', ruleValidate);app.method('rule-add', mutator(addRule));-app.method('rule-update', mutator(updateRule));-app.method('rule-delete', mutator(deleteRule));+app.method('rule-update', mutator(undoable(updateRule)));+app.method('rule-delete', mutator(undoable(deleteRule)));app.method('rule-delete-all', mutator(undoable(deleteAllRules)));app.method('rule-apply-actions', mutator(undoable(applyRuleActions)));app.method('rule-add-payee-rename', mutator(addRulePayeeRename));@@ -114,9 +114,9 @@ async function addRule(return { id, ...rule };}-async function updateRule<- PartialRule extends Partial<Omit<RuleEntity, 'id'>> & Pick<RuleEntity, 'id'>,->(rule: PartialRule): Promise<{ error: ValidationError } | PartialRule> {+async function updateRule(+ rule: RuleEntity,+): Promise<{ error: ValidationError } | RuleEntity> {const error = validateRule(rule);if (error) {return { error };diff --git a/upcoming-release-notes/5906.md b/upcoming-release-notes/5906.mdnew file mode 100644index 0000000000..c0b441740c--- /dev/null+++ b/upcoming-release-notes/5906.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [MatissJanis]+---++Mobile rules: add undo notifications