Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
fix(web): show error state instead of empty state when invoice fetch fails (#559)
jorge arambulaf8119af92d11
diff --git a/web/src/components/settings/invoice-list.tsx b/web/src/components/settings/invoice-list.tsxindex 983b432a2..b7768dd64 100644--- a/web/src/components/settings/invoice-list.tsx+++ b/web/src/components/settings/invoice-list.tsx@@ -1,8 +1,8 @@'use client';-import { useEffect, useState } from 'react';+import { useCallback, useEffect, useState } from 'react';import { useTranslations } from 'next-intl';-import { Download } from 'lucide-react';+import { Download, AlertCircle, RotateCw } from 'lucide-react';import {Table,TableBody,@@ -12,6 +12,7 @@ import {TableRow,} from '@/components/ui/table';import { Badge } from '@/components/ui/badge';+import { Button } from '@/components/ui/button';import { Skeleton } from '@/components/ui/skeleton';interface Invoice {@@ -26,18 +27,33 @@ interface Invoice {export function InvoiceList() {const t = useTranslations('settings');+ const tCommon = useTranslations('common');const [invoices, setInvoices] = useState<Invoice[]>([]);const [loading, setLoading] = useState(true);+ const [error, setError] = useState<string | null>(null);- useEffect(() => {- fetch('/api/stripe/invoices')- .then((r) => r.json())- .then((data) => {- if (Array.isArray(data)) setInvoices(data);- })- .finally(() => setLoading(false));+ const load = useCallback(async () => {+ setLoading(true);+ setError(null);+ try {+ const res = await fetch('/api/stripe/invoices');+ const body = (await res.json().catch(() => ({}))) as Invoice[] | { error?: string };+ if (!res.ok) {+ const message = !Array.isArray(body) ? body.error : undefined;+ throw new Error(message || 'Failed to load invoices');+ }+ setInvoices(Array.isArray(body) ? body : []);+ } catch (err) {+ setError(err instanceof Error ? err.message : 'Failed to load invoices');+ } finally {+ setLoading(false);+ }}, []);+ useEffect(() => {+ void load();+ }, [load]);+if (loading) {return (<div className="space-y-3">@@ -48,6 +64,19 @@ export function InvoiceList() {);}+ if (error) {+ return (+ <div className="flex flex-col items-center gap-3 rounded-md border border-destructive/20 bg-destructive/5 p-6 text-center">+ <AlertCircle className="h-5 w-5 text-destructive" />+ <p className="text-sm text-muted-foreground">{error}</p>+ <Button variant="outline" size="sm" onClick={() => void load()}>+ <RotateCw className="mr-2 h-4 w-4" />+ {tCommon('retry')}+ </Button>+ </div>+ );+ }+if (invoices.length === 0) {return <p className="text-sm text-muted-foreground">{t('noInvoices')}</p>;}