{
if (res.ok && res.status !== 204) return res.blob();
@@ -283,6 +284,7 @@ const System = {
return await fetch(`${API_BASE}/system/welcome-messages`, {
method: "GET",
cache: "no-cache",
+ headers: baseHeaders(),
})
.then((res) => {
if (!res.ok) throw new Error("Could not fetch welcome messages.");
diff --git a/frontend/src/pages/Admin/Users/UserRow/index.jsx b/frontend/src/pages/Admin/Users/UserRow/index.jsx
index d734759fc6..cd1c477327 100644
--- a/frontend/src/pages/Admin/Users/UserRow/index.jsx
+++ b/frontend/src/pages/Admin/Users/UserRow/index.jsx
@@ -3,9 +3,17 @@ import { titleCase } from "text-case";
import Admin from "@/models/admin";
import EditUserModal, { EditUserModalId } from "./EditUserModal";
import { DotsThreeOutline } from "@phosphor-icons/react";
+import showToast from "@/utils/toast";
+
+const ModMap = {
+ admin: ["admin", "manager", "default"],
+ manager: ["manager", "default"],
+ default: [],
+};
export default function UserRow({ currUser, user }) {
const rowRef = useRef(null);
+ const canModify = ModMap[currUser?.role || "default"].includes(user.role);
const [suspended, setSuspended] = useState(user.suspended === 1);
const handleSuspend = async () => {
if (
@@ -14,8 +22,19 @@ export default function UserRow({ currUser, user }) {
)
)
return false;
- setSuspended(!suspended);
- await Admin.updateUser(user.id, { suspended: suspended ? 0 : 1 });
+
+ const { success, error } = await Admin.updateUser(user.id, {
+ suspended: suspended ? 0 : 1,
+ });
+ if (!success) showToast(error, "error", { clear: true });
+ if (success) {
+ showToast(
+ `User ${!suspended ? "has been suspended" : "is no longer suspended"}.`,
+ "success",
+ { clear: true }
+ );
+ setSuspended(!suspended);
+ }
};
const handleDelete = async () => {
if (
@@ -24,8 +43,12 @@ export default function UserRow({ currUser, user }) {
)
)
return false;
- rowRef?.current?.remove();
- await Admin.deleteUser(user.id);
+ const { success, error } = await Admin.deleteUser(user.id);
+ if (!success) showToast(error, "error", { clear: true });
+ if (success) {
+ rowRef?.current?.remove();
+ showToast("User deleted from system.", "success", { clear: true });
+ }
};
return (
@@ -40,7 +63,7 @@ export default function UserRow({ currUser, user }) {
{titleCase(user.role)} |
{user.createdAt} |
- {currUser?.role !== "default" && (
+ {canModify && (
)}
- {currUser?.id !== user.id && currUser?.role !== "default" && (
+ {currUser?.id !== user.id && canModify && (
<>
|