//! The Askama entry point for the two described promo-code deletes. //! //! Shape 8 (`b279b9eb`), through the glue-module ruling `27d5e5b8`. Both //! destroy and both ask; what differs is what they act on, which is what the //! two prompts are for. //! //! `DELETE /api/promo-codes{,/id}` is a plain API route the description layer //! does not serve. It answers the whole list rebuilt, so the control says where //! that lands. See [`Action::replaces`]. //! //! Ids arrive as `impl Display` rather than `&str`: the caller is Askama and //! the server's ids are typed newtypes over `Uuid`, so asking for a string //! would push a `to_string()` into every call site to say what `format!` //! already says here. use std::fmt; use makeover_layout::Tone; use quasi_router::screen::Act; use quasi_router::{Action, Node}; /// The list both acts redraw. const REGION: &str = "promo-codes-list"; /// Delete one code. #[must_use] pub fn html(code_id: impl fmt::Display) -> String { fragment( Act::new( "Delete", Action::delete(format!("/api/promo-codes/{code_id}")).replacing(REGION), ) .tone(Tone::Danger) .confirm("Delete this code? It will no longer be usable."), ) } /// Delete every code that has already run out. /// /// Its own act rather than the row act under a different address: it asks about /// a set nobody has named on screen, and the prompt is the only place the /// reader learns how much goes. #[must_use] pub fn expired_html() -> String { fragment( Act::new( "Delete all expired", Action::delete("/api/promo-codes/expired").replacing(REGION), ) .tone(Tone::Danger) .confirm("Delete all expired promo codes?"), ) } /// No shell and no region: this lands inside a document Askama has already /// built, which is what every glue module here does. fn fragment(act: Act) -> String { use quasi_axum::Serves as _; quasi_webview::Webview::new().fragment(&Node::Act(act)) } #[cfg(test)] mod tests { #[test] fn deleting_one_code_names_its_route_its_region_and_its_prompt() { let html = super::html("11"); assert!( html.contains(r#"hx-delete="/api/promo-codes/11""#), "{html}" ); assert!( html.contains(r##"hx-target="#promo-codes-list""##), "{html}" ); assert!( html.contains(r#"hx-confirm="Delete this code? It will no longer be usable.""#), "{html}" ); } #[test] fn the_bulk_delete_asks_about_the_set_it_acts_on() { let html = super::expired_html(); assert!( html.contains(r#"hx-delete="/api/promo-codes/expired""#), "{html}" ); assert!( html.contains(r#"hx-confirm="Delete all expired promo codes?""#), "{html}" ); } #[test] fn both_deletes_say_they_are_dangerous() { assert!(super::html("11").contains(r#"data-tone="danger""#)); assert!(super::expired_html().contains(r#"data-tone="danger""#)); } }