feat: use radio for proxy type + style improvements

This commit is contained in:
karishmas6
2024-09-30 23:27:59 +05:30
parent 15ac55b44a
commit 83adb99b04

View File

@@ -1,32 +1,24 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { TextField, Button, MenuItem, Box } from '@mui/material'; import { TextField, Button, RadioGroup, FormControlLabel, Radio, Box } from '@mui/material';
import { styled } from '@mui/system'; import { styled } from '@mui/system';
import axios from 'axios'; import axios from 'axios';
const proxyTypes = [
{ label: 'HTTP', value: 'http' },
{ label: 'HTTPS', value: 'https' },
{ label: 'SOCKS5', value: 'socks5' },
];
const FormContainer = styled(Box)({ const FormContainer = styled(Box)({
display: 'flex', display: 'flex',
flexDirection: 'column', flexDirection: 'column',
gap: '20px', gap: '16px',
width: '400px',
margin: '0 auto',
padding: '20px', padding: '20px',
backgroundColor: '#f9f9f9', backgroundColor: '#f9f9f9',
borderRadius: '8px', borderRadius: '8px',
}); });
const FormControl = styled(Box)({ const FormControl = styled(Box)({
marginBottom: '10px', marginBottom: '16px',
}); });
const ProxyForm: React.FC = () => { const ProxyForm: React.FC = () => {
const [proxyConfig, setProxyConfig] = useState({ const [proxyConfig, setProxyConfig] = useState({
type: '', type: 'http',
server: '', server: '',
username: '', username: '',
password: '', password: '',
@@ -41,7 +33,7 @@ const ProxyForm: React.FC = () => {
e.preventDefault(); e.preventDefault();
try { try {
const response = await axios.post('/api/proxy', proxyConfig); const response = await axios.post('/api/proxy', proxyConfig);
alert(`Successfully added the proxy`); alert(`Success!`);
} catch (error) { } catch (error) {
alert('Error submitting proxy configuration'); alert('Error submitting proxy configuration');
} }
@@ -50,22 +42,20 @@ const ProxyForm: React.FC = () => {
return ( return (
<FormContainer> <FormContainer>
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
<TextField <FormControl>
select <RadioGroup
label="Proxy Type"
name="type" name="type"
value={proxyConfig.type} value={proxyConfig.type}
onChange={handleChange} onChange={handleChange}
fullWidth row
required
> >
{proxyTypes.map((option) => ( <FormControlLabel value="http" control={<Radio />} label="HTTP" />
<MenuItem key={option.value} value={option.value}> <FormControlLabel value="https" control={<Radio />} label="HTTPS" />
{option.label} <FormControlLabel value="socks5" control={<Radio />} label="SOCKS5" />
</MenuItem> </RadioGroup>
))} </FormControl>
</TextField>
<FormControl>
<TextField <TextField
label="Proxy Server URL" label="Proxy Server URL"
name="server" name="server"
@@ -75,7 +65,9 @@ const ProxyForm: React.FC = () => {
required required
helperText="e.g., http://proxy-server.com:8080" helperText="e.g., http://proxy-server.com:8080"
/> />
</FormControl>
<FormControl>
<TextField <TextField
label="Username (Optional)" label="Username (Optional)"
name="username" name="username"
@@ -83,7 +75,9 @@ const ProxyForm: React.FC = () => {
onChange={handleChange} onChange={handleChange}
fullWidth fullWidth
/> />
</FormControl>
<FormControl>
<TextField <TextField
label="Password (Optional)" label="Password (Optional)"
name="password" name="password"
@@ -92,6 +86,7 @@ const ProxyForm: React.FC = () => {
type="password" type="password"
fullWidth fullWidth
/> />
</FormControl>
<Button variant="contained" color="primary" type="submit" fullWidth> <Button variant="contained" color="primary" type="submit" fullWidth>
Submit Proxy Submit Proxy