mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-28 18:40:34 -05:00
Enhance mobile rules with undo notifications for save and delete actions (#5906)
This commit is contained in:
committed by
GitHub
parent
c1d97fcc75
commit
7a3794295f
@@ -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);
|
||||
|
||||
@@ -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 };
|
||||
|
||||
6
upcoming-release-notes/5906.md
Normal file
6
upcoming-release-notes/5906.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Enhancements
|
||||
authors: [MatissJanis]
|
||||
---
|
||||
|
||||
Mobile rules: add undo notifications
|
||||
Reference in New Issue
Block a user