Commit 9e3eeab9 authored by Alexandre Delanoë's avatar Alexandre Delanoë

Merge remote-tracking branch 'origin/431-dev-lost-password-email' into dev-merge

parents 8dcbc1c4 6c842cd0
...@@ -33,46 +33,58 @@ forgotPasswordCpt = here.component "forgotPassword" cpt where ...@@ -33,46 +33,58 @@ forgotPasswordCpt = here.component "forgotPassword" cpt where
cpt { backend, sessions } _ = do cpt { backend, sessions } _ = do
email <- T.useBox "" email <- T.useBox ""
message <- T.useBox "" message <- T.useBox ""
disabled <- T.useBox false
pure $ H.div { className: "row" } pure $ H.div { className: "row" }
[ H.form { className: "text-center col-md-12" } [ H.form { className: "text-center col-md-12" }
[ H.h4 {} [ H.text "Forgot password" ] [ H.h4 {} [ H.text "Forgot password" ]
, messageDisplay { message } , messageDisplay { message }
, formGroup , formGroup
[ emailInput email ] [ emailInput { email, disabled} ]
, submitButton { backend, email, sessions, message } , submitButton { backend, email, sessions, message, disabled }
] ]
] ]
emailInput :: forall cell. T.ReadWrite cell Email => cell -> R.Element emailInput :: R2.Leaf (email :: T.Box Email, disabled :: T.Box Boolean)
emailInput value = F.bindInput { value emailInput = R2.leaf emailInputCpt
, type: "email"
, className: "form-control" emailInputCpt :: R.Component (email :: T.Box Email, disabled :: T.Box Boolean)
, id: "id_email" emailInputCpt = here.component "emailInput" cpt where
, placeholder: "email" cpt { email, disabled } _ = do
, name: "email" disabled' <- T.useLive T.unequal disabled
, maxLength: "254" } pure $ F.bindInput { value: email
, type: "email"
, className: "form-control"
, id: "id_email"
, placeholder: "email"
, name: "email"
, maxLength: "254"
, disabled: disabled' }
type SubmitButtonProps = type SubmitButtonProps =
( email :: T.Box Email ( email :: T.Box Email
, message :: T.Box String , message :: T.Box String
, disabled :: T.Box Boolean
| Props ) | Props )
submitButton :: R2.Leaf SubmitButtonProps submitButton :: R2.Leaf SubmitButtonProps
submitButton = R2.leafComponent submitButtonCpt submitButton = R2.leafComponent submitButtonCpt
submitButtonCpt :: R.Component SubmitButtonProps submitButtonCpt :: R.Component SubmitButtonProps
submitButtonCpt = here.component "submitButton" cpt where submitButtonCpt = here.component "submitButton" cpt where
cpt { backend, email, sessions, message} _ = do cpt { backend, email, sessions, message, disabled} _ = do
email' <- T.useLive T.unequal email email' <- T.useLive T.unequal email
disabled' <- T.useLive T.unequal disabled
pure $ H.div {className: "form-group text-center"} pure $ H.div {className: "form-group text-center"}
[ H.button { className: "btn btn-primary" [ H.button { className: "btn btn-primary"
, disabled: disabled'
, on: { click: click email' }} , on: { click: click email' }}
[ H.text "Submit" ] [ H.text "Submit" ]
] ]
where where
click :: Email -> R.SyntheticEvent DE.MouseEvent -> Effect Unit click :: Email -> R.SyntheticEvent DE.MouseEvent -> Effect Unit
click email' e = do click email' e = do
liftEffect $ T.write_ true disabled
E.preventDefault e E.preventDefault e
here.log2 "email" email' here.log2 "email" email'
here.log2 "backend" backend here.log2 "backend" backend
...@@ -81,7 +93,9 @@ submitButtonCpt = here.component "submitButton" cpt where ...@@ -81,7 +93,9 @@ submitButtonCpt = here.component "submitButton" cpt where
res <- postForgotPasswordRequest backend email' res <- postForgotPasswordRequest backend email'
liftEffect $ here.log2 "res" res liftEffect $ here.log2 "res" res
liftEffect $ case res of liftEffect $ case res of
Left s -> T.write_ s message Left s -> do
T.write_ false disabled
T.write_ s message
Right _ -> T.write_ "Request sent!" message Right _ -> T.write_ "Request sent!" message
messageDisplay :: R2.Leaf (message :: T.Box String) messageDisplay :: R2.Leaf (message :: T.Box String)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment