Contact us page done

This commit is contained in:
Franklin 2023-04-14 18:22:34 -04:00
parent 89fe0495cb
commit b12b7bb34d
4 changed files with 20 additions and 10 deletions

View File

@ -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
- [x] Contact us Functionality

View File

@ -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! {

View File

@ -4,4 +4,5 @@ pub mod details;
pub mod not_found;
pub mod contact;
pub mod admin;
pub mod agents;
pub mod agents;
pub mod thanks;

0
src/pages/thanks.rs Normal file
View File