Enhance mobile rules with undo notifications for save and delete actions (#5906)

This commit is contained in:
Matiss Janis Aboltins
2025-10-13 19:02:46 +02:00
committed by GitHub
parent c1d97fcc75
commit 7a3794295f
3 changed files with 21 additions and 13 deletions

View File

@@ -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 list
navigate('/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);

View File

@@ -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 };

View File

@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [MatissJanis]
---
Mobile rules: add undo notifications