cleaning up interface for account.

This commit is contained in:
Bryce Covert
2019-04-25 18:46:54 -07:00
parent 459e0b3e52
commit dd86b2be48
4 changed files with 64 additions and 80 deletions

View File

@@ -2,7 +2,7 @@
(:require [auto-ap.forms :as forms]
[auto-ap.subs :as subs]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.components.expense-accounts-field :refer [expense-accounts-field]]
[auto-ap.views.components.expense-accounts-field :refer [expense-accounts-field] :as expense-accounts-field]
[auto-ap.views.pages.transactions.common :refer [transaction-read]]
[auto-ap.views.utils :refer [bind-field dispatch-event]]
[re-frame.core :as re-frame]
@@ -57,22 +57,9 @@
:client-id (:id (:client which))
:vendor-id (:id (:vendor which))
:vendor-name (:name (:vendor which))
:accounts (if (seq (:accounts which))
(vec (map
(fn [a]
(-> a
(update :amount js/parseFloat)
(assoc :amount-percentage (* 100 (/ (js/parseFloat (:amount a))
(Math/abs (js/parseFloat (:amount which))))))
(assoc :amount-mode "$")))
(:accounts which)))
[{:id (str "new-" (random-uuid))
:amount-mode "$"
:amount (Math/abs (:amount which))
:amount-percentage 100
:location (if (= 1 (count locations))
(first locations)
nil)}])})))))
:accounts (expense-accounts-field/from-graphql (:accounts which)
(:amount which)
locations)})))))
(re-frame/reg-event-fx
@@ -111,22 +98,14 @@
::change-vendor
[(forms/in-form ::edit-transaction)]
(fn [{{:keys [data]} :db} [_ field value]]
(let [has-only-one-expense-account? (and value
(or (not (seq (:accounts data)))
(<= 1 (count (:accounts data))))
(not (get-in data [:accounts 0 :account :id])))]
(if has-only-one-expense-account?
{:dispatch [::forms/change ::edit-transaction
field value
[:accounts] [{:id (str "new-" (random-uuid))
: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]}))))
(if (and value (expense-accounts-field/can-replace-with-default? (:accounts data)))
{:dispatch [::forms/change ::edit-transaction
field value
[:accounts] (expense-accounts-field/default-account (:accounts data)
@(re-frame/subscribe [::subs/vendor-default-account value])
(:amount data))]}
{:dispatch [::forms/change ::edit-transaction field value]})))
(re-frame/reg-event-db
::manual-match
@@ -149,11 +128,6 @@
(re-frame/dispatch-sync [::saving edit-completed]))}
[:h1.title.is-2 "Edit Transaction"]
(comment
[:div.notification
[:p "This transaction matches Invoice 'ABC' for 'DBI Beverages'. " [:a "Create payment and match"] "."]])
[:div.field
[:p.help "Merchant"]
[:div.control