import React, { useState } from 'react'; import { styled } from '@mui/system'; import { TextField, Button, Switch, FormControlLabel, Box, Typography } from '@mui/material'; import { sendProxyConfig } from '../../api/proxy'; import { useGlobalInfoStore } from '../../context/globalInfo'; const FormContainer = styled(Box)({ display: 'flex', flexDirection: 'column', gap: '16px', padding: '20px', borderRadius: '8px', }); const FormControl = styled(Box)({ marginBottom: '16px', }); const ProxyForm: React.FC = () => { const [proxyConfig, setProxyConfig] = useState({ server: '', username: '', password: '', }); const [requiresAuth, setRequiresAuth] = useState(false); const { notify } = useGlobalInfoStore(); const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setProxyConfig({ ...proxyConfig, [name]: value }); }; const handleAuthToggle = (e: React.ChangeEvent) => { setRequiresAuth(e.target.checked); if (!e.target.checked) { setProxyConfig({ ...proxyConfig, username: '', password: '' }); } }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); await sendProxyConfig(proxyConfig).then((response) => { if (response) { notify('success', 'Proxy configuration submitted successfully'); } else { notify('error', 'Failed to submit proxy configuration. Try again.'); } }); }; return (
Proxy Configuration } label="Does The Proxy Require Authentication?" /> {requiresAuth && ( <> )}
); }; export default ProxyForm;