Skip to content

Commit 336e3d8

Browse files
feat: pressing enter in new Convo form adds the email address to list (#612)
1 parent e73d8e6 commit 336e3d8

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

apps/web/src/app/[orgShortcode]/convo/_components/create-convo-form.tsx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ export default function CreateConvoForm() {
424424
}
425425
setSelectedEmailIdentity(value);
426426
}}>
427-
<SelectTrigger className="h-fit">
427+
<SelectTrigger>
428428
<SelectValue>
429429
{selectedEmailIdentityString ?? 'Select an Email Identity to Use'}
430430
</SelectValue>
@@ -470,7 +470,7 @@ export default function CreateConvoForm() {
470470
type="text"
471471
value={topic}
472472
onChange={(e) => setTopic(e.target.value)}
473-
className="h-fit w-full"
473+
className="w-full"
474474
/>
475475
</div>
476476

@@ -531,6 +531,7 @@ function ParticipantsComboboxPopover({
531531
);
532532

533533
const [currentSelectValue, setCurrentSelectValue] = useState('');
534+
const [search, setSearch] = useState('');
534535
const hasExternalParticipants = useMemo(
535536
() =>
536537
selectedParticipants.some(
@@ -540,6 +541,30 @@ function ParticipantsComboboxPopover({
540541
[selectedParticipants]
541542
);
542543

544+
const setEmailParticipants = useSetAtom(newEmailParticipantsAtom);
545+
const addSelectedParticipant = useSetAtom(selectedParticipantsAtom);
546+
547+
const addEmailParticipant = (email: string) => {
548+
setEmailParticipants((prev) =>
549+
prev.includes(email) ? prev : prev.concat(email)
550+
);
551+
addSelectedParticipant((prev) =>
552+
prev.find((p) => p.publicId === email)
553+
? prev
554+
: prev.concat({
555+
type: 'email',
556+
publicId: email,
557+
address: email,
558+
keywords: [email],
559+
avatarPublicId: null,
560+
avatarTimestamp: null,
561+
color: null,
562+
own: false,
563+
name: email
564+
})
565+
);
566+
};
567+
543568
return (
544569
<div className="flex w-full items-center space-x-4">
545570
<Popover
@@ -638,20 +663,28 @@ function ParticipantsComboboxPopover({
638663
<CommandInput asChild>
639664
<Input
640665
label="Search or type an Email address"
641-
className="h-8"
666+
value={search}
667+
onChange={(e) => setSearch(e.target.value)}
642668
onKeyDown={(e) => {
643669
// Hack to prevent cmdk from preventing Home and End keys
644670
if (e.key === 'Home' || e.key === 'End') {
645671
e.stopPropagation();
646672
}
673+
if (e.key === 'Enter') {
674+
if (z.string().email().safeParse(search).success) {
675+
addEmailParticipant(search);
676+
setCurrentSelectValue('');
677+
setSearch('');
678+
}
679+
}
647680
}}
648681
onFocus={() => {
649682
// Remove current select value when input is focused
650683
setCurrentSelectValue('');
651684
}}
652685
/>
653686
</CommandInput>
654-
<CommandList className="max-h-[calc(var(--radix-popover-content-available-height)*0.9)] overflow-scroll">
687+
<CommandList className="max-h-[calc(var(--radix-popover-content-available-height)*0.9)] overflow-x-clip overflow-y-scroll">
655688
{loading && <CommandLoading>Loading Participants</CommandLoading>}
656689
<CommandGroup className="flex flex-col gap-2 px-1">
657690
{!loading && <EmptyStateHandler />}

0 commit comments

Comments
 (0)