"use client" import { useState } from "react" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Card, CardContent, CardDescription, CardHeader, } from "@/components/ui/card" import { deriveRuntimeConfig, ultiSpaceOrigin, type RuntimeConfig, } from "@/lib/runtime-config" import { persistNativeRuntimeConfig } from "@/lib/runtime-config/native" import { cn } from "@/lib/utils" const CARD_CLASS = cn( "w-full gap-4 border-0 bg-transparent px-4 py-6 shadow-none", "sm:gap-5 sm:bg-card sm:px-8 sm:py-8" ) /** * Pre-login server picker for the native shells: choose the hosted UltiSpace or * point at a self-hosted instance. OIDC discovery derives the full runtime * config, which is persisted to the shared secure store (cross-app SSO). */ export function ServerPicker({ onSelected, }: { onSelected: (cfg: RuntimeConfig) => void }) { const [mode, setMode] = useState<"choose" | "self">("choose") const [url, setUrl] = useState("") const [loading, setLoading] = useState(false) const [error, setError] = useState(null) async function select(rawOrigin: string, label?: string) { setLoading(true) setError(null) try { const cfg = await deriveRuntimeConfig(rawOrigin, { label }) await persistNativeRuntimeConfig(cfg) onSelected(cfg) } catch (err) { setError(err instanceof Error ? err.message : "Connexion impossible.") } finally { setLoading(false) } } return (
UltiSuite
Choisis ton serveur pour te connecter. {error ? (

{error}

) : null}
{mode === "choose" ? ( <> ) : (
{ e.preventDefault() if (url.trim()) void select(url.trim()) }} > setUrl(e.target.value)} disabled={loading} />
)}
) }