import React, { useCallback } from "react"; import { useFetcher } from "@remix-run/react"; import { Button } from "~/components/ui/button"; import { Check } from "lucide-react"; interface ConnectedAccountSectionProps { activeAccount?: { id: string; createdAt: string; }; } export function ConnectedAccountSection({ activeAccount, }: ConnectedAccountSectionProps) { const disconnectFetcher = useFetcher(); const handleDisconnect = useCallback(() => { if (!activeAccount?.id) return; disconnectFetcher.submit( { integrationAccountId: activeAccount.id, }, { method: "post", action: "/api/v1/integration_account/disconnect", encType: "application/json", }, ); }, [activeAccount?.id, disconnectFetcher]); React.useEffect(() => { if (disconnectFetcher.state === "idle" && disconnectFetcher.data) { window.location.reload(); } }, [disconnectFetcher.state, disconnectFetcher.data]); if (!activeAccount) return null; return (
Connected on{" "} {new Date(activeAccount.createdAt).toLocaleDateString()}