From b12b7bb34d775d3743b5d36dc98305ce45d81915 Mon Sep 17 00:00:00 2001 From: Franklin Date: Fri, 14 Apr 2023 18:22:34 -0400 Subject: [PATCH] Contact us page done --- Readme.md | 2 +- src/pages/contact.rs | 25 +++++++++++++++++-------- src/pages/mod.rs | 3 ++- src/pages/thanks.rs | 0 4 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 src/pages/thanks.rs diff --git a/Readme.md b/Readme.md index bc12489..42c0de0 100644 --- a/Readme.md +++ b/Readme.md @@ -32,4 +32,4 @@ New todo's - [ ] Admin panel with page loads & contact us clicks - [ ] Put JL on top of the Agents section - [ ] If someone enters the page from an agent, make anything that appears on the website reference them. -- [ ] Contact us Functionality \ No newline at end of file +- [x] Contact us Functionality \ No newline at end of file diff --git a/src/pages/contact.rs b/src/pages/contact.rs index 9016bfd..9ed0e77 100644 --- a/src/pages/contact.rs +++ b/src/pages/contact.rs @@ -1,17 +1,20 @@ use jl_types::dto::payloads::contact::ContactPayload; use yew::prelude::*; +use yew_router::prelude::use_navigator; -use crate::{components::{nav_bar::NavigationBar, footer::PageFooter}, utils::input::{get_value_from_input_event, get_value_from_textarea_event}, api::backend::create_new_contact_request}; +use crate::{components::{nav_bar::NavigationBar, footer::PageFooter}, utils::input::{get_value_from_input_event, get_value_from_textarea_event}, api::backend::create_new_contact_request, routes::main_router::Route}; #[function_component(ContactPage)] pub fn contact_page() -> Html { + let navigator = use_navigator().unwrap(); + let first_name = use_state(|| String::new()); let last_name = use_state(|| String::new()); let credential = use_state(|| String::new()); let messsage = use_state(|| String::new()); - + //TODO: Think about how this renders each time an input is typed onto. (Pretty sure it does, as use_state re-renders the whole component it's in when called) let on_fn_input_changed = { let first_name = first_name.clone(); @@ -49,12 +52,18 @@ pub fn contact_page() -> Html { credential: (*credential).clone(), message: (*messsage).clone() }; - wasm_bindgen_futures::spawn_local(async move { - match create_new_contact_request(contact).await { - Ok(_) => {}, - Err(error) => log::error!("Error in sending a contact request to the backend: {error}") - }; - }); + let navigator = navigator.clone(); + if contact.first_name.len() > 1 && contact.last_name.len() > 1 && contact.credential.len() > 3 && contact.message.len() > 5 { + wasm_bindgen_futures::spawn_local(async move { + match create_new_contact_request(contact).await { + Ok(_) => { + // TODO: Take to homepage? Say thanks? + navigator.push(&Route::LandingPage); + }, + Err(error) => log::error!("Error in sending a contact request to the backend: {error}") + }; + }); + } }) }; html! { diff --git a/src/pages/mod.rs b/src/pages/mod.rs index 7796b72..4cd1a6d 100644 --- a/src/pages/mod.rs +++ b/src/pages/mod.rs @@ -4,4 +4,5 @@ pub mod details; pub mod not_found; pub mod contact; pub mod admin; -pub mod agents; \ No newline at end of file +pub mod agents; +pub mod thanks; \ No newline at end of file diff --git a/src/pages/thanks.rs b/src/pages/thanks.rs new file mode 100644 index 0000000..e69de29