({
selectedContactEmail,
groups,
contacts,
account,
domain,
onClose,
}: NewMessageProps)
| 41 | } |
| 42 | |
| 43 | export function MessageForm({ |
| 44 | selectedContactEmail, |
| 45 | groups, |
| 46 | contacts, |
| 47 | account, |
| 48 | domain, |
| 49 | onClose, |
| 50 | }: NewMessageProps) { |
| 51 | const supabase = createClient() |
| 52 | const router = useRouter() |
| 53 | const [subject, setSubject] = useState("") |
| 54 | const [body, setBody] = useState("") |
| 55 | const [selectedGroups, setSelectedGroups] = useState<Group[]>([]) |
| 56 | const [isSendingEmail, setIsSendingEmail] = useState(false) |
| 57 | const subjectInputRef = useRef<HTMLInputElement>(null) |
| 58 | const [recipients, setRecipients] = useState<Recipient[]>([]) |
| 59 | |
| 60 | const customComponents = { |
| 61 | MultiValue: ({ children, removeProps, ...props }: any) => { |
| 62 | const isEmail = "isEmail" in props.data && props.data.isEmail |
| 63 | return ( |
| 64 | <Badge |
| 65 | className="flex items-center gap-1 m-1" |
| 66 | style={{ |
| 67 | backgroundColor: isEmail ? "gray" : props.data.color, |
| 68 | color: "white", |
| 69 | }} |
| 70 | > |
| 71 | {children} |
| 72 | <span {...removeProps} className="cursor-pointer hover:opacity-75"> |
| 73 | <X size={14} /> |
| 74 | </span> |
| 75 | </Badge> |
| 76 | ) |
| 77 | }, |
| 78 | } |
| 79 | |
| 80 | const handleKeyDown = (event: React.KeyboardEvent) => { |
| 81 | if (event.key === "Tab" && !event.shiftKey) { |
| 82 | event.preventDefault() |
| 83 | subjectInputRef.current?.focus() |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | const handleRecipientChange = (newValue: any, actionMeta: any) => { |
| 88 | if (actionMeta.action === "create-option") { |
| 89 | const newOption = newValue[newValue.length - 1] |
| 90 | if (isValidEmail(newOption.value)) { |
| 91 | setRecipients([ |
| 92 | ...newValue.slice(0, -1), |
| 93 | { ...newOption, isEmail: true }, |
| 94 | ]) |
| 95 | } else { |
| 96 | // Optionally, show an error message for invalid email |
| 97 | toast({ |
| 98 | variant: "destructive", |
| 99 | description: `Invalid email address: ${newOption.value}`, |
| 100 | }) |
nothing calls this directly
no test coverage detected