"use client" import { useEffect, useState } from "react" import { useRouter, useSearchParams } from "next/navigation" import { Loader2 } from "lucide-react" import { MeetHeader } from "@/components/meet/meet-header" import { MeetRoomFrame } from "@/components/meet/meet-room-frame" import { Button } from "@/components/ui/button" import { useMeetConfig, useMeetRoomToken } from "@/lib/api/hooks/use-meet-queries" import { meetRoomPath, parseMeetUrl } from "@/lib/meet/meet-url" export function MeetJoinClient() { const router = useRouter() const searchParams = useSearchParams() const rawUrl = searchParams.get("u") ?? "" const parsed = parseMeetUrl(rawUrl) const { data: config, isLoading: configLoading } = useMeetConfig() const roomToken = useMeetRoomToken() const [embedUrl, setEmbedUrl] = useState(null) const [error, setError] = useState(null) useEffect(() => { if (!parsed) { setError("Lien de réunion invalide") return } if (parsed.jwt) { setEmbedUrl(parsed.embedUrl) return } if (!config?.enabled) return let cancelled = false void roomToken .mutateAsync(parsed.room) .then((token) => { if (!cancelled) setEmbedUrl(token.meet_url) }) .catch(() => { if (!cancelled) setError("Impossible de rejoindre la réunion") }) return () => { cancelled = true } // eslint-disable-next-line react-hooks/exhaustive-deps -- join once when URL/config ready }, [rawUrl, config?.enabled]) if (!rawUrl) { return (
Lien de réunion manquant.
) } if (configLoading || (!embedUrl && !error && parsed && !parsed.jwt)) { return (
Préparation de la salle…
) } if (error || !config?.enabled) { return (

{error ?? "UltiMeet n'est pas activé sur cette instance."}

) } if (!embedUrl || !parsed) return null return (
router.push(meetRoomPath(parsed.room))} > Ouvrir en plein écran } />
) }