1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use crate::{
components::{
SectionStyled,
alert::{Alert, AlertSeverity},
heading::{Heading, SubHeading},
loading::LoadingIndicator,
},
settings::{avatar_edit::AvatarSection, profile::ProfileSection},
};
use leptos::prelude::*;
use leptos_router::hooks::use_navigate;
use crate::session::get_user;
#[component]
pub fn SettingsHome() -> impl IntoView {
let _navigate = use_navigate();
let user_resource = Resource::new(|| (), |_| get_user());
view! {
<div class="container mx-auto">
<div class="">
<div class="mb-8">
<Heading>"Settings"</Heading>
<SubHeading>"Manage your account settings and preferences"</SubHeading>
</div>
<Suspense fallback=move || {
view! {
<div class="">
<LoadingIndicator size=crate::components::loading::LoadingIndicatorSize::Huge />
</div>
}
}>
{move || {
user_resource
.get()
.map(|user| match user {
Ok(user) => {
let usera = user.clone();
let userb = user.clone();
view! {
<div class="grid grid-cols-1 lg:grid-cols-2 gap-5">
<SectionStyled>
<div class="flex flex-col gap-5">
<Heading>"Account"</Heading>
<AvatarSection
user=userb.clone()
on_update=move || user_resource.refetch()
/>
<ProfileSection user=usera.clone() />
</div>
</SectionStyled>
<SectionStyled>
<div class="flex flex-col gap-5">
<Heading>"Delivery Details"</Heading>
<crate::auth::account_details::AccountForm />
</div>
</SectionStyled>
</div>
}
.into_any()
}
Err(e) => {
view! {
<Alert severity=AlertSeverity::Error>
"Error loading user data: " {e.to_string()}
</Alert>
}
.into_any()
}
})
}}
</Suspense>
</div>
</div>
}
}