From d202efa883e4eb0975c7a7cec1d228783c4290cb Mon Sep 17 00:00:00 2001 From: Michael Liendo Date: Thu, 1 Aug 2024 22:22:53 -0400 Subject: [PATCH] feat(web): login modal (#213) --- crates/web/src/components/auth/login.rs | 76 ++++++++++++++++++++++ crates/web/src/components/auth/mod.rs | 1 + crates/web/src/components/layout/header.rs | 26 ++++++-- crates/web/src/views/login.rs | 64 ------------------ crates/web/src/views/mod.rs | 1 - 5 files changed, 97 insertions(+), 71 deletions(-) create mode 100644 crates/web/src/components/auth/login.rs delete mode 100644 crates/web/src/views/login.rs diff --git a/crates/web/src/components/auth/login.rs b/crates/web/src/components/auth/login.rs new file mode 100644 index 0000000..4a08a97 --- /dev/null +++ b/crates/web/src/components/auth/login.rs @@ -0,0 +1,76 @@ +use leptos::{ + component, create_action, create_rw_signal, create_signal, view, IntoView, RwSignal, Show, + SignalGet, SignalGetUntracked, SignalSet, +}; + +use townhall_client::Client; + +use crate::components::text_field::{TextField, TextFieldType}; + +#[component] +pub fn LoginCard( + #[prop(into)] signup_status: RwSignal, + #[prop(into)] login_status: RwSignal, +) -> impl IntoView { + let (error_getter, error_setter) = create_signal::>(None); + + let email_value = create_rw_signal(String::default()); + let password_value = create_rw_signal(String::default()); + + let handle_submit = create_action(move |_| async move { + let client = Client::new(); + let res = client + .auth + .token_create(email_value.get_untracked(), password_value.get_untracked()) + .await; + + if let Some(ref error) = res.error { + error_setter.set(Some(error.message.to_owned())); + } + }); + + let handle_switch = move |_| { + login_status.set(false); + signup_status.set(true); + }; + + view! { + +
+

Log in

+
+ + + + +
+ {error_getter.get().unwrap()} +
+
+ +
+ {"Don't have an account? "} +
+
+ } +} diff --git a/crates/web/src/components/auth/mod.rs b/crates/web/src/components/auth/mod.rs index f862bee..8d32f68 100644 --- a/crates/web/src/components/auth/mod.rs +++ b/crates/web/src/components/auth/mod.rs @@ -1 +1,2 @@ +pub mod login; pub mod register; diff --git a/crates/web/src/components/layout/header.rs b/crates/web/src/components/layout/header.rs index 6132b19..fe788aa 100644 --- a/crates/web/src/components/layout/header.rs +++ b/crates/web/src/components/layout/header.rs @@ -1,10 +1,16 @@ -use leptos::{component, create_rw_signal, view, IntoView, SignalSet}; +use leptos::{component, create_rw_signal, view, IntoView, Show, SignalGet, SignalSet}; -use crate::components::{auth::register::SignupCard, icons::home::Home, modal::Modal}; +use crate::components::{ + auth::{login::LoginCard, register::SignupCard}, + icons::home::Home, + modal::Modal, +}; #[component] pub fn Header() -> impl IntoView { - let is_open_auth_modal = create_rw_signal(false); + let is_open_auth_signup_modal = create_rw_signal(false); + let is_open_auth_login_modal = create_rw_signal(false); + view! {
@@ -16,14 +22,22 @@ pub fn Header() -> impl IntoView {
- + + - + + + + + + + + } } diff --git a/crates/web/src/views/login.rs b/crates/web/src/views/login.rs deleted file mode 100644 index 2a137f6..0000000 --- a/crates/web/src/views/login.rs +++ /dev/null @@ -1,64 +0,0 @@ -use leptos::{ - component, create_action, create_rw_signal, create_signal, view, IntoView, Show, SignalGet, - SignalGetUntracked, SignalSet, -}; - -use townhall_client::Client; - -use crate::components::text_field::{TextField, TextFieldType}; - -#[component] -pub fn Login() -> impl IntoView { - let (error_getter, error_setter) = create_signal::>(None); - let email_value = create_rw_signal(String::default()); - let password_value = create_rw_signal(String::default()); - - let handle_submit = create_action(move |_| async move { - let client = Client::new(); - let res = client - .auth - .token_create(email_value.get_untracked(), password_value.get_untracked()) - .await; - - if let Some(ref error) = res.error { - error_setter.set(Some(error.message.to_owned())); - } - }); - - view! { -
-
-
-
-

TownHall

-
- - - - -
- {error_getter.get().unwrap()} -
-
- -
- {"Don't have an account? "} - Sign up! - -
-
-
-
- } -} diff --git a/crates/web/src/views/mod.rs b/crates/web/src/views/mod.rs index f567f27..9b86bcf 100644 --- a/crates/web/src/views/mod.rs +++ b/crates/web/src/views/mod.rs @@ -1,2 +1 @@ pub mod home; -pub mod login;