Skip to content

Commit

Permalink
webui: add toggle switch for acme account
Browse files Browse the repository at this point in the history
  • Loading branch information
picoHz committed Sep 10, 2023
1 parent c367a1d commit 31f4e68
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions taxy-webui/src/pages/cert_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ pub fn cert_list() -> Html {
<th scope="col" class="px-4 py-3">
{"Provider"}
</th>
<th scope="col" class="px-4 py-3">
{"Active"}
</th>
<th scope="col" class="px-4 py-3">
<span class="sr-only">{"Edit"}</span>
</th>
Expand Down Expand Up @@ -314,6 +317,12 @@ pub fn cert_list() -> Html {
navigator_cloned.push(&Route::CertLogView {id});
});

let active = entry.config.active;
let onchange = Callback::from(move |_: Event| {
wasm_bindgen_futures::spawn_local(async move {
let _ = toggle_acme(id).await;
});
});

html! {
<tr class="border-b">
Expand All @@ -323,6 +332,12 @@ pub fn cert_list() -> Html {
<td class="px-4 py-4">
{provider}
</td>
<td class="px-4 py-4 w-0 whitespace-nowrap" align="right">
<label class="relative inline-flex items-center cursor-pointer mt-1">
<input {onchange} type="checkbox" checked={active} class="sr-only peer" />
<div class="w-9 h-4 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-3 after:w-4 after:transition-all peer-checked:bg-blue-600"></div>
</label>
</td>
<td class="px-4 py-4 w-0 whitespace-nowrap" align="right">
<a class="cursor-pointer font-medium text-blue-600 hover:underline mr-5" onclick={log_onclick}>{"Log"}</a>
<a class="cursor-pointer font-medium text-red-600 hover:underline" onclick={delete_onclick}>{"Delete"}</a>
Expand Down Expand Up @@ -391,6 +406,20 @@ async fn delete_acme(id: ShortId) -> Result<(), gloo_net::Error> {
Ok(())
}

async fn toggle_acme(id: ShortId) -> Result<(), gloo_net::Error> {
let mut acme: AcmeInfo = Request::get(&format!("{API_ENDPOINT}/acme/{id}"))
.send()
.await?
.json()
.await?;
acme.config.active = !acme.config.active;
Request::put(&format!("{API_ENDPOINT}/acme/{id}"))
.json(&acme.config)?
.send()
.await?;
Ok(())
}

mod location {
use wasm_bindgen::prelude::*;

Expand Down

0 comments on commit 31f4e68

Please sign in to comment.