Skip to content

A local-first personal finance app

Fix condition mapping for payee rule creation from payee modal (#414)

winklevosa86ffbcca8c1
diff --git a/packages/desktop-client/src/components/ManageRules.js b/packages/desktop-client/src/components/ManageRules.js
index 8b93bff0b1..93e843c1d3 100644
--- a/packages/desktop-client/src/components/ManageRules.js
+++ b/packages/desktop-client/src/components/ManageRules.js
@@ -588,20 +588,29 @@ export default function ManageRules({
}, []);
function onCreateRule() {
+ let rule = {
+ stage: null,
+ conditions: [
+ {
+ field: 'payee',
+ op: 'is',
+ value: payeeId || null,
+ type: 'id'
+ }
+ ],
+ actions: [
+ {
+ op: 'set',
+ field: 'category',
+ value: null,
+ type: 'id'
+ }
+ ]
+ };
+
dispatch(
pushModal('edit-rule', {
- rule: {
- stage: null,
- conditions: [{ op: 'is', field: 'payee', value: null, type: 'id' }],
- actions: [
- {
- op: 'set',
- field: 'category',
- value: null,
- type: 'id'
- }
- ]
- },
+ rule,
onSave: async newRule => {
let newRules = await loadRules();
diff --git a/packages/desktop-client/src/components/payees/ManagePayeesWithData.js b/packages/desktop-client/src/components/payees/ManagePayeesWithData.js
index 8d2f05e198..fa44a492fb 100644
--- a/packages/desktop-client/src/components/payees/ManagePayeesWithData.js
+++ b/packages/desktop-client/src/components/payees/ManagePayeesWithData.js
@@ -90,19 +90,24 @@ function ManagePayeesWithData({
}
function onCreateRule(id) {
- let payee = payees.find(p => p.id === id);
let rule = {
- id: null,
stage: null,
conditions: [
{
- field: 'description',
+ field: 'payee',
op: 'is',
- value: payee.id,
+ value: id,
type: 'id'
}
],
- actions: []
+ actions: [
+ {
+ op: 'set',
+ field: 'category',
+ value: null,
+ type: 'id'
+ }
+ ]
};
pushModal('edit-rule', { rule });
}