import { useMemo, useState } from "react"; import { Form, useActionData, useLoaderData, useNavigate, useNavigation } from "react-router"; import { useTranslation } from "react-i18next"; import { FeatherChevronRight, FeatherPlus, FeatherUserPlus, FeatherUsers, } from "@subframe/core"; import * as SubframeCore from "@subframe/core"; import { useRootData } from "~/utils/data/useRootData"; import { Avatar } from "~/ui/components/Avatar"; import { Button } from "~/ui/components/Button"; import { Card } from "~/ui/components/Card"; import { DropdownMenu } from "~/ui/components/DropdownMenu"; import { ErrorState } from "~/ui/components/ErrorState"; import { Logo } from "~/ui/components/Logo"; import { SearchInput } from "~/ui/components/SearchInput"; import { Tag_Label } from "~/ui/components/Tag_Label"; import type { ActionData, LoaderData } from "~/routeModules/auth/select-tenant.impl"; // D-D0a — Flow "Login Tenantauswahl (Admin)". 1:1 an Davids Subframe-Page "Tenantauswahl": Logo + // Karten-Box (Such-Feld immer sichtbar, Profil-Karten, Divider, "Profil hinzufuegen"-Dropdown). An die // echten Tenants des Users (Loader-VM) verdrahtet: Karte = Form-Submit -> Action (CSRF + Membership- // Check serverseitig) -> Tenant-Space. SearchInput filtert client-seitig. Fehler/Empty via ~/ui ErrorState. // data-ui-id-Marker bleiben beim spaeteren Subframe-Swap erhalten. export default function SelectTenantRoute() { const { t } = useTranslation(); const { csrf } = useRootData(); const { vm } = useLoaderData(); const actionData = useActionData(); const navigate = useNavigate(); const navigation = useNavigation(); const isSubmitting = navigation.state !== "idle"; const [query, setQuery] = useState(""); const tenants = vm.status === "ready" ? vm.data.tenants : []; const visibleTenants = useMemo(() => { const q = query.trim().toLowerCase(); if (!q) return tenants; return tenants.filter((tenant) => tenant.name.toLowerCase().includes(q)); }, [tenants, query]); return (

{t("account.selectTenant.title")}

{t("account.selectTenant.subtitle")}

{actionData?.error ? ( ) : null} {vm.status === "ready" ? ( setQuery(event.target.value)} aria-label={t("account.selectTenant.searchPlaceholder")} data-ui-id="ui.auth.selectTenant.search" /> ) : null} {vm.status === "empty" ? (

{t("account.selectTenant.empty")}

) : (
{visibleTenants.length === 0 ? (

{t("account.selectTenant.noResults")}

) : ( visibleTenants.map((tenant) => (
)) )}
)}
} onClick={() => navigate("/login")} data-ui-id="ui.auth.selectTenant.addExisting" > {t("account.selectTenant.addExisting")} } onClick={() => navigate("/new-account")} data-ui-id="ui.auth.selectTenant.addNew" > {t("account.selectTenant.addNew")}
); }