Skip to content

Commit

Permalink
Merge pull request #802 from MarechJ/feature/console-admin-action
Browse files Browse the repository at this point in the history
UI: Added console admin action
  • Loading branch information
FlorianSW authored Dec 20, 2024
2 parents ebd988c + cdbda68 commit aea1d08
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
31 changes: 30 additions & 1 deletion rcongui/src/features/player-action/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import FlagIcon from "@mui/icons-material/Flag";
import HowToRegIcon from "@mui/icons-material/HowToReg";
import AddCommentIcon from "@mui/icons-material/AddComment";
import AccountBalanceIcon from "@mui/icons-material/AccountBalance";
import AdminPanelSettingsIcon from '@mui/icons-material/AdminPanelSettings';
import { cmd, execute } from "@/utils/fetchUtils";
import { MessageFormFields } from "@/features/player-action/forms/MessageFormFields";
import { PunishFormFields } from "@/features/player-action/forms/PunishFormFields";
Expand All @@ -26,6 +27,7 @@ import { AddCommentFormFields } from "@/features/player-action/forms/AddCommentF
import { BlacklistPlayerFormFields } from "@/features/player-action/forms/BlacklistPlayerFields";
import { playerProfileQueryOptions } from "@/queries/player-profile-query";
import { RemoveFlagFormFields } from "./forms/RemoveFlagFormFields";
import { AddConsoleAdminFormFields } from "./forms/AddConsoleAdminFormFields";

const executeAction = (command) => async (payload) => {
// In the UI, it does not make sense to ask for a reason and message
Expand All @@ -38,7 +40,7 @@ const executeAction = (command) => async (payload) => {
payload.name = payload.player;
}
// v10.x.x 'add_vip' change param from 'name' to 'description'
if (command === "add_vip") {
if (command === "add_vip" || command === "add_admin") {
payload.description = payload.player_name;
}
return await execute(command, payload);
Expand Down Expand Up @@ -215,6 +217,31 @@ export const clearAccountAction = {
permission: ["can_remove_perma_bans"],
};

export const addConsoleAdminAction = {
name: "Add Admin",
description: "Add a console admin to the player.",
component: AddConsoleAdminFormFields,
icon: <AdminPanelSettingsIcon />,
execute: executeAction("add_admin"),
permission: ["can_add_admin_roles"],
context: [
{
type: "admin_groups",
getQuery: () => ({
queryKey: ["get_admin_groups"],
queryFn: () => cmd.GET_CONSOLE_ADMIN_GROUPS({ throwRouteError: false }),
}),
},
],
};

/**
* Generate player actions based on the given parameters.
* @param {Object} params - The parameters for generating player actions.
* @param {boolean} [params.multiAction=false] - Whether these actions are applied to multiple players.
* @param {boolean} [params.onlineAction=false] - Whether these actions are applied to online players.
* @returns {Array} An array of player actions.
*/
export const generatePlayerActions = (
{ multiAction = false, onlineAction = false } = {
multiAction: false,
Expand All @@ -233,6 +260,7 @@ export const generatePlayerActions = (
clearAccountAction,
flagAction,
commentAction,
addConsoleAdminAction,
]
: [
watchAction,
Expand All @@ -246,6 +274,7 @@ export const generatePlayerActions = (
flagAction,
unflagAction,
commentAction,
addConsoleAdminAction,
];

const gameActions = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ControlledSelect } from "@/components/form/core/ControlledSelect";
import { Stack } from "@mui/material";
import { useEffect } from "react";

export const AddConsoleAdminFormFields = ({
contextData,
control,
setError,
contextError,
}) => {
useEffect(() => {
if (contextError) {
setError("role", { message: contextError.message });
}
}, [contextError]);

return (
<Stack spacing={2}>
<ControlledSelect
control={control}
name="role"
label="Admin Groups"
rules={{ required: true }}
options={contextData?.admin_groups?.map((groupName) => ({
label: groupName,
value: groupName,
}))}
/>
</Stack>
);
};

0 comments on commit aea1d08

Please sign in to comment.