import { Button, Group, NumberInput, Space, Notification, Modal, Center, Title } from '@mantine/core'; import { useForm } from '@mantine/hooks'; import React, { useEffect, useState } from 'react'; import { changeports, fireUpdateRequest, okNotify } from '../../js/utils'; import { ImCross } from "react-icons/im" import { Service } from '../../js/models'; import { BsArrowDownSquareFill } from 'react-icons/bs'; type InputForm = { internalPort:number, port:number } function ChangePortModal({ service, opened, onClose }:{ service:Service, opened:boolean, onClose:()=>void }) { const form = useForm({ initialValues: { internalPort: service.internal_port, port: service.public_port }, validationRules:{ internalPort: (value) => value>0 && value<65536, port: (value) => value>0 && value<65536 } }) useEffect(()=>{ form.setValues({internalPort: service.internal_port, port:service.public_port}) },[opened]) const close = () =>{ onClose() form.reset() setError(null) } const [submitLoading, setSubmitLoading] = useState(false) const [error, setError] = useState(null) const submitRequest = (data:InputForm) =>{ setSubmitLoading(true) changeports(service.id, data).then( res => { if (!res){ setSubmitLoading(false) close(); fireUpdateRequest(); okNotify(`Internal port on ${service.name} service has changed in ${data.internalPort}`, `Successfully changed internal port of service with id ${service.id}`) }else{ setSubmitLoading(false) setError("Invalid request! [ "+res+" ]") } }).catch( err => { setSubmitLoading(false) setError("Request Failed! [ "+err+" ]") }) } return
The change of the ports will cause a temporarily shutdown of the service! ⚠️
{error?<> } color="red" onClose={()=>{setError(null)}}> Error: {error} :null}
} export default ChangePortModal;