From 8f65740c1464d89c61947c41e86c322cbedc5496 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 24 Jun 2024 02:53:20 +0200 Subject: [PATCH] fix(web): email not needed, show register feedback --- web/src/page/register.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/web/src/page/register.rs b/web/src/page/register.rs index fc9a2c38..854ce58d 100644 --- a/web/src/page/register.rs +++ b/web/src/page/register.rs @@ -8,6 +8,12 @@ macro_rules! get_ref { } } +macro_rules! reset_ref { + ($r:ident) => { + $r.get().map(|x| x.set_value("")) + } +} + // TODO this should get moved in a common crate so its not duplicated across FE/BE #[derive(Debug, Clone, serde::Serialize)] pub struct RegisterForm { @@ -34,6 +40,7 @@ pub fn RegisterPage() -> impl IntoView {
impl IntoView { password: password.unwrap_or_default(), display_name, summary, avatar_url, banner_url }; - if let Err(e) = Http::request(Method::PUT, &format!("{URL_BASE}/auth"), Some(&payload), auth).await { - set_error.set(Some( + match Http::request(Method::PUT, &format!("{URL_BASE}/auth"), Some(&payload), auth).await { + Err(e) => set_error.set(Some( view! {
{e.to_string()}
} - )); + )), + Ok(res) => match res.error_for_status() { + Err(e) => set_error.set(Some( + view! {
{e.to_string()}
} + )), + Ok(_) => { + reset_ref!(username_ref); + reset_ref!(password_ref); + reset_ref!(display_name_ref); + reset_ref!(summary_ref); + reset_ref!(avatar_url_ref); + reset_ref!(banner_url_ref); + }, + }, } }); } >
username
- +
password