Added get unit with id & get agent with id to backend routes

This commit is contained in:
Franklin 2023-04-25 08:53:47 -04:00
parent 825a54c96d
commit 661127b7e9
4 changed files with 60 additions and 7 deletions

View File

@ -107,6 +107,32 @@ pub async fn get_agent_with_shortcode(shortcode: &String) -> Result<Agent, err::
.await .await
} }
pub async fn get_agent_with_id(id: &Uuid) -> Result<Agent, err::Error> {
perform_request_without_client::<String, Agent>(
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<Unit, err::Error> {
perform_request_without_client::<String, Unit>(
BASE_URL.into(),
Method::GET,
format!("read/unit/{id}"),
None,
200,
Vec::new(),
None,
)
.await
}
pub async fn get_all_page_visits_count() -> Result<Count, err::Error> { pub async fn get_all_page_visits_count() -> Result<Count, err::Error> {
perform_request_without_client::<String, Count>( perform_request_without_client::<String, Count>(
BASE_URL.into(), BASE_URL.into(),

View File

@ -6,7 +6,7 @@ use yew_router::prelude::use_navigator;
use crate::{ use crate::{
api::backend::{ api::backend::{
get_project_listing, get_project_listing, get_agent_with_id,
}, },
components::{ components::{
admin_nav_bar::AdminNavigationBar, admin_nav_bar::AdminNavigationBar,
@ -19,10 +19,27 @@ use crate::{
pub fn edit_page(props: &AdminEditPageProps) -> Html { pub fn edit_page(props: &AdminEditPageProps) -> Html {
let _navigator = use_navigator().unwrap(); let _navigator = use_navigator().unwrap();
let listing = use_state(|| None); let listing = use_state(|| None);
let agent = use_state(|| None);
let unit = use_state(|| None);
use_state(|| { use_state(|| {
let listing = listing.clone(); let listing = listing.clone();
match props.edit_item { 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 => { EditItem::Project => {
match props.edit_type { match props.edit_type {
EditType::New => {} EditType::New => {}
@ -61,9 +78,9 @@ pub fn edit_page(props: &AdminEditPageProps) -> Html {
<div class={"admin-project-fields-container"}> <div class={"admin-project-fields-container"}>
{ {
match props.edit_item { match props.edit_item {
EditItem::Agent => {html! { <AgentFields /> }}, EditItem::Agent => { html! { <AgentFields edittype={props.edit_type.clone()} agent={(*agent).clone()} /> } },
EditItem::Project => {html! { <ProjectFields listing={(*listing).clone()} edittype={props.edit_type.clone()}/> }}, EditItem::Project => { html! { <ProjectFields listing={(*listing).clone()} edittype={props.edit_type.clone()}/> } },
EditItem::Unit(_) => {html! { <UnitFields /> }}, EditItem::Unit(project_id) => { html! { <UnitFields edittype={props.edit_type.clone()} unit={}/> } },
} }
} }
</div> </div>

View File

@ -1,5 +1,7 @@
use jl_types::domain::agent::Agent; use jl_types::domain::agent::Agent;
use uuid::Uuid;
use yew::prelude::*; use yew::prelude::*;
use yew_router::prelude::use_navigator;
use crate::pages::admin::edit::EditType; use crate::pages::admin::edit::EditType;
@ -10,7 +12,10 @@ pub struct AgentFieldsProps {
} }
#[function_component(AgentFields)] #[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! { html! {
} }

View File

@ -1,5 +1,6 @@
use jl_types::domain::unit::Unit; use jl_types::domain::unit::Unit;
use yew::prelude::*; use yew::prelude::*;
use yew_router::prelude::use_navigator;
use crate::pages::admin::edit::EditType; use crate::pages::admin::edit::EditType;
@ -7,10 +8,14 @@ use crate::pages::admin::edit::EditType;
pub struct UnitFieldsProps { pub struct UnitFieldsProps {
pub unit: Option<Unit>, pub unit: Option<Unit>,
pub edittype: EditType, pub edittype: EditType,
pub projectid: Option<Uuid>,
} }
#[function_component(UnitFields)] #[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! { html! {
} }