Added tables for agent, for units, and finished project edit except for actualizar button functionality
This commit is contained in:
parent
89a7b99ed2
commit
cd9b53a05d
63
src/components/admin_agent.rs
Normal file
63
src/components/admin_agent.rs
Normal file
@ -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! {
|
||||
<div class={"admin-project-container"} onclick={onclick_item}>
|
||||
<div class={"admin-project-index"}>
|
||||
{props.index + 1}
|
||||
</div>
|
||||
<div class={"admin-project-column"}>
|
||||
{props.agent.full_name.clone()}
|
||||
</div>
|
||||
<div class={"admin-project-column"}>
|
||||
{props.agent.credential.clone()}
|
||||
</div>
|
||||
<div class={"admin-project-column"}>
|
||||
{format!("Miembro Desde: {}", props.agent.time_created.date_naive().to_string())}
|
||||
</div>
|
||||
<div class={if *is_attempting_delete {"admin-project-trash-bin-selected"} else {"admin-project-trash-bin"}} onclick={delete_agent}>
|
||||
<i class="fa-regular fa-trash-can"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Properties, Clone)]
|
||||
pub struct AdminAgentProps {
|
||||
pub agent: Agent,
|
||||
pub index: usize,
|
||||
}
|
@ -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();
|
||||
|
79
src/components/admin_unit.rs
Normal file
79
src/components/admin_unit.rs
Normal file
@ -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! {
|
||||
<div class={"admin-project-container"} onclick={onclick_item}>
|
||||
<div class={"admin-project-index"}>
|
||||
{props.index + 1}
|
||||
</div>
|
||||
<div class={"admin-project-column"}>
|
||||
{price_usd}
|
||||
</div>
|
||||
<div class={"admin-project-column"}>
|
||||
{match props.unit.admin_tag.clone() {
|
||||
Some(admin_tag) => admin_tag,
|
||||
None => props.unit.unit_type.to_string()
|
||||
}}
|
||||
</div>
|
||||
<div class={"admin-project-column"}>
|
||||
{props.unit.rooms.clone()}
|
||||
</div>
|
||||
<div class={"admin-project-column"}>
|
||||
{props.unit.bathrooms.clone()}
|
||||
</div>
|
||||
<div class={if *is_attempting_delete {"admin-project-trash-bin-selected"} else {"admin-project-trash-bin"}} onclick={delete_unit}>
|
||||
<i class="fa-regular fa-trash-can"></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Properties, Clone)]
|
||||
pub struct AdminUnitProps {
|
||||
pub unit: Unit,
|
||||
pub index: usize,
|
||||
}
|
@ -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;
|
@ -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 {
|
||||
<div class={"admin-page-container"}>
|
||||
<div class={"admin-start-container"}>
|
||||
<div class={"admin-panel-page-title"}>{"Agentes"}</div>
|
||||
<div class={"admin-projects-table"}>
|
||||
<div class={"admin-navbar-divider"}></div>
|
||||
{(*agents).clone().into_iter().enumerate().map(|(key, agent)| html! {
|
||||
<>
|
||||
<AdminAgent agent={agent} index={key}/>
|
||||
<div class={"admin-navbar-divider"}></div>
|
||||
</>
|
||||
}).collect::<Html>()}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
@ -25,7 +25,7 @@ pub fn admin_contacts() -> Html {
|
||||
<div class={"admin-page-container"}>
|
||||
<div class={"admin-start-container"}>
|
||||
<div class={"admin-panel-page-title"}>{"Solicitudes de Contacto"}</div>
|
||||
|
||||
//TODO: Finish this
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
@ -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! {
|
||||
<NewThingWidget item={EditItem::Unit(listing.project.id)}/>
|
||||
}
|
||||
} else {
|
||||
html! {}
|
||||
}
|
||||
}
|
||||
<TextField label={"Ciudad"} value={location_city} required={true} onchange={ontype_cb.clone()}/>
|
||||
<TextField label={"Distrito"} value={location_district} required={true} onchange={ontype_cb.clone()} />
|
||||
<MediaPicker value={media} onchange={ontype_cb.clone()} item={jl_types::dto::item::Item::Project}/>
|
||||
@ -302,6 +316,7 @@ pub fn generate_fields_for_project(props: &ProjectFieldsProps) -> Html {
|
||||
<div class={"admin-edit-submit-button"}>
|
||||
{"Actualizar"}
|
||||
</div>
|
||||
<AdminUnits units={(*units).clone()}/>
|
||||
</>
|
||||
}
|
||||
}
|
||||
|
@ -4,3 +4,4 @@ pub mod edit;
|
||||
pub mod login;
|
||||
pub mod projects;
|
||||
pub mod start;
|
||||
pub mod units;
|
31
src/pages/admin/units.rs
Normal file
31
src/pages/admin/units.rs
Normal file
@ -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! {
|
||||
<div class={"admin-start-container"} style={"min-height: 10vh; margin-top: 10vh;"}>
|
||||
<div class={"admin-panel-page-title"}>{"Unidades"}</div>
|
||||
<div class={"admin-projects-table"}>
|
||||
<div class={"admin-navbar-divider"}></div>
|
||||
{props.units.clone().into_iter().enumerate().map(|(key, unit)| html! {
|
||||
<>
|
||||
<AdminUnit unit={unit} index={key}/>
|
||||
<div class={"admin-navbar-divider"}></div>
|
||||
</>
|
||||
}).collect::<Html>()}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Properties, Clone)]
|
||||
pub struct AdminUnitProps {
|
||||
pub units: Vec<Unit>
|
||||
}
|
Loading…
Reference in New Issue
Block a user