diff --git a/src/components/admin_agent.rs b/src/components/admin_agent.rs new file mode 100644 index 0000000..58758c2 --- /dev/null +++ b/src/components/admin_agent.rs @@ -0,0 +1,63 @@ +use jl_types::{domain::{agent::Agent}}; +use yew::prelude::*; +use yew_router::prelude::use_navigator; + +use crate::{ + pages::admin::edit::{EditItem, EditType}, + routes::main_router::Route, +}; + +//TODO: Add admin tag + +#[function_component(AdminAgent)] +pub fn admin_agent(props: &AdminAgentProps) -> Html { + let navigator = use_navigator().unwrap(); + let is_attempting_delete = use_state(|| false); + let delete_agent = { + let is_attempting_delete = is_attempting_delete.clone(); + Callback::from(move |event: MouseEvent| { + if *is_attempting_delete { + // Call delete + is_attempting_delete.set(false); + } else { + is_attempting_delete.set(true); + } + event.stop_propagation(); + }) + }; + let onclick_item = { + let props = props.clone(); + Callback::from(move |_| { + navigator.push(&Route::AdminEdit { + edit_type: EditType::Existing(props.agent.id), + edit_item: EditItem::Agent, + }); + }) + }; + html! { +
+
+ {props.index + 1} +
+
+ {props.agent.full_name.clone()} +
+
+ {props.agent.credential.clone()} +
+
+ {format!("Miembro Desde: {}", props.agent.time_created.date_naive().to_string())} +
+
+ +
+
+ + } +} + +#[derive(PartialEq, Properties, Clone)] +pub struct AdminAgentProps { + pub agent: Agent, + pub index: usize, +} diff --git a/src/components/admin_project.rs b/src/components/admin_project.rs index 9d66840..3d6e205 100644 --- a/src/components/admin_project.rs +++ b/src/components/admin_project.rs @@ -7,6 +7,8 @@ use crate::{ routes::main_router::Route, }; +//TODO: Add admin tag + #[function_component(AdminProject)] pub fn admin_project(props: &AdminProjectProps) -> Html { let navigator = use_navigator().unwrap(); diff --git a/src/components/admin_unit.rs b/src/components/admin_unit.rs new file mode 100644 index 0000000..f3811e1 --- /dev/null +++ b/src/components/admin_unit.rs @@ -0,0 +1,79 @@ +use jl_types::domain::unit::Unit; +use thousands::Separable; +use yew::prelude::*; +use yew_router::prelude::use_navigator; + +use crate::{ + pages::admin::edit::{EditItem, EditType}, + routes::main_router::Route, +}; + +#[function_component(AdminUnit)] +pub fn admin_project(props: &AdminUnitProps) -> Html { + let navigator = use_navigator().unwrap(); + let price_usd = format!( + "Desde US${}", + { + let price_separated = props.unit.price_usd.separate_with_commas(); + if price_separated.contains(".") { + price_separated + } else { + format!("{price_separated}.00") + } + } + ); + let is_attempting_delete = use_state(|| false); + let delete_unit = { + let is_attempting_delete = is_attempting_delete.clone(); + Callback::from(move |event: MouseEvent| { + if *is_attempting_delete { + // Call delete + is_attempting_delete.set(false); + } else { + is_attempting_delete.set(true); + } + event.stop_propagation(); + }) + }; + let onclick_item = { + let props = props.clone(); + Callback::from(move |_| { + navigator.push(&Route::AdminEdit { + edit_type: EditType::Existing(props.unit.id), + edit_item: EditItem::Unit(props.unit.project_id), + }); + }) + }; + html! { +
+
+ {props.index + 1} +
+
+ {price_usd} +
+
+ {match props.unit.admin_tag.clone() { + Some(admin_tag) => admin_tag, + None => props.unit.unit_type.to_string() + }} +
+
+ {props.unit.rooms.clone()} +
+
+ {props.unit.bathrooms.clone()} +
+
+ +
+
+ + } +} + +#[derive(PartialEq, Properties, Clone)] +pub struct AdminUnitProps { + pub unit: Unit, + pub index: usize, +} diff --git a/src/components/mod.rs b/src/components/mod.rs index 2125c2c..6fd1311 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -12,3 +12,5 @@ pub mod nav_bar; pub mod new_widget; pub mod project_card; pub mod textfield; +pub mod admin_unit; +pub mod admin_agent; \ No newline at end of file diff --git a/src/pages/admin/agents.rs b/src/pages/admin/agents.rs index 3a16b5b..13962bf 100644 --- a/src/pages/admin/agents.rs +++ b/src/pages/admin/agents.rs @@ -1,6 +1,6 @@ use yew::prelude::*; -use crate::{api::backend::get_all_agents, components::admin_nav_bar::AdminNavigationBar}; +use crate::{api::backend::get_all_agents, components::{admin_nav_bar::AdminNavigationBar, admin_agent::AdminAgent}}; #[function_component(AdminAgents)] pub fn admin_agents() -> Html { @@ -24,6 +24,15 @@ pub fn admin_agents() -> Html {
{"Agentes"}
+
+
+ {(*agents).clone().into_iter().enumerate().map(|(key, agent)| html! { + <> + +
+ + }).collect::()} +
diff --git a/src/pages/admin/contacts.rs b/src/pages/admin/contacts.rs index e638757..db4201b 100644 --- a/src/pages/admin/contacts.rs +++ b/src/pages/admin/contacts.rs @@ -25,7 +25,7 @@ pub fn admin_contacts() -> Html {
{"Solicitudes de Contacto"}
- +//TODO: Finish this
diff --git a/src/pages/admin/edit.rs b/src/pages/admin/edit.rs index ebb31a5..6cdc937 100644 --- a/src/pages/admin/edit.rs +++ b/src/pages/admin/edit.rs @@ -18,8 +18,8 @@ use crate::{ datepicker::DatePicker, dropdown::DropDown, media_picker::MediaPicker, - textfield::{TextField, TextFieldType}, - }, + textfield::{TextField, TextFieldType}, new_widget::NewThingWidget, + }, pages::admin::units::AdminUnits, }; /// All of the editing actions of the admin panel will lead to here. This should take an id of anything. A unit, a project, an agent. And its corresponding ID. @@ -222,10 +222,24 @@ pub fn generate_fields_for_project(props: &ProjectFieldsProps) -> Html { media_list: Vec::new(), }, }); + units.set(match listing_opt.clone() { + Some(listing) => listing.units, + None => Vec::new(), + }); } + html! { <> + { + if let Some(listing) = listing_opt { + html! { + + } + } else { + html! {} + } + } @@ -302,6 +316,7 @@ pub fn generate_fields_for_project(props: &ProjectFieldsProps) -> Html {
{"Actualizar"}
+ } } diff --git a/src/pages/admin/mod.rs b/src/pages/admin/mod.rs index 5f31fe2..7bf65e2 100644 --- a/src/pages/admin/mod.rs +++ b/src/pages/admin/mod.rs @@ -4,3 +4,4 @@ pub mod edit; pub mod login; pub mod projects; pub mod start; +pub mod units; \ No newline at end of file diff --git a/src/pages/admin/units.rs b/src/pages/admin/units.rs new file mode 100644 index 0000000..65ce641 --- /dev/null +++ b/src/pages/admin/units.rs @@ -0,0 +1,31 @@ +use jl_types::domain::unit::Unit; +use yew::prelude::*; + +use crate::{ + components::{ + admin_unit::AdminUnit, + }, +}; + +#[function_component(AdminUnits)] +pub fn admin_units(props: &AdminUnitProps) -> Html { + html! { +
+
{"Unidades"}
+
+
+ {props.units.clone().into_iter().enumerate().map(|(key, unit)| html! { + <> + +
+ + }).collect::()} +
+
+ } +} + +#[derive(PartialEq, Properties, Clone)] +pub struct AdminUnitProps { + pub units: Vec +} \ No newline at end of file