Files
frigate/web/src/components/overlay/RoleChangeDialog.tsx
T

142 lines
4.4 KiB
TypeScript
Raw Normal View History

2025-04-19 20:05:49 -05:00
import { Trans, useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
2025-03-08 10:01:08 -06:00
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
2025-03-08 10:01:08 -06:00
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
2025-03-08 10:01:08 -06:00
import { useState } from "react";
import { LuShield, LuUser } from "react-icons/lu";
type RoleChangeDialogProps = {
show: boolean;
username: string;
currentRole: string;
availableRoles: string[];
onSave: (role: string) => void;
2025-03-08 10:01:08 -06:00
onCancel: () => void;
};
export default function RoleChangeDialog({
show,
username,
currentRole,
availableRoles,
2025-03-08 10:01:08 -06:00
onSave,
onCancel,
}: RoleChangeDialogProps) {
const { t } = useTranslation(["views/settings"]);
const [selectedRole, setSelectedRole] = useState<string>(currentRole);
2025-03-08 10:01:08 -06:00
return (
<Dialog open={show} onOpenChange={onCancel}>
<DialogContent className="sm:max-w-[425px]">
<DialogHeader>
2025-10-09 07:23:03 -05:00
<DialogTitle className="text-xl">
{t("users.dialog.changeRole.title")}
2025-03-08 10:01:08 -06:00
</DialogTitle>
<DialogDescription>
2025-04-19 20:05:49 -05:00
<Trans
i18nKey="users.dialog.changeRole.desc"
ns="views/settings"
values={{ username }}
components={{
strong: <span className="font-medium" />,
}}
/>
2025-03-08 10:01:08 -06:00
</DialogDescription>
</DialogHeader>
2025-04-17 08:34:24 -05:00
<div className="py-3">
2025-03-08 10:01:08 -06:00
<div className="mb-4 text-sm text-muted-foreground">
2025-04-17 08:34:24 -05:00
<p>{t("users.dialog.changeRole.roleInfo.intro")}</p>
<ul className="mt-2 list-disc space-y-1 pl-5">
<li>
<span className="font-medium">
{t("users.dialog.changeRole.roleInfo.admin")}
</span>
: {t("users.dialog.changeRole.roleInfo.adminDesc")}
</li>
<li>
<span className="font-medium">
{t("users.dialog.changeRole.roleInfo.viewer")}
</span>
: {t("users.dialog.changeRole.roleInfo.viewerDesc")}
</li>
{availableRoles
.filter((role) => role !== "admin" && role !== "viewer")
.map((role) => (
<li key={role}>
<span className="font-medium">{role}</span>:{" "}
{t("users.dialog.changeRole.roleInfo.customDesc")}
</li>
))}
2025-04-17 08:34:24 -05:00
</ul>
2025-03-08 10:01:08 -06:00
</div>
<Select value={selectedRole} onValueChange={setSelectedRole}>
2025-03-08 10:01:08 -06:00
<SelectTrigger className="w-full">
2025-05-19 16:45:02 -05:00
<SelectValue placeholder={t("users.dialog.changeRole.select")} />
2025-03-08 10:01:08 -06:00
</SelectTrigger>
<SelectContent>
{availableRoles.map((role) => (
<SelectItem
key={role}
value={role}
className="flex items-center gap-2"
>
<div className="flex items-center gap-2">
{role === "admin" ? (
<LuShield className="size-4 text-primary" />
) : role === "viewer" ? (
<LuUser className="size-4 text-primary" />
) : (
<LuUser className="size-4 text-muted-foreground" />
)}
<span>
{role === "admin"
? t("role.admin", { ns: "common" })
: role === "viewer"
? t("role.viewer", { ns: "common" })
: role}
</span>
</div>
</SelectItem>
))}
2025-03-08 10:01:08 -06:00
</SelectContent>
</Select>
</div>
2026-05-29 17:00:30 -05:00
<DialogFooter>
<Button
aria-label={t("button.cancel", { ns: "common" })}
onClick={onCancel}
type="button"
>
{t("button.cancel", { ns: "common" })}
</Button>
<Button
variant="select"
aria-label={t("button.save", { ns: "common" })}
onClick={() => onSave(selectedRole)}
type="button"
disabled={selectedRole === currentRole}
>
{t("button.save", { ns: "common" })}
</Button>
2025-03-08 10:01:08 -06:00
</DialogFooter>
</DialogContent>
</Dialog>
);
}