"use client"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Cloud, Loader2, Trash2, X } from "@/components/icons/platform-icons"; import { useEffect, useRef } from "react"; import { useGoogleDriveConnections, useRemoveGoogleDriveConnection } from "@/modules/files/hooks/useGoogleDrive"; import { useQueryClient } from "@tanstack/react-query"; import { queryKeys } from "@/lib/shared/query-keys"; type GoogleDriveDialogProps = { isOpen: boolean; onClose: () => void; }; export function GoogleDriveDialog({ isOpen, onClose }: GoogleDriveDialogProps) { const connectionsQuery = useGoogleDriveConnections(); const removeConnection = useRemoveGoogleDriveConnection(); const queryClient = useQueryClient(); const popupRef = useRef(null); useEffect(() => { function handleMessage(event: MessageEvent) { if (event.origin !== window.location.origin) return; if (event.data?.type === "gd-oauth-complete") { void queryClient.invalidateQueries({ queryKey: queryKeys.googleDriveConnections }); popupRef.current = null; } } window.addEventListener("message", handleMessage); return () => window.removeEventListener("message", handleMessage); }, [queryClient]); function handleConnect() { const popup = window.open( "/api/v1/files/google-drive/auth", "google-drive-auth", "width=600,height=700,left=200,top=100", ); if (popup) popupRef.current = popup; } const connections = connectionsQuery.data?.connections ?? []; const isConfigured = connectionsQuery.data?.configured ?? true; return ( !open && onClose()}> Google Drive Connect and manage Google Drive accounts. {/* Window chrome title bar */}
{/* Traffic lights */}
{/* Centered title */}
Google Drive
{/* Right gutter — balances traffic lights */}
{/* Body */}
{connectionsQuery.isLoading ? (
) : !isConfigured ? (

Google Drive not configured

Add GOOGLE_CLIENT_ID{" "} and{" "} GOOGLE_CLIENT_SECRET{" "} to your environment variables.

) : connections.length === 0 ? (

No accounts connected

Connect a Google account to access your Drive files.

) : (
    {connections.map((conn) => (
  • {conn.displayName ?? conn.email}

    {conn.email}

  • ))}
)}
{/* Footer */} {isConfigured && (
)} {connectionsQuery.error && isConfigured ? (
{connectionsQuery.error instanceof Error ? connectionsQuery.error.message : "Unknown error"}
) : null}
); }