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