feat(settings): per-integration Test button with live API checks

Each integration card now has a Test button that re-runs its
connectivity check on demand and updates the badge in place.

- Refactors checkIntegrationStatus into checkIntegration(name) so a
  single integration can be tested without firing the others.
- Adds POST /api/settings/test for the on-demand check.
- Replaces the "key exists ⇒ connected" placeholder for Tavily,
  Gemini, and Nextdoor with real API calls (Tavily search, Gemini
  models list, Nextdoor advertiser fetch). 401/403 surface as
  "Invalid API key" / "Token expired or invalid" so a stale
  credential is obvious instead of pretending to be healthy.
- Fixes Postiz auth header (was Bearer, the rest of the codebase
  passes the API key bare — matches lib/postiz.ts now).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Trey T
2026-05-03 21:03:16 -05:00
parent 63698333ff
commit 55fb221faa
3 changed files with 203 additions and 87 deletions
+58 -11
View File
@@ -12,7 +12,7 @@ import {
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { CheckCircle2, XCircle, Loader2, ExternalLink } from "lucide-react";
import { CheckCircle2, XCircle, Loader2, ExternalLink, FlaskConical } from "lucide-react";
interface SettingsGroup {
name: string;
@@ -110,6 +110,7 @@ export default function SettingsPage() {
const [saving, setSaving] = useState<string | null>(null);
const [saved, setSaved] = useState<string | null>(null);
const [loading, setLoading] = useState(true);
const [testing, setTesting] = useState<string | null>(null);
useEffect(() => {
fetch("/api/settings?status=true")
@@ -159,6 +160,27 @@ export default function SettingsPage() {
return status[key] || { connected: false, error: "Unknown" };
}
async function handleTest(group: SettingsGroup) {
const integration = group.name.toLowerCase();
setTesting(integration);
try {
const res = await fetch("/api/settings/test", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ integration }),
});
const result = await res.json();
setStatus((prev) => ({ ...prev, [integration]: result }));
} catch {
setStatus((prev) => ({
...prev,
[integration]: { connected: false, error: "Test request failed" },
}));
} finally {
setTesting(null);
}
}
if (loading) {
return (
<div className="flex items-center justify-center py-20">
@@ -179,6 +201,8 @@ export default function SettingsPage() {
{SETTINGS_GROUPS.map((group) => {
const groupStatus = getGroupStatus(group);
const integrationKey = group.name.toLowerCase();
const isTesting = testing === integrationKey;
return (
<Card key={group.name}>
@@ -186,7 +210,15 @@ export default function SettingsPage() {
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<CardTitle>{group.name}</CardTitle>
{groupStatus.connected ? (
{isTesting ? (
<Badge
variant="outline"
className="text-blue-600 border-blue-200 bg-blue-50"
>
<Loader2 className="h-3 w-3 mr-1 animate-spin" />
Testing
</Badge>
) : groupStatus.connected ? (
<Badge
variant="outline"
className="text-green-600 border-green-200 bg-green-50"
@@ -204,15 +236,30 @@ export default function SettingsPage() {
</Badge>
)}
</div>
<a
href={group.docsUrl}
target="_blank"
rel="noopener noreferrer"
className="text-sm text-muted-foreground hover:text-foreground flex items-center gap-1"
>
Docs
<ExternalLink className="h-3 w-3" />
</a>
<div className="flex items-center gap-3">
<Button
variant="outline"
size="sm"
onClick={() => handleTest(group)}
disabled={isTesting}
>
{isTesting ? (
<Loader2 className="h-3.5 w-3.5 animate-spin" />
) : (
<FlaskConical className="h-3.5 w-3.5 mr-1" />
)}
{isTesting ? "" : "Test"}
</Button>
<a
href={group.docsUrl}
target="_blank"
rel="noopener noreferrer"
className="text-sm text-muted-foreground hover:text-foreground flex items-center gap-1"
>
Docs
<ExternalLink className="h-3 w-3" />
</a>
</div>
</div>
<CardDescription>{group.description}</CardDescription>
</CardHeader>