just some refactoring for action-dialogue.
This commit is contained in:
@@ -4,11 +4,11 @@
|
||||
[reagent.core :as reagent]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events.admin.companies :as events]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.entities.companies :as entity]
|
||||
[auto-ap.views.components.address :refer [address-field]]
|
||||
[auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field dispatch-event]]
|
||||
[auto-ap.views.components.modal :refer [modal]]
|
||||
[auto-ap.views.components.modal :refer [modal action-modal]]
|
||||
[auto-ap.utils :refer [by replace-if]]
|
||||
[cljs.reader :as edn]
|
||||
[auto-ap.routes :as routes]
|
||||
@@ -49,6 +49,7 @@
|
||||
(re-frame/reg-event-db
|
||||
::edit
|
||||
(fn [db [_ d]]
|
||||
(re-frame/dispatch [::events/modal-status ::edit-user {:visible? true}])
|
||||
(if-let [user (get (by :id (::users db)) d)]
|
||||
(assoc-in db [::editing :user] user)
|
||||
(dissoc db ::editing))))
|
||||
@@ -84,6 +85,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::saved
|
||||
(fn [{:keys [db]} [_ {:keys [edit-user]}]]
|
||||
(re-frame/dispatch [::events/modal-completed ::edit-user])
|
||||
{:db (-> db
|
||||
(assoc-in [::editing :saving?] false )
|
||||
(dissoc ::editing)
|
||||
@@ -107,75 +109,71 @@
|
||||
[:td name]
|
||||
[:td role]
|
||||
[:td (str/join ", " (map :name companies))]])]]))
|
||||
|
||||
|
||||
|
||||
(def admin-users-page
|
||||
(with-meta
|
||||
(fn []
|
||||
[:div
|
||||
(let [companies (re-frame/subscribe [::users])
|
||||
editing @(re-frame/subscribe [::editing])]
|
||||
|
||||
[:div
|
||||
[:h1.title "Users"]
|
||||
[users-table]
|
||||
|
||||
(when editing
|
||||
[modal {:title (str "Edit " (:name (:user editing)))
|
||||
:foot [:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::save]))
|
||||
:class (when (:saving? editing)
|
||||
"is-loading"
|
||||
)}
|
||||
[:span "Save"]]
|
||||
:hide-event [::edit nil]}
|
||||
[horizontal-field
|
||||
[:label.label "Name"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field [:user :name]
|
||||
:spec ::entity/name
|
||||
:event ::change
|
||||
:subscription editing}]]]]
|
||||
[action-modal {:title (str "Edit " (:name (:user editing)))
|
||||
:id ::edit-user
|
||||
:action-text "Save"
|
||||
:save-event [::save]
|
||||
:editing editing}
|
||||
[horizontal-field
|
||||
[:label.label "Name"]
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field [:user :name]
|
||||
:spec ::entity/name
|
||||
:event ::change
|
||||
:subscription editing}]]]
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Role"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:select.select {:type "select"
|
||||
:field [:user :role]
|
||||
:spec ::entity/name
|
||||
:event ::change
|
||||
:subscription editing}
|
||||
[:option {:value "none"} "None"]
|
||||
[:option {:value "user"} "User"]
|
||||
[:option {:value "admin"} "Admin"]]]]]
|
||||
|
||||
|
||||
(when (= "user" (:role (:user editing)))
|
||||
[horizontal-field
|
||||
[:label.label "Companies"]
|
||||
[:div.control
|
||||
|
||||
[:div.field.has-addons
|
||||
[:p.control
|
||||
[:div.select
|
||||
[bind-field
|
||||
[:select {:type "select"
|
||||
:field [:adding-company]
|
||||
[horizontal-field
|
||||
[:label.label "Role"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:select.select {:type "select"
|
||||
:field [:user :role]
|
||||
:spec ::entity/name
|
||||
:event ::change
|
||||
:subscription editing}
|
||||
[:option]
|
||||
(let [used-companies (set (map :id (:companies (:user editing))))]
|
||||
(for [{:keys [id name]} @(re-frame/subscribe [::subs/companies])
|
||||
:when (not (used-companies id))]
|
||||
^{:key id} [:option {:value id} name]))]]]]
|
||||
[:p.control
|
||||
[:button.button.is-primary {:on-click (dispatch-event [::add-company])} "Add"]]]
|
||||
|
||||
[:ul
|
||||
(for [{:keys [id name]} (:companies (:user editing))]
|
||||
^{:key id} [:li name [:a.icon {:on-click (dispatch-event [::remove-company id])} [:i.fa.fa-times ]]])]]])
|
||||
[:option {:value "none"} "None"]
|
||||
[:option {:value "user"} "User"]
|
||||
[:option {:value "admin"} "Admin"]]]]]
|
||||
|
||||
|
||||
(when (= "user" (:role (:user editing)))
|
||||
[horizontal-field
|
||||
[:label.label "Companies"]
|
||||
[:div.control
|
||||
|
||||
[:div.field.has-addons
|
||||
[:p.control
|
||||
[:div.select
|
||||
[bind-field
|
||||
[:select {:type "select"
|
||||
:field [:adding-company]
|
||||
:event ::change
|
||||
:subscription editing}
|
||||
[:option]
|
||||
(let [used-companies (set (map :id (:companies (:user editing))))]
|
||||
(for [{:keys [id name]} @(re-frame/subscribe [::subs/companies])
|
||||
:when (not (used-companies id))]
|
||||
^{:key id} [:option {:value id} name]))]]]]
|
||||
[:p.control
|
||||
[:button.button.is-primary {:on-click (dispatch-event [::add-company])} "Add"]]]
|
||||
|
||||
(when (:saving? editing) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])])])])
|
||||
[:ul
|
||||
(for [{:keys [id name]} (:companies (:user editing))]
|
||||
^{:key id} [:li name [:a.icon {:on-click (dispatch-event [::remove-company id])} [:i.fa.fa-times ]]])]]])]])])
|
||||
{:component-will-mount #(re-frame/dispatch-sync [::users-mounted {}]) }))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user