import { ActionIcon, Badge, Grid, Space, Title } 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 } 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 [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!`) }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!`) }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)!`) }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}
Status: {service.status} Regex: {service.n_regex} Connections Blocked: {service.n_packets}
{additional_buttons} {["pause","wait"].includes(service.status)? : }
{onClick?:null}
setStopModal(false)} action={stopService} opened={stopModal} />
} export default ServiceRow;