|
1 | 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
2 | 2 | import { zodResolver } from "@hookform/resolvers/zod"; |
3 | 3 | import { Separator } from "@radix-ui/react-dropdown-menu"; |
4 | | -import { useState } from "react"; |
| 4 | +import { useEffect, useState } from "react"; |
5 | 5 | import { useForm } from "react-hook-form"; |
6 | 6 | import { useTranslation } from "react-i18next"; |
7 | 7 | import { toast } from "react-toastify"; |
@@ -42,15 +42,28 @@ function Proxy() { |
42 | 42 | const form = useForm<FormSchemaType>({ |
43 | 43 | resolver: zodResolver(formSchema), |
44 | 44 | defaultValues: { |
45 | | - enabled: proxy?.enabled ?? false, |
46 | | - host: proxy?.host ?? "", |
47 | | - port: proxy?.port ?? "", |
48 | | - protocol: proxy?.protocol ?? "http", |
49 | | - username: proxy?.username ?? "", |
50 | | - password: proxy?.password ?? "", |
| 45 | + enabled: false, |
| 46 | + host: "", |
| 47 | + port: "", |
| 48 | + protocol: "http", |
| 49 | + username: "", |
| 50 | + password: "", |
51 | 51 | }, |
52 | 52 | }); |
53 | 53 |
|
| 54 | + useEffect(() => { |
| 55 | + if (proxy) { |
| 56 | + form.reset({ |
| 57 | + enabled: proxy.enabled, |
| 58 | + host: proxy.host, |
| 59 | + port: proxy.port, |
| 60 | + protocol: proxy.protocol, |
| 61 | + username: proxy.username, |
| 62 | + password: proxy.password, |
| 63 | + }); |
| 64 | + } |
| 65 | + }, [proxy]); // eslint-disable-line react-hooks/exhaustive-deps |
| 66 | + |
54 | 67 | const onSubmit = async (data: FormSchemaType) => { |
55 | 68 | if (!instance) return; |
56 | 69 |
|
|
0 commit comments