Skip to content

Commit

Permalink
manual add admin button
Browse files Browse the repository at this point in the history
  • Loading branch information
LoV432 committed Jan 30, 2024
1 parent 6841b06 commit 85e9ea7
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 2 deletions.
13 changes: 12 additions & 1 deletion app/components/AdminsListTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useRef, useState } from 'react';
import { dbReturnAllAdmins } from '../lib/get-admins-list';
import { ConfirmationModal } from './ConfirmationModals';
import { AddAdminManualModal, ConfirmationModal } from './ConfirmationModals';
import Image from 'next/image';
import { execRcon } from '../lib/exec-rcon';

Expand All @@ -16,8 +16,15 @@ export default function AdminsListTable({
>();
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">
Expand All @@ -40,6 +47,10 @@ export default function AdminsListTable({
})}
</tbody>
</table>
<AddAdminManualModal
modalRef={addAdminModal}
updateAdminsList={updateAdminsList}
/>
<RemoveAdminPopUp
player={selectedPlayer}
removeAdminModal={removeAdminModal}
Expand Down
96 changes: 95 additions & 1 deletion app/components/ConfirmationModals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export function ConfirmationModalAdmin({
<input
ref={timeRef}
className="input mt-5 w-full placeholder:text-slate-500"
placeholder="Time in seconds/0 perm"
placeholder="Time in minutes/0 perm"
></input>
<input
required
Expand Down Expand Up @@ -312,6 +312,100 @@ export function AddVipManualModal({
);
}

export function AddAdminManualModal({
modalRef,
updateAdminsList
}: {
modalRef: React.MutableRefObject<HTMLDialogElement>;
updateAdminsList: () => Promise<void>;
}) {
const timeRef = useRef() as React.MutableRefObject<HTMLInputElement>;
const playerNameRef = useRef() as React.MutableRefObject<HTMLInputElement>;
const idRef = useRef() as React.MutableRefObject<HTMLInputElement>;
const immunityRef = useRef() as React.MutableRefObject<HTMLInputElement>;
const adminFlagsRef = useRef() as React.MutableRefObject<HTMLInputElement>;
async function addAdmin(
time: number,
steamId: string,
playerName: string,
adminFlags: string,
immunity: number
) {
if (
adminFlags == null ||
adminFlags == '' ||
playerName == null ||
playerName == '' ||
steamId == null ||
steamId == ''
) {
return;
}
await execRcon(
`css_addadmin ${steamId} "${playerName}" "${adminFlags}" ${immunity} ${time}`
);
updateAdminsList();
closePopUp();
}
function closePopUp() {
modalRef.current.close();
timeRef.current.value = '';
playerNameRef.current.value = '';
idRef.current.value = '';
immunityRef.current.value = '';
adminFlagsRef.current.value = '';
}
return (
<ConfirmationModalWrapper modalRef={modalRef} closePopUp={closePopUp}>
<h3 className="pb-5 text-lg font-bold capitalize">Add New ADMIN</h3>
<form
onSubmit={(e) => {
e.preventDefault();
addAdmin(
Number(timeRef.current.value) || 0,
String(idRef.current.value),
String(playerNameRef.current.value),
String(adminFlagsRef.current.value),
Number(immunityRef.current.value) || 0
);
}}
>
<input
required
ref={idRef}
className="input mt-5 w-full placeholder:text-slate-500"
placeholder="Player SteamID*"
></input>
<input
required
ref={playerNameRef}
className="input mt-5 w-full placeholder:text-slate-500"
placeholder="Player Name*"
></input>
<input
ref={timeRef}
className="input mt-5 w-full placeholder:text-slate-500"
placeholder="Time in minutes/0 perm"
></input>
<input
required
ref={adminFlagsRef}
className="input mt-5 w-full placeholder:text-slate-500"
placeholder="Admin flags/groups*"
></input>
<input
ref={immunityRef}
className="input mt-5 w-full placeholder:text-slate-500"
placeholder="Immunity (Defaults to 0)"
></input>
<button type="submit" className="btn btn-success mt-5 w-full">
MAKE ADMIN
</button>
</form>
</ConfirmationModalWrapper>
);
}

function ConfirmationModalWrapper({
modalRef,
closePopUp,
Expand Down

0 comments on commit 85e9ea7

Please sign in to comment.