refactor: context menu in profile blocks

This commit is contained in:
Tristan Yang
2023-06-15 18:28:08 +08:00
parent 0b48d674ae
commit e8782492aa
4 changed files with 47 additions and 32 deletions
+2 -2
View File
@@ -26,8 +26,8 @@
"remove_account_desc": "Are you sure remove this account?", "remove_account_desc": "Are you sure remove this account?",
"remove_from_channel": "Remove from channel", "remove_from_channel": "Remove from channel",
"roles": "Roles", "roles": "Roles",
"set_admin": "Set as admin", "set_admin": "Admin",
"set_normal": "Set as normal user", "set_normal": "Normal User",
"search_not_found": "Not found, or this user is not allowed to be searched.", "search_not_found": "Not found, or this user is not allowed to be searched.",
"search_by_id": "Search by ID", "search_by_id": "Search by ID",
+2 -2
View File
@@ -25,8 +25,8 @@
"remove_account_desc": "确定永久注销该账号?", "remove_account_desc": "确定永久注销该账号?",
"remove_from_channel": "从频道移除", "remove_from_channel": "从频道移除",
"roles": "设置角色", "roles": "设置角色",
"set_admin": "设置为管理员", "set_admin": "管理员",
"set_normal": "设置为普通用户", "set_normal": "普通用户",
"search_not_found": "用户不存在,或者不允许搜索", "search_not_found": "用户不存在,或者不允许搜索",
"search_by_id": "用户ID", "search_by_id": "用户ID",
+1 -1
View File
@@ -50,7 +50,7 @@ const WrapWithSubmenu = ({
} = sub; } = sub;
return ( return (
<li <li
className={`item ${underline ? "bottom_line" : ""} ${danger ? "danger" : ""}`} className={`item group ${underline ? "bottom_line" : ""} ${danger ? "danger" : ""}`}
key={title} key={title}
onClick={(evt) => { onClick={(evt) => {
evt.stopPropagation(); evt.stopPropagation();
+42 -27
View File
@@ -11,6 +11,7 @@ import IconCall from "@/assets/icons/call.svg";
import IconMessage from "@/assets/icons/message.svg"; import IconMessage from "@/assets/icons/message.svg";
import IconMore from "@/assets/icons/more.svg"; import IconMore from "@/assets/icons/more.svg";
import Avatar from "../Avatar"; import Avatar from "../Avatar";
import ContextMenu, { Item } from "../ContextMenu";
interface Props { interface Props {
uid: number; uid: number;
@@ -91,33 +92,47 @@ const Profile: FC<Props> = ({ uid, type = "embed", cid }) => {
trigger="click" trigger="click"
hideOnClick={true} hideOnClick={true}
content={ content={
<ul className="context-menu"> <ContextMenu
{agoraEnabled && type == "card" && ( items={
<li className="item" onClick={startCall}> [
{t("call")} agoraEnabled &&
</li> type == "card" && {
)} title: t("call"),
{canCopyEmail && ( handler: startCall
<li className="item" onClick={copyEmail.bind(undefined, email)}> },
{t("copy_email")} canCopyEmail && {
</li> title: t("copy_email"),
)} handler: copyEmail
{canUpdateRole && ( },
<li className="item" onClick={updateRole}> canUpdateRole && {
{isAdmin ? t("set_normal") : t("set_admin")} title: t("roles"),
</li> handler: updateRole,
)} subs: [
{canRemoveFromChannel && ( {
<li className="item danger" onClick={removeFromChannel.bind(null, uid)}> title: t("set_normal"),
{t("remove_from_channel")} checked: !isAdmin,
</li> handler: updateRole
)} },
{canRemoveFromServer && ( {
<li className="item danger" onClick={removeUser.bind(null, uid)}> title: t("set_admin"),
{t("remove")} checked: isAdmin,
</li> handler: updateRole
)} }
</ul> ]
},
canRemoveFromChannel && {
title: t("remove_from_channel"),
danger: true,
handler: removeFromChannel
},
canRemoveFromServer && {
title: t("remove"),
handler: removeUser,
danger: true
}
].filter(Boolean) as Item[]
}
/>
} }
> >
<li className={`${iconClass} icon ${hasMore ? "" : "text-gray-500"}`}> <li className={`${iconClass} icon ${hasMore ? "" : "text-gray-500"}`}>