From 97a6c7d399e83dcde887bb776e570de30f3070ff Mon Sep 17 00:00:00 2001 From: Declan Chidlow <84255570+DeclanChidlow@users.noreply.github.com> Date: Wed, 29 Jan 2025 21:39:03 +0800 Subject: [PATCH] fix: remove ability for owners to leave server from ServerInfo modal (#1070) Co-authored-by: Declan Chidlow --- .../modals/components/ServerInfo.tsx | 80 +++++++++++-------- 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/src/controllers/modals/components/ServerInfo.tsx b/src/controllers/modals/components/ServerInfo.tsx index 23598af0..ffda6807 100644 --- a/src/controllers/modals/components/ServerInfo.tsx +++ b/src/controllers/modals/components/ServerInfo.tsx @@ -5,6 +5,7 @@ import { Text } from "preact-i18n"; import { Column, H1, IconButton, Modal, Row } from "@revoltchat/ui"; import Markdown from "../../../components/markdown/Markdown"; +import { useClient } from "../../client/ClientController"; import { report } from "../../safety"; import { modalController } from "../ModalController"; import { ModalProps } from "../types"; @@ -13,6 +14,49 @@ export default function ServerInfo({ server, ...props }: ModalProps<"server_info">) { + const client = useClient(); + const isOwner = server.owner === client.user?._id; + + const actions = [ + { + onClick: () => { + modalController.push({ + type: "server_identity", + member: server.member!, + }); + return true; + }, + children: "Edit Identity", + palette: "primary", + }, + ]; + + if (!isOwner) { + actions.push({ + onClick: () => { + modalController.push({ + type: "leave_server", + target: server, + }); + return true; + }, + children: "Leave Server", + palette: "error", + }); + } + + actions.push({ + onClick: () => { + modalController.push({ + type: "report", + target: server, + }); + return true; + }, + children: , + palette: "error", + }); + return ( } - actions={[ - { - onClick: () => { - modalController.push({ - type: "server_identity", - member: server.member!, - }); - return true; - }, - children: "Edit Identity", - palette: "primary", - }, - { - onClick: () => { - modalController.push({ - type: "leave_server", - target: server, - }); - return true; - }, - children: "Leave Server", - palette: "error", - }, - { - onClick: () => { - modalController.push({ - type: "report", - target: server, - }); - return true; - }, - children: , - palette: "error", - }, - ]}> + actions={actions}> );