import { ActionIcon, Badge, Divider, Grid, MediaQuery, Menu, Space, Title, Tooltip } from '@mantine/core'; import React, { useState } from 'react'; import { FaPause, FaPlay, FaStop } from 'react-icons/fa'; import { Service } from '../../js/models'; import { MdOutlineArrowForwardIos } from "react-icons/md" import style from "./ServiceRow.module.scss"; import YesNoModal from '../YesNoModal'; import { deleteservice, errorNotify, fireUpdateRequest, okNotify, pauseservice, regenport, startservice, stopservice } from '../../js/utils'; import { BsArrowRepeat, BsTrashFill } from 'react-icons/bs'; import { TbNumbers } from 'react-icons/tb'; import { BiRename } from 'react-icons/bi' import ChangeInternalPort from './ChangeInternalPort'; //"status":"stop"/"wait"/"active"/"pause", function ServiceRow({ service, onClick }:{ service:Service, onClick?:()=>void }) { let status_color = "gray"; switch(service.status){ case "stop": status_color = "red"; break; case "wait": status_color = "yellow"; break; case "active": status_color = "teal"; break; case "pause": status_color = "cyan"; break; } const [stopModal, setStopModal] = useState(false); const [buttonLoading, setButtonLoading] = useState(false) const [tooltipStopOpened, setTooltipStopOpened] = useState(false); const [deleteModal, setDeleteModal] = useState(false) const [changePortModal, setChangePortModal] = useState(false) const [chooseInternalPortModal, setChooseInternalPortModal] = useState(false) const stopService = async () => { setButtonLoading(true) await stopservice(service.id).then(res => { if(!res){ okNotify(`Service ${service.id} stopped successfully!`,`The service ${service.name} has been stopped!`) fireUpdateRequest(); }else{ errorNotify(`An error as occurred during the stopping of the service ${service.id}`,`Error: ${res}`) } }).catch(err => { errorNotify(`An error as occurred during the stopping of the service ${service.id}`,`Error: ${err}`) }) setButtonLoading(false); } const startService = async () => { setButtonLoading(true) await startservice(service.id).then(res => { if(!res){ okNotify(`Service ${service.id} started successfully!`,`The service ${service.name} has been started!`) fireUpdateRequest(); }else{ errorNotify(`An error as occurred during the starting of the service ${service.id}`,`Error: ${res}`) } }).catch(err => { errorNotify(`An error as occurred during the starting of the service ${service.id}`,`Error: ${err}`) }) setButtonLoading(false) } const pauseService = async () => { setButtonLoading(true) await pauseservice(service.id).then(res => { if(!res){ okNotify(`Service ${service.id} paused successfully!`,`The service ${service.name} has been paused (Transparent mode)!`) fireUpdateRequest(); }else{ errorNotify(`An error as occurred during the pausing of the service ${service.id}`,`Error: ${res}`) } }).catch(err => { errorNotify(`An error as occurred during the pausing of the service ${service.id}`,`Error: ${err}`) }) setButtonLoading(false) } const deleteService = () => { deleteservice(service.id).then(res => { if (!res){ okNotify("Service delete complete!",`The service ${service.id} has been deleted!`) fireUpdateRequest(); }else errorNotify("An error occurred while deleting a service",`Error: ${res}`) }).catch(err => { errorNotify("An error occurred while deleting a service",`Error: ${err}`) }) } const changePort = () => { regenport(service.id).then(res => { if (!res){ okNotify("Service port regeneration completed!",`The service ${service.id} has changed the internal port!`) fireUpdateRequest(); }else errorNotify("An error occurred while changing the internal service port",`Error: ${res}`) }).catch(err => { errorNotify("An error occurred while changing the internal service port",`Error: ${err}`) }) } return <>
{service.name} :{service.public_port}
{service.internal_port} {"->"} {service.public_port}
{service.name} :{service.public_port}
{service.internal_port} {"->"} {service.public_port}
<>
Status: {service.status} Regex: {service.n_regex} Connections Blocked: {service.n_packets}
<>
Rename service } onClick={()=>{}}>Change service name Public proxy port } onClick={()=>{}}>Change port Internal proxy port } onClick={()=>setChangePortModal(true)}>Regen port } onClick={()=>setChooseInternalPortModal(true)}>Choose port Delete service } onClick={()=>setDeleteModal(true)}>Delete Service {["pause","wait"].includes(service.status)? setStopModal(true)} size="xl" radius="md" variant="filled" disabled={service.status === "stop"} aria-describedby="tooltip-stop-id" onFocus={() => setTooltipStopOpened(false)} onBlur={() => setTooltipStopOpened(false)} onMouseEnter={() => setTooltipStopOpened(true)} onMouseLeave={() => setTooltipStopOpened(false)}> : }
{onClick?
:null} <> {setStopModal(false);}} action={stopService} opened={stopModal} />
setDeleteModal(false) } action={deleteService} opened={deleteModal} /> setChangePortModal(false)} action={changePort} opened={changePortModal} /> setChooseInternalPortModal(false)} opened={chooseInternalPortModal} /> } export default ServiceRow;