updates the location of the expense account when one is selected.

This commit is contained in:
Bryce Covert
2019-04-25 16:20:45 -07:00
parent 672ee019f6
commit 459e0b3e52
2 changed files with 38 additions and 29 deletions

View File

@@ -12,11 +12,14 @@
(re-frame/reg-event-fx
::add-expense-account
(fn [_ [_ event expense-accounts]]
(fn [_ [_ event expense-accounts locations]]
{:dispatch (conj event (conj expense-accounts
{:amount 0 :id (str "new-" (random-uuid))
:amount-mode "%"
:amount-percentage 0}))}))
:amount-percentage 0
:location (if (= 1 (count locations))
(first locations)
nil)}))}))
(re-frame/reg-event-fx
::remove-expense-account
@@ -79,7 +82,7 @@
(when-not disabled
[:p.buttons
[:a.button {:on-click (dispatch-event [::spread-evenly event expense-accounts max-value])} "Spread evenly"]
[:a.button {:on-click (dispatch-event [::add-expense-account event expense-accounts])} "Add"]])]]
[:a.button {:on-click (dispatch-event [::add-expense-account event expense-accounts locations])} "Add"]])]]
(for [[index {:keys [account id location amount amount-mode] :as expense-account}] (map vector (range) expense-accounts)
:let [account (accounts-by-id (:id account))]]
@@ -128,7 +131,6 @@
:subscription expense-accounts}
(map (fn [l] ^{:key l} [:option {:value l} l]) locations)]]])]]]]
[:div.field
[:p.help "Amount"]
[:div.control

View File

@@ -44,6 +44,7 @@
(re-frame/reg-event-db
::editing
(fn [db [_ which potential-payment-matches]]
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])]
(-> db
(forms/start-form ::edit-transaction {:id (:id which)
:yodlee-merchant (:yodlee-merchant which)
@@ -68,7 +69,10 @@
[{:id (str "new-" (random-uuid))
:amount-mode "$"
:amount (Math/abs (:amount which))
:amount-percentage 100}])}))))
:amount-percentage 100
:location (if (= 1 (count locations))
(first locations)
nil)}])})))))
(re-frame/reg-event-fx
@@ -118,6 +122,9 @@
:amount (Math/abs (:amount data))
:amount-percentage 100
:amount-mode "%"
:location (or
(:location @(re-frame/subscribe [::subs/vendor-default-account value]))
(get-in data [:accounts 0 :account :location]))
:account @(re-frame/subscribe [::subs/vendor-default-account value])}]]}
{:dispatch [::forms/change ::edit-transaction field value]}))))