From 661127b7e94b70152c2783a19df43c7d3e7c9d58 Mon Sep 17 00:00:00 2001 From: Franklin Date: Tue, 25 Apr 2023 08:53:47 -0400 Subject: [PATCH] Added get unit with id & get agent with id to backend routes --- src/api/backend/mod.rs | 26 ++++++++++++++++++++++++++ src/pages/admin/edit.rs | 27 ++++++++++++++++++++++----- src/pages/admin/fields/agent.rs | 7 ++++++- src/pages/admin/fields/unit.rs | 7 ++++++- 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/api/backend/mod.rs b/src/api/backend/mod.rs index aef413f..d8c5bf6 100644 --- a/src/api/backend/mod.rs +++ b/src/api/backend/mod.rs @@ -107,6 +107,32 @@ pub async fn get_agent_with_shortcode(shortcode: &String) -> Result Result { + perform_request_without_client::( + BASE_URL.into(), + Method::GET, + format!("read/agent/{id}"), + None, + 200, + Vec::new(), + None, + ) + .await +} + +pub async fn get_unit_with_id(id: &Uuid) -> Result { + perform_request_without_client::( + BASE_URL.into(), + Method::GET, + format!("read/unit/{id}"), + None, + 200, + Vec::new(), + None, + ) + .await +} + pub async fn get_all_page_visits_count() -> Result { perform_request_without_client::( BASE_URL.into(), diff --git a/src/pages/admin/edit.rs b/src/pages/admin/edit.rs index 210430a..31ef606 100644 --- a/src/pages/admin/edit.rs +++ b/src/pages/admin/edit.rs @@ -6,7 +6,7 @@ use yew_router::prelude::use_navigator; use crate::{ api::backend::{ - get_project_listing, + get_project_listing, get_agent_with_id, }, components::{ admin_nav_bar::AdminNavigationBar, @@ -19,10 +19,27 @@ use crate::{ pub fn edit_page(props: &AdminEditPageProps) -> Html { let _navigator = use_navigator().unwrap(); let listing = use_state(|| None); + let agent = use_state(|| None); + let unit = use_state(|| None); use_state(|| { let listing = listing.clone(); match props.edit_item { - EditItem::Agent => {} + EditItem::Agent => { + match props.edit_type { + EditType::New => {} + EditType::Existing(uid) => { + wasm_bindgen_futures::spawn_local(async move { + let agent_result = get_agent_with_id(&uid).await; + match agent_result { + Ok(agent_persisted) => { + agent.set(Some(agent_persisted)); + } + Err(error) => log::error!("Error loading agent: {error}"), + }; + }); + } + }; + } EditItem::Project => { match props.edit_type { EditType::New => {} @@ -61,9 +78,9 @@ pub fn edit_page(props: &AdminEditPageProps) -> Html {
{ match props.edit_item { - EditItem::Agent => {html! { }}, - EditItem::Project => {html! { }}, - EditItem::Unit(_) => {html! { }}, + EditItem::Agent => { html! { } }, + EditItem::Project => { html! { } }, + EditItem::Unit(project_id) => { html! { } }, } }
diff --git a/src/pages/admin/fields/agent.rs b/src/pages/admin/fields/agent.rs index e7ac238..1cb8dd0 100644 --- a/src/pages/admin/fields/agent.rs +++ b/src/pages/admin/fields/agent.rs @@ -1,5 +1,7 @@ use jl_types::domain::agent::Agent; +use uuid::Uuid; use yew::prelude::*; +use yew_router::prelude::use_navigator; use crate::pages::admin::edit::EditType; @@ -10,7 +12,10 @@ pub struct AgentFieldsProps { } #[function_component(AgentFields)] -pub fn agent_fields() -> Html { +pub fn agent_fields(props: &AgentFieldsProps) -> Html { + let navigator = use_navigator().unwrap(); + let user_typed = use_state(|| false); + html! { } diff --git a/src/pages/admin/fields/unit.rs b/src/pages/admin/fields/unit.rs index b743036..e93e482 100644 --- a/src/pages/admin/fields/unit.rs +++ b/src/pages/admin/fields/unit.rs @@ -1,5 +1,6 @@ use jl_types::domain::unit::Unit; use yew::prelude::*; +use yew_router::prelude::use_navigator; use crate::pages::admin::edit::EditType; @@ -7,10 +8,14 @@ use crate::pages::admin::edit::EditType; pub struct UnitFieldsProps { pub unit: Option, pub edittype: EditType, + pub projectid: Option, } #[function_component(UnitFields)] -pub fn unit_fields() -> Html { +pub fn unit_fields(props: &UnitFieldsProps) -> Html { + let navigator = use_navigator().unwrap(); + let user_typed = use_state(|| false); + html! { }