From 320ff4f2ecedee825059e7f52db0dafeb488a8ab Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Mon, 3 Jul 2023 16:41:36 +0200 Subject: [PATCH] Fix admin toggle. --- .../AuthenticationDaemonAdminInterface.purs | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/App/AuthenticationDaemonAdminInterface.purs b/src/App/AuthenticationDaemonAdminInterface.purs index 3b1f664..b21bd95 100644 --- a/src/App/AuthenticationDaemonAdminInterface.purs +++ b/src/App/AuthenticationDaemonAdminInterface.purs @@ -63,9 +63,10 @@ data Action | HandleAddUserInput AddUserInput - | AddUserAttempt Event + | AddUserAttempt -- | Finalize | HandleWebSocket (WebSocketEvent WebSocketMessageType) + | PreventSubmit Event type StateAddUserForm = { login :: String, admin :: Boolean, email :: String, pass :: String } @@ -130,7 +131,7 @@ render { should_be_disabled = (maybe (HP.disabled true) (\_ -> HP.enabled true) wsInfo.connection) render_adduser_form = HH.form - [ HE.onSubmit AddUserAttempt ] + [ HE.onSubmit PreventSubmit ] [ Bulma.box_input "User login" "login" -- title, placeholder (HandleAddUserInput <<< ADDUSER_INP_login) -- action addUserForm.login -- value @@ -140,8 +141,7 @@ render { (show addUserForm.admin) -- value (HandleAddUserInput ADDUSER_toggle_admin) -- action1 (HandleAddUserInput ADDUSER_toggle_admin) -- action2 - true -- validity (TODO) - -- should_be_disabled -- condition + true -- validity , Bulma.box_input "User email" "email" -- title, placeholder (HandleAddUserInput <<< ADDUSER_INP_email) -- action addUserForm.email -- value @@ -152,14 +152,13 @@ render { addUserForm.pass -- value true -- validity (TODO) should_be_disabled -- condition - , HH.div_ - [ HH.button - [ HP.style "padding: 0.5rem 1.25rem;" - , HP.type_ HP.ButtonSubmit - , maybe (HP.disabled true) (\_ -> HP.enabled true) wsInfo.connection - ] - [ HH.text "Send Message to Server" ] + , HH.button + [ HP.style "padding: 0.5rem 1.25rem;" + , HP.type_ HP.ButtonSubmit + , HE.onClick \ _ -> AddUserAttempt + , maybe (HP.disabled true) (\_ -> HP.enabled true) wsInfo.connection ] + [ HH.text "Send Message to Server" ] ] render_messages = HH.ul_ $ map (\msg -> HH.li_ [ HH.text msg ]) messages @@ -215,9 +214,9 @@ handleAction = case _ of ADDUSER_toggle_admin -> H.modify_ _ { addUserForm { admin = not addUserForm.admin } } ADDUSER_INP_pass v -> H.modify_ _ { addUserForm { pass = v } } - AddUserAttempt ev -> do - H.liftEffect $ Event.preventDefault ev + PreventSubmit ev -> H.liftEffect $ Event.preventDefault ev + AddUserAttempt -> do { wsInfo, addUserForm } <- H.get let login = addUserForm.login email = addUserForm.email