()
| 29 | type ConnectionFormValues = z.infer<typeof connectionSchema>; |
| 30 | |
| 31 | export function ConnectionForm() { |
| 32 | const platform = usePlatform(); |
| 33 | const serverUrl = useServerStore((state) => state.serverUrl); |
| 34 | const setServerUrl = useServerStore((state) => state.setServerUrl); |
| 35 | const keepServerRunningOnClose = useServerStore((state) => state.keepServerRunningOnClose); |
| 36 | const setKeepServerRunningOnClose = useServerStore((state) => state.setKeepServerRunningOnClose); |
| 37 | const mode = useServerStore((state) => state.mode); |
| 38 | const setMode = useServerStore((state) => state.setMode); |
| 39 | const { toast } = useToast(); |
| 40 | const { data: health, isLoading, error: healthError } = useServerHealth(); |
| 41 | |
| 42 | const form = useForm<ConnectionFormValues>({ |
| 43 | resolver: zodResolver(connectionSchema), |
| 44 | defaultValues: { |
| 45 | serverUrl: serverUrl, |
| 46 | }, |
| 47 | }); |
| 48 | |
| 49 | // Sync form with store when serverUrl changes externally |
| 50 | useEffect(() => { |
| 51 | form.reset({ serverUrl }); |
| 52 | }, [serverUrl, form]); |
| 53 | |
| 54 | const { isDirty } = form.formState; |
| 55 | |
| 56 | function onSubmit(data: ConnectionFormValues) { |
| 57 | setServerUrl(data.serverUrl); |
| 58 | form.reset(data); |
| 59 | toast({ |
| 60 | title: 'Server URL updated', |
| 61 | description: `Connected to ${data.serverUrl}`, |
| 62 | }); |
| 63 | } |
| 64 | |
| 65 | return ( |
| 66 | <Card role="region" aria-label="Server Connection" tabIndex={0}> |
| 67 | <CardHeader> |
| 68 | <CardTitle>Server Connection</CardTitle> |
| 69 | </CardHeader> |
| 70 | <CardContent> |
| 71 | <Form {...form}> |
| 72 | <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4"> |
| 73 | <FormField |
| 74 | control={form.control} |
| 75 | name="serverUrl" |
| 76 | render={({ field }) => ( |
| 77 | <FormItem> |
| 78 | <FormLabel>Server URL</FormLabel> |
| 79 | <FormControl> |
| 80 | <Input placeholder="http://127.0.0.1:17493" {...field} /> |
| 81 | </FormControl> |
| 82 | <FormDescription>Enter the URL of your voicebox backend server</FormDescription> |
| 83 | <FormMessage /> |
| 84 | </FormItem> |
| 85 | )} |
| 86 | /> |
| 87 | |
| 88 | {isDirty && <Button type="submit">Update Connection</Button>} |
nothing calls this directly
no test coverage detected