set blank values by default (fix uncontrolled warnings)

This commit is contained in:
ppc
2024-08-08 17:03:44 +01:00
parent 84fa0947e1
commit 0c168554c0
2 changed files with 24 additions and 31 deletions
+19 -30
View File
@@ -109,11 +109,13 @@ function ServerList(props: { servers: AimeServer[] | undefined }) {
function ServerAddForm() {
const router = useRouter();
const form = useForm<z.infer<typeof serverAdditionSchema>>({
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<typeof serverAdditionSchema>) {
@@ -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) && (<div></div>)}
{showHttpsWarning && (
<Alert variant="blank" className="text-yellow-500 border-yellow-500">
<ShieldAlert className="h-5 w-5 text-yellow-500"/>
<AlertTitle>HTTPS Warning</AlertTitle>
<AlertDescription>
AimeNet doesn&apos;t support HTTPS out-the-box.
If you&apos;re using HTTPS, ensure a reverse-proxy or <Link target="_blank"
className="underline"
href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/httpsys">
HTTP.SYS <SquareArrowOutUpRight className="inline h-3 w-3"/>
</Link> has been configured and a valid, trusted SSL certificate has been configured.
</AlertDescription>
</Alert>
)}
{(showPortWarning && !showHttpsWarning) && (
<Alert variant="blank" className="text-purple-500 border-purple-500">
<Network className="h-5 w-5 text-purple-500"/>
<AlertTitle>Default Port Detected</AlertTitle>
<AlertDescription>
Ensure you&apos;ve set the correct port in the address field. By default, AimeNet uses
port <code>6070</code>.
</AlertDescription>
</Alert>
{showHttpsWarning && (<>
<div></div>
<Alert variant="blank" className="text-yellow-500 border-yellow-500">
<ShieldAlert className="h-5 w-5 text-yellow-500"/>
<AlertTitle>HTTPS Warning</AlertTitle>
<AlertDescription>
AimeNet doesn&apos;t support HTTPS out-the-box.
If you&apos;re using HTTPS, ensure a reverse-proxy or <Link target="_blank"
className="underline"
href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/httpsys">
HTTP.SYS <SquareArrowOutUpRight className="inline h-3 w-3"/>
</Link> has been configured and a valid, trusted SSL certificate has been configured.
</AlertDescription>
</Alert>
</>
)}
<Form {...form}>
@@ -192,7 +182,6 @@ function ServerAddForm() {
<FormField
control={form.control}
name="address"
render={({field}) => (
<FormItem className="flex-grow">
<FormControl>
@@ -85,7 +85,11 @@ export function CardCreationDialog(props: { children: Readonly<React.ReactNode>
function AimeCardCreationForm(props: { callback?: () => void }) {
const form = useForm<z.infer<typeof schema>>({
resolver: zodResolver(schema)
resolver: zodResolver(schema),
defaultValues: {
id: '',
name: ''
}
});
async function onSubmit(values: z.infer<typeof schema>) {