From c1398fe1fcb6e241fad65c52e03276e55914bf10 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sun, 9 Nov 2025 07:28:53 +0000 Subject: [PATCH] Create Discord diagnostic component for admin panel cgen-e2505ddc7df84ffe9ba1bc2539c66b75 --- .../admin/AdminDiscordDiagnostic.tsx | 279 ++++++++++++++++++ 1 file changed, 279 insertions(+) create mode 100644 client/components/admin/AdminDiscordDiagnostic.tsx diff --git a/client/components/admin/AdminDiscordDiagnostic.tsx b/client/components/admin/AdminDiscordDiagnostic.tsx new file mode 100644 index 00000000..f7576a20 --- /dev/null +++ b/client/components/admin/AdminDiscordDiagnostic.tsx @@ -0,0 +1,279 @@ +import { useState, useEffect } from "react"; +import { AlertCircle, CheckCircle, AlertTriangle, RefreshCw } from "lucide-react"; + +interface DiagnosticData { + timestamp: string; + environment: { + botTokenSet: boolean; + clientIdSet: boolean; + publicKeySet: boolean; + }; + tokenValidation: { + length: number; + format: string; + preview: string | null; + minLengthMet: boolean; + }; + clientIdValidation: { + value: string | null; + isNumeric: boolean; + }; + testRequest: { + url: string; + method: string; + headerFormat: string; + status: string; + responseCode?: number; + error?: string; + }; + recommendations: string[]; +} + +export default function AdminDiscordDiagnostic() { + const [diagnostic, setDiagnostic] = useState(null); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + + const fetchDiagnostic = async () => { + setLoading(true); + setError(null); + try { + const response = await fetch("/api/discord/diagnostic"); + if (!response.ok) { + throw new Error(`HTTP ${response.status}`); + } + const data = await response.json(); + setDiagnostic(data); + } catch (err) { + setError( + err instanceof Error ? err.message : "Failed to fetch diagnostic" + ); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + fetchDiagnostic(); + }, []); + + return ( +
+
+

Discord Configuration Diagnostic

+ +
+ + {error && ( +
+ +
+

Error

+

{error}

+
+
+ )} + + {loading && ( +
+

Loading diagnostic...

+
+ )} + + {diagnostic && ( +
+ {/* Environment Variables Status */} +
+

+ + Environment Variables +

+
+
+

DISCORD_BOT_TOKEN

+
+ {diagnostic.environment.botTokenSet ? ( + + ) : ( + + )} + + {diagnostic.environment.botTokenSet ? "Set" : "Missing"} + +
+
+
+

DISCORD_CLIENT_ID

+
+ {diagnostic.environment.clientIdSet ? ( + + ) : ( + + )} + + {diagnostic.environment.clientIdSet ? "Set" : "Missing"} + +
+
+
+

DISCORD_PUBLIC_KEY

+
+ {diagnostic.environment.publicKeySet ? ( + + ) : ( + + )} + + {diagnostic.environment.publicKeySet ? "Set" : "Missing"} + +
+
+
+
+ + {/* Token Validation */} +
+

+ {diagnostic.tokenValidation.minLengthMet ? ( + + ) : ( + + )} + Token Validation +

+
+
+

Token Length

+
+ + {diagnostic.tokenValidation.length} characters + + + {diagnostic.tokenValidation.minLengthMet + ? "✓ Valid" + : "✗ Too Short"} + +
+
+ {diagnostic.tokenValidation.preview && ( +
+

Token Preview

+

+ {diagnostic.tokenValidation.preview} +

+
+ )} +
+
+ + {/* API Test Results */} +
+

+ {diagnostic.testRequest.status.startsWith("✅") ? ( + + ) : diagnostic.testRequest.status.startsWith("❌") ? ( + + ) : ( + + )} + Discord API Test +

+
+
+

Endpoint

+

+ {diagnostic.testRequest.url} +

+
+
+

Status

+

{diagnostic.testRequest.status}

+
+ {diagnostic.testRequest.responseCode && ( +
+

Response Code

+

+ {diagnostic.testRequest.responseCode} +

+
+ )} + {diagnostic.testRequest.error && ( +
+

Error

+

+ {diagnostic.testRequest.error} +

+
+ )} +
+
+ + {/* Recommendations */} +
+

Recommendations

+
+ {diagnostic.recommendations.length === 0 ? ( +

✅ All systems operational!

+ ) : ( + diagnostic.recommendations.map((rec, idx) => ( +
+ {rec.startsWith("✅") ? ( + + ) : rec.startsWith("❌") ? ( + + ) : ( + + )} +

{rec}

+
+ )) + )} +
+
+ + {/* Last Updated */} +

+ Last updated: {new Date(diagnostic.timestamp).toLocaleString()} +

+
+ )} +
+ ); +}