Files
parcer/src/components/organisms/ProxyForm.tsx

106 lines
3.5 KiB
TypeScript
Raw Normal View History

2024-09-30 17:20:16 +05:30
import React, { useState } from 'react';
2024-09-30 23:35:00 +05:30
import { TextField, Button, RadioGroup, FormControlLabel, Radio, Box, Typography } from '@mui/material';
2024-09-30 17:20:16 +05:30
import { styled } from '@mui/system';
import axios from 'axios';
const FormContainer = styled(Box)({
2024-09-30 23:29:06 +05:30
display: 'flex',
flexDirection: 'column',
gap: '16px',
padding: '20px',
borderRadius: '8px',
2024-09-30 17:20:16 +05:30
});
2024-09-30 23:26:24 +05:30
const FormControl = styled(Box)({
2024-09-30 23:29:06 +05:30
marginBottom: '16px',
2024-09-30 23:26:24 +05:30
});
2024-09-30 17:20:16 +05:30
const ProxyForm: React.FC = () => {
2024-09-30 23:29:06 +05:30
const [proxyConfig, setProxyConfig] = useState({
type: 'http',
server: '',
username: '',
password: '',
});
2024-09-30 17:20:16 +05:30
2024-09-30 23:29:06 +05:30
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target;
setProxyConfig({ ...proxyConfig, [name]: value });
};
2024-09-30 17:20:16 +05:30
2024-09-30 23:29:06 +05:30
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
try {
2024-09-30 23:49:50 +05:30
const response = await axios.post('http://localhost:8080/proxy/config', proxyConfig);
2024-09-30 23:51:12 +05:30
if (response.status === 200) {
return response.data;
} else {
throw new Error(`Failed to submit proxy configuration. Try again.`);
}
2024-09-30 23:29:06 +05:30
} catch (error) {
alert('Error submitting proxy configuration');
}
};
2024-09-30 17:20:16 +05:30
2024-09-30 23:29:06 +05:30
return (
<FormContainer>
<form onSubmit={handleSubmit}>
<FormControl>
2024-09-30 23:35:00 +05:30
<Typography variant="subtitle1" gutterBottom>Select Proxy Type</Typography>
2024-09-30 23:29:06 +05:30
<RadioGroup
name="type"
value={proxyConfig.type}
onChange={handleChange}
row
>
<FormControlLabel value="http" control={<Radio />} label="HTTP" />
<FormControlLabel value="https" control={<Radio />} label="HTTPS" />
<FormControlLabel value="socks5" control={<Radio />} label="SOCKS5" />
</RadioGroup>
</FormControl>
2024-09-30 17:20:16 +05:30
2024-09-30 23:44:00 +05:30
<Typography variant="subtitle1" gutterBottom style={{ marginBottom: '20px', marginTop: '20px' }}>Proxy Configuration</Typography>
2024-09-30 23:36:33 +05:30
2024-09-30 23:29:06 +05:30
<FormControl>
<TextField
label="Proxy Server URL"
name="server"
value={proxyConfig.server}
onChange={handleChange}
fullWidth
required
helperText="e.g., http://proxy-server.com:8080"
/>
</FormControl>
2024-09-30 17:20:16 +05:30
2024-09-30 23:29:06 +05:30
<FormControl>
<TextField
label="Username (Optional)"
name="username"
value={proxyConfig.username}
onChange={handleChange}
fullWidth
/>
</FormControl>
2024-09-30 17:20:16 +05:30
2024-09-30 23:29:06 +05:30
<FormControl>
<TextField
label="Password (Optional)"
name="password"
value={proxyConfig.password}
onChange={handleChange}
type="password"
fullWidth
/>
</FormControl>
2024-09-30 17:20:16 +05:30
2024-09-30 23:29:06 +05:30
<Button variant="contained" color="primary" type="submit" fullWidth>
Add Proxy
</Button>
</form>
</FormContainer>
);
2024-09-30 17:20:16 +05:30
};
export default ProxyForm;