implemented crud
This commit is contained in:
@@ -4,9 +4,14 @@
|
||||
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
|
||||
[auto-ap.views.components.layouts :refer [appearing-side-bar side-bar-layout]]
|
||||
[auto-ap.views.pages.admin.rules.table :as table]
|
||||
[auto-ap.views.pages.admin.rules.form :as form]
|
||||
[auto-ap.views.pages.admin.rules.common :refer [default-read]]
|
||||
[auto-ap.views.utils :refer [dispatch-event with-user]]
|
||||
[auto-ap.utils :refer [replace-by]]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
;; SUBS
|
||||
|
||||
(re-frame/reg-sub
|
||||
::notification
|
||||
(fn [db]
|
||||
@@ -22,13 +27,22 @@
|
||||
(fn [db]
|
||||
(-> db (::params {}))))
|
||||
|
||||
(def rule-read [:description-matches])
|
||||
(re-frame/reg-event-db
|
||||
::edit-completed
|
||||
(fn [db [_ edit-transaction-rule]]
|
||||
(println edit-transaction-rule)
|
||||
(-> db
|
||||
(update-in [::page :transaction-rules]
|
||||
replace-by :id (assoc edit-transaction-rule :class "live-added")))))
|
||||
|
||||
;; EVENTS
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received
|
||||
(fn [db [_ data]]
|
||||
(println data)
|
||||
(-> db
|
||||
(update ::page merge (first (:rule-page data)))
|
||||
(update ::page merge (:transaction-rule-page data))
|
||||
(assoc-in [:status :loading] false))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
@@ -39,14 +53,22 @@
|
||||
(assoc-in [:status :loading] true)
|
||||
(assoc-in [::params] params))
|
||||
:graphql {:token user
|
||||
:query-obj {:venia/queries [[:rule_page
|
||||
:query-obj {:venia/queries [[:transaction_rule_page
|
||||
(assoc params :client-id (:id @(re-frame/subscribe [::subs/client])))
|
||||
[[:rules rule-read]
|
||||
[[:transaction-rules default-read]
|
||||
:total
|
||||
:start
|
||||
:end]]]}
|
||||
:on-success [::received]}}))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::new-rule-clicked
|
||||
(fn [{:keys [db]} _]
|
||||
{:dispatch [::form/adding {:client @(re-frame/subscribe [::subs/client])}]}))
|
||||
|
||||
;; VIEWS
|
||||
|
||||
(def rules-content
|
||||
(with-meta
|
||||
(fn []
|
||||
@@ -57,17 +79,19 @@
|
||||
[:h1.title "Transaction Rules"]
|
||||
(when (= "admin" (:user/role user))
|
||||
[:div.is-pulled-right
|
||||
[:button.button.is-outlined.is-primary {:on-click (dispatch-event [::create-rule-clicked])} "New Rule"]])
|
||||
[:button.button.is-outlined.is-primary {:on-click (dispatch-event [::new-rule-clicked])} "New Rule"]])
|
||||
[table/table {:id :transactions
|
||||
:params (re-frame/subscribe [::params])
|
||||
:rule-page (re-frame/subscribe [::page])
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:on-params-change (fn [params]
|
||||
(re-frame/dispatch [::params-change params]))}]
|
||||
]))
|
||||
{:component-will-mount #(re-frame/dispatch-sync [::params-change {}]) }))
|
||||
|
||||
(defn admin-rules-page []
|
||||
(let [{:keys [active?]} @(re-frame/subscribe [::forms/form ::new-client])]
|
||||
(let [{:keys [active?]} @(re-frame/subscribe [::forms/form ::form/form])]
|
||||
[side-bar-layout {:side-bar [admin-side-bar {}]
|
||||
:main [rules-content]
|
||||
:right-side-bar [appearing-side-bar {:visible? active?} [:div]] }]))
|
||||
:right-side-bar [appearing-side-bar {:visible? active?}
|
||||
[form/form {:rule-saved [::edit-completed]}]] }]))
|
||||
|
||||
Reference in New Issue
Block a user