"use client"; import Link from "next/link"; import { HoverCard, HoverCardTrigger, HoverCardContent } from "@/components/ui/hover-card"; import { AlertTriangleIcon } from "lucide-react"; import { useDomain } from "@/hooks/useDomain"; import { getConnections } from "@/actions"; import { useState } from "react"; import { useEffect } from "react"; import { isServiceError } from "@/lib/utils"; import { SyncStatusMetadataSchema } from "@/lib/syncStatusMetadataSchema"; interface Warning { connectionId?: number; connectionName?: string; } export const WarningNavIndicator = () => { const domain = useDomain(); const [warnings, setWarnings] = useState([]); useEffect(() => { const fetchWarnings = async () => { const connections = await getConnections(domain); const warnings: Warning[] = []; if (!isServiceError(connections)) { for (const connection of connections) { const parseResult = SyncStatusMetadataSchema.safeParse(connection.syncStatusMetadata); if (parseResult.success && parseResult.data.notFound) { const { notFound } = parseResult.data; if (notFound.users.length > 0 || notFound.orgs.length > 0 || notFound.repos.length > 0) { warnings.push({ connectionId: connection.id, connectionName: connection.name }); } } } } setWarnings(prevWarnings => { // Only update if the warnings have actually changed const warningsChanged = prevWarnings.length !== warnings.length || prevWarnings.some((warning, idx) => warning.connectionId !== warnings[idx]?.connectionId || warning.connectionName !== warnings[idx]?.connectionName ); return warningsChanged ? warnings : prevWarnings; }); }; fetchWarnings(); const intervalId = setInterval(fetchWarnings, 1000); return () => clearInterval(intervalId); }, [domain]); if (warnings.length === 0) { return null; } return (
{warnings.length}

Missing References

The following connections have references that could not be found:

{warnings.slice(0, 10).map(warning => (
{warning.connectionName}
))} {warnings.length > 10 && (
And {warnings.length - 10} more...
)}
); };