Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -0,0 +1,171 @@
// R-P2b — groups bulk add/remove (interim UI per AD-28). David parked groups
// for RBAC V2, so this is a `~/ui` preview screen with an open design-nachzug:
// a real Dialog (M 720) with the group's members and the remaining tenant
// members as checkbox pick lists, wired to the idempotent bulk backend ops.
// Pure presentational: VM + action callbacks as props, no loader access.
import { useState } from "react";
import { useTranslation } from "react-i18next";
import type { GroupMemberRow, GroupsDetailVM } from "@hivegrid/view-models";
import { filterGroupMemberRows } from "@hivegrid/view-models";
import { Avatar } from "~/ui/components/Avatar";
import { Button } from "~/ui/components/Button";
import { Checkbox } from "~/ui/components/Checkbox";
import { Dialog } from "~/ui/components/Dialog";
import { EmptyState } from "~/ui/components/EmptyState";
import { SearchInput } from "~/ui/components/SearchInput";
export type GroupMembersActions = {
/** Posts the `bulk-add` intent (idempotent addUsersToGroup). */
onAdd: (userIds: string[]) => void;
/** Posts the `bulk-remove` intent (idempotent removeUsersFromGroup). */
onRemove: (userIds: string[]) => void;
};
export function GroupMembersDialog({
vm,
actions,
submitting,
onClose,
}: {
vm: GroupsDetailVM;
actions: GroupMembersActions;
submitting: boolean;
onClose: () => void;
}) {
const { t } = useTranslation();
const [query, setQuery] = useState("");
const [selectedMembers, setSelectedMembers] = useState<ReadonlySet<string>>(new Set());
const [selectedCandidates, setSelectedCandidates] = useState<ReadonlySet<string>>(new Set());
if (vm.status !== "ready" || !vm.data) return null;
const data = vm.data;
const members = filterGroupMemberRows(data.memberRows, query);
const candidates = filterGroupMemberRows(data.candidateRows, query);
function toggle(set: ReadonlySet<string>, userId: string, next: (value: Set<string>) => void) {
const updated = new Set(set);
if (updated.has(userId)) updated.delete(userId);
else updated.add(userId);
next(updated);
}
return (
<Dialog open onOpenChange={(open: boolean) => (open ? undefined : onClose())}>
<Dialog.Content className="w-[720px] max-w-[95vw] p-6">
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.groups.bulk.dialog">
<div className="flex flex-col gap-0">
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
{t("settings.members.groups.bulk.title", { name: data.name })}
</span>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
{t("settings.members.groups.bulk.description")}
</span>
</div>
<SearchInput
className="max-w-[320px]"
placeholder={t("settings.members.groups.bulk.searchPlaceholder")}
hideShortcut
value={query}
onChange={(event) => setQuery(event.target.value)}
/>
<div className="flex w-full gap-6 mobile:flex-col">
<PickList
titleKey="settings.members.groups.bulk.membersTitle"
rows={members}
emptyKey={data.emptyMembersKey}
selected={selectedMembers}
onToggle={(userId) => toggle(selectedMembers, userId, setSelectedMembers)}
dataUiId="ui.settings.groups.bulk.members"
/>
<PickList
titleKey="settings.members.groups.bulk.candidatesTitle"
rows={candidates}
emptyKey={data.emptyCandidatesKey}
selected={selectedCandidates}
onToggle={(userId) => toggle(selectedCandidates, userId, setSelectedCandidates)}
dataUiId="ui.settings.groups.bulk.candidates"
/>
</div>
<div className="flex w-full flex-wrap items-center justify-end gap-2">
<Button variant="tertiary" onClick={onClose}>
{t("shared.close")}
</Button>
{data.canManage ? (
<>
<Button
variant="destructive"
disabled={selectedMembers.size === 0}
loading={submitting}
onClick={() => {
actions.onRemove([...selectedMembers]);
setSelectedMembers(new Set());
}}
data-ui-id="ui.settings.groups.bulk.remove"
>
{t("settings.members.groups.bulk.removeSelected", { count: selectedMembers.size })}
</Button>
<Button
disabled={selectedCandidates.size === 0}
loading={submitting}
onClick={() => {
actions.onAdd([...selectedCandidates]);
setSelectedCandidates(new Set());
}}
data-ui-id="ui.settings.groups.bulk.add"
>
{t("settings.members.groups.bulk.addSelected", { count: selectedCandidates.size })}
</Button>
</>
) : null}
</div>
</div>
</Dialog.Content>
</Dialog>
);
}
function PickList({
titleKey,
rows,
emptyKey,
selected,
onToggle,
dataUiId,
}: {
titleKey: string;
rows: readonly GroupMemberRow[];
emptyKey: string;
selected: ReadonlySet<string>;
onToggle: (userId: string) => void;
dataUiId: string;
}) {
const { t } = useTranslation();
return (
<div className="flex w-full flex-col gap-4" data-ui-id={dataUiId}>
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t(titleKey)}</span>
{rows.length === 0 ? (
<EmptyState variant="no-results" title={t(emptyKey)} />
) : (
<div className="flex max-h-[40vh] w-full flex-col gap-2 overflow-y-auto">
{rows.map((row) => (
<div key={row.userId} className="flex w-full items-center justify-between gap-3">
<div className="flex items-center gap-3">
<Avatar size="small">{row.initials}</Avatar>
<div className="flex flex-col items-start">
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">{row.name}</span>
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">{row.email}</span>
</div>
</div>
<Checkbox checked={selected.has(row.userId)} onCheckedChange={() => onToggle(row.userId)} />
</div>
))}
</div>
)}
</div>
);
}
@@ -0,0 +1,69 @@
// R-P2b — D-P2 "WF-P2 Admin RBAC" M01 "Mitarbeiter einladen" form in David's
// Subframe optics (real Dialog content, S 560 — the members route wraps the
// outlet in Dialog.Content). Posts to the existing members/new action, keeping
// the invite contract (fields email/first-name/last-name/send-invitation-email,
// csrf, data-ui-id ui.settings.members.new.form) untouched.
// Role-at-invite from David's wireframe is NOT built: the invitation backend
// stores no role — roles are assigned in the list (D01) after acceptance.
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { Form, useActionData, useNavigation } from "react-router";
import toast from "react-hot-toast";
import type { NewMemberActionData } from "~/routes/app.$tenant/settings/members/new";
import { useRootData } from "~/utils/data/useRootData";
import { Button } from "~/ui/components/Button";
import { Checkbox } from "~/ui/components/Checkbox";
import { TextInput } from "~/ui/components/TextInput";
export function InviteMemberForm({ onClose }: { onClose: () => void }) {
const { t } = useTranslation();
const actionData = useActionData<NewMemberActionData>();
const navigation = useNavigation();
const rootData = useRootData();
const loading = navigation.state === "submitting";
// ~/ui Checkbox is controlled-only — mirror it into a hidden field for the action.
const [sendEmail, setSendEmail] = useState(false);
useEffect(() => {
if (actionData?.error) toast.error(actionData.error);
}, [actionData]);
return (
<Form method="post" className="flex w-full flex-col gap-6" data-ui-id="ui.settings.members.new.form">
{rootData.csrf && <input type="hidden" name="csrf" value={rootData.csrf} />}
<div className="flex flex-col gap-2">
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("settings.members.form.newTitle")}</span>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
{t("settings.members.form.newDescription")}
</span>
</div>
<div className="flex w-full flex-col gap-4">
<TextInput className="w-full" label={t("models.user.email")} showLabel>
<TextInput.Input name="email" type="email" required autoComplete="off" defaultValue={actionData?.fields?.email} />
</TextInput>
<div className="flex w-full gap-4">
<TextInput className="w-full" label={t("models.user.firstName")} showLabel>
<TextInput.Input name="first-name" required autoComplete="off" defaultValue={actionData?.fields?.firstName} />
</TextInput>
<TextInput className="w-full" label={t("models.user.lastName")} showLabel>
<TextInput.Input name="last-name" autoComplete="off" defaultValue={actionData?.fields?.lastName} />
</TextInput>
</div>
{/* Radix renders the form-proxy input for `name` (posts "on" when checked). */}
<Checkbox name="send-invitation-email" label={t("settings.members.sendInvitationEmail.title")} checked={sendEmail} onCheckedChange={setSendEmail} />
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
{t("settings.members.sendInvitationEmail.description")}
</span>
</div>
<div className="flex w-full items-center justify-end gap-2">
<Button type="button" variant="tertiary" onClick={onClose} data-ui-id="ui.settings.members.new.cancel">
{t("shared.cancel")}
</Button>
<Button type="submit" loading={loading} data-ui-id="ui.settings.members.new.submit">
{t("settings.members.actions.new")}
</Button>
</div>
</Form>
);
}
@@ -0,0 +1,420 @@
// R-P2b — D-P2 "WF-P2 Admin RBAC" S01 Mitarbeiterliste in David's Subframe optics.
// Pure presentational component: renders the server-built MembersListVM passed
// as a prop and reports mutations through injected actions (route posts the
// intents). No useLoaderData, no server imports (AD-28 / DoD A.5).
// S01 — list with search + role/status/2FA filters, invited rows inline
// D01 — inline role dropdown per row (checkbox items + link to S02)
// M03 — deactivate confirm as a real Dialog (XS 420, danger action)
// V01 — last-admin blocker dialog (server code "last-admin" opens it)
// Reassign-on-deactivate is Backlog/V2 by David's decision — plain confirm only.
import { useEffect, useState } from "react";
import { Link } from "react-router";
import { useTranslation } from "react-i18next";
import * as SubframeCore from "@subframe/core";
import { FeatherChevronDown, FeatherMoreHorizontal, FeatherPlus, FeatherTrash, FeatherUserCheck, FeatherUserX } from "@subframe/core";
import type { MembersListRow, MembersListVM } from "@hivegrid/view-models";
import { EMPTY_MEMBERS_FILTER, filterMembersRows, type MembersListFilterState, type MemberStatus } from "@hivegrid/view-models";
import { roleDisplayName } from "~/components/core/roles/roleDisplay";
import { Avatar } from "~/ui/components/Avatar";
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
import { Button } from "~/ui/components/Button";
import { Checkbox } from "~/ui/components/Checkbox";
import { Dialog } from "~/ui/components/Dialog";
import { DropdownMenu } from "~/ui/components/DropdownMenu";
import { EmptyState } from "~/ui/components/EmptyState";
import { IconButton } from "~/ui/components/IconButton";
import { SearchInput } from "~/ui/components/SearchInput";
import { Select } from "~/ui/components/Select";
import { Table } from "~/ui/components/Table";
import { Tabs } from "~/ui/components/Tabs";
// Non-empty sentinel for the "any" option (empty string is not a valid Select value).
const FILTER_ALL = "__all__";
const STATUS_OPTIONS: readonly MemberStatus[] = ["active", "invited", "inactive"];
export type MembersActions = {
/** Posts the existing `edit` intent (role add/remove) — D01 inline dropdown. */
onToggleRole: (input: { userId: string; roleId: string; add: boolean }) => void;
/** Posts the `deactivate` intent after the M03 confirm. */
onDeactivate: (input: { userId: string }) => void;
/** Posts the `reactivate` intent. */
onReactivate: (input: { userId: string }) => void;
/** Posts the existing `delete-invitation` intent. */
onDeleteInvitation: (input: { invitationId: string }) => void;
/** Opens the invite flow (M01 dialog route). */
onInvite: () => void;
};
export type MembersPageProps = {
vm: MembersListVM;
actions: MembersActions;
/** Tab bar between S01 (members) and S02 (roles & permissions), plus the D01 dropdown footer link. */
rolesTabHref: string | null;
/** Href of the member edit route (existing remove flow stays reachable). */
editRouteFor: (tenantUserId: string) => string;
/** True while a deactivate/reactivate submission is in flight. */
submitting: boolean;
/** Server said "last-admin" — opens the V01 blocker dialog. */
lastAdminBlocked: boolean;
};
export function MembersPage({ vm, actions, rolesTabHref, editRouteFor, submitting, lastAdminBlocked }: MembersPageProps) {
const { t } = useTranslation();
const [filter, setFilter] = useState<MembersListFilterState>(EMPTY_MEMBERS_FILTER);
const [deactivateRow, setDeactivateRow] = useState<MembersListRow | null>(null);
const [blockerDismissed, setBlockerDismissed] = useState(false);
// Server response (code "last-admin") re-opens the blocker; a new attempt resets the dismissal.
useEffect(() => {
if (lastAdminBlocked) setBlockerDismissed(false);
}, [lastAdminBlocked]);
// Close the confirm dialog when the pending submission finished.
useEffect(() => {
if (!submitting) setDeactivateRow(null);
}, [submitting]);
if (vm.status !== "ready" || !vm.data) {
return <div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.members.page" />;
}
const data = vm.data;
const rows = filterMembersRows(data.rows, filter);
const hasAnyRows = data.rows.length > 0 || data.pendingInvitations.length > 0;
return (
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.members.page">
{/* Header: title + description (0px rhythm) + invite CTA (M01) */}
<div className="flex flex-wrap items-start justify-between gap-4">
<div className="flex flex-col gap-0">
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("settings.members.title")}</span>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
{t("settings.members.description")}
</span>
</div>
{data.canInvite ? (
<Button icon={<FeatherPlus />} onClick={actions.onInvite} data-ui-id="ui.settings.members.invite">
{t("settings.members.actions.new")}
</Button>
) : null}
</div>
{/* Tabs: Mitarbeiter | Rollen und Berechtigungen (David's S01 structure) */}
{rolesTabHref ? (
<Tabs>
<Tabs.Item active>{t("settings.members.tabs.members")}</Tabs.Item>
<Link to={rolesTabHref} className="contents no-underline" data-ui-id="ui.settings.members.tab.roles">
<Tabs.Item>{t("settings.members.tabs.rolesAndPermissions")}</Tabs.Item>
</Link>
</Tabs>
) : null}
{/* Toolbar: search (name/email/phone) + role/status/2FA filters */}
<div className="flex flex-wrap items-end gap-4" data-ui-id="ui.settings.members.search">
<SearchInput
className="max-w-[320px]"
placeholder={t("settings.members.filters.searchPlaceholder")}
hideShortcut
value={filter.query}
onChange={(event) => setFilter((prev) => ({ ...prev, query: event.target.value }))}
/>
<Select
className="max-w-[200px]"
label={t("settings.members.filters.role")}
showLabel
value={filter.roleId ?? FILTER_ALL}
onValueChange={(value: string) => setFilter((prev) => ({ ...prev, roleId: value === FILTER_ALL ? null : value }))}
>
<Select.Item value={FILTER_ALL}>{t("settings.members.filters.all")}</Select.Item>
{data.assignableRoles.map((role) => (
<Select.Item key={role.id} value={role.id}>
{roleDisplayName(role, t)}
</Select.Item>
))}
</Select>
<Select
className="max-w-[180px]"
label={t("settings.members.columns.status")}
showLabel
value={filter.status ?? FILTER_ALL}
onValueChange={(value: string) => setFilter((prev) => ({ ...prev, status: value === FILTER_ALL ? null : (value as MemberStatus) }))}
>
<Select.Item value={FILTER_ALL}>{t("settings.members.filters.all")}</Select.Item>
{STATUS_OPTIONS.map((status) => (
<Select.Item key={status} value={status}>
{t(`settings.members.status.${status === "inactive" ? "deactivated" : status}`)}
</Select.Item>
))}
</Select>
<Select
className="max-w-[160px]"
label={t("settings.members.columns.twoFactor")}
showLabel
value={filter.mfa === null ? FILTER_ALL : filter.mfa ? "on" : "off"}
onValueChange={(value: string) => setFilter((prev) => ({ ...prev, mfa: value === FILTER_ALL ? null : value === "on" }))}
>
<Select.Item value={FILTER_ALL}>{t("settings.members.filters.all")}</Select.Item>
<Select.Item value="on">{t("settings.members.twoFactor.on")}</Select.Item>
<Select.Item value="off">{t("settings.members.twoFactor.off")}</Select.Item>
</Select>
</div>
{!hasAnyRows ? (
<div data-ui-id="ui.settings.members.empty">
<EmptyState title={t(data.emptyHeadlineKey)} body={t(data.emptyBodyKey)} />
</div>
) : (
<div className="w-full overflow-x-auto" data-ui-id="ui.settings.members.table">
<Table
header={
<Table.HeaderRow>
<Table.HeaderCell>{t("models.user.object")}</Table.HeaderCell>
<Table.HeaderCell>{t("models.role.object")}</Table.HeaderCell>
<Table.HeaderCell>{t("settings.members.columns.status")}</Table.HeaderCell>
<Table.HeaderCell>{t("settings.members.columns.twoFactor")}</Table.HeaderCell>
<Table.HeaderCell> </Table.HeaderCell>
</Table.HeaderRow>
}
>
{rows.map((row) => (
<MemberRow
key={row.tenantUserId}
row={row}
data={data}
actions={actions}
editRouteFor={editRouteFor}
rolesTabHref={rolesTabHref}
onAskDeactivate={() => setDeactivateRow(row)}
/>
))}
{/* Invited users appear inline with status "Eingeladen" (David's S01). */}
{data.pendingInvitations.map((invitation) => (
<Table.Row key={invitation.id} data-ui-id="ui.settings.members.row">
<Table.Cell>
<div className="flex items-center gap-3">
<Avatar size="small">{invitation.email.charAt(0).toUpperCase()}</Avatar>
<div className="flex flex-col items-start">
<span className="whitespace-nowrap text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
{invitation.name || invitation.email}
</span>
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
{invitation.email}
</span>
</div>
</div>
</Table.Cell>
<Table.Cell>
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-subtle">—</span>
</Table.Cell>
<Table.Cell>
<BadgeFeedback farbe="subtle-warning">{t("settings.members.status.invited")}</BadgeFeedback>
</Table.Cell>
<Table.Cell>
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-subtle">—</span>
</Table.Cell>
<Table.Cell>
<div className="flex grow shrink-0 basis-0 items-center justify-end">
{data.canManageMembers ? (
<IconButton
icon={<FeatherTrash />}
title={t("shared.delete")}
onClick={() => actions.onDeleteInvitation({ invitationId: invitation.id })}
data-ui-id="ui.settings.members.invitation.delete"
/>
) : null}
</div>
</Table.Cell>
</Table.Row>
))}
{rows.length === 0 && data.pendingInvitations.length === 0 ? null : null}
</Table>
{rows.length === 0 && data.pendingInvitations.length === 0 ? (
<div className="pt-4" data-ui-id="ui.settings.members.noMatches">
<EmptyState title={t(data.noMatchesKey)} body={t(data.emptyBodyKey)} />
</div>
) : null}
</div>
)}
{/* M03 — deactivate confirm (real Dialog, XS 420, danger action) */}
<Dialog open={deactivateRow !== null} onOpenChange={(open: boolean) => (open ? undefined : setDeactivateRow(null))}>
<Dialog.Content className="w-[420px] max-w-[90vw] p-4">
{deactivateRow ? (
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.members.deactivate.dialog">
<div className="flex flex-col gap-2">
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("settings.members.deactivate.title")}</span>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
{deactivateRow.name} · {deactivateRow.email}
</span>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
{t("settings.members.deactivate.body")}
</span>
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
{t("settings.members.deactivate.staysVisible")}
</span>
</div>
<div className="flex w-full items-center justify-end gap-2">
<Button variant="tertiary" onClick={() => setDeactivateRow(null)} data-ui-id="ui.settings.members.deactivate.cancel">
{t("shared.cancel")}
</Button>
<Button
variant="destructive"
loading={submitting}
onClick={() => actions.onDeactivate({ userId: deactivateRow.userId })}
data-ui-id="ui.settings.members.deactivate.confirm"
>
{t("settings.members.deactivate.confirm")}
</Button>
</div>
</div>
) : (
<div />
)}
</Dialog.Content>
</Dialog>
{/* V01 — last-admin blocker (server guard result, copy from David's wireframe) */}
<Dialog open={lastAdminBlocked && !blockerDismissed} onOpenChange={(open: boolean) => (open ? undefined : setBlockerDismissed(true))}>
<Dialog.Content className="w-[420px] max-w-[90vw] p-4">
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.members.lastAdmin.dialog">
<div className="flex flex-col gap-2">
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">{t("settings.members.errors.lastAdminTitle")}</span>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
{t("settings.members.errors.lastAdminBody")}
</span>
</div>
<div className="flex w-full items-center justify-end">
<Button onClick={() => setBlockerDismissed(true)} data-ui-id="ui.settings.members.lastAdmin.dismiss">
{t("settings.members.errors.lastAdminDismiss")}
</Button>
</div>
</div>
</Dialog.Content>
</Dialog>
</div>
);
}
function MemberRow({
row,
data,
actions,
editRouteFor,
rolesTabHref,
onAskDeactivate,
}: {
row: MembersListRow;
data: NonNullable<MembersListVM["data"]>;
actions: MembersActions;
editRouteFor: (tenantUserId: string) => string;
rolesTabHref: string | null;
onAskDeactivate: () => void;
}) {
const { t } = useTranslation();
const roleLabels = row.roles.map((role) => roleDisplayName(role, t)).join(", ");
const assignedRoleIds = new Set(row.roles.map((role) => role.id));
const badge =
row.status === "active" ? ("subtle-positive" as const) : row.status === "inactive" ? ("subtle-neutral" as const) : ("subtle-warning" as const);
return (
<Table.Row data-ui-id="ui.settings.members.row">
<Table.Cell>
<div className="flex items-center gap-3">
<Avatar size="small">{row.initials}</Avatar>
<div className="flex flex-col items-start">
<span className="whitespace-nowrap text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{row.name}</span>
<span className="whitespace-nowrap text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-tertiary">
{row.email}
{row.phone ? ` · ${row.phone}` : ""}
</span>
</div>
</div>
</Table.Cell>
<Table.Cell>
{/* D01 — inline role dropdown: checkbox item per role + link to S02 */}
{data.canEditRoles ? (
<SubframeCore.DropdownMenu.Root>
<SubframeCore.DropdownMenu.Trigger asChild>
<Button variant="tertiary" size="small" iconRight={<FeatherChevronDown />} data-ui-id="ui.settings.members.roleDropdown">
{roleLabels || t("settings.members.roles.none")}
</Button>
</SubframeCore.DropdownMenu.Trigger>
<SubframeCore.DropdownMenu.Portal>
<SubframeCore.DropdownMenu.Content side="bottom" align="start" sideOffset={4} asChild>
<DropdownMenu>
<div className="flex w-full flex-col items-start gap-2 px-3 py-2">
{data.assignableRoles.map((role) => (
<Checkbox
key={role.id}
label={roleDisplayName(role, t)}
checked={assignedRoleIds.has(role.id)}
onCheckedChange={(checked: boolean) => actions.onToggleRole({ userId: row.userId, roleId: role.id, add: checked })}
/>
))}
{/* D01 footer entry: jump to S02 ("Rollen und Berechtigungen bearbeiten"). */}
{rolesTabHref ? (
<Link to={rolesTabHref} className="no-underline" data-ui-id="ui.settings.members.roleDropdown.editRoles">
<span className="text-body-small-regular-0 font-body-small-regular-0 text-brand-brand-text-solid-default">
{t("settings.members.roles.editRolesLink")}
</span>
</Link>
) : null}
</div>
</DropdownMenu>
</SubframeCore.DropdownMenu.Content>
</SubframeCore.DropdownMenu.Portal>
</SubframeCore.DropdownMenu.Root>
) : (
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
{roleLabels || "—"}
</span>
)}
</Table.Cell>
<Table.Cell>
<BadgeFeedback farbe={badge}>{t(row.statusLabelKey)}</BadgeFeedback>
</Table.Cell>
<Table.Cell>
<BadgeFeedback farbe={row.mfaEnabled ? "subtle-positive" : "subtle-neutral"}>
{row.mfaEnabled ? t("settings.members.twoFactor.on") : t("settings.members.twoFactor.off")}
</BadgeFeedback>
</Table.Cell>
<Table.Cell>
<div className="flex grow shrink-0 basis-0 items-center justify-end">
{data.canManageMembers || data.canEditRoles ? (
<SubframeCore.DropdownMenu.Root>
<SubframeCore.DropdownMenu.Trigger asChild>
<IconButton icon={<FeatherMoreHorizontal />} data-ui-id="ui.settings.members.rowActions" />
</SubframeCore.DropdownMenu.Trigger>
<SubframeCore.DropdownMenu.Portal>
<SubframeCore.DropdownMenu.Content side="bottom" align="end" sideOffset={4} asChild>
<DropdownMenu>
{row.canDeactivate ? (
<DropdownMenu.DropdownItem icon={<FeatherUserX />} onClick={onAskDeactivate} data-ui-id="ui.settings.members.menu.deactivate">
{t("settings.members.menu.deactivate")}
</DropdownMenu.DropdownItem>
) : null}
{row.canReactivate ? (
<DropdownMenu.DropdownItem
icon={<FeatherUserCheck />}
onClick={() => actions.onReactivate({ userId: row.userId })}
data-ui-id="ui.settings.members.menu.reactivate"
>
{t("settings.members.menu.reactivate")}
</DropdownMenu.DropdownItem>
) : null}
{data.canManageMembers ? (
<Link to={editRouteFor(row.tenantUserId)} className="no-underline">
<DropdownMenu.DropdownItem icon={<FeatherTrash />}>{t("settings.members.menu.remove")}</DropdownMenu.DropdownItem>
</Link>
) : null}
</DropdownMenu>
</SubframeCore.DropdownMenu.Content>
</SubframeCore.DropdownMenu.Portal>
</SubframeCore.DropdownMenu.Root>
) : null}
</div>
</Table.Cell>
</Table.Row>
);
}
@@ -0,0 +1,531 @@
// R-P2b — D-P2 "WF-P2 Admin RBAC" S02 "Rollen und Berechtigungen" in David's
// Subframe optics. Pure presentational: renders the server-built RolesListVM
// and reports mutations through injected actions (route owns the fetcher).
// S02 — merged roles tab: search + type/in-use filters, Typ/Mitglieder columns
// M04A — "Rolle anlegen" basics step → M02
// M04B — "Rolle duplizieren" basics step (copied permissions) → M02
// M02 — large permission editor (L 1200): section sidebar + search + switches
// D03 — "Rolle in Nutzung blockiert" delete blocker
// David's "Status" column has no data-model backing (no Role.status) and the
// "Bereich/Kategorie" select has no Role.category — both omitted, tracked as
// design-nachzug. Role duplication = create with the source's permission set
// preloaded into the editor (same audited createWorkspaceRole path).
import { useEffect, useMemo, useState } from "react";
import { Link } from "react-router";
import { useTranslation } from "react-i18next";
import * as SubframeCore from "@subframe/core";
import { FeatherCopy, FeatherEdit2, FeatherMoreHorizontal, FeatherPlus, FeatherTrash } from "@subframe/core";
import type { RoleEditorInputPermission, RolesListRow, RolesListVM, RoleTypeKey } from "@hivegrid/view-models";
import { buildRoleEditorVM, filterRoleEditorSections, togglePermission, EMPTY_ROLES_FILTER, filterRolesRows, type RolesListFilterState } from "@hivegrid/view-models";
import { permissionDisplayDescription, permissionDisplayName, roleDisplayDescription, roleDisplayName } from "~/components/core/roles/roleDisplay";
import { useLocaleFormatters } from "~/locale/format";
import { Alert } from "~/ui/components/Alert";
import { Button } from "~/ui/components/Button";
import { Dialog } from "~/ui/components/Dialog";
import { DropdownMenu } from "~/ui/components/DropdownMenu";
import { EmptyState } from "~/ui/components/EmptyState";
import { IconButton } from "~/ui/components/IconButton";
import { SearchInput } from "~/ui/components/SearchInput";
import { Select } from "~/ui/components/Select";
import { Switch } from "~/ui/components/Switch";
import { Table } from "~/ui/components/Table";
import { Tabs } from "~/ui/components/Tabs";
import { TextArea } from "~/ui/components/TextArea";
import { TextInput } from "~/ui/components/TextInput";
const FILTER_ALL = "__all__";
export type RoleMutationInput = { name: string; description: string; permissionNames: string[] };
export type RolesActions = {
/** POSTs the existing create contract (roles/new, action=create). */
onCreate: (input: RoleMutationInput) => void;
/** POSTs the existing update contract (roles/:id, action=edit). */
onUpdate: (roleId: string, input: RoleMutationInput) => void;
/** POSTs the existing delete contract (roles/:id, action=delete). */
onDelete: (roleId: string) => void;
};
export type RolesPageProps = {
vm: RolesListVM;
/** App permission catalog feeding the M02 editor sections. */
editorCatalog: readonly RoleEditorInputPermission[];
/** roleId → assigned permission names (editor prefill + M04B duplication). */
rolePermissionNames: Readonly<Record<string, readonly string[]>>;
/** Tab bar back to S01 (members). */
membersTabHref: string;
actions: RolesActions;
submitting: boolean;
errorMessage: string | null;
/** Increments after a successful mutation — closes any open dialog. */
closeSignal: number;
};
/** M04A/M04B basics step. */
type BasicsState = { source: RolesListRow | null; name: string; description: string };
/** M02 editor state. roleId null = create (after M04A/M04B). */
type EditorState = {
roleId: string | null;
duplicatedFromName: string | null;
name: string;
description: string;
enabled: ReadonlySet<string>;
};
export function RolesPage({ vm, editorCatalog, rolePermissionNames, membersTabHref, actions, submitting, errorMessage, closeSignal }: RolesPageProps) {
const { t } = useTranslation();
const formatters = useLocaleFormatters();
const [filter, setFilter] = useState<RolesListFilterState>(EMPTY_ROLES_FILTER);
const [basics, setBasics] = useState<BasicsState | null>(null);
const [editor, setEditor] = useState<EditorState | null>(null);
const [deleteRow, setDeleteRow] = useState<RolesListRow | null>(null);
useEffect(() => {
if (closeSignal > 0) {
setBasics(null);
setEditor(null);
setDeleteRow(null);
}
}, [closeSignal]);
if (vm.status !== "ready" || !vm.data) {
return <div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.rolesAndPermissions.roles" />;
}
const data = vm.data;
const rows = filterRolesRows(data.rows, filter);
function openEditorFor(row: RolesListRow) {
setEditor({
roleId: row.id,
duplicatedFromName: null,
name: row.name,
description: row.description,
enabled: new Set(rolePermissionNames[row.id] ?? []),
});
}
function continueToPermissions(state: BasicsState) {
setBasics(null);
setEditor({
roleId: null,
duplicatedFromName: state.source ? state.source.name : null,
name: state.name,
description: state.description,
enabled: new Set(state.source ? (rolePermissionNames[state.source.id] ?? []) : []),
});
}
return (
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.rolesAndPermissions.roles">
{/* Header: title + subtitle (0px rhythm) + create CTA (M04A) */}
<div className="flex flex-wrap items-start justify-between gap-4">
<div className="flex flex-col gap-0">
<span className="text-heading-2 font-heading-2 text-text-neutral-primary">{t("settings.members.tabs.rolesAndPermissions")}</span>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
{t("settings.rolesAndPermissions.subtitle")}
</span>
</div>
{data.canCreate ? (
<Button
icon={<FeatherPlus />}
onClick={() => setBasics({ source: null, name: "", description: "" })}
data-ui-id="ui.settings.rolesAndPermissions.roles.new"
>
{t("settings.rolesAndPermissions.create")}
</Button>
) : null}
</div>
{/* Tabs: Mitarbeiter | Rollen und Berechtigungen (shared with S01) */}
<Tabs>
<Link to={membersTabHref} className="contents no-underline" data-ui-id="ui.settings.rolesAndPermissions.tab.members">
<Tabs.Item>{t("settings.members.tabs.members")}</Tabs.Item>
</Link>
<Tabs.Item active>{t("settings.members.tabs.rolesAndPermissions")}</Tabs.Item>
</Tabs>
{/* Toolbar: search (name/description) + type/in-use filters */}
<div className="flex flex-wrap items-end gap-4" data-ui-id="ui.settings.rolesAndPermissions.roles.filter">
<SearchInput
className="max-w-[320px]"
placeholder={t("settings.rolesAndPermissions.filters.searchPlaceholder")}
hideShortcut
value={filter.query}
onChange={(event) => setFilter((prev) => ({ ...prev, query: event.target.value }))}
/>
<Select
className="max-w-[200px]"
label={t("settings.rolesAndPermissions.columns.type")}
showLabel
value={filter.type ?? FILTER_ALL}
onValueChange={(value: string) => setFilter((prev) => ({ ...prev, type: value === FILTER_ALL ? null : (value as RoleTypeKey) }))}
>
<Select.Item value={FILTER_ALL}>{t("settings.members.filters.all")}</Select.Item>
<Select.Item value="system">{t("settings.rolesAndPermissions.type.system")}</Select.Item>
<Select.Item value="custom">{t("settings.rolesAndPermissions.type.custom")}</Select.Item>
</Select>
<Select
className="max-w-[200px]"
label={t("settings.rolesAndPermissions.filters.inUse")}
showLabel
value={filter.inUse === null ? FILTER_ALL : filter.inUse ? "yes" : "no"}
onValueChange={(value: string) => setFilter((prev) => ({ ...prev, inUse: value === FILTER_ALL ? null : value === "yes" }))}
>
<Select.Item value={FILTER_ALL}>{t("settings.members.filters.all")}</Select.Item>
<Select.Item value="yes">{t("settings.rolesAndPermissions.filters.inUseYes")}</Select.Item>
<Select.Item value="no">{t("settings.rolesAndPermissions.filters.inUseNo")}</Select.Item>
</Select>
</div>
{data.rows.length === 0 ? (
<div data-ui-id="ui.settings.rolesAndPermissions.roles.empty">
<EmptyState title={t(data.emptyHeadlineKey)} body={t(data.emptyBodyKey)} />
</div>
) : (
<div className="w-full overflow-x-auto">
<Table
header={
<Table.HeaderRow>
<Table.HeaderCell>{t("models.role.object")}</Table.HeaderCell>
<Table.HeaderCell>{t("models.role.description")}</Table.HeaderCell>
<Table.HeaderCell>{t("settings.rolesAndPermissions.columns.type")}</Table.HeaderCell>
<Table.HeaderCell>{t("settings.rolesAndPermissions.columns.members")}</Table.HeaderCell>
<Table.HeaderCell>{t("models.permission.plural")}</Table.HeaderCell>
<Table.HeaderCell> </Table.HeaderCell>
</Table.HeaderRow>
}
>
{rows.map((row) => (
<Table.Row key={row.id} data-ui-id="ui.settings.rolesAndPermissions.roles.row">
<Table.Cell>
<span className="whitespace-nowrap text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
{roleDisplayName({ name: row.name, description: row.description }, t)}
</span>
</Table.Cell>
<Table.Cell>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-tertiary">
{roleDisplayDescription({ name: row.name, description: row.description }, t) || "—"}
</span>
</Table.Cell>
<Table.Cell>
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
{t(row.typeLabelKey)}
</span>
</Table.Cell>
<Table.Cell>
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
{formatters.number(row.memberCount)}
</span>
</Table.Cell>
<Table.Cell>
<span className="whitespace-nowrap text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-secondary">
{t("models.permission.count", { count: row.permissionCount, formattedCount: formatters.number(row.permissionCount) })}
</span>
</Table.Cell>
<Table.Cell>
<div className="flex grow shrink-0 basis-0 items-center justify-end">
{row.canEdit || row.canDuplicate || row.canDelete ? (
<SubframeCore.DropdownMenu.Root>
<SubframeCore.DropdownMenu.Trigger asChild>
<IconButton icon={<FeatherMoreHorizontal />} data-ui-id="ui.settings.rolesAndPermissions.roles.rowActions" />
</SubframeCore.DropdownMenu.Trigger>
<SubframeCore.DropdownMenu.Portal>
<SubframeCore.DropdownMenu.Content side="bottom" align="end" sideOffset={4} asChild>
<DropdownMenu>
{row.canEdit ? (
<DropdownMenu.DropdownItem icon={<FeatherEdit2 />} onClick={() => openEditorFor(row)}>
{t("shared.edit")}
</DropdownMenu.DropdownItem>
) : null}
{row.canDuplicate ? (
<DropdownMenu.DropdownItem
icon={<FeatherCopy />}
onClick={() =>
setBasics({
source: row,
name: t("settings.rolesAndPermissions.duplicate.copyName", { name: row.name }),
description: row.description,
})
}
>
{t("settings.rolesAndPermissions.duplicate.action")}
</DropdownMenu.DropdownItem>
) : null}
{row.canDelete ? (
<DropdownMenu.DropdownItem icon={<FeatherTrash />} onClick={() => setDeleteRow(row)}>
{t("shared.delete")}
</DropdownMenu.DropdownItem>
) : null}
</DropdownMenu>
</SubframeCore.DropdownMenu.Content>
</SubframeCore.DropdownMenu.Portal>
</SubframeCore.DropdownMenu.Root>
) : null}
</div>
</Table.Cell>
</Table.Row>
))}
</Table>
{rows.length === 0 ? (
<div className="pt-4">
<EmptyState variant="no-results" title={t(data.noMatchesKey)} body={t(data.emptyBodyKey)} />
</div>
) : null}
</div>
)}
{/* M04A / M04B — basics step (S 560) */}
<Dialog open={basics !== null} onOpenChange={(open: boolean) => (open ? undefined : setBasics(null))}>
<Dialog.Content className="w-[560px] max-w-[90vw] p-6">
{basics ? <RoleBasicsDialog state={basics} onChange={setBasics} onContinue={continueToPermissions} onCancel={() => setBasics(null)} /> : <div />}
</Dialog.Content>
</Dialog>
{/* M02 — large permission editor (L 1200) */}
<Dialog open={editor !== null} onOpenChange={(open: boolean) => (open ? undefined : setEditor(null))}>
<Dialog.Content className="w-[1200px] max-w-[95vw] p-6">
{editor ? (
<RoleEditorDialog
state={editor}
onChange={setEditor}
editorCatalog={editorCatalog}
submitting={submitting}
errorMessage={errorMessage}
onCancel={() => setEditor(null)}
onSave={() => {
const input = { name: editor.name, description: editor.description, permissionNames: [...editor.enabled] };
if (editor.roleId) actions.onUpdate(editor.roleId, input);
else actions.onCreate(input);
}}
/>
) : (
<div />
)}
</Dialog.Content>
</Dialog>
{/* Delete confirm / D03 blocker (XS 420) */}
<Dialog open={deleteRow !== null} onOpenChange={(open: boolean) => (open ? undefined : setDeleteRow(null))}>
<Dialog.Content className="w-[420px] max-w-[90vw] p-4">
{deleteRow ? (
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.rolesAndPermissions.roles.deleteConfirm">
<div className="flex flex-col gap-2">
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
{deleteRow.deleteBlockedInUse ? t("settings.rolesAndPermissions.deleteBlocked.title") : t("settings.rolesAndPermissions.delete.title")}
</span>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
{deleteRow.deleteBlockedInUse
? t("settings.rolesAndPermissions.deleteBlocked.description", { name: deleteRow.name, count: deleteRow.memberCount })
: t("settings.rolesAndPermissions.delete.description", { name: deleteRow.name })}
</span>
</div>
<div className="flex w-full items-center justify-end gap-2">
<Button variant="tertiary" onClick={() => setDeleteRow(null)}>
{deleteRow.deleteBlockedInUse ? t("shared.close") : t("shared.cancel")}
</Button>
{!deleteRow.deleteBlockedInUse ? (
<Button
variant="destructive"
loading={submitting}
onClick={() => actions.onDelete(deleteRow.id)}
data-ui-id="ui.settings.rolesAndPermissions.roles.deleteSubmit"
>
{t("shared.delete")}
</Button>
) : null}
</div>
</div>
) : (
<div />
)}
</Dialog.Content>
</Dialog>
</div>
);
}
function RoleBasicsDialog({
state,
onChange,
onContinue,
onCancel,
}: {
state: BasicsState;
onChange: (state: BasicsState) => void;
onContinue: (state: BasicsState) => void;
onCancel: () => void;
}) {
const { t } = useTranslation();
const isDuplicate = state.source !== null;
const nameMissing = state.name.trim().length === 0;
return (
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.rolesAndPermissions.roles.basics">
<div className="flex flex-col gap-2">
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
{isDuplicate ? t("settings.rolesAndPermissions.duplicate.title") : t("settings.rolesAndPermissions.createDialog.title")}
</span>
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
{isDuplicate
? t("settings.rolesAndPermissions.duplicate.hint", { name: state.source?.name ?? "" })
: t("settings.rolesAndPermissions.createDialog.description")}
</span>
</div>
<div className="flex w-full flex-col gap-4">
<TextInput className="w-full" label={t("models.role.name")} showLabel>
<TextInput.Input value={state.name} onChange={(event) => onChange({ ...state, name: event.target.value })} required />
</TextInput>
<TextArea className="w-full" label={t("models.role.description")} showLabel>
<TextArea.Input value={state.description} onChange={(event) => onChange({ ...state, description: event.target.value })} />
</TextArea>
</div>
<div className="flex w-full items-center justify-end gap-2">
<Button variant="tertiary" onClick={onCancel}>
{t("shared.cancel")}
</Button>
<Button disabled={nameMissing} onClick={() => onContinue(state)} data-ui-id="ui.settings.rolesAndPermissions.roles.basics.continue">
{t("settings.rolesAndPermissions.editor.continue")}
</Button>
</div>
</div>
);
}
function RoleEditorDialog({
state,
onChange,
editorCatalog,
submitting,
errorMessage,
onCancel,
onSave,
}: {
state: EditorState;
onChange: (state: EditorState) => void;
editorCatalog: readonly RoleEditorInputPermission[];
submitting: boolean;
errorMessage: string | null;
onCancel: () => void;
onSave: () => void;
}) {
const { t } = useTranslation();
const [query, setQuery] = useState("");
const [selectedSection, setSelectedSection] = useState<string | null>(null);
// Pure VM grouping (scope → David's sections); enabled state comes from the dialog.
const sections = useMemo(() => {
const vm = buildRoleEditorVM({
role: state.roleId ? { id: state.roleId, name: state.name, description: state.description } : null,
duplicatedFromName: state.duplicatedFromName,
appPermissions: editorCatalog,
assignedPermissionNames: [...state.enabled],
});
return vm.data?.sections ?? [];
}, [state.roleId, state.name, state.description, state.duplicatedFromName, state.enabled, editorCatalog]);
const searched = useMemo(() => filterRoleEditorSections(sections, query), [sections, query]);
const visible = query.trim() ? searched : selectedSection ? searched.filter((section) => section.id === selectedSection) : searched;
const nameMissing = state.name.trim().length === 0;
return (
<div className="flex w-full flex-col gap-6" data-ui-id="ui.settings.rolesAndPermissions.roles.editor">
<div className="flex flex-col gap-2">
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
{state.roleId ? t("settings.rolesAndPermissions.editor.title") : t("settings.rolesAndPermissions.createDialog.title")}
</span>
{state.duplicatedFromName ? (
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
{t("settings.rolesAndPermissions.duplicate.hint", { name: state.duplicatedFromName })}
</span>
) : null}
{errorMessage ? <Alert variant="error" title={errorMessage} /> : null}
</div>
<div className="flex w-full gap-6 mobile:flex-col">
{/* Sidebar: search + sections (Apple-settings pattern from David's M02) */}
<div className="flex w-64 flex-none flex-col gap-4 mobile:w-full">
<SearchInput
placeholder={t("settings.rolesAndPermissions.editor.searchPlaceholder")}
hideShortcut
value={query}
onChange={(event) => setQuery(event.target.value)}
/>
<div className="flex flex-col gap-1">
<Button
variant={selectedSection === null ? "secondary" : "ghost"}
className="justify-start"
onClick={() => setSelectedSection(null)}
>
{t("settings.rolesAndPermissions.editor.allSections")}
</Button>
{sections.map((section) => (
<Button
key={section.id}
variant={selectedSection === section.id ? "secondary" : "ghost"}
className="justify-start"
onClick={() => setSelectedSection(section.id)}
>
{`${t(section.labelKey)} (${section.enabledCount}/${section.permissions.length})`}
</Button>
))}
</div>
</div>
{/* Main: role base data + permission rows as switches */}
<div className="flex max-h-[60vh] w-full flex-col gap-6 overflow-y-auto pr-2">
<div className="flex w-full flex-col gap-4">
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">
{t("settings.rolesAndPermissions.editor.roleSection")}
</span>
<TextInput className="w-full" label={t("models.role.name")} showLabel>
<TextInput.Input value={state.name} onChange={(event) => onChange({ ...state, name: event.target.value })} required />
</TextInput>
<TextArea className="w-full" label={t("models.role.description")} showLabel>
<TextArea.Input value={state.description} onChange={(event) => onChange({ ...state, description: event.target.value })} />
</TextArea>
</div>
{visible.length === 0 ? (
<EmptyState variant="no-results" title={t("settings.rolesAndPermissions.editor.noMatches")} />
) : (
visible.map((section) => (
<div key={section.id} className="flex w-full flex-col gap-4" data-editor-section={section.id}>
<span className="text-body-default-medium-0 font-body-default-medium-0 text-text-neutral-primary">{t(section.labelKey)}</span>
<div className="flex w-full flex-col gap-4">
{section.permissions.map((permission) => (
<div key={permission.name} className="flex w-full items-start justify-between gap-4" data-editor-permission={permission.name}>
<div className="flex flex-col gap-0">
<span className="text-body-default-regular-0 font-body-default-regular-0 text-text-neutral-primary">
{permissionDisplayName({ name: permission.name, description: permission.description }, t)}
</span>
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
{permissionDisplayDescription({ name: permission.name, description: permission.description }, t) ?? permission.name}
</span>
</div>
<Switch
checked={state.enabled.has(permission.name)}
onCheckedChange={(checked: boolean) => onChange({ ...state, enabled: togglePermission(state.enabled, permission.name, checked) })}
/>
</div>
))}
</div>
</div>
))
)}
</div>
</div>
<div className="flex w-full items-center justify-end gap-2">
<Button variant="tertiary" onClick={onCancel}>
{t("shared.cancel")}
</Button>
<Button loading={submitting} disabled={nameMissing} onClick={onSave} data-ui-id="ui.settings.rolesAndPermissions.roles.editor.save">
{t("shared.save")}
</Button>
</div>
</div>
);
}