separating transaction stuff out.
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
[auto-ap.views.components.paginator :refer [paginator]]
|
[auto-ap.views.components.paginator :refer [paginator]]
|
||||||
[auto-ap.views.components.layouts :refer [side-bar-layout appearing-side-bar]]
|
[auto-ap.views.components.layouts :refer [side-bar-layout appearing-side-bar]]
|
||||||
[auto-ap.views.components.bank-account-filter :refer [bank-account-filter]]
|
[auto-ap.views.components.bank-account-filter :refer [bank-account-filter]]
|
||||||
|
[auto-ap.views.pages.transactions.edit :as edit]
|
||||||
[auto-ap.events :as events]
|
[auto-ap.events :as events]
|
||||||
[auto-ap.views.utils :refer [dispatch-event date->str bind-field nf]]
|
[auto-ap.views.utils :refer [dispatch-event date->str bind-field nf]]
|
||||||
[auto-ap.utils :refer [by]]
|
[auto-ap.utils :refer [by]]
|
||||||
@@ -29,7 +30,18 @@
|
|||||||
[:client [:name :id]]
|
[:client [:name :id]]
|
||||||
[:bank-account [:name :yodlee-account-id]]])
|
[:bank-account [:name :yodlee-account-id]]])
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::edit-completed
|
||||||
|
(fn [db [_ edit-transaction]]
|
||||||
|
|
||||||
|
(-> db
|
||||||
|
(update-in [::transaction-page :transactions]
|
||||||
|
(fn [ts]
|
||||||
|
(mapv (fn [t]
|
||||||
|
(if (= (:id t) (:id edit-transaction))
|
||||||
|
(assoc edit-transaction :class "live-added")
|
||||||
|
t))
|
||||||
|
ts))))))
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::transaction-page
|
::transaction-page
|
||||||
(fn [db]
|
(fn [db]
|
||||||
@@ -63,58 +75,13 @@
|
|||||||
(assoc ::transaction-page (first (:transaction-page data)))
|
(assoc ::transaction-page (first (:transaction-page data)))
|
||||||
(assoc-in [:status :loading] false))))
|
(assoc-in [:status :loading] false))))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
|
||||||
::transaction-editing
|
|
||||||
(fn [db [_ which]]
|
|
||||||
(println (:vendor which))
|
|
||||||
(-> db
|
|
||||||
(forms/start-form ::edit-transaction {:id (:id which)
|
|
||||||
:vendor-id (:id (:vendor which))
|
|
||||||
:vendor-name (:name (:vendor which))}))))
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::invalidated
|
::invalidated
|
||||||
(fn [cofx [_ params]]
|
(fn [cofx [_ params]]
|
||||||
{:dispatch [::params-change @(re-frame/subscribe [::params])]}))
|
{:dispatch [::params-change @(re-frame/subscribe [::params])]}))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
|
||||||
::can-submit-edit-transaction
|
|
||||||
:<- [::forms/form ::edit-transaction]
|
|
||||||
(fn [{:keys [data status]} _]
|
|
||||||
(not= :loading status)))
|
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
|
||||||
::transaction-edited
|
|
||||||
(fn [{:keys [db]} [_ {:keys [edit-transaction]}]]
|
|
||||||
{:db (-> db
|
|
||||||
(forms/stop-form ::edit-transaction)
|
|
||||||
(update-in [::transaction-page :transactions]
|
|
||||||
(fn [ts]
|
|
||||||
(mapv (fn [t]
|
|
||||||
(if (= (:id t) (:id edit-transaction))
|
|
||||||
(assoc edit-transaction :class "live-added")
|
|
||||||
t))
|
|
||||||
ts))))}))
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
|
||||||
::edit-transaction-saving
|
|
||||||
(fn [{:keys [db]} _]
|
|
||||||
(when @(re-frame/subscribe [::can-submit-edit-transaction])
|
|
||||||
(let [{{:keys [id vendor-id]} :data :as data} @(re-frame/subscribe [::forms/form ::edit-transaction])]
|
|
||||||
|
|
||||||
{:db (forms/loading db ::edit-transaction )
|
|
||||||
:graphql
|
|
||||||
{:token (-> db :user)
|
|
||||||
:query-obj {:venia/operation {:operation/type :mutation
|
|
||||||
:operation/name "EditTransaction"}
|
|
||||||
|
|
||||||
:venia/queries [{:query/data [:edit-transaction
|
|
||||||
{:transaction {:id id :vendor-id vendor-id}}
|
|
||||||
|
|
||||||
transaction-read]}]}
|
|
||||||
:on-success [::transaction-edited]
|
|
||||||
:on-error [::forms/save-error ::edit-transaction]}}))))
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::change-selected-bank-account
|
::change-selected-bank-account
|
||||||
@@ -209,7 +176,7 @@
|
|||||||
[:td status]
|
[:td status]
|
||||||
[:td (:name bank-account )]
|
[:td (:name bank-account )]
|
||||||
[:td
|
[:td
|
||||||
[:a.button {:on-click (dispatch-event [::transaction-editing i])} [:span [:span.icon [:i.fa.fa-pencil]]]]
|
[:a.button {:on-click (dispatch-event [::edit/transaction-editing i])} [:span [:span.icon [:i.fa.fa-pencil]]]]
|
||||||
(when check
|
(when check
|
||||||
[:a.tag {:href (:s3-url check) :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number check) " (" (gstring/format "$%.2f" amount ) ")")])]
|
[:a.tag {:href (:s3-url check) :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " (:check-number check) " (" (gstring/format "$%.2f" amount ) ")")])]
|
||||||
]))]]]))))
|
]))]]]))))
|
||||||
@@ -307,80 +274,8 @@
|
|||||||
[manual-yodlee-import-modal]]))
|
[manual-yodlee-import-modal]]))
|
||||||
{:component-will-mount #(re-frame/dispatch-sync [::params-change {}]) }))
|
{:component-will-mount #(re-frame/dispatch-sync [::params-change {}]) }))
|
||||||
|
|
||||||
|
|
||||||
(defn edit-transaction-form []
|
|
||||||
[forms/side-bar-form {:form ::edit-transaction }
|
|
||||||
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::edit-transaction])
|
|
||||||
data (assoc data :merchant-name "Hello") ;; TODO - just until merchant is added
|
|
||||||
current-client @(re-frame/subscribe [::subs/client])
|
|
||||||
change-event [::forms/change ::edit-transaction]]
|
|
||||||
^{:key id}
|
|
||||||
[:form { :on-submit (fn [e]
|
|
||||||
(when (.-stopPropagation e)
|
|
||||||
(.stopPropagation e)
|
|
||||||
(.preventDefault e))
|
|
||||||
(re-frame/dispatch-sync [::edit-transaction-saving]))}
|
|
||||||
[:h1.title.is-2 "Edit Transaction"]
|
|
||||||
|
|
||||||
[:div.notification
|
|
||||||
[:p "This transaction matches Invoice 'ABC' for 'DBI Beverages'. " [:a "Create payment and match"] "."]]
|
|
||||||
|
|
||||||
|
|
||||||
[:div.field
|
|
||||||
[:p.help "Merchant"]
|
|
||||||
[:div.control
|
|
||||||
[bind-field
|
|
||||||
[:input.input {:type "text"
|
|
||||||
:field [:merchant-name]
|
|
||||||
:disabled "disabled"
|
|
||||||
:subscription data}]]]]
|
|
||||||
|
|
||||||
|
|
||||||
[:div.field
|
|
||||||
[:p.help "Vendor"]
|
|
||||||
[:div.control
|
|
||||||
[bind-field
|
|
||||||
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/vendors]))
|
|
||||||
:type "typeahead"
|
|
||||||
:auto-focus true
|
|
||||||
:field [:vendor-id]
|
|
||||||
:text-field [:vendor-name]
|
|
||||||
:event change-event
|
|
||||||
:subscription data}]]]]
|
|
||||||
|
|
||||||
[:div.field
|
|
||||||
|
|
||||||
[:p.control
|
|
||||||
[:label.checkbox
|
|
||||||
[:input.checkbox {:type "checkbox"
|
|
||||||
:field [:always-map]
|
|
||||||
:subscription data}]
|
|
||||||
" Always match Merchant '" (:merchant-name data) "' to '" (:vendor-name data) "'" ]]]
|
|
||||||
|
|
||||||
[:div.field
|
|
||||||
[:p.help "Credit Account"]
|
|
||||||
[:div.control
|
|
||||||
[bind-field
|
|
||||||
[typeahead {:matches (map (fn [x] [(:id x) (str (:id x) " - " (:name x))]) @(re-frame/subscribe [::subs/chooseable-expense-accounts]))
|
|
||||||
:type "typeahead"
|
|
||||||
:field [:expense-account-id]
|
|
||||||
:event [::change id]
|
|
||||||
:subscription data}]]]]
|
|
||||||
|
|
||||||
(when error
|
|
||||||
^{:key error} [:div.notification.is-warning.animated.fadeInUp
|
|
||||||
error])
|
|
||||||
|
|
||||||
[:button.button.is-medium.is-primary.is-fullwidth {:disabled (if @(re-frame/subscribe [::can-submit-edit-transaction])
|
|
||||||
""
|
|
||||||
"disabled")
|
|
||||||
:class (str @(re-frame/subscribe [::forms/loading-class ::edit-transaction])
|
|
||||||
(when error " animated shake"))} "Save"]
|
|
||||||
])]
|
|
||||||
)
|
|
||||||
|
|
||||||
(defn transactions-page []
|
(defn transactions-page []
|
||||||
(let [{transaction-bar-active? :active?} @(re-frame/subscribe [::forms/form ::edit-transaction])]
|
(let [{transaction-bar-active? :active?} @(re-frame/subscribe [::forms/form ::edit/edit-transaction])]
|
||||||
[side-bar-layout {:side-bar [:div
|
[side-bar-layout {:side-bar [:div
|
||||||
[:p.menu-label "Bank Account"]
|
[:p.menu-label "Bank Account"]
|
||||||
|
|
||||||
@@ -389,5 +284,5 @@
|
|||||||
:value (:bank-acount-filter @(re-frame/subscribe [::transaction-page]))
|
:value (:bank-acount-filter @(re-frame/subscribe [::transaction-page]))
|
||||||
:bank-accounts @(re-frame/subscribe [::subs/bank-accounts])}]]]
|
:bank-accounts @(re-frame/subscribe [::subs/bank-accounts])}]]]
|
||||||
:main [transactions-content]
|
:main [transactions-content]
|
||||||
:right-side-bar [appearing-side-bar {:visible? transaction-bar-active?} [edit-transaction-form]]}]))
|
:right-side-bar [appearing-side-bar {:visible? transaction-bar-active?} [edit/edit-transaction-form {:edit-completed [::edit-completed]}]]}]))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user