improvements to rule gen to make it so you can't set account incorrectly.

This commit is contained in:
Bryce Covert
2020-10-01 07:41:57 -07:00
parent 3ace024437
commit 5445d55063

View File

@@ -95,9 +95,14 @@
(re-frame/reg-event-fx
::expense-account-changed
(fn [_ [_ event expense-accounts max-value field value]]
(println field value)
(let [updated-accounts (cond-> expense-accounts
true (assoc-in field value)
(= (list :account :id) (drop 1 field)) (assoc-in [(first field) :account] @(re-frame/subscribe [::subs/account nil value]))
(= (list :account) (drop 1 field)) (assoc-in [(first field) :location] nil)
(= (list :account :id) (drop 1 field)) (-> (assoc-in [(first field) :account] @(re-frame/subscribe [::subs/account nil value]))
(assoc-in [(first field) :location] nil))
(= (list :amount-percentage) (drop 1 field)) (assoc-in [(first field) :amount]
(js/parseFloat
(goog.string/format "%.2f"
@@ -108,6 +113,7 @@
updated-accounts (if-let [location (get-in updated-accounts [(first field) :account :location])]
(assoc-in updated-accounts [(first field) :location] location)
updated-accounts)]
(println updated-accounts)
{:dispatch (into event [updated-accounts])})))