logging in, and updating users, works.
This commit is contained in:
@@ -2,13 +2,14 @@
|
||||
(:require-macros [cljs.core.async.macros :refer [go]])
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events.admin.companies :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.utils :refer [by]]
|
||||
[auto-ap.utils :refer [by replace-if]]
|
||||
[cljs.reader :as edn]
|
||||
[auto-ap.routes :as routes]
|
||||
[bidi.bidi :as bidi]))
|
||||
@@ -62,9 +63,35 @@
|
||||
(re-frame/reg-event-db
|
||||
::remove-company
|
||||
(fn [db [_ d]]
|
||||
(println "remove compnay " d)
|
||||
(update-in db [::editing :user :companies] #(filter (fn [c] (not= (:id c) d)) %))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save
|
||||
(fn [{:keys [db]} [_]]
|
||||
{:db (-> db
|
||||
(assoc-in [::editing :saving?] true ))
|
||||
:graphql
|
||||
{:token (-> db :user)
|
||||
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "EditUser"}
|
||||
|
||||
:venia/queries [{:query/data [:edit-user
|
||||
{:edit-user (update (get-in db [::editing :user]) :companies #(map :id %))}
|
||||
[:id :name :role [:companies [:id :name]]]]}]}
|
||||
:on-success [::saved]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::saved
|
||||
(fn [{:keys [db]} [_ {:keys [edit-user]}]]
|
||||
{:db (-> db
|
||||
(assoc-in [::editing :saving?] false )
|
||||
(dissoc ::editing)
|
||||
(update ::users
|
||||
(fn [us]
|
||||
(replace-if #(= (:id %1) (:id %2)) edit-user us)
|
||||
)))}))
|
||||
|
||||
(defn users-table []
|
||||
(let [users (re-frame/subscribe [::users])]
|
||||
[:table {:class "table", :style {:width "100%"}}
|
||||
@@ -79,14 +106,13 @@
|
||||
:style {"cursor" "pointer"}}
|
||||
[:td name]
|
||||
[:td role]
|
||||
[:td]])]]))
|
||||
[: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])]
|
||||
(println editing)
|
||||
|
||||
[:div
|
||||
[:h1.title "Users"]
|
||||
@@ -94,11 +120,11 @@
|
||||
|
||||
(when editing
|
||||
[modal {:title (str "Edit " (:name (:user editing)))
|
||||
:foot [:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/save]))}
|
||||
[:span "Save"]
|
||||
(when (:saving? editing)
|
||||
[:span.icon
|
||||
[:i.fa.fa-spin.fa-spinner]])]
|
||||
: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"]
|
||||
|
||||
@@ -4,14 +4,26 @@
|
||||
[reagent.core :as reagent]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.views.utils :refer [login-url]]
|
||||
[auto-ap.views.utils :refer [login-url dispatch-event]]
|
||||
[cljs.reader :as edn]
|
||||
[auto-ap.routes :as routes]
|
||||
[bidi.bidi :as bidi]
|
||||
[goog.string :as gstring]))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::relogin
|
||||
(fn [{:keys [db]} _]
|
||||
{
|
||||
:db (assoc db :user nil)}
|
||||
))
|
||||
|
||||
|
||||
(defn needs-activation-page []
|
||||
[:div
|
||||
[:h2 "Sorry, your user is not activated yet. Please have Ben Skinner enable your account."]])
|
||||
[:h2 "Sorry, your user is not activated yet. Please have Ben Skinner enable your account. Click "
|
||||
[:a {:on-click (fn []
|
||||
(re-frame/dispatch-sync [::relogin])
|
||||
true)
|
||||
:href login-url}
|
||||
"here"]
|
||||
" to try again."]])
|
||||
|
||||
Reference in New Issue
Block a user