Files
member-console/internal/embeds/static/success-toast.js
T
cgalo5758 c89d40a4a5 Split grant lifecycle from delivery and update UI
Add delivery-aware queries and wire them into server, templates,
and tests. Treat grants.status as lifecycle and use pool_provisions
joins for "currently delivering" semantics. Enable 422 validation
swaps and an error toast trigger; update docs and milestones.
2026-05-17 17:05:05 -05:00

46 lines
1.9 KiB
JavaScript

// Success feedback toast.
//
// Fired by an `HX-Trigger` response header carrying a `showSuccessToast`
// key. Works for both HTMX partial swaps and (post-7d) hx-boost page
// navigations, because `.toast-container` lives outside the swap target
// and survives the swap.
//
// Server-side API:
// w.Header().Set("HX-Trigger", `{"showSuccessToast": "Product created"}`)
//
// htmx dispatches a `showSuccessToast` event on <body> when it sees that
// header; the message string is in `event.detail.value`.
//
// CSP-safe: lives in static/ and is loaded via <script defer src>.
// (CSP `script-src 'self'` blocks inline handlers, so this is wired as a
// DOM event listener.)
(function () {
function showSuccessToast(message) {
var toastEl = document.getElementById("successToast");
var toastBody = document.getElementById("successToastBody");
if (!toastEl || !toastBody || !window.bootstrap) {
return;
}
toastBody.textContent = message || "Done.";
window.bootstrap.Toast.getOrCreateInstance(toastEl, { delay: 5000 }).show();
}
document.body.addEventListener("showSuccessToast", function (event) {
var detail = event.detail || {};
showSuccessToast(detail.value);
});
// Mirror of the success-toast contract for error flows. Lets server
// handlers surface a visible toast on error in addition to (or instead
// of) an in-body .alert-danger banner — important for mutations
// triggered from a scrolled-down section, where the banner would
// otherwise be invisible until the operator scrolls up. The error
// toast UI itself lives in error-handler.js (#errorToast).
document.body.addEventListener("showErrorToast", function (event) {
var detail = event.detail || {};
if (typeof window.showErrorToast === "function") {
window.showErrorToast(detail.value);
}
});
})();