3 Commits

Author SHA1 Message Date
Scott Idem
d35a28f912 ui(badges): show template name on create form when only one exists
Single-template events auto-select silently but gave no visual
confirmation. Added a read-only display of the template name so staff
can verify the correct template is in use before submitting.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 18:06:26 -04:00
Scott Idem
2e01e7f115 fix(badges): always pre-select first template on badge create
Every badged event must have a template — without one the badge cannot
render. Changed auto-select from === 1 to >= 1 so multi-template events
also get a default (first template). Added an error message and disabled
submit when no templates are configured at all. Removed blank
"-- Select Template --" option so the form never submits with null.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 18:03:15 -04:00
Scott Idem
f7ddcaa448 fix(badges): use base fields instead of _override on badge create
Professional title, organization, and location entered during manual
badge creation were being stored in the *_override fields. Override
fields are intended for overriding imported/AMS person data — for new
manually created badges, the base fields (professional_title,
affiliations, location) are correct.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 17:53:48 -04:00

View File

@@ -34,19 +34,21 @@ let {
let given_name: string = $state('');
let family_name: string = $state('');
let full_name_override: string = $state('');
let professional_title_override: string = $state('');
let affiliations_override: string = $state('');
let location_override: string = $state('');
let professional_title: string = $state('');
let affiliations: string = $state('');
let location: string = $state('');
let email: string = $state('');
let allow_tracking: boolean = $state(false);
let badge_type_code: string = $state('');
// Auto-select the first template when only one is available; otherwise let the user pick.
// event_badge_template_id is sent to the API so the badge renders with the correct layout.
// Always pre-select the first template. Every badged event must have at least one template —
// without one the badge cannot render. If there's only one we auto-select silently; if there
// are multiple the dropdown lets the user switch, but we never start with no selection.
// The !selected_template_id guard prevents a reactive re-fire from overriding a user's pick.
let selected_template_id: string = $state('');
$effect(() => {
if (template_li.length === 1 && template_li[0].event_badge_template_id) {
selected_template_id = template_li[0].event_badge_template_id;
if (template_li.length >= 1 && !selected_template_id) {
selected_template_id = template_li[0].event_badge_template_id ?? '';
}
});
@@ -121,9 +123,9 @@ async function handle_submit(event: Event) {
family_name,
email: email || null,
full_name_override: full_name_override || null,
professional_title_override: professional_title_override || null,
affiliations_override: affiliations_override || null,
location_override: location_override || null,
professional_title: professional_title || null,
affiliations: affiliations || null,
location: location || null,
allow_tracking,
badge_type_code: badge_type_code || null
};
@@ -214,13 +216,22 @@ let step_label = $derived(
<span class="label-text">Email</span>
<input type="email" bind:value={email} class="input" placeholder="jane@example.com" />
</label>
{#if template_li.length > 1}
<!-- Template selector — only shown when the event has multiple templates.
Single-template events auto-select; the selector would just add noise. -->
{#if template_li.length === 0}
<!-- No templates configured — badge cannot render without one. Block submission. -->
<p class="text-error-600 dark:text-error-400 text-sm font-medium">
No badge templates are configured for this event. Set up a template before creating badges.
</p>
{:else if template_li.length === 1}
<!-- Single template — auto-selected. Show it so the user can confirm. -->
<div class="text-sm">
<span class="text-surface-500">Badge Template:</span>
<span class="text-surface-900-50 font-medium">{template_li[0].name}</span>
</div>
{:else}
<!-- Multiple templates — let the user pick; always pre-selected to first. -->
<label class="label">
<span class="label-text">Badge Template</span>
<select bind:value={selected_template_id} class="select">
<option value="">-- Select Template --</option>
{#each template_li as tmpl (tmpl.event_badge_template_id)}
<option value={tmpl.event_badge_template_id}>{tmpl.name}</option>
{/each}
@@ -241,15 +252,15 @@ let step_label = $derived(
<label class="label">
<span class="label-text">Professional Title <span class="text-surface-400 font-normal">(optional)</span></span>
<input type="text" bind:value={professional_title_override} class="input" placeholder="e.g. Chief Medical Officer" />
<input type="text" bind:value={professional_title} class="input" placeholder="e.g. Chief Medical Officer" />
</label>
<label class="label">
<span class="label-text">Organization <span class="text-surface-400 font-normal">(optional)</span></span>
<input type="text" bind:value={affiliations_override} class="input" placeholder="e.g. Acme Hospital" />
<input type="text" bind:value={affiliations} class="input" placeholder="e.g. Acme Hospital" />
</label>
<label class="label">
<span class="label-text">Location <span class="text-surface-400 font-normal">(optional)</span></span>
<input type="text" bind:value={location_override} class="input" placeholder="City, State" />
<input type="text" bind:value={location} class="input" placeholder="City, State" />
</label>
<label class="flex items-center gap-2">
<input type="checkbox" bind:checked={allow_tracking} class="checkbox" />
@@ -275,7 +286,7 @@ let step_label = $derived(
<button
type="submit"
class="btn preset-filled-primary"
disabled={is_submitting || !given_name || !family_name}>
disabled={is_submitting || !given_name || !family_name || template_li.length === 0}>
Create Badge
</button>
</div>