added ability to remove a transaction rule.

This commit is contained in:
Bryce Covert
2020-08-03 16:54:12 -07:00
parent a22eb01008
commit d989279058
10 changed files with 185 additions and 51 deletions

View File

@@ -10,17 +10,15 @@
[auto-ap.views.pages.admin.rules.common :refer [default-read]]
[auto-ap.views.utils :refer [dispatch-event with-user]]
[vimsical.re-frame.cofx.inject :as inject]
[vimsical.re-frame.fx.track :as track]
[day8.re-frame.forward-events-fx]
[auto-ap.events :as events]
[auto-ap.utils :refer [replace-by]]
[auto-ap.utils :refer [replace-by merge-by]]
[re-frame.core :as re-frame]
[auto-ap.status :as status]))
;; SUBS
(re-frame/reg-sub
::notification
(fn [db]
(-> db ::notification)))
(re-frame/reg-sub
::page
@@ -57,34 +55,22 @@
(update :transaction-rules (fn [rules]
(mapv ungraphql-transaction-rule rules))))))))
(re-frame/reg-sub
::last-params
(fn [db]
(-> db ::last-params)))
(re-frame/reg-sub
::params
:<- [::last-params]
:<- [::subs/client]
:<- [::side-bar/filter-params]
:<- [::table/table-params]
(fn [[last-params client filter-params table-params]]
(let [params (cond-> {}
client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params)
(seq table-params) (merge table-params))]
(when (not= params last-params)
(re-frame/dispatch [::params-change]))
params)))
(fn [[client filter-params table-params]]
(cond-> {}
client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params)
(seq table-params) (merge table-params))))
(re-frame/reg-event-fx
::params-change
[with-user (re-frame/inject-cofx ::inject/sub [::params])]
(fn [{:keys [db user] ::keys [params] :as cofx} _]
{:db (-> db
(assoc-in [::last-params] params))
:graphql {:token user
[with-user ]
(fn [{:keys [db user] :as cofx} [_ params]]
{:graphql {:token user
:owns-state {:single ::page}
:query-obj {:venia/queries [[:transaction_rule_page
(or params {})
@@ -102,13 +88,34 @@
(fn [{:keys [db]} _]
{:dispatch [::form/adding {:client @(re-frame/subscribe [::subs/client])}]}))
;; VIEWS
(re-frame/reg-event-db
::deleted-transaction-rule
[(re-frame/path [::page :transaction-rules])]
(fn [transaction-rules [_ [_ {id :delete-transaction-rule}]]]
(merge-by transaction-rules :id {:id id :class "live-removed"})))
(re-frame/reg-event-fx
::mounted
(fn [{:keys [db]}]
{:dispatch-n [[::events/yodlee-merchants-needed]]
:forward-events {:register ::page
:events #{::table/deleted-transaction-rule}
:dispatch-to [::deleted-transaction-rule]}
::track/register {:id ::params
:subscription [::params]
:event-fn (fn [params] [::params-change params])}}))
(re-frame/reg-event-fx
::unmounted
(fn [{:keys [db]}]
{:forward-events {:unregister ::page}
::track/dispose {:id ::params}}))
;; VIEWS
(def rules-content
(with-meta
(fn []
(let [notification (re-frame/subscribe [::notification])
current-client @(re-frame/subscribe [::subs/client])
(let [current-client @(re-frame/subscribe [::subs/client])
user @(re-frame/subscribe [::subs/user])]
[:div
[:h1.title "Transaction Rules"]
@@ -123,16 +130,14 @@
(println "CHANGING PARAMS TO" params)
(re-frame/dispatch [::params-change params]))}]
]))
{:component-will-mount #(do (re-frame/dispatch-sync [::params-change {}])
(re-frame/dispatch [::events/yodlee-merchants-needed])) }))
{:component-did-mount (dispatch-event [::mounted ])
:component-will-unmount #(re-frame/dispatch-sync [::unmounted])}))
(defn admin-rules-page []
(let [{:keys [active?]} @(re-frame/subscribe [::forms/form ::form/form])
params @(re-frame/subscribe [::params])]
(let [{:keys [active?]} @(re-frame/subscribe [::forms/form ::form/form])]
[side-bar-layout {:side-bar [admin-side-bar {}
[:<>
[side-bar/rule-side-bar]
]]
[side-bar/rule-side-bar]]]
:main [rules-content]
:right-side-bar [appearing-side-bar {:visible? active?}
[form/form {:rule-saved [::edit-completed]}]]