From 39716d74ca74e0a97b1f8df20ac04d3e6fadadc9 Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Tue, 19 Dec 2023 11:39:34 -0500 Subject: [PATCH] fix leave server and better handling --- src/components/modals/LeaveServerModal.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/components/modals/LeaveServerModal.tsx b/src/components/modals/LeaveServerModal.tsx index f2af500..881d86c 100644 --- a/src/components/modals/LeaveServerModal.tsx +++ b/src/components/modals/LeaveServerModal.tsx @@ -1,22 +1,34 @@ import { Routes } from "@spacebarchat/spacebar-api-types/v9"; import { useState } from "react"; +import { useNavigate } from "react-router-dom"; import { ModalProps, modalController } from "../../controllers/modals"; +import useLogger from "../../hooks/useLogger"; import { useAppStore } from "../../stores/AppStore"; import { Modal } from "./ModalComponents"; export function LeaveServerModal({ target, ...props }: ModalProps<"leave_server">) { const app = useAppStore(); + const logger = useLogger("LeaveServerModal"); + const navigate = useNavigate(); const [isDisabled, setDisabled] = useState(false); async function leaveGuild() { setDisabled(true); await app.rest - .delete(Routes.guildMember(target.id, "@me")) + .delete(Routes.userGuild(target.id)) .then(() => { modalController.pop("close"); + navigate("/channels/@me"); }) .catch((e) => { - console.error(e); + logger.error(e); + modalController.pop("close"); + modalController.push({ + type: "error", + error: e, + title: "Failed to leave server", + description: "An error occurred while trying to leave the server.", + }); }) .finally(() => setDisabled(false)); }