simple change to get accounts auto-populating.

This commit is contained in:
Bryce Covert
2019-04-17 11:13:19 -07:00
parent c51d235a36
commit d30b0948d4
4 changed files with 39 additions and 17 deletions

View File

@@ -135,6 +135,26 @@
[:client-id] value
[:location] first-location]})))
(re-frame/reg-event-fx
::change-vendor
[(forms/in-form ::form)]
(fn [{{:keys [data]} :db} [_ location field value]]
(println "data" data)
(let [has-only-one-expense-account? (and value
(or (not (seq (:expense-accounts data)))
(<= 1 (count (:expense-accounts data))))
(not (get-in data [:expense-accounts 0 :account :id])))]
(println "has only one?" has-only-one-expense-account?)
(if has-only-one-expense-account?
{:dispatch [::forms/change ::form
field value
[:expense-accounts] [{:id (str "new-" (random-uuid))
:amount (:total data)
:account @(re-frame/subscribe [::subs/vendor-default-account value])}]]}
{:dispatch [::forms/change ::form
field value]}))))
(re-frame/reg-event-fx
@@ -214,19 +234,7 @@
:event [::change-new-invoice-client [::form]]
:spec ::invoice/client-id
:subscription data}]]]])
(when (and should-select-location? (not exists?))
[:div.field
[:p.help "Location"]
[:div.control
[:div.select
[bind-field
[:select {:type "select"
:field [:location]
:spec (set locations)
:event change-event
:subscription data}
(map (fn [l] [:option {:value l} l]) locations)]]]]])
[:div.field
[:p.help "Vendor"]
[:div.control
@@ -237,7 +245,8 @@
:auto-focus (if @(re-frame/subscribe [::subs/client]) true false)
:field [:vendor-id]
:text-field [:vendor-name]
:event change-event
:text-event change-event
:event [::change-vendor [::form]]
:spec (s/nilable ::invoice/vendor-id)
:subscription data}]]]]