diff --git a/src/uxbox/ui/auth.cljs b/src/uxbox/ui/auth.cljs index 4261a1ed7..87735881a 100644 --- a/src/uxbox/ui/auth.cljs +++ b/src/uxbox/ui/auth.cljs @@ -1,11 +1,13 @@ (ns uxbox.ui.auth (:require [sablono.core :as html :refer-macros [html]] [lentes.core :as l] + [cuerdas.core :as str] [rum.core :as rum] [uxbox.router :as r] [uxbox.state :as s] [uxbox.rstore :as rs] [uxbox.data.auth :as da] + [uxbox.util.dom :as dom] [uxbox.ui.icons :as i] [uxbox.ui.messages :as uum] [uxbox.ui.navigation :as nav] @@ -15,11 +17,30 @@ ;; Login ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defn- login-submit + [local] + (let [form (:form @local)] + (rs/emit! (da/login {:username (:email form) + :password (:password form)})))) + +(defn- login-submit-enabled? + [local] + (let [form (:form @local)] + (and (not (str/empty? (:email form ""))) + (not (str/empty? (:password form "")))))) + +(defn- login-field-change + [local field event] + (let [value (str/trim (dom/event->value event))] + (println @local value) + (swap! local assoc-in [:form field] value))) + (defn- login-render [own local] - (letfn [(on-submit [] - (rs/emit! (da/login {:username "cirilla" - :password "secret"})))] + (let [on-submit #(login-submit local) + submit-enabled? (login-submit-enabled? local) + form (:form @local)] + (println "submit-enabled?" submit-enabled?) (html [:div.login [:div.login-body @@ -28,10 +49,16 @@ [:div.login-content [:input.input-text {:name "email" + :ref "email" + :value (:email form "") + :on-change #(login-field-change local :email %) :placeholder "Email or Username" :type "text"}] [:input.input-text {:name "password" + :ref "password" + :value (:password form "") + :on-change #(login-field-change local :password %) :placeholder "Password" :type "password"}] #_[:div.input-checkbox.check-primary @@ -40,6 +67,8 @@ [:label {:for "checkbox1"} "Keep Me Signed in"]] [:input.btn-primary {:name "login" + :class (when-not submit-enabled? "btn-disabled") + :disabled (not submit-enabled?) :value "Continue" :type "submit" :on-click on-submit}]