import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Description as DialogDescription, Title as DialogTitle } from "@radix-ui/react-dialog"; import { FeatherArchive, FeatherArrowLeft, FeatherLock, FeatherLogOut, FeatherSettings, FeatherShield, FeatherTrash2, FeatherUnlock, FeatherUserPlus, } from "@subframe/core"; import type { ChatChannelSettingsMemberRole, ChatChannelSettingsVM } from "@hivegrid/view-models"; import { Alert } from "~/ui/components/Alert"; import { Avatar } from "~/ui/components/Avatar"; import { BadgeFeedback } from "~/ui/components/BadgeFeedback"; import { Button } from "~/ui/components/Button"; import { ButtonGroup } from "~/ui/components/ButtonGroup"; import { Card } from "~/ui/components/Card"; import { Dialog } from "~/ui/components/Dialog"; import { EmptyState } from "~/ui/components/EmptyState"; import { LoadingIndicatorSkeleton } from "~/ui/components/LoadingIndicatorSkeleton"; import { Select } from "~/ui/components/Select"; import { PAGE_HEADER_ICON_CLASS, PageBody, PageHeader, PageShell } from "../shared/PageShell"; import { ChatSwitch } from "./ChatSwitch"; export type ChatChannelSettingsActions = Readonly<{ onBack: () => void; onRetry: () => void | Promise; onAddMember: (userId: string) => void | Promise; onChangeRole: (userId: string, role: ChatChannelSettingsMemberRole) => void | Promise; onRemoveMember: (userId: string) => void | Promise; onPrivacyChange: (privacy: "public" | "private") => void | Promise; onLeave: () => void | Promise; onArchive: () => void | Promise; }>; export type ChatChannelSettingsPageProps = Readonly<{ vm: ChatChannelSettingsVM; actions: ChatChannelSettingsActions; busy?: boolean; actionErrorKey?: string | null; }>; export function ChatChannelSettingsPage({ vm, actions, busy = false, actionErrorKey = null }: ChatChannelSettingsPageProps): React.JSX.Element { const { t } = useTranslation(); const [candidateUserId, setCandidateUserId] = useState(""); const [confirmAction, setConfirmAction] = useState<"archive" | "leave" | null>(null); const readyData = vm.status === "ready" ? vm.data : null; const headerActions = ( ); if (vm.status === "idle" || vm.status === "loading") { return ( ); } if (vm.status === "error") { return ( void actions.onRetry()}> {t("shared.retry")} } data-ui-id="ui.chat.channelSettings.error" /> ); } if (vm.status === "empty" || !readyData) { return ( ); } const canAddMember = readyData.permissions.canManageGroupMembers || readyData.permissions.canManageManualGuests; return ( {actionErrorKey ? ( ) : null} {readyData.channel.title} {readyData.channel.description ? ( {readyData.channel.description} ) : null} {t(`chat.channel.kind.${readyData.channel.kind}`)} {readyData.infoKey ? : null} {readyData.channel.kind === "group" ? ( {readyData.channel.privacy === "private" ? void actions.onPrivacyChange(checked ? "private" : "public")} aria-label={t("chat.channelSettings.privacy.private")} data-ui-id="ui.chat.channelSettings.privacyToggle" /> ) : null} {t("chat.channelSettings.members.title")} {t("chat.channelSettings.members.count", { count: readyData.members.length })} {canAddMember && readyData.candidateUsers.length > 0 ? ( ) : null} {readyData.members.length === 0 ? ( ) : ( readyData.members.map((member) => ( {member.avatar.fallbackLabel} {member.displayName} {member.email} {t(member.roleLabelKey)} {t(member.sourceLabelKey)} {member.actions.canPromoteToAdmin ? ( ) : null} {member.actions.canDemoteFromAdmin ? ( ) : null} {member.actions.canRemoveFromGroup || member.actions.canRemoveManualGuest ? ( ) : null} {readyData.permissions.canArchive ? ( ) : null} ) : null} (open ? undefined : setConfirmAction(null))}> {t(`chat.channelSettings.confirm.${confirmAction ?? "leave"}.title`)} {t(`chat.channelSettings.confirm.${confirmAction ?? "leave"}.body`)} ); } function SettingsShell({ children, actions }: { readonly children: React.ReactNode; readonly actions?: React.ReactNode }): React.JSX.Element { const { t } = useTranslation(); return ( } title={t("chat.channelSettings.title")} subtitle={t("chat.channelSettings.subtitle")} actions={actions} uiId="ui.chat.channelSettings.header" /> {children} ); }