supports validation and multiple account entering.

This commit is contained in:
Bryce Covert
2019-04-17 18:35:41 -07:00
parent a4eea929e5
commit 4fe52cad5a
10 changed files with 156 additions and 87 deletions

View File

@@ -5,7 +5,7 @@
:amount
:location
[:vendor [:name :id]]
[:account [:id :name]]
[:accounts [:id :amount :location [:account [:name :id :location]]]]
:date
[:yodlee_merchant [:name :yodlee-id]]
:post_date

View File

@@ -5,32 +5,24 @@
[auto-ap.views.components.expense-accounts-field :refer [expense-accounts-field]]
[auto-ap.views.pages.transactions.common :refer [transaction-read]]
[auto-ap.views.utils :refer [bind-field]]
[re-frame.core :as re-frame]))
[re-frame.core :as re-frame]
[clojure.string :as str]))
(re-frame/reg-event-db
::editing
(fn [db [_ which]]
(-> db
(forms/start-form ::edit-transaction {:id (:id which)
:yodlee-merchant (:yodlee-merchant which)
:description-original (:description-original which)
:location (:location which)
:client-id (:id (:client which))
:account-id (:id (:account which))
:account-name (:name (:account which))
:vendor-id (:id (:vendor which))
:vendor-name (:name (:vendor which))
:expense-accounts (or (:expense-accounts which)
[{:id (str "new-" (random-uuid))
:amount (Math/abs (:amount which))}])}))))
;; SUBS
(re-frame/reg-sub
::request
:<- [::forms/form ::edit-transaction]
(fn [{{:keys [id vendor-id account-id location]} :data}]
(fn [{{:keys [id vendor-id accounts]} :data}]
{:transaction {:id id
:location location
:vendor-id vendor-id
:account-id account-id}}))
:accounts (map
(fn [{:keys [id account amount location]}]
{:id (when-not (str/starts-with? id "new-")
id)
:account-id (:id account)
:location location
:amount amount})
accounts)}}))
(re-frame/reg-sub
::can-submit
@@ -39,12 +31,30 @@
(not= :loading status)))
;; EVENTS
(re-frame/reg-event-fx
::edited
(fn [{:keys [db]} [_ edit-completed {:keys [edit-transaction]}]]
{:db (-> db
(forms/stop-form ::edit-transaction))
:dispatch (conj edit-completed edit-transaction)}))
(re-frame/reg-event-db
::editing
(fn [db [_ which]]
(-> db
(forms/start-form ::edit-transaction {:id (:id which)
:yodlee-merchant (:yodlee-merchant which)
:description-original (:description-original which)
:location (:location which)
:client-id (:id (:client which))
:vendor-id (:id (:vendor which))
:vendor-name (:name (:vendor which))
:accounts (or (vec (:accounts which))
[{:id (str "new-" (random-uuid))
:amount (Math/abs (:amount which))}])}))))
(re-frame/reg-event-fx
::saving
@@ -72,6 +82,8 @@
{:dispatch [::forms/change ::edit-transaction f a]})))
;; VIEWS
(defn form [{:keys [edit-completed]}]
[forms/side-bar-form {:form ::edit-transaction }
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::edit-transaction])
@@ -121,15 +133,15 @@
:event change-event
:subscription data}]]]]
[:div.field
[bind-field
[expense-accounts-field
{:type "expense-accounts"
:field [:expense-accounts]
:descriptor "credit account"
:locations locations
:event change-event
:subscription data}]]]
[:div.field]
[bind-field
[expense-accounts-field
{:type "expense-accounts"
:field [:accounts]
:descriptor "credit account"
:locations locations
:event change-event
:subscription data}]]
(comment
[:div.field