From 85e9ea738df5acbb8bea60494644e13963a7af81 Mon Sep 17 00:00:00 2001 From: LoV432 Date: Tue, 30 Jan 2024 19:42:36 +0500 Subject: [PATCH] manual add admin button --- app/components/AdminsListTable.tsx | 13 +++- app/components/ConfirmationModals.tsx | 96 ++++++++++++++++++++++++++- 2 files changed, 107 insertions(+), 2 deletions(-) diff --git a/app/components/AdminsListTable.tsx b/app/components/AdminsListTable.tsx index c4c41fd..3b77f0c 100644 --- a/app/components/AdminsListTable.tsx +++ b/app/components/AdminsListTable.tsx @@ -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'; @@ -16,8 +16,15 @@ export default function AdminsListTable({ >(); const removeAdminModal = useRef() as React.MutableRefObject; + const addAdminModal = useRef() as React.MutableRefObject; return ( <> + @@ -40,6 +47,10 @@ export default function AdminsListTable({ })}
+ ; + updateAdminsList: () => Promise; +}) { + const timeRef = useRef() as React.MutableRefObject; + const playerNameRef = useRef() as React.MutableRefObject; + const idRef = useRef() as React.MutableRefObject; + const immunityRef = useRef() as React.MutableRefObject; + const adminFlagsRef = useRef() as React.MutableRefObject; + 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 ( + +

Add New ADMIN

+
{ + 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 + ); + }} + > + + + + + + +
+
+ ); +} + function ConfirmationModalWrapper({ modalRef, closePopUp,