"use client" import React, { useState } from "react"; import { GoogleDrivePicker } from "@/components/google-drive-picker" import { useTask } from "@/contexts/task-context" interface GoogleDriveFile { id: string; name: string; mimeType: string; webViewLink?: string; iconLink?: string; } export default function ConnectorsPage() { const { addTask } = useTask() const [selectedFiles, setSelectedFiles] = useState([]); const [isSyncing, setIsSyncing] = useState(false); const [syncResult, setSyncResult] = useState<{ processed?: number; total?: number; status?: string; error?: string; added?: number; errors?: number; } | null>(null); const handleFileSelection = (files: GoogleDriveFile[]) => { setSelectedFiles(files); }; const handleSync = async (connector: { connectionId: string, type: string }) => { if (!connector.connectionId || selectedFiles.length === 0) return setIsSyncing(true) setSyncResult(null) try { const syncBody: { connection_id: string; max_files?: number; selected_files?: string[]; } = { connection_id: connector.connectionId, selected_files: selectedFiles.map(file => file.id) } const response = await fetch(`/api/connectors/${connector.type}/sync`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(syncBody), }) const result = await response.json() if (response.status === 201) { const taskId = result.task_id if (taskId) { addTask(taskId) setSyncResult({ processed: 0, total: selectedFiles.length, status: 'started' }) } } else if (response.ok) { setSyncResult(result) } else { console.error('Sync failed:', result.error) setSyncResult({ error: result.error || 'Sync failed' }) } } catch (error) { console.error('Sync error:', error) setSyncResult({ error: 'Network error occurred' }) } finally { setIsSyncing(false) } }; return (

Connectors

This is a demo page for the Google Drive picker component. For full connector functionality, visit the Settings page.

{selectedFiles.length > 0 && (
{syncResult && (
{syncResult.error ? (
Error: {syncResult.error}
) : syncResult.status === 'started' ? (
Sync started for {syncResult.total} files. Check the task notification for progress.
) : (
Processed: {syncResult.processed || 0}
Added: {syncResult.added || 0}
{syncResult.errors &&
Errors: {syncResult.errors}
}
)}
)}
)}
); }