Skip to content

Commit

Permalink
feature: add/remove admins
Browse files Browse the repository at this point in the history
commit 85e9ea7
Author: LoV432 <[email protected]>
Date:   Tue Jan 30 19:42:36 2024 +0500

    manual add admin button

commit 6841b06
Author: LoV432 <[email protected]>
Date:   Tue Jan 30 19:20:32 2024 +0500

    add admins list

commit 51804f6
Author: LoV432 <[email protected]>
Date:   Tue Jan 30 16:17:50 2024 +0500

    option to add admin
  • Loading branch information
LoV432 committed Jan 31, 2024
1 parent 75d1b69 commit 8fc0bed
Show file tree
Hide file tree
Showing 5 changed files with 436 additions and 3 deletions.
22 changes: 20 additions & 2 deletions app/components/AdminActionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
} from '../lib/get-bans-mutes-list';
import PunishmentsListTable from './PunishmentsListTable';
import { dbReturnAllVipsAction, getVipsList } from '../lib/get-vip-list';
import { getAdmins, dbReturnAllAdmins } from '../lib/get-admins-list';
import VipsListTable from './VipListTable';
import AdminsListTable from './AdminsListTable';

export default function AdminActionListButton({
featureFlags
Expand All @@ -20,13 +22,17 @@ export default function AdminActionListButton({
function closePopUp() {
adminActionListModal.current.close();
}

const [punishmentsList, setPunishmentsList] = useState(
[] as dbReturnAllPunishmentAction
);
const [vipsList, setVipsList] = useState([] as dbReturnAllVipsAction);
const [adminsList, setAdminsList] = useState([] as dbReturnAllAdmins);

const adminActionListModal =
useRef() as React.MutableRefObject<HTMLDialogElement>;
const defaultTab = useRef() as React.MutableRefObject<HTMLInputElement>;

async function updatePunishmentsList() {
const punishmentsList = await getBansAndMutes();
if ('error' in punishmentsList) return;
Expand All @@ -37,10 +43,17 @@ export default function AdminActionListButton({
if ('error' in vipsList) return;
setVipsList(vipsList);
}
async function updateAdminsList() {
const adminsList = await getAdmins();
if ('error' in adminsList) return;
setAdminsList(adminsList);
}

useEffect(() => {
defaultTab.current.click(); // TODO: If i put "checked" directly on the HTML Input element the tabs dont switch
updatePunishmentsList();
updateVipsList();
updateAdminsList();
}, []);
return (
<div className="flex w-full place-content-center">
Expand All @@ -49,6 +62,7 @@ export default function AdminActionListButton({
onClick={() => {
updatePunishmentsList();
updateVipsList();
updateAdminsList();
adminActionListModal.current.showModal();
}}
>
Expand All @@ -69,7 +83,7 @@ export default function AdminActionListButton({
type="radio"
name="Admin_Action_Borders"
role="tab"
className="tab h-12 after:overflow-hidden after:overflow-ellipsis text-lg font-semibold transition-all checked:bg-zinc-700 hover:bg-zinc-800 checked:hover:bg-zinc-700 focus:outline-0"
className="tab h-12 text-lg font-semibold transition-all after:overflow-hidden after:overflow-ellipsis checked:bg-zinc-700 hover:bg-zinc-800 checked:hover:bg-zinc-700 focus:outline-0"
aria-label="Punishments"
onClick={updatePunishmentsList}
/>
Expand Down Expand Up @@ -145,10 +159,14 @@ export default function AdminActionListButton({
role="tab"
className="tab h-12 text-lg font-semibold transition-all checked:bg-zinc-700 hover:bg-zinc-800 checked:hover:bg-zinc-700 focus:outline-0"
aria-label="Admins"
onClick={updateAdminsList}
/>
<div role="tabpanel" className="tab-content pt-5">
{featureFlags.adminPluginIsEnabled ? (
<p>Coming Soon (Maybe)</p>
<AdminsListTable
adminsList={adminsList}
updateAdminsList={updateAdminsList}
/>
) : (
<p>
You can enable this panel by installing{' '}
Expand Down
38 changes: 37 additions & 1 deletion app/components/AdminPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Player } from '../lib/parse-players';
import {
ConfirmationModalWithInput,
ConfirmationModal,
ConfirmationModalVip
ConfirmationModalVip,
ConfirmationModalAdmin
} from './ConfirmationModals';
import { execRcon } from '../lib/exec-rcon';
import {
Expand All @@ -27,6 +28,7 @@ export default function AdminPanel({
const kickPlayerModal = useRef() as React.MutableRefObject<HTMLDialogElement>;
const banPlayerModal = useRef() as React.MutableRefObject<HTMLDialogElement>;
const makeVipModal = useRef() as React.MutableRefObject<HTMLDialogElement>;
const makeAdminModal = useRef() as React.MutableRefObject<HTMLDialogElement>;
const mutePlayerModal = useRef() as React.MutableRefObject<HTMLDialogElement>;
const slayPlayerModal = useRef() as React.MutableRefObject<HTMLDialogElement>;
function closePopUp() {
Expand Down Expand Up @@ -93,6 +95,14 @@ export default function AdminPanel({
>
Slay
</button>
<button
onClick={() => {
makeAdminModal.current.showModal();
}}
className="btn btn-outline w-1/3"
>
Make ADMIN
</button>
</>
) : (
<>
Expand All @@ -105,6 +115,9 @@ export default function AdminPanel({
<button className="btn btn-disabled btn-outline w-1/3">
Slay
</button>
<button className="btn btn-disabled btn-outline w-1/3">
Make ADMIN
</button>
</>
)}
{featureFlags.vipPluginIsEnabled ? (
Expand Down Expand Up @@ -189,6 +202,11 @@ export default function AdminPanel({
player={selectedPlayer}
slayPlayerModal={slayPlayerModal}
/>
<MakeAdminPopUp
adminPanelModal={adminPanelModal}
player={selectedPlayer}
makeAdminModal={makeAdminModal}
/>
</>
);
}
Expand Down Expand Up @@ -266,6 +284,24 @@ function MakeVipPopUp({
);
}

function MakeAdminPopUp({
player,
makeAdminModal,
adminPanelModal
}: {
player: Player;
makeAdminModal: React.MutableRefObject<HTMLDialogElement>;
adminPanelModal: React.MutableRefObject<HTMLDialogElement>;
}) {
return (
<ConfirmationModalAdmin
modalRef={makeAdminModal}
playerName={player.name}
adminPanelModal={adminPanelModal}
/>
);
}

function KickPlayerPopUp({
player,
kickPlayerModal,
Expand Down
158 changes: 158 additions & 0 deletions app/components/AdminsListTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { useRef, useState } from 'react';
import { dbReturnAllAdmins } from '../lib/get-admins-list';
import { AddAdminManualModal, ConfirmationModal } from './ConfirmationModals';
import Image from 'next/image';
import { execRcon } from '../lib/exec-rcon';

export default function AdminsListTable({
adminsList,
updateAdminsList
}: {
adminsList: dbReturnAllAdmins;
updateAdminsList: () => Promise<void>;
}) {
const [selectedPlayer, setSelectedPlayer] = useState<
dbReturnAllAdmins[0] | undefined
>();
const removeAdminModal =
useRef() as React.MutableRefObject<HTMLDialogElement>;
const addAdminModal = useRef() as React.MutableRefObject<HTMLDialogElement>;
return (
<>
<button
onClick={() => addAdminModal.current.showModal()}
className="btn btn-success float-right h-9 min-h-0 w-28"
>
Add ADMIN
</button>
<table className="table">
<thead className="text-slate-300">
<tr className="border-slate-300 border-opacity-30">
<th>Name</th>
<th>Immunity</th>
<th>Flag</th>
<th>Ends on</th>
</tr>
</thead>
<tbody>
{adminsList.map((punishment) => {
return (
<AdminItemList
key={`${punishment.id}`}
adminItem={punishment}
setSelectedPlayer={setSelectedPlayer}
removeAdminModal={removeAdminModal}
/>
);
})}
</tbody>
</table>
<AddAdminManualModal
modalRef={addAdminModal}
updateAdminsList={updateAdminsList}
/>
<RemoveAdminPopUp
player={selectedPlayer}
removeAdminModal={removeAdminModal}
updateAdminsList={updateAdminsList}
/>
</>
);
}

function AdminItemList({
adminItem,
setSelectedPlayer,
removeAdminModal
}: {
adminItem: dbReturnAllAdmins[0];
setSelectedPlayer: (player: dbReturnAllAdmins[0]) => void;
removeAdminModal: React.MutableRefObject<HTMLDialogElement>;
}) {
return (
<tr className="border-slate-300 border-opacity-30 text-base">
<th>
<a
className="link underline-offset-4"
target={'_blank'}
href={`https://steamcommunity.com/profiles/${adminItem.player_steamid}/`}
>
{adminItem.player_name}
</a>
</th>
<td className="font-semibold">{adminItem.immunity}</td>
<td className="font-semibold">{adminItem.flags}</td>
{adminItem.ends === null ? (
<td className="font-semibold">Permanent</td>
) : (
<td className="font-semibold">
{new Date(adminItem.ends * 1000).toLocaleString('en-US', {
day: '2-digit',
month: 'short',
hour: 'numeric',
minute: '2-digit'
})}
</td>
)}

<td>
<button
onClick={() => {
setSelectedPlayer(adminItem);
removeAdminModal.current.showModal();
}}
className="btn btn-error h-10 min-h-0 w-10 p-0"
>
<Image
src={'/trash-outline.svg'}
width={20}
height={20}
alt="Delete"
aria-label="Delete"
/>
</button>
</td>
</tr>
);
}

function RemoveAdminPopUp({
player,
removeAdminModal,
updateAdminsList
}: {
player: dbReturnAllAdmins[0] | undefined;
removeAdminModal: React.MutableRefObject<HTMLDialogElement>;
updateAdminsList: () => Promise<void>;
}) {
const removeAdmin = () => {
execRcon(`css_deladmin ${player?.player_steamid}`);
removeAdminModal.current.close();
setTimeout(() => {
updateAdminsList();
}, 500);
};

if (!player) {
{
/* Will never reach */
}
return (
<ConfirmationModal
modalAction={removeAdmin}
modalName={``}
modalRef={removeAdminModal}
playerName={''}
/>
);
}

return (
<ConfirmationModal
modalAction={removeAdmin}
modalName={`Remove ADMIN`}
modalRef={removeAdminModal}
playerName={player.player_name}
/>
);
}
Loading

0 comments on commit 8fc0bed

Please sign in to comment.