continuing to refactor form.
This commit is contained in:
@@ -47,6 +47,8 @@
|
||||
[form-name]
|
||||
(re-frame/path [::forms form-name]))
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change
|
||||
(fn [db [_ form & path-pairs]]
|
||||
@@ -74,6 +76,16 @@
|
||||
(assoc-in [::forms id :status] :loading)
|
||||
(assoc-in [::forms id :error] nil)))
|
||||
|
||||
(defn triggers-loading [form]
|
||||
(re-frame/enrich
|
||||
(fn [db event]
|
||||
(loading db form))))
|
||||
|
||||
(defn triggers-stop [form]
|
||||
(re-frame/enrich
|
||||
(fn [db event]
|
||||
(stop-form db form))))
|
||||
|
||||
(defn save-succeeded [db id]
|
||||
(-> db
|
||||
(assoc-in [::forms id :status] nil)
|
||||
@@ -82,13 +94,15 @@
|
||||
|
||||
(defn vertical-form [{:keys [can-submit id change-event submit-event ]}]
|
||||
{:form (fn [{:keys [title] :as params} & children]
|
||||
(let [{:keys [data active? error]} @(re-frame/subscribe [::form id])]
|
||||
(let [{:keys [data active? error]} @(re-frame/subscribe [::form id])
|
||||
can-submit @(re-frame/subscribe can-submit)]
|
||||
|
||||
(into ^{:key id} [:form { :on-submit (fn [e]
|
||||
(when (.-stopPropagation e)
|
||||
(.stopPropagation e)
|
||||
(.preventDefault e))
|
||||
(re-frame/dispatch-sync (conj submit-event params)))}
|
||||
(when can-submit
|
||||
(re-frame/dispatch-sync (conj submit-event params))))}
|
||||
[:h1.title.is-2 title]
|
||||
|
||||
]
|
||||
|
||||
@@ -13,9 +13,8 @@
|
||||
(not (get-in accounts [0 :account :id]))))
|
||||
|
||||
(defn default-account [accounts default-account amount locations]
|
||||
[{:id (doto (get-in accounts [0 :id]
|
||||
[{:id (get-in accounts [0 :id]
|
||||
(str "new-" (random-uuid)))
|
||||
println)
|
||||
:amount (Math/abs amount)
|
||||
:amount-percentage 100
|
||||
:amount-mode "%"
|
||||
@@ -137,7 +136,7 @@
|
||||
[:div.column.is-narrow
|
||||
(when-not disabled
|
||||
[:a.delete {:on-click (dispatch-event [::remove-expense-account event expense-accounts id])}])]]
|
||||
(println "TYPAHEAD" expense-accounts)
|
||||
|
||||
[:div.field
|
||||
[:div.columns
|
||||
[:div.column
|
||||
|
||||
@@ -5,16 +5,20 @@
|
||||
[auto-ap.views.components.typeahead :refer [typeahead typeahead-entity]]
|
||||
[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]]
|
||||
[auto-ap.views.utils :refer [bind-field dispatch-event with-user]]
|
||||
[re-frame.core :as re-frame]
|
||||
[clojure.string :as str]
|
||||
[clojure.set :as set]))
|
||||
|
||||
;; SUBS
|
||||
(re-frame/reg-sub
|
||||
::request
|
||||
::submit-query
|
||||
:<- [::forms/form ::form]
|
||||
(fn [{{:keys [id vendor accounts exclude-from-ledger]} :data}]
|
||||
{:venia/operation {:operation/type :mutation
|
||||
:operation/name "EditTransaction"}
|
||||
:venia/queries [{:query/data
|
||||
[:edit-transaction
|
||||
{:transaction {:id id
|
||||
:vendor-id (:id vendor)
|
||||
:exclude-from-ledger exclude-from-ledger
|
||||
@@ -25,7 +29,8 @@
|
||||
:account-id (:id account)
|
||||
:location location
|
||||
:amount amount})
|
||||
accounts)}}))
|
||||
accounts)}}
|
||||
transaction-read]}]}))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::can-submit
|
||||
@@ -64,28 +69,21 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::saving
|
||||
(fn [{:keys [db]} [_ params]]
|
||||
(when @(re-frame/subscribe [::can-submit])
|
||||
(let [{{:keys [id vendor-id account-id location]} :data :as data} @(re-frame/subscribe [::forms/form ::form])]
|
||||
{:db (forms/loading db ::form )
|
||||
:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "EditTransaction"}
|
||||
:venia/queries [{:query/data [:edit-transaction
|
||||
@(re-frame/subscribe [::request])
|
||||
transaction-read]}]}
|
||||
[with-user (forms/triggers-loading ::form) (forms/in-form ::form)]
|
||||
(fn [{:keys [user]} [_ params]]
|
||||
{:graphql
|
||||
{:token user
|
||||
:query-obj @(re-frame/subscribe [::submit-query])
|
||||
:on-success [::edited params]
|
||||
:on-error [::forms/save-error ::form]}}))))
|
||||
:on-error [::forms/save-error ::form]}}))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::matching
|
||||
(fn [{:keys [db]} [_ params payment-id]]
|
||||
(let [{{:keys [id ]} :data :as data} @(re-frame/subscribe [::forms/form ::form])]
|
||||
{:db (forms/loading db ::form )
|
||||
:graphql
|
||||
{:token (-> db :user)
|
||||
[with-user (forms/triggers-loading ::form) (forms/in-form ::form)]
|
||||
(fn [{{{:keys [id]} :data} :db user :user} [_ params payment-id]]
|
||||
{:graphql
|
||||
{:token user
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "MatchTransaction"}
|
||||
:venia/queries [{:query/data [:match-transaction
|
||||
@@ -93,13 +91,13 @@
|
||||
:payment-id payment-id}
|
||||
transaction-read]}]}
|
||||
:on-success [::edited params]
|
||||
:on-error [::forms/save-error ::form]}})))
|
||||
:on-error [::forms/save-error ::form]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::edited
|
||||
[(forms/triggers-stop ::form)]
|
||||
(fn [{:keys [db]} [_ {:keys [edit-completed]} {:keys [edit-transaction match-transaction]}]]
|
||||
{:db (-> db (forms/stop-form ::form))
|
||||
:dispatch (conj edit-completed (or edit-transaction match-transaction))}))
|
||||
{:dispatch (conj edit-completed (or edit-transaction match-transaction))}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::manual-match
|
||||
|
||||
@@ -270,3 +270,10 @@
|
||||
|
||||
(defn local-now []
|
||||
(t/to-default-time-zone (t/now)))
|
||||
|
||||
(def with-user
|
||||
(re-frame/->interceptor
|
||||
:id :with-user
|
||||
:before (fn [context]
|
||||
(-> context
|
||||
(assoc-in [:coeffects :user] (get-in context [:coeffects :db :user]))))))
|
||||
|
||||
Reference in New Issue
Block a user