From 992c75bf0000f2ed15e93cd22fb5831205cb36b7 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Wed, 2 Oct 2024 23:33:16 +0530 Subject: [PATCH] feat: check if proxy requires auth & accordingly show username & password fields --- src/components/organisms/ProxyForm.tsx | 58 ++++++++++++++++++-------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/src/components/organisms/ProxyForm.tsx b/src/components/organisms/ProxyForm.tsx index c2a17b3f..b82bb86f 100644 --- a/src/components/organisms/ProxyForm.tsx +++ b/src/components/organisms/ProxyForm.tsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import { styled } from '@mui/system'; -import { TextField, Button, RadioGroup, FormControlLabel, Radio, Box, Typography } from '@mui/material'; +import { TextField, Button, Switch, FormControlLabel, Box, Typography } from '@mui/material'; import { sendProxyConfig } from '../../api/proxy'; import { useGlobalInfoStore } from '../../context/globalInfo'; @@ -22,6 +22,7 @@ const ProxyForm: React.FC = () => { username: '', password: '', }); + const [requiresAuth, setRequiresAuth] = useState(false); const { notify } = useGlobalInfoStore(); @@ -30,6 +31,13 @@ const ProxyForm: React.FC = () => { 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) => { @@ -44,7 +52,9 @@ const ProxyForm: React.FC = () => { return (
- Proxy Configuration + + Proxy Configuration + { /> - - - - } + label="Requires Authentication?" /> + {requiresAuth && ( + <> + + + + + + + + )}