diff --git a/src/components/admin/settings/NotifikasiTab.tsx b/src/components/admin/settings/NotifikasiTab.tsx index 7a8a81b..e18d923 100644 --- a/src/components/admin/settings/NotifikasiTab.tsx +++ b/src/components/admin/settings/NotifikasiTab.tsx @@ -422,7 +422,7 @@ export function NotifikasiTab() { const seedTemplates = async () => { try { console.log('Seeding default templates...'); - const toInsert = DEFAULT_TEMPLATES.map(t => ({ + const toUpsert = DEFAULT_TEMPLATES.map(t => ({ key: t.key, name: t.name, is_active: false, @@ -431,8 +431,14 @@ export function NotifikasiTab() { webhook_url: '', })); - console.log('Inserting templates:', toInsert.length); - const { data, error } = await supabase.from('notification_templates').insert(toInsert).select(); + console.log('Upserting templates:', toUpsert.length); + const { data, error } = await supabase + .from('notification_templates') + .upsert(toUpsert, { + onConflict: 'key', + ignoreDuplicates: false + }) + .select(); if (error) { console.error('Error seeding templates:', error); @@ -444,7 +450,7 @@ export function NotifikasiTab() { return; } - console.log('Templates seeded successfully:', data); + console.log('Templates seeded/updated successfully:', data); if (data) { setTemplates(data); toast({