Improve item-create toasts

demo-mode
Wes Holland 10 months ago
parent 57a7bbc94c
commit 705f8d9902

@ -8,14 +8,14 @@ use crate::error::{AppError, QueryExtractor};
use crate::app::common::query_args::search::SearchQueryArgs; use crate::app::common::query_args::search::SearchQueryArgs;
#[derive(Template)] #[derive(Template)]
#[template(path = "catalog.html")] #[template(path = "catalog/catalog.html")]
struct CatalogTemplate { struct CatalogTemplate {
items: Vec<DbInventoryItem>, items: Vec<DbInventoryItem>,
query: SearchQueryArgs, query: SearchQueryArgs,
} }
#[derive(Template)] #[derive(Template)]
#[template(path = "catalog_item_fragment.html")] #[template(path = "catalog/catalog-item-table.html")]
struct CatalogItemFragmentTemplate { struct CatalogItemFragmentTemplate {
items: Vec<DbInventoryItem> items: Vec<DbInventoryItem>
} }

@ -4,6 +4,7 @@ use askama::Template;
use askama_axum::{IntoResponse, Response}; use askama_axum::{IntoResponse, Response};
use axum::extract::State; use axum::extract::State;
use axum::{async_trait, debug_handler, Form}; use axum::{async_trait, debug_handler, Form};
use axum_htmx::{HxEvent, HxResponseTrigger};
use serde::Deserialize; use serde::Deserialize;
use tracing::info; use tracing::info;
use crate::app::routes::AppState; use crate::app::routes::AppState;
@ -168,7 +169,17 @@ pub async fn create_item_form_post(
&form_data.pims_id, &form_data.vetcove_id, &form_data.pims_id, &form_data.vetcove_id,
).await?; ).await?;
Ok(CreateItemFormData::base_template(&state).await?.into_response()) let fresh_form = CreateItemFormData::base_template(&state).await?;
let events = vec![
HxEvent::from("form-submit-success"),
HxEvent::from("new-item"),
];
Ok( (
HxResponseTrigger::normal(events),
fresh_form.into_response()
).into_response() )
} }
#[debug_handler] #[debug_handler]

@ -3,7 +3,9 @@
{% block content %} {% block content %}
<div class="relative h-auto" x-data="{ show_sidebar: false }" > <div class="relative h-auto" x-data="{ show_sidebar: false }"
x-on:form-submit-success="show_sidebar = false;"
>
<div class="absolute w-screen h-full" x-show="show_sidebar"> <div class="absolute w-screen h-full" x-show="show_sidebar">
<div class="relative w-full h-full bg-neutral-300 backdrop-blur-md opacity-90 py-4 z-10"> <div class="relative w-full h-full bg-neutral-300 backdrop-blur-md opacity-90 py-4 z-10">
</div> </div>
@ -83,7 +85,7 @@
</div> </div>
<div id="items" class="container"> <div id="items" class="container">
{% include "catalog_item_fragment.html" %} {% include "catalog-item-table.html" %}
</div> </div>
</div> </div>

@ -3,7 +3,8 @@
hx-post="/item/create" hx-post="/item/create"
hx-target="this" hx-target="this"
hx-swap="outerHTML" hx-swap="outerHTML"
x-on:htmx:response-error="$dispatch('notice', {type: 'error', text: 'Unknown error!'})" x-on:htmx:response-error="$dispatch('notice', {type: 'error', text: 'Unknown error'})"
x-on:form-submit-success="$dispatch('notice', {type: 'info', text: 'New item created'})"
> >
<div class="mb-5 grid grid-cols-6 gap-4 p-2"> <div class="mb-5 grid grid-cols-6 gap-4 p-2">
<div class="col-span-6"> <div class="col-span-6">

Loading…
Cancel
Save

Powered by TurnKey Linux.