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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
use leptos::{
IntoView, component,
prelude::{Get, Show, signal},
task::spawn_local,
view,
};
use leptos_router::{
NavigateOptions,
hooks::{use_navigate, use_query_map},
};
use rocie_client::models::{ProvisionInfo, UserStub};
use rocie_macros::Form;
use crate::{
api::{get_config, provision_external_wrapped},
components::{banner::Banner, catch_errors::CatchErrors, site_header::SiteHeader},
};
#[component]
pub fn Provision() -> impl IntoView {
let back = || {
let back = use_query_map()
.get()
.get("back")
.expect("Should always have a back, because the router would otherwise not match");
if back.starts_with('/') {
back
} else {
// Prevent a redirect like `/provision?back=https://gnu.org` to work
"/".to_owned()
}
};
let (error_message, error_message_set) = signal(None);
view! {
<CatchErrors>
<SiteHeader
logo=icondata_io::IoArrowBack
back_location="/"
name="Provision this instance"
/>
<Show when=move || error_message.get().is_some()>
<Banner text=move || error_message.get().expect("Is some") />
</Show>
{
Form! {
on_submit = |user_name, password, should_use_defaults| {
let config = get_config!();
let navigate = use_navigate();
let back = back();
spawn_local(async move {
match provision_external_wrapped(
&config,
ProvisionInfo {
// TODO: Make it possible to give this user a description <2025-12-30>
user: UserStub { description: None, name: user_name, password },
use_defaults: should_use_defaults
}
).await {
Ok(_) => {
navigate(back.as_str(), NavigateOptions::default());
}
Err(err) => error_message_set.set(Some(format!("Failed to provision: {err}"))),
}
});
};
<Input
name=user_name,
rust_type=String,
html_type="text",
label="Username"
/>
<Input
name=password,
rust_type=String,
html_type="password",
label="Password"
/>
<Checkbox
name=should_use_defaults,
label="Use defaults"
/>
}
}
</CatchErrors>
}
}
|