2025-04-20 04:05:49 +03:00
|
|
|
import { Trans, useTranslation } from "react-i18next";
|
2025-09-12 14:19:29 +03:00
|
|
|
import { Button } from "@/components/ui/button";
|
2025-03-08 19:01:08 +03:00
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogDescription,
|
|
|
|
|
DialogFooter,
|
|
|
|
|
DialogHeader,
|
|
|
|
|
DialogTitle,
|
2025-09-12 14:19:29 +03:00
|
|
|
} from "@/components/ui/dialog";
|
2025-03-08 19:01:08 +03:00
|
|
|
import {
|
|
|
|
|
Select,
|
|
|
|
|
SelectContent,
|
|
|
|
|
SelectItem,
|
|
|
|
|
SelectTrigger,
|
|
|
|
|
SelectValue,
|
2025-09-12 14:19:29 +03:00
|
|
|
} from "@/components/ui/select";
|
2025-03-08 19:01:08 +03:00
|
|
|
import { useState } from "react";
|
|
|
|
|
import { LuShield, LuUser } from "react-icons/lu";
|
|
|
|
|
|
|
|
|
|
type RoleChangeDialogProps = {
|
|
|
|
|
show: boolean;
|
|
|
|
|
username: string;
|
2025-09-12 14:19:29 +03:00
|
|
|
currentRole: string;
|
|
|
|
|
availableRoles: string[];
|
|
|
|
|
onSave: (role: string) => void;
|
2025-03-08 19:01:08 +03:00
|
|
|
onCancel: () => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default function RoleChangeDialog({
|
|
|
|
|
show,
|
|
|
|
|
username,
|
|
|
|
|
currentRole,
|
2025-09-12 14:19:29 +03:00
|
|
|
availableRoles,
|
2025-03-08 19:01:08 +03:00
|
|
|
onSave,
|
|
|
|
|
onCancel,
|
|
|
|
|
}: RoleChangeDialogProps) {
|
2025-03-16 18:36:20 +03:00
|
|
|
const { t } = useTranslation(["views/settings"]);
|
2025-09-12 14:19:29 +03:00
|
|
|
const [selectedRole, setSelectedRole] = useState<string>(currentRole);
|
2025-03-08 19:01:08 +03:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Dialog open={show} onOpenChange={onCancel}>
|
|
|
|
|
<DialogContent className="sm:max-w-[425px]">
|
|
|
|
|
<DialogHeader>
|
2025-10-09 15:23:03 +03:00
|
|
|
<DialogTitle className="text-xl">
|
2025-03-16 18:36:20 +03:00
|
|
|
{t("users.dialog.changeRole.title")}
|
2025-03-08 19:01:08 +03:00
|
|
|
</DialogTitle>
|
|
|
|
|
<DialogDescription>
|
2025-04-20 04:05:49 +03:00
|
|
|
<Trans
|
|
|
|
|
i18nKey="users.dialog.changeRole.desc"
|
|
|
|
|
ns="views/settings"
|
|
|
|
|
values={{ username }}
|
|
|
|
|
components={{
|
|
|
|
|
strong: <span className="font-medium" />,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2025-03-08 19:01:08 +03:00
|
|
|
</DialogDescription>
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
|
2025-04-17 16:34:24 +03:00
|
|
|
<div className="py-3">
|
2025-03-08 19:01:08 +03:00
|
|
|
<div className="mb-4 text-sm text-muted-foreground">
|
2025-04-17 16:34:24 +03: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>
|
2025-09-12 14:19:29 +03:00
|
|
|
{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 16:34:24 +03:00
|
|
|
</ul>
|
2025-03-08 19:01:08 +03:00
|
|
|
</div>
|
|
|
|
|
|
2025-09-12 14:19:29 +03:00
|
|
|
<Select value={selectedRole} onValueChange={setSelectedRole}>
|
2025-03-08 19:01:08 +03:00
|
|
|
<SelectTrigger className="w-full">
|
2025-05-20 00:45:02 +03:00
|
|
|
<SelectValue placeholder={t("users.dialog.changeRole.select")} />
|
2025-03-08 19:01:08 +03:00
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
2025-09-12 14:19:29 +03:00
|
|
|
{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 19:01:08 +03:00
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<DialogFooter className="flex gap-3 sm:justify-end">
|
|
|
|
|
<div className="flex flex-1 flex-col justify-end">
|
|
|
|
|
<div className="flex flex-row gap-2 pt-5">
|
|
|
|
|
<Button
|
|
|
|
|
className="flex flex-1"
|
2025-03-16 18:36:20 +03:00
|
|
|
aria-label={t("button.cancel", { ns: "common" })}
|
2025-09-12 14:19:29 +03:00
|
|
|
variant="outline"
|
2025-03-08 19:01:08 +03:00
|
|
|
onClick={onCancel}
|
|
|
|
|
type="button"
|
|
|
|
|
>
|
2025-03-16 18:36:20 +03:00
|
|
|
{t("button.cancel", { ns: "common" })}
|
2025-03-08 19:01:08 +03:00
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
variant="select"
|
2025-03-16 18:36:20 +03:00
|
|
|
aria-label={t("button.save", { ns: "common" })}
|
2025-03-08 19:01:08 +03:00
|
|
|
className="flex flex-1"
|
|
|
|
|
onClick={() => onSave(selectedRole)}
|
2025-09-12 14:19:29 +03:00
|
|
|
type="button"
|
2025-03-08 19:01:08 +03:00
|
|
|
disabled={selectedRole === currentRole}
|
|
|
|
|
>
|
2025-03-16 18:36:20 +03:00
|
|
|
{t("button.save", { ns: "common" })}
|
2025-03-08 19:01:08 +03:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</DialogFooter>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
}
|