diff --git a/ui/admin/app/components/agent/Publish.tsx b/ui/admin/app/components/agent/Publish.tsx index 0c3efc5ea..520f7f88b 100644 --- a/ui/admin/app/components/agent/Publish.tsx +++ b/ui/admin/app/components/agent/Publish.tsx @@ -1,6 +1,9 @@ +import { zodResolver } from "@hookform/resolvers/zod"; import { Eye } from "lucide-react"; -import { useState } from "react"; +import { useForm } from "react-hook-form"; +import { z } from "zod"; +import { ControlledInput } from "~/components/form/controlledInputs"; import { Button } from "~/components/ui/button"; import { Dialog, @@ -10,7 +13,7 @@ import { DialogTitle, DialogTrigger, } from "~/components/ui/dialog"; -import { Input } from "~/components/ui/input"; +import { Form } from "~/components/ui/form"; type PublishProps = { className?: string; @@ -18,10 +21,29 @@ type PublishProps = { onPublish: (alias: string) => void; }; +const publishSchema = z.object({ + alias: z + .string() + .min(1, "Alias is required.") + .regex( + /^[a-zA-Z0-9_-]+$/, + "Only alphanumeric characters, dashes, and underscores are allowed." + ), +}); + +type PublishFormValues = z.infer; + export function Publish({ className, alias: _alias, onPublish }: PublishProps) { - const [alias, setAlias] = useState(_alias); + const form = useForm({ + resolver: zodResolver(publishSchema), + defaultValues: { + alias: _alias, + }, + }); - const handlePublish = () => onPublish(alias); + const handlePublish = (values: PublishFormValues) => { + onPublish(values.alias); + }; return ( @@ -32,46 +54,54 @@ export function Publish({ className, alias: _alias, onPublish }: PublishProps) { -
- - Enter a handle for this agent: - - setAlias(e.target.value)} - /> -
-
-

- This agent will be available at: -

+
+ +
+ + Enter a handle for this agent: + + +
+
+

+ This agent will be available at: +

-

- {`${window.location.protocol}//${window.location.host}/${alias}`} -

+

+ {`${window.location.protocol}//${window.location.host}/${form.watch("alias")}`} +

-

- If you have another agent with this handle, you will - need to unpublish it before this agent can be accessed - at the above URL. -

-
- -
- - - - - - -
-
+

+ If you have another agent with this handle, you + will need to unpublish it before this agent can + be accessed at the above URL. +

+
+ +
+ + + + +
+
+ +
);