fix(templates): map "None" header sentinel to null before save

The header type Select uses value="none" as a sentinel (Radix disallows
value=""), but the Save handler passed it through verbatim to Supabase.
The DB CHECK constraint on message_templates.header_type only allows
text|image|video|document, so picking "None" raised a constraint
violation and the template never saved.

Normalize "none" (and any falsy value) to '' at the input boundary so
form.header_type is always either '' (→ null on save) or a valid type.

Closes #147 (the header-dropdown half — Meta submission is tracked separately).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Arnas Donauskas 2026-05-29 11:45:59 +02:00
parent e828372fe3
commit 266e487ac8
No known key found for this signature in database

View File

@ -405,7 +405,15 @@ export function TemplateManager() {
<Label className="text-slate-300">Header Type</Label> <Label className="text-slate-300">Header Type</Label>
<Select <Select
value={form.header_type} value={form.header_type}
onValueChange={(val) => setForm({ ...form, header_type: val || '' })} onValueChange={(val) =>
// "none" is a sentinel (the Select disallows value="")
// — normalize it back to empty string so the DB CHECK
// constraint (text|image|video|document) doesn't reject it.
setForm({
...form,
header_type: !val || val === 'none' ? '' : val,
})
}
> >
<SelectTrigger className="w-full bg-slate-800 border-slate-700 text-white"> <SelectTrigger className="w-full bg-slate-800 border-slate-700 text-white">
<SelectValue placeholder="None" /> <SelectValue placeholder="None" />