diff --git a/src/web/ui/src/Login/Login.fs b/src/web/ui/src/Login/Login.fs index 2e87f538f..998f3a5ed 100644 --- a/src/web/ui/src/Login/Login.fs +++ b/src/web/ui/src/Login/Login.fs @@ -3,6 +3,7 @@ module Login open Fable.Core.JsInterop open Fable.Helpers.React open Fable.Helpers.React.Props +open Elmish // // Types @@ -12,27 +13,31 @@ type Message = | Password of string | Submit | Help - | LoginFailure of string + | LoginSuccess // // Model type Model = { user : string password : string + error : string } let init() = - { user = ""; password = "" }, [] + { user = ""; password = ""; error = "" }, [] let update msg model = match msg with - | Username u -> { model with user = u }, [] - | Password p -> { model with password = p }, [] + | Username u -> { model with user = u; error = "" }, Cmd.Empty + | Password p -> { model with password = p; error = "" }, Cmd.Empty | Help -> printfn "No help for you" - model, [] + model, Cmd.Empty | Submit -> printfn "Login with %s %s" model.user model.password - model, [] + if (model.user = "bts") then + model, Elmish.Cmd.ofMsg LoginSuccess + else + { model with error = "Please use username 'bts'" }, Cmd.Empty // // View @@ -65,6 +70,7 @@ let root model dispatch = Type "password" OnChange (handler Password) Placeholder "Password" ] ] ] + div [] [str model.error] button [OnClick (fun _ -> dispatch Submit) Class "button is-block is-info is-large is-fullwidth" ] [ str "Login" ] ] ] diff --git a/src/web/ui/src/State.fs b/src/web/ui/src/State.fs index 7db61c432..5924d5010 100644 --- a/src/web/ui/src/State.fs +++ b/src/web/ui/src/State.fs @@ -29,6 +29,9 @@ let update msg model = | HomeMsg msg, HomeModel m -> let (home, homeCmd) = Home.State.update msg m { model with pageModel = HomeModel home }, Cmd.map HomeMsg homeCmd + | LoginMsg Login.LoginSuccess, _ -> + let (home, homeCmd) = Home.State.init() + { model with pageModel = HomeModel home }, Cmd.map HomeMsg homeCmd | LoginMsg msg, LoginModel l -> let (lmodel, lcmd) = Login.update msg l { model with pageModel = LoginModel lmodel }, Cmd.map LoginMsg lcmd