{server && (
-
+
)}
{showMembersButton && (
diff --git a/components/layout/ServerSettingsMenu.tsx b/components/layout/ServerSettingsMenu.tsx
index 8485c63..744bd89 100644
--- a/components/layout/ServerSettingsMenu.tsx
+++ b/components/layout/ServerSettingsMenu.tsx
@@ -15,12 +15,14 @@ import { CreateChannelModal } from "@/components/modals/CreateChannelModal";
interface ServerSettingsMenuProps {
serverId: string;
serverName: string;
+ serverColor: string;
}
/** Renders a server management dropdown menu with modal triggers for channel, category, and server settings. */
export function ServerSettingsMenu({
serverId,
serverName,
+ serverColor,
}: ServerSettingsMenuProps) {
const [isMenuOpen, setIsMenuOpen] = useState(false);
const [isEditServerOpen, setIsEditServerOpen] = useState(false);
@@ -102,6 +104,7 @@ export function ServerSettingsMenu({
isOpen={isEditServerOpen}
serverId={serverId}
initialName={serverName}
+ initialColor={serverColor}
onClose={() => setIsEditServerOpen(false)}
/>
void} onClose - Callback function triggered to close the modal.
* @property {string} serverId - The unique identifier of the server being edited.
* @property {string} initialName - The current name of the server.
+ * @property {string} [initialColor] - The current accent color of the server.
*/
interface EditServerModalProps {
isOpen: boolean;
onClose: () => void;
serverId: string;
initialName: string;
+ initialColor: string;
}
/**
* Renders a modal dialog allowing users to modify server properties or delete the server.
- *
- * @param {EditServerModalProps} props - The component props.
- * @param {boolean} props.isOpen - Determines whether the modal dialog is currently visible.
- * @param {() => void} props.onClose - Callback function triggered to close the modal.
- * @param {string} props.serverId - The unique identifier of the server.
- * @param {string} props.initialName - The current name of the server.
- * @returns {JSX.Element | null} The rendered edit server modal, or null if closed.
*/
export function EditServerModal({
isOpen,
onClose,
serverId,
initialName,
+ initialColor,
}: EditServerModalProps) {
const [name, setName] = useState(initialName);
+ const [color, setColor] = useState(initialColor);
const [isLoading, setIsLoading] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
const [isConfirmingDelete, setIsConfirmingDelete] = useState(false);
@@ -52,21 +53,17 @@ export function EditServerModal({
useEffect(() => {
setName(initialName);
- }, [initialName]);
+ setColor(initialColor);
+ }, [initialName, initialColor]);
if (!isOpen) return null;
- const isChanged = name.trim() !== initialName;
+ const isChanged = name.trim() !== initialName || color !== initialColor;
const isValid = name.trim().length > 0;
const canSave = isChanged && isValid && !isLoading && !isDeleting;
/**
- * Handles the asynchronous update of the server name.
- *
- * @async
- * @function handleUpdate
- * @param {React.FormEvent} e - The form submission event.
- * @returns {Promise} Resolves when the server update process completes or fails.
+ * Handles the asynchronous update of the server name and accent color.
*/
const handleUpdate = async (e: React.FormEvent) => {
e.preventDefault();
@@ -79,7 +76,7 @@ export function EditServerModal({
const response = await fetch(`/api/servers/${serverId}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ name: name.trim() }),
+ body: JSON.stringify({ name: name.trim(), color }),
});
if (!response.ok) {
@@ -96,11 +93,7 @@ export function EditServerModal({
};
/**
- * Handles the asynchronous deletion of the server and redirects the user to the home page.
- *
- * @async
- * @function handleDelete
- * @returns {Promise} Resolves when the server deletion process completes or fails.
+ * Handles the asynchronous deletion of the server.
*/
const handleDelete = async () => {
if (!isConfirmingDelete) {
@@ -154,7 +147,7 @@ export function EditServerModal({
Change server details or delete this server.
-