From 0c168554c08e307e304658b2a8e1bdb6e5daf28a Mon Sep 17 00:00:00 2001 From: ppc Date: Thu, 8 Aug 2024 17:03:44 +0100 Subject: [PATCH] set blank values by default (fix uncontrolled warnings) --- aimenet-web/app/page.tsx | 49 +++++++------------ aimenet-web/components/card-creation-form.tsx | 6 ++- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/aimenet-web/app/page.tsx b/aimenet-web/app/page.tsx index aada902..ada1080 100644 --- a/aimenet-web/app/page.tsx +++ b/aimenet-web/app/page.tsx @@ -109,11 +109,13 @@ function ServerList(props: { servers: AimeServer[] | undefined }) { function ServerAddForm() { const router = useRouter(); const form = useForm>({ - resolver: zodResolver(serverAdditionSchema) + resolver: zodResolver(serverAdditionSchema), + defaultValues: { + address: '' + } }); const [showHttpsWarning, setHttpsWarning] = useState(false); - const [showPortWarning, setPortWarning] = useState(false); const [blockSubmit, setBlockSubmit] = useState(true); async function onSubmit(values: z.infer) { @@ -147,11 +149,9 @@ function ServerAddForm() { const address = new URL(event.target.value); setBlockSubmit(false); - setPortWarning(!address.port); setHttpsWarning(address.protocol !== "http:"); } catch { setBlockSubmit(true); - setPortWarning(false); setHttpsWarning(false); } @@ -160,31 +160,21 @@ function ServerAddForm() { return ( <> - {(showHttpsWarning || showPortWarning) && (
)} - {showHttpsWarning && ( - - - HTTPS Warning - - AimeNet doesn't support HTTPS out-the-box. - If you're using HTTPS, ensure a reverse-proxy or - HTTP.SYS - has been configured and a valid, trusted SSL certificate has been configured. - - - )} - - {(showPortWarning && !showHttpsWarning) && ( - - - Default Port Detected - - Ensure you've set the correct port in the address field. By default, AimeNet uses - port 6070. - - + {showHttpsWarning && (<> +
+ + + HTTPS Warning + + AimeNet doesn't support HTTPS out-the-box. + If you're using HTTPS, ensure a reverse-proxy or + HTTP.SYS + has been configured and a valid, trusted SSL certificate has been configured. + + + )}
@@ -192,7 +182,6 @@ function ServerAddForm() { ( diff --git a/aimenet-web/components/card-creation-form.tsx b/aimenet-web/components/card-creation-form.tsx index 8084279..df68466 100644 --- a/aimenet-web/components/card-creation-form.tsx +++ b/aimenet-web/components/card-creation-form.tsx @@ -85,7 +85,11 @@ export function CardCreationDialog(props: { children: Readonly function AimeCardCreationForm(props: { callback?: () => void }) { const form = useForm>({ - resolver: zodResolver(schema) + resolver: zodResolver(schema), + defaultValues: { + id: '', + name: '' + } }); async function onSubmit(values: z.infer) {