Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 63 additions & 25 deletions apps/web/src/app/settings/integrations/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
SelectValue,
} from '@/components/ui/select';
import { Skeleton } from '@/components/ui/skeleton';
import { ArrowLeft, Cable, Plug2, Loader2, ExternalLink, AlertCircle, Package, Clock } from 'lucide-react';
import { ArrowLeft, Cable, Calendar, Plug2, Loader2, AlertCircle, Package, Clock, CheckCircle2 } from 'lucide-react';
import { toast } from 'sonner';
import { useProviders, useUserConnections, useAvailableBuiltins } from '@/hooks/useIntegrations';
import { useProviders, useUserConnections, useAvailableBuiltins, useGoogleCalendarStatus } from '@/hooks/useIntegrations';
import { IntegrationStatusBadge } from '@/components/integrations/IntegrationStatusBadge';
import { ConnectIntegrationDialog } from '@/components/integrations/ConnectIntegrationDialog';
import { DisconnectWithAgentCount } from '@/components/integrations/DisconnectConfirmDialog';
Expand All @@ -34,6 +34,7 @@ export default function IntegrationsSettingsPage() {
const { connections, isLoading: loadingConnections, error: connectionsError, mutate: mutateConnections } = useUserConnections();

const { builtins, isLoading: loadingBuiltins, error: builtinsError, mutate: mutateBuiltins } = useAvailableBuiltins();
const { connected: gcalConnected, connection: gcalConnection, error: gcalError, isLoading: gcalLoading } = useGoogleCalendarStatus();

const [connectProvider, setConnectProvider] = useState<SafeProvider | null>(null);
const [disconnectConnection, setDisconnectConnection] = useState<SafeConnection | null>(null);
Expand Down Expand Up @@ -103,13 +104,6 @@ export default function IntegrationsSettingsPage() {

const isLoading = loadingProviders || loadingConnections;

const getProviderDetailHref = (connection: SafeConnection) => {
if (connection.provider?.slug === 'google-calendar') {
return '/settings/integrations/google-calendar';
}
return null;
};

return (
<div className="container mx-auto px-4 py-10 sm:px-6 lg:px-10 max-w-2xl">
<div className="mb-8">
Expand All @@ -129,6 +123,66 @@ export default function IntegrationsSettingsPage() {
</div>

<div className="space-y-6">
{/* Google Calendar */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Calendar className="h-5 w-5" />
Google Calendar
</CardTitle>
<CardDescription>
Sync events with Google Calendar.
</CardDescription>
</CardHeader>
<CardContent>
{gcalLoading ? (
<Skeleton className="h-16 w-full" />
) : gcalError ? (
<div className="flex items-center gap-2 p-4 text-sm text-destructive bg-destructive/10 rounded-lg">
<AlertCircle className="h-4 w-4" />
<span>Failed to load Google Calendar status</span>
</div>
) : gcalConnected && gcalConnection ? (
Comment on lines +138 to +145

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle Google Calendar status fetch errors distinctly

When /api/integrations/google-calendar/status fails (for example due to a transient 500), useGoogleCalendarStatus() defaults to connected: false/connection: null, and this branch renders the “Not connected” state. That makes an existing integration look disconnected and can send users through unnecessary re-setup; add an explicit error state (or only show “Not connected” when !error) so fetch failures are not interpreted as real disconnects.

Useful? React with 👍 / 👎.

<div className="flex items-center justify-between p-3 border rounded-lg bg-card">
<div className="flex items-center gap-3 min-w-0">
<CheckCircle2 className="h-5 w-5 text-green-500 flex-shrink-0" />
<div className="min-w-0">
<span className="font-medium">Connected</span>
<p className="text-xs text-muted-foreground truncate">
{gcalConnection.googleEmail}
</p>
</div>
</div>
<Button
size="sm"
variant="outline"
onClick={() => router.push('/settings/integrations/google-calendar')}
>
Manage
</Button>
</div>
) : (
<div className="flex items-center justify-between p-3 border rounded-lg bg-card">
<div className="flex items-center gap-3 min-w-0">
<Calendar className="h-5 w-5 text-muted-foreground flex-shrink-0" />
<div className="min-w-0">
<span className="font-medium">Not connected</span>
<p className="text-xs text-muted-foreground">
Connect your Google Calendar to sync events.
</p>
</div>
</div>
<Button
size="sm"
onClick={() => router.push('/settings/integrations/google-calendar')}
>
Set up
</Button>
</div>
)}
</CardContent>
</Card>

{/* Connected Integrations */}
<Card>
<CardHeader>
Expand Down Expand Up @@ -161,10 +215,8 @@ export default function IntegrationsSettingsPage() {
<ConnectionRow
key={connection.id}
connection={connection}
detailHref={getProviderDetailHref(connection)}
updatingVisibility={updatingVisibility === connection.id}
onVisibilityChange={(v) => handleVisibilityChange(connection.id, v)}
onDetail={(href) => router.push(href)}
onDisconnect={() => setDisconnectConnection(connection)}
/>
))}
Expand Down Expand Up @@ -334,17 +386,13 @@ function formatRelativeTime(dateStr: string): string {

function ConnectionRow({
connection,
detailHref,
updatingVisibility,
onVisibilityChange,
onDetail,
onDisconnect,
}: {
connection: SafeConnection;
detailHref: string | null;
updatingVisibility: boolean;
onVisibilityChange: (visibility: string) => void;
onDetail: (href: string) => void;
onDisconnect: () => void;
}) {
const accountInfo = connection.accountMetadata;
Expand Down Expand Up @@ -400,16 +448,6 @@ function ConnectionRow({
</SelectContent>
</Select>
)}
{detailHref && (
<Button
variant="ghost"
size="sm"
aria-label={`${connection.name} details`}
onClick={() => onDetail(detailHref)}
>
<ExternalLink className="h-3.5 w-3.5" />
</Button>
)}
<Button
variant="ghost"
size="sm"
Expand Down
9 changes: 8 additions & 1 deletion apps/web/src/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useMCP } from "@/hooks/useMCP";
import { useAuth } from "@/hooks/useAuth";
import { useBillingVisibility } from "@/hooks/useBillingVisibility";
import { Button } from "@/components/ui/button";
import { User, Plug2, Key, ArrowLeft, CreditCard, Bell, Shield, ChevronRight, Keyboard, Sparkles, Eye, Cable } from "lucide-react";
import { User, Plug2, Key, ArrowLeft, CreditCard, Bell, Shield, ChevronRight, Keyboard, Sparkles, Eye, Cable, Calendar } from "lucide-react";

interface SettingsItem {
title: string;
Expand Down Expand Up @@ -132,6 +132,13 @@ export default function SettingsPage() {
{
title: "Integrations",
items: filterItems([
{
title: "Google Calendar",
description: "Sync events with Google Calendar",
icon: Calendar,
href: "/settings/integrations/google-calendar",
available: true,
},
{
title: "Service Connections",
description: "Connect external APIs and services to your AI assistants",
Expand Down
23 changes: 23 additions & 0 deletions apps/web/src/hooks/useIntegrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,29 @@ export function useConnectionGrantCount(connectionId: string | null) {
return { count: data?.total ?? 0, error, isLoading };
}

export function useGoogleCalendarStatus() {
const { data, error, isLoading } = useSWR<{
connected: boolean;
connection: {
status: string;
googleEmail: string;
lastSyncAt: string | null;
} | null;
syncedEventCount: number;
}>(
'/api/integrations/google-calendar/status',
fetcher,
{ revalidateOnFocus: false }
);
return {
connected: data?.connected ?? false,
connection: data?.connection ?? null,
syncedEventCount: data?.syncedEventCount ?? 0,
error,
isLoading,
};
}

export function useIntegrationAuditLogs(driveId: string | null, params: AuditLogsParams = {}) {
const searchParams = new URLSearchParams();
if (params.limit != null) searchParams.set('limit', String(params.limit));
Expand Down
Loading