Skip to content

Commit 35bd35f

Browse files
committed
feat: add NewAgentDialog component and enhance agent selection with creation option in MeetingForm
1 parent 55e1bfb commit 35bd35f

1 file changed

Lines changed: 82 additions & 67 deletions

File tree

src/modules/meetings/ui/components/meeting-form.tsx

Lines changed: 82 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Button } from "@/components/ui/button";
22
import {
33
Form,
44
FormControl,
5+
FormDescription,
56
FormField,
67
FormItem,
78
FormLabel,
@@ -18,6 +19,7 @@ import type { z } from "zod";
1819

1920
import { CommandSelect } from "@/components/command-select";
2021
import { GenerateAvatar } from "@/components/generate-avatar";
22+
import NewAgentDialog from "@/modules/agents/ui/components/new-agent-dialog";
2123
import { meetingsInsertSchema } from "../../schemas";
2224
import { MeetingGetOne } from "../../types";
2325

@@ -30,7 +32,7 @@ interface MeetingFormProps {
3032
export const MeetingForm = ({ onSuccess, onCancel, initialValues }: MeetingFormProps) => {
3133
const trpc = useTRPC();
3234
const [agentSearch, setAgentSearch] = useState<string>("");
33-
const [open, setOpen] = useState<boolean>(false);
35+
const [openNewAgentDialog, setOpenNewAgentDialog] = useState<boolean>(false);
3436

3537
const queryClient = useQueryClient();
3638
const firstInputRef = useRef<HTMLInputElement>(null);
@@ -102,72 +104,85 @@ export const MeetingForm = ({ onSuccess, onCancel, initialValues }: MeetingFormP
102104
};
103105

104106
return (
105-
<Form {...form}>
106-
<form className="space-y-4" onSubmit={form.handleSubmit(onSubmit)}>
107-
<FormField
108-
name="name"
109-
control={form.control}
110-
render={({ field }) => (
111-
<FormItem>
112-
<FormLabel>Name</FormLabel>
113-
<FormControl>
114-
<Input {...field} placeholder="Enter meeting name" />
115-
</FormControl>
116-
<FormMessage />
117-
</FormItem>
118-
)}
119-
/>
120-
121-
<FormField
122-
name="agentId"
123-
control={form.control}
124-
render={({ field }) => (
125-
<FormItem>
126-
<FormLabel>Agent</FormLabel>
127-
<FormControl>
128-
<CommandSelect
129-
options={(agents.data?.items ?? []).map((agent) => ({
130-
id: agent.id,
131-
value: agent.id,
132-
children: (
133-
<div className="flex items-center gap-x-2">
134-
<GenerateAvatar
135-
seed={agent.name}
136-
className="border size-6"
137-
variant="botttsNeutral"
138-
/>
139-
<span>{agent.name}</span>
140-
</div>
141-
),
142-
}))}
143-
onSelect={(value) => field.onChange(value)}
144-
onSearch={setAgentSearch}
145-
value={field.value}
146-
placeholder="Select an agent..."
147-
/>
148-
</FormControl>
149-
<FormMessage />
150-
</FormItem>
151-
)}
152-
/>
153-
154-
<div className="flex justify-between gap-x-2">
155-
{onCancel && (
156-
<Button
157-
onClick={onCancel}
158-
disabled={isPending}
159-
variant="ghost"
160-
className="mr-2"
161-
type="button"
162-
>
163-
Cancel
107+
<>
108+
<NewAgentDialog open={openNewAgentDialog} onOpenChange={setOpenNewAgentDialog} />
109+
<Form {...form}>
110+
<form className="space-y-4" onSubmit={form.handleSubmit(onSubmit)}>
111+
<FormField
112+
name="name"
113+
control={form.control}
114+
render={({ field }) => (
115+
<FormItem>
116+
<FormLabel>Name</FormLabel>
117+
<FormControl>
118+
<Input {...field} placeholder="Enter meeting name" />
119+
</FormControl>
120+
<FormMessage />
121+
</FormItem>
122+
)}
123+
/>
124+
125+
<FormField
126+
name="agentId"
127+
control={form.control}
128+
render={({ field }) => (
129+
<FormItem>
130+
<FormLabel>Agent</FormLabel>
131+
<FormControl>
132+
<CommandSelect
133+
options={(agents.data?.items ?? []).map((agent) => ({
134+
id: agent.id,
135+
value: agent.id,
136+
children: (
137+
<div className="flex items-center gap-x-2">
138+
<GenerateAvatar
139+
seed={agent.name}
140+
className="border size-6"
141+
variant="botttsNeutral"
142+
/>
143+
<span>{agent.name}</span>
144+
</div>
145+
),
146+
}))}
147+
onSelect={(value) => field.onChange(value)}
148+
onSearch={setAgentSearch}
149+
value={field.value}
150+
placeholder="Select an agent..."
151+
/>
152+
</FormControl>
153+
<FormDescription>
154+
Not found what you&apos;re looking for?{" "}
155+
<button
156+
type="button"
157+
className="text-primary hover:underline"
158+
onClick={() => setOpenNewAgentDialog(true)}
159+
>
160+
Create a new agent
161+
</button>
162+
</FormDescription>
163+
<FormMessage />
164+
</FormItem>
165+
)}
166+
/>
167+
168+
<div className="flex justify-between gap-x-2">
169+
{onCancel && (
170+
<Button
171+
onClick={onCancel}
172+
disabled={isPending}
173+
variant="ghost"
174+
className="mr-2"
175+
type="button"
176+
>
177+
Cancel
178+
</Button>
179+
)}
180+
<Button type="submit" disabled={isPending}>
181+
{isEdit ? "Update Meeting" : "Create Meeting"}
164182
</Button>
165-
)}
166-
<Button type="submit" disabled={isPending}>
167-
{isEdit ? "Update Meeting" : "Create Meeting"}
168-
</Button>
169-
</div>
170-
</form>
171-
</Form>
183+
</div>
184+
</form>
185+
</Form>
186+
</>
172187
);
173188
};

0 commit comments

Comments
 (0)