"use client" import { useEffect, useState } from "react" import { Check, Copy } from "lucide-react" import { toast } from "sonner" import { TechBrandSelectLabel } from "@/components/admin/settings/tech-brand-select-label" import { FieldGroup } from "@/components/admin/settings/field-group" import { useOrgSettingsStore } from "@/lib/admin-settings/org-settings-store" import type { DriveMountOAuthProvider, DriveMountOAuthSettings } from "@/lib/admin-settings/org-settings-types" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Switch } from "@/components/ui/switch" import { buildDriveMountOAuthRedirectURI } from "@/lib/drive/drive-mount-oauth" const PROVIDERS: { id: DriveMountOAuthProvider label: string hint: string icon: string }[] = [ { id: "google", label: "Google Drive", hint: "Console Google Cloud — API Drive, redirect URI ci-dessous", icon: "logos:google-drive", }, { id: "dropbox", label: "Dropbox", hint: "App Dropbox — permissions files.metadata.read, files.content.read/write", icon: "logos:dropbox", }, { id: "microsoft", label: "Microsoft OneDrive", hint: "Azure AD — Microsoft Graph Files.ReadWrite", icon: "logos:microsoft-onedrive", }, ] const SECRET_KEYS: Record = { google: "mount_oauth_google", dropbox: "mount_oauth_dropbox", microsoft: "mount_oauth_microsoft", } export function DriveMountOAuthSection({ draft, onChange, embedded = false, }: { draft: DriveMountOAuthSettings onChange: (next: DriveMountOAuthSettings) => void embedded?: boolean }) { const secrets = useOrgSettingsStore((s) => s.meta?.secrets) const [redirectUri, setRedirectUri] = useState("") const [copied, setCopied] = useState(false) useEffect(() => { setRedirectUri(buildDriveMountOAuthRedirectURI()) }, []) const updateProvider = (provider: DriveMountOAuthProvider, patch: Partial) => { onChange({ ...draft, [provider]: { ...draft[provider], ...patch }, }) } const copyRedirectUri = async () => { const uri = redirectUri || buildDriveMountOAuthRedirectURI() try { await navigator.clipboard.writeText(uri) setCopied(true) toast.success("URI de redirection copiée") window.setTimeout(() => setCopied(false), 2000) } catch { toast.error("Impossible de copier l'URI") } } return (
{!embedded ? (

Connexion cloud (OAuth)

Permet aux utilisateurs de monter Google Drive, Dropbox ou OneDrive depuis UltiDrive.

) : null}

Basée sur l'URL actuelle du navigateur. Enregistrez-la chez chaque fournisseur OAuth (Google, Dropbox, Microsoft).

{PROVIDERS.map(({ id, label, hint, icon }) => { const provider = draft[id] const configured = Boolean(secrets?.[SECRET_KEYS[id]]?.configured) return (
{provider.enabled ? (
updateProvider(id, { client_id: e.target.value })} autoComplete="off" /> updateProvider(id, { client_secret: e.target.value })} placeholder={configured ? "•••••••• (laisser vide pour conserver)" : "Coller le secret"} autoComplete="off" /> {configured && !provider.client_secret.trim() ? (

Secret configuré

) : null}
) : null}
) })}
) }