Replace both buttons with a centered "Saving..." spinner when the form is submitting. Add x_mark icon to the cancel button for clarity.
106 lines
4 KiB
HTML
106 lines
4 KiB
HTML
{% extends "base.html" %}
|
|
{% import "partials/icons.html" as icons %}
|
|
{% import "partials/image_section.html" as img %}
|
|
{% block title %}Brewlog · Edit Cup{% endblock %}
|
|
|
|
{% block content %}
|
|
<header class="flex flex-col gap-2">
|
|
<h1 class="text-3xl font-semibold">Edit Cup</h1>
|
|
<p class="max-w-2xl text-sm text-text-secondary">Update cup details.</p>
|
|
</header>
|
|
|
|
<section class="rounded-lg border bg-surface p-5">
|
|
<form
|
|
class="flex flex-col gap-4"
|
|
data-signals:_submitting="false"
|
|
data-signals:_submit-error="''"
|
|
data-on:submit="$_submitting = true; $_submitError = ''; @put('/api/v1/cups/{{ id }}', {contentType: 'form'})"
|
|
data-on:datastar-fetch="if (!$_submitting) return;
|
|
if (evt.detail.type === 'finished') { $_submitting = false; sessionStorage.setItem('toast', 'Cup updated') }
|
|
else if (evt.detail.type === 'error') { $_submitting = false; $_submitError = 'Failed to save changes.' }"
|
|
>
|
|
<div class="grid gap-4 sm:grid-cols-2">
|
|
<div class="flex flex-col gap-1 text-sm">
|
|
<span
|
|
class="text-xs font-semibold text-text-muted uppercase tracking-wide"
|
|
>Coffee*</span
|
|
>
|
|
<searchable-select
|
|
name="roast_id"
|
|
placeholder="Type to search roasts…"
|
|
initial-value="{{ roast_id }}"
|
|
>
|
|
{% for roast in roast_options %}
|
|
<button
|
|
type="button"
|
|
value="{{ roast.id }}"
|
|
data-display="{{ roast.name }}"
|
|
class="w-full px-3 py-2 text-left text-sm hover:bg-surface-alt transition"
|
|
>
|
|
<span class="font-medium text-text">{{ roast.name }}</span>
|
|
<span class="ml-2 text-xs text-text-muted"
|
|
>{{ roast.roaster_name }}</span
|
|
>
|
|
</button>
|
|
{% endfor %}
|
|
</searchable-select>
|
|
</div>
|
|
<div class="flex flex-col gap-1 text-sm">
|
|
<span
|
|
class="text-xs font-semibold text-text-muted uppercase tracking-wide"
|
|
>Cafe*</span
|
|
>
|
|
<searchable-select
|
|
name="cafe_id"
|
|
placeholder="Type to search cafes…"
|
|
initial-value="{{ cafe_id }}"
|
|
>
|
|
{% for cafe in cafe_options %}
|
|
<button
|
|
type="button"
|
|
value="{{ cafe.id }}"
|
|
data-display="{{ cafe.name }}"
|
|
class="w-full px-3 py-2 text-left text-sm hover:bg-surface-alt transition"
|
|
>
|
|
<span class="font-medium text-text">{{ cafe.name }}</span>
|
|
<span class="ml-2 text-xs text-text-muted"
|
|
>{{ cafe.city }}</span
|
|
>
|
|
</button>
|
|
{% endfor %}
|
|
</searchable-select>
|
|
</div>
|
|
</div>
|
|
{{ img::deferred_upload_with_preview("edit-cup-image", "Cup Image", "cup", id, image_url) }}
|
|
<p
|
|
data-show="$_submitError"
|
|
data-text="$_submitError"
|
|
style="display:none"
|
|
class="text-sm text-error"
|
|
role="alert"
|
|
></p>
|
|
<div
|
|
data-show="$_submitting"
|
|
style="display:none"
|
|
class="flex items-center justify-center gap-3 py-2 text-sm text-accent"
|
|
>
|
|
{{ icons::spinner("h-5 w-5") }} Saving…
|
|
</div>
|
|
<div class="flex flex-col gap-2" data-show="!$_submitting">
|
|
<button
|
|
type="submit"
|
|
class="inline-flex w-full items-center justify-center gap-2 rounded-md bg-accent px-4 py-2 text-sm font-semibold text-accent-text transition hover:bg-accent-hover disabled:opacity-50"
|
|
>
|
|
{{ icons::check("h-4 w-4") }} Save Changes
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onclick="history.back()"
|
|
class="inline-flex w-full items-center justify-center gap-2 rounded-md border px-4 py-2 text-sm font-medium text-text-secondary transition hover:bg-surface-alt"
|
|
>
|
|
{{ icons::x_mark("h-4 w-4") }} Cancel
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
{% endblock %}
|