@@ -573,6 +573,7 @@ export default function CreateConvoForm({
573
573
< div className = "flex w-full flex-col gap-2 text-sm" >
574
574
< h4 className = "font-bold" > Participants</ h4 >
575
575
< ParticipantsComboboxPopover
576
+ disabled = { userEmailIdentities ?. emailIdentities . length === 0 }
576
577
participants = { allParticipants }
577
578
loading = { allParticipantsLoaded }
578
579
selectedParticipants = { selectedParticipants }
@@ -646,39 +647,49 @@ export default function CreateConvoForm({
646
647
< SelectValue placeholder = "Select an email address" />
647
648
</ SelectTrigger >
648
649
< SelectContent >
649
- { userEmailIdentities ?. emailIdentities . map ( ( email ) => (
650
- < SelectItem
651
- key = { email . publicId }
652
- value = { email . publicId }
653
- className = "[&>span:last-child]:w-full" >
654
- < span
655
- className = { cn (
656
- 'flex !min-w-0 items-center justify-between' ,
657
- ! email . sendingEnabled && 'text-base-11'
658
- ) } >
659
- < span className = "truncate" >
660
- { `${ email . sendName } (${ email . username } @${ email . domainName } )` }
650
+ { userEmailIdentities ?. emailIdentities . length == 0 ? (
651
+ < span
652
+ className = { cn (
653
+ 'text-base-11 flex !min-w-0 items-center justify-between truncate text-sm'
654
+ ) } >
655
+ { `No email identities available` }
656
+ </ span >
657
+ ) : (
658
+ userEmailIdentities ?. emailIdentities . map ( ( email ) => (
659
+ < SelectItem
660
+ key = { email . publicId }
661
+ value = { email . publicId }
662
+ className = "[&>span:last-child]:w-full" >
663
+ < span
664
+ className = { cn (
665
+ 'flex !min-w-0 items-center justify-between' ,
666
+ ! email . sendingEnabled && 'text-base-11'
667
+ ) } >
668
+ < span className = "truncate" >
669
+ { `${ email . sendName } (${ email . username } @${ email . domainName } )` }
670
+ </ span >
671
+ { ! email . sendingEnabled && (
672
+ < Tooltip >
673
+ < TooltipTrigger >
674
+ < Question size = { 14 } />
675
+ </ TooltipTrigger >
676
+ < TooltipContent className = "flex flex-col" >
677
+ < span >
678
+ Sending from this email identity is
679
+ disabled.
680
+ </ span >
681
+ < span >
682
+ { isAdmin
683
+ ? 'Please check that the DNS records are correctly set up.'
684
+ : 'Please contact your admin for assistance.' }
685
+ </ span >
686
+ </ TooltipContent >
687
+ </ Tooltip >
688
+ ) }
661
689
</ span >
662
- { ! email . sendingEnabled && (
663
- < Tooltip >
664
- < TooltipTrigger >
665
- < Question size = { 14 } />
666
- </ TooltipTrigger >
667
- < TooltipContent className = "flex flex-col" >
668
- < span >
669
- Sending from this email identity is disabled.
670
- </ span >
671
- < span >
672
- { isAdmin
673
- ? 'Please check that the DNS records are correctly set up.'
674
- : 'Please contact your admin for assistance.' }
675
- </ span >
676
- </ TooltipContent >
677
- </ Tooltip >
678
- ) }
679
- </ span >
680
- </ SelectItem >
681
- ) ) }
690
+ </ SelectItem >
691
+ ) )
692
+ ) }
682
693
</ SelectContent >
683
694
</ Select >
684
695
</ div >
@@ -740,9 +751,16 @@ export default function CreateConvoForm({
740
751
) ;
741
752
}
742
753
754
+ const showDisabledMessage = ( ) => {
755
+ toast . warning (
756
+ 'You cannot add participants to conversation until you have an email identity associated.'
757
+ ) ;
758
+ } ;
759
+
743
760
type ParticipantsComboboxPopoverProps = {
744
761
participants : NewConvoParticipant [ ] ;
745
762
loading : boolean ;
763
+ disabled ?: boolean ;
746
764
selectedParticipants : NewConvoParticipant [ ] ;
747
765
setSelectedParticipants : Dispatch < SetStateAction < NewConvoParticipant [ ] > > ;
748
766
setNewEmailParticipants : Dispatch < SetStateAction < string [ ] > > ;
@@ -751,6 +769,7 @@ type ParticipantsComboboxPopoverProps = {
751
769
function ParticipantsComboboxPopover ( {
752
770
participants,
753
771
loading,
772
+ disabled = false ,
754
773
selectedParticipants,
755
774
setSelectedParticipants,
756
775
setNewEmailParticipants
@@ -768,6 +787,7 @@ function ParticipantsComboboxPopover({
768
787
) ;
769
788
770
789
const addEmailParticipant = ( email : string ) => {
790
+ if ( disabled ) return ;
771
791
setNewEmailParticipants ( ( prev ) =>
772
792
prev . includes ( email ) ? prev : prev . concat ( email )
773
793
) ;
@@ -795,29 +815,11 @@ function ParticipantsComboboxPopover({
795
815
onOpenChange = { setOpen } >
796
816
< PopoverTrigger asChild >
797
817
< Button
798
- variant = { ' outline' }
818
+ variant = " outline"
799
819
className = "h-fit w-full justify-between" >
800
820
{ selectedParticipants . length > 0 ? (
801
821
< div className = "flex flex-wrap gap-2 overflow-hidden" >
802
822
{ selectedParticipants . map ( ( participant , i ) => {
803
- let info = '' ;
804
- switch ( participant . type ) {
805
- case 'orgMember' :
806
- info = participant . name ;
807
- break ;
808
- case 'team' :
809
- info = participant . name ;
810
- break ;
811
- case 'contact' :
812
- info = participant . name
813
- ? `${ participant . name } (${ participant . address ! } )`
814
- : participant . address ! ;
815
- break ;
816
- case 'email' :
817
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
818
- info = participant . address ! ;
819
- break ;
820
- }
821
823
return (
822
824
< div
823
825
key = { participant . publicId }
@@ -838,9 +840,13 @@ function ParticipantsComboboxPopover({
838
840
hideTooltip
839
841
/>
840
842
< p className = "text-base-11 text-sm" >
841
- { participant . own && participant . own
843
+ { participant . own
842
844
? 'You (already a participant)'
843
- : `${ participant . name } ${ participant . title ? `(${ participant . title } )` : '' } ` }
845
+ : `${ participant . name } ${
846
+ participant . title
847
+ ? `(${ participant . title } )`
848
+ : ''
849
+ } `}
844
850
</ p >
845
851
< AvatarIcon
846
852
avatarProfilePublicId = {
@@ -889,22 +895,19 @@ function ParticipantsComboboxPopover({
889
895
value = { search }
890
896
onChange = { ( e ) => setSearch ( e . target . value ) }
891
897
onKeyDown = { ( e ) => {
892
- // Hack to prevent cmdk from preventing Home and End keys
893
898
if ( e . key === 'Home' || e . key === 'End' ) {
894
899
e . stopPropagation ( ) ;
895
900
}
896
901
if ( e . key === 'Enter' ) {
902
+ if ( disabled ) return showDisabledMessage ( ) ;
897
903
if ( z . string ( ) . email ( ) . safeParse ( search ) . success ) {
898
904
addEmailParticipant ( search ) ;
899
905
setCurrentSelectValue ( '' ) ;
900
906
setSearch ( '' ) ;
901
907
}
902
908
}
903
909
} }
904
- onFocus = { ( ) => {
905
- // Remove current select value when input is focused
906
- setCurrentSelectValue ( '' ) ;
907
- } }
910
+ onFocus = { ( ) => setCurrentSelectValue ( '' ) }
908
911
/>
909
912
</ CommandInput >
910
913
< CommandList className = "max-h-[calc(var(--radix-popover-content-available-height)*0.9)] overflow-x-clip overflow-y-scroll" >
@@ -914,6 +917,7 @@ function ParticipantsComboboxPopover({
914
917
< EmptyStateHandler
915
918
addSelectedParticipant = { setSelectedParticipants }
916
919
setEmailParticipants = { setNewEmailParticipants }
920
+ disabled = { disabled }
917
921
/>
918
922
) }
919
923
{ participants . map ( ( participant ) => (
@@ -931,7 +935,7 @@ function ParticipantsComboboxPopover({
931
935
} } >
932
936
< HoverCard >
933
937
< Button
934
- variant = { ' ghost' }
938
+ variant = " ghost"
935
939
className = { cn (
936
940
'my-1 w-full items-center justify-start gap-2 px-1' ,
937
941
selectedParticipants . find (
@@ -964,9 +968,13 @@ function ParticipantsComboboxPopover({
964
968
hideTooltip
965
969
/>
966
970
< p className = "text-base-11 text-sm" >
967
- { participant . own && participant . own
971
+ { participant . own
968
972
? 'You (already a participant)'
969
- : `${ participant . name } ${ participant . title ? `(${ participant . title } )` : '' } ` }
973
+ : `${ participant . name } ${
974
+ participant . title
975
+ ? `(${ participant . title } )`
976
+ : ''
977
+ } `}
970
978
</ p >
971
979
</ HoverCardTrigger >
972
980
< AvatarIcon
@@ -1022,11 +1030,13 @@ function ParticipantsComboboxPopover({
1022
1030
type EmptyStateHandlerProps = {
1023
1031
setEmailParticipants : Dispatch < SetStateAction < string [ ] > > ;
1024
1032
addSelectedParticipant : Dispatch < SetStateAction < NewConvoParticipant [ ] > > ;
1033
+ disabled ?: boolean ;
1025
1034
} ;
1026
1035
1027
1036
function EmptyStateHandler ( {
1028
1037
setEmailParticipants,
1029
- addSelectedParticipant
1038
+ addSelectedParticipant,
1039
+ disabled = false
1030
1040
} : EmptyStateHandlerProps ) {
1031
1041
const isEmpty = useCommandState ( ( state ) => state . filtered . count === 0 ) ;
1032
1042
const email = useCommandState ( ( state ) => state . search ) ;
@@ -1036,6 +1046,7 @@ function EmptyStateHandler({
1036
1046
) ;
1037
1047
1038
1048
const addEmailParticipant = ( email : string ) => {
1049
+ if ( disabled ) return ;
1039
1050
setEmailParticipants ( ( prev ) =>
1040
1051
prev . includes ( email ) ? prev : prev . concat ( email )
1041
1052
) ;
@@ -1060,10 +1071,12 @@ function EmptyStateHandler({
1060
1071
< CommandItem
1061
1072
key = { email }
1062
1073
value = { email }
1074
+ disabled = { disabled }
1063
1075
forceMount
1064
1076
onKeyDown = { ( e ) => {
1065
1077
// Submit email on Enter key
1066
1078
if ( e . key === 'Enter' ) {
1079
+ if ( disabled ) return showDisabledMessage ( ) ;
1067
1080
addEmailParticipant ( email ) ;
1068
1081
}
1069
1082
} } >
@@ -1072,6 +1085,7 @@ function EmptyStateHandler({
1072
1085
className = "my-1 w-full justify-start px-1"
1073
1086
color = "gray"
1074
1087
onClick = { ( ) => {
1088
+ if ( disabled ) return showDisabledMessage ( ) ;
1075
1089
addEmailParticipant ( email ) ;
1076
1090
} } >
1077
1091
< At className = "mr-2 h-4 w-4" />
0 commit comments