-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display and navigate b/w organisations in the sidebar #12
Changes from all commits
040d444
87a7bee
47fd7e4
e9bbd98
cb980bc
025d4df
5fc0a46
7970b4c
e04f237
9f45a2d
dd86386
d79f2b5
58de60b
63b7e8c
72a7fea
8827bbc
da0140e
84e8c77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
(ns villagebookUI.api.organisation | ||
[:require [ajax.core :refer [POST]]]) | ||
[:require [ajax.core :refer [GET POST]]]) | ||
|
||
(def ^:private create-org-api "/api/organisations") | ||
(def ^:private get-all-orgs-api "/api/organisations") | ||
|
||
(defn create-org [org-data handler-fn error-handler-fn] | ||
(defn create [org-data handler error-handler] | ||
(POST create-org-api | ||
{:params org-data | ||
:format :raw | ||
:handler handler-fn | ||
:error-handler error-handler-fn})) | ||
:handler handler | ||
:error-handler error-handler})) | ||
|
||
(defn get-all [handler error-handler] | ||
(GET get-all-orgs-api | ||
{:handler handler | ||
:response-format :json | ||
:error-handler error-handler})) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
(ns villagebookUI.api.user | ||
[:require [ajax.core :refer [GET]]]) | ||
(:require [ajax.core :refer [GET]] | ||
[villagebookUI.store.user :as store])) | ||
|
||
(def ^:private get-user-data-api "/api/user") | ||
|
||
(defn get-user-data | ||
[handler-fn error-handler-fn] | ||
(defn get-data [handler error-handler finally-fn] | ||
(GET get-user-data-api | ||
{:handler handler-fn | ||
:error-handler error-handler-fn})) | ||
{:handler handler | ||
:error-handler error-handler | ||
:finally finally-fn})) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
(ns villagebookUI.components.create-org | ||
(:require [reagent.core :as r] | ||
[villagebookUI.helpers :refer [random-color handle-esc]] | ||
[villagebookUI.fetchers :as fetchers] | ||
[villagebookUI.components.utils :as utils] | ||
[villagebookUI.api.organisation :as org])) | ||
[villagebookUI.api.organisation :as org-api])) | ||
|
||
(defn- create-org [form success-handler error-handler] | ||
(when (:name form) | ||
(org/create-org form | ||
(org-api/create form | ||
success-handler | ||
error-handler))) | ||
|
||
(defn submit-create-org! | ||
[org success-handler error-handler] | ||
(create-org org | ||
(fn [res] | ||
(success-handler) | ||
(fetchers/fetch-orgs! last)) | ||
error-handler)) | ||
|
||
(defn org-creation-form [on-close-handler] | ||
(let [color (random-color) | ||
form (r/atom {:name nil | ||
|
@@ -18,9 +27,9 @@ | |
(fn [] | ||
[:form.inline-block {:on-submit (fn [e] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extract this handler function out. Don't write more than a line of code inside the view, it isn't as tangible, and is not testable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
(.preventDefault e) | ||
(create-org @form | ||
on-close-handler | ||
#(reset! error true)))} | ||
(submit-create-org! @form | ||
on-close-handler | ||
#(reset! error true)))} | ||
[:div.inline-block | ||
[utils/color-picker-patch | ||
{:init-color color | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ | |
(:require [villagebookUI.components.sidebar :refer [sidebar]] | ||
[villagebookUI.components.main-content :refer [main-content]])) | ||
|
||
(defn dashboard [] | ||
(let [] | ||
(fn [] | ||
[:div | ||
[sidebar] | ||
[main-content]]))) | ||
(defn dashboard [on-mount-cb] | ||
(on-mount-cb) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When in the component lifecycle is this called? Not sure that this gives you good enough control. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is called once per component (when it's rendered the first time). Reagent provides this construct for setup or initialising local state. Works just like componentDidMount. Relevant doc |
||
(fn [] | ||
[:div | ||
[sidebar] | ||
[main-content]])) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,48 @@ | ||
(ns villagebookUI.components.login | ||
(:require [reagent.core :as r] | ||
[accountant.core :as accountant] | ||
[villagebookUI.helpers :as helpers :refer [validate-input]] | ||
[villagebookUI.components.utils :refer [reqd-input]] | ||
[villagebookUI.fetchers :as fetchers] | ||
[villagebookUI.api.auth :as auth-api])) | ||
|
||
[villagebookUI.api.auth :as auth] | ||
[villagebookUI.store :as store])) | ||
(defn redirect-dashboard [] | ||
(fetchers/fetch-user!) | ||
(accountant/navigate! "/dashboard")) | ||
|
||
(defn validate! | ||
[elementID formdata] | ||
(if (.checkValidity (.getElementById js/document elementID)) | ||
(swap! formdata assoc-in [:validation-classes elementID] "") | ||
(swap! formdata assoc-in [:validation-classes elementID] "check-invalid"))) | ||
|
||
(defn input [formdata k placeholder type & required] | ||
[:input.form-control.mt-3.mt-3 {:placeholder placeholder | ||
:name k | ||
:id k | ||
:on-change #(swap! formdata assoc-in [:user k] (-> % .-target .-value)) | ||
:on-blur #(validate! (name k) formdata) | ||
:type type | ||
:required required | ||
:class (str | ||
(get-in @formdata [:validation-classes (name k)]) " " | ||
(get-in @formdata [:validation-classes "login-form"]))}]) | ||
(defn submit-login | ||
[user show-validness show-error] | ||
(helpers/submit-auth-form :login-form auth-api/login user redirect-dashboard show-validness show-error)) | ||
|
||
(defn login [] | ||
(let [formdata (r/atom {}) | ||
error (r/atom {})] | ||
(let [user (r/atom {}) | ||
validness (r/atom {}) | ||
error (r/atom {}) | ||
fields [{:id :email :type :email :placeholder "Email"} | ||
{:id :password :type :password :placeholder "Password"}]] | ||
(fn [] | ||
(if @store/user | ||
(do | ||
(accountant/navigate! "/dashboard") | ||
[:div]) | ||
[:div.l-page-center.formbox | ||
[:a.brand {:href "/"} "villagebook"] | ||
[:form#login-form.mt-5.form-group | ||
[input formdata :email "Email" "email" :required] | ||
[input formdata :password "Password" "password" :required] | ||
[:div.auth-error (:message @error)] | ||
[:button.btn.btn-outline-primary.login-btn.mt-2 | ||
{:type "submit" | ||
:on-click #(do | ||
(.preventDefault %) | ||
(validate! "login-form" formdata) | ||
(auth/login | ||
(:user @formdata) | ||
(fn [res] | ||
(swap! error assoc :message "") | ||
(accountant/navigate! "/dashboard")) | ||
(fn [res] | ||
(swap! error assoc :message (:response res)))))} | ||
"Login"]] | ||
[:span.small "Don't have an account? "] | ||
[:a {:href "/signup"} "Signup"]])))) | ||
[:div.l-page-center.formbox | ||
[:a.brand {:href "/"} "villagebook"] | ||
[:form#login-form.mt-5.form-group | ||
(doall | ||
(for [field fields | ||
:let [id (:id field)]] | ||
[reqd-input {:id id | ||
:key id | ||
:type (:type field) | ||
:placeholder (:placeholder field) | ||
:class [:form-control :mt-3 (get @validness id)(:form @validness)] | ||
:on-change #(swap! user assoc id %) | ||
:on-blur #(validate-input id | ||
(fn [v] (swap! validness assoc id v)))}])) | ||
[:div.auth-error (:message @error)] | ||
[:button.btn.btn-outline-primary.login-btn.mt-2 | ||
{:type "submit" | ||
:on-click (fn [e] | ||
(.preventDefault e) | ||
(submit-login @user | ||
#(swap! validness assoc :form %) | ||
#(swap! error assoc :message %)))} | ||
"Login"]] | ||
[:span.small "Don't have an account? "] | ||
[:a {:href "/signup"} "Signup"]]))) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
(ns villagebookUI.components.main-content) | ||
(ns villagebookUI.components.main-content | ||
(:require [villagebookUI.store.organisations :as org-store])) | ||
|
||
(defn main-content [] | ||
[:div.main-content | ||
[:div.navbar]]) | ||
[:div.navbar | ||
[:h5 (:name (org-store/get-selected))]]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capitals in the ns name seems odd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes🤷♂ but decided to stick with it, changing would be too much effort.