import { ActionIcon, Badge, Grid, MediaQuery, 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 { errorNotify, okNotify, pauseservice, startservice, stopservice, servicelist } from '../../js/utils'; //"status":"stop"/"wait"/"active"/"pause", function ServiceRow({ service, onClick, additional_buttons }:{ service:Service, onClick?:()=>void, additional_buttons?:any }) { 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 [services, setServices] = useState([]); const [loader, setLoader] = useState(true); const updateInfo = async () => { await servicelist().then(res => { setServices(res) }).catch(err => { errorNotify("Home Page Auto-Update failed!", err.toString()) }) setLoader(false) } const [stopModal, setStopModal] = useState(false); const [buttonLoading, setButtonLoading] = 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!`) updateInfo(); }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!`) updateInfo(); }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)!`) updateInfo(); }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) } 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}
<>
{additional_buttons} {["pause","wait"].includes(service.status)? setStopModal(true)} size="xl" radius="md" variant="filled" disabled={service.status === "stop"}> : }
{onClick?
:null} <> {setStopModal(false);updateInfo();}} action={stopService} opened={stopModal} />
} export default ServiceRow;