diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index f2b72cd..f904b6c 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -45,7 +45,7 @@ export default function DashboardPage() { const { data } = await supabase .from('invoices') .select('*') - .eq('originator', user.id) + .eq('originator_id', user.id) .order('created_at', { ascending: false }); if (data) setInvoices(data as unknown as Invoice[]); setLoading(false); diff --git a/src/components/invoices/InvoiceForm.tsx b/src/components/invoices/InvoiceForm.tsx index faceaaa..2dcfc63 100644 --- a/src/components/invoices/InvoiceForm.tsx +++ b/src/components/invoices/InvoiceForm.tsx @@ -103,7 +103,7 @@ export function InvoiceForm({ onSuccess }: InvoiceFormProps) { // Always mirror to Supabase for indexing / display const { data: { user } } = await supabase.auth.getUser(); - await supabase.from('invoices').insert({ + const { error: insertError } = await supabase.from('invoices').insert({ id: invoiceId, originator: publicKey, originator_id: user?.id ?? null, @@ -112,6 +112,13 @@ export function InvoiceForm({ onSuccess }: InvoiceFormProps) { due_date: new Date(values.dueDate).toISOString(), status: 'Pending', }); + if (insertError) { + throw new Error( + CONTRACT_OK + ? `Invoice registered on-chain, but saving to the database failed: ${insertError.message}. It won't appear in lists until this is resolved.` + : `Saving the invoice failed: ${insertError.message}`, + ); + } toast({ title: CONTRACT_OK ? 'Invoice registered!' : 'Invoice saved!',