import React, { useEffect, useRef, useState } from 'react'; import { DEFAULT_INVITE_MESSAGE } from '../../lib/onboarding-chain/content'; import { isValidEmail } from '../../utils/validators'; import { GRADIENT, MONO } from '../signup-mirror/theme'; import { ModalShell } from './modal-shell'; const FIELD_LABEL = `block ${MONO} text-[10px] tracking-[0.14em] uppercase text-[#8c9196] mb-1.5`; const FIELD = 'w-full p-[12px_13px] rounded-[10px] bg-white border border-[#e1e3e5] text-[#202223] text-[14px] outline-none transition focus:border-[#C8175D] focus:shadow-[0_0_0_3px_rgba(200,23,93,0.15)]'; export function InviteModal({ onSend, onClose, onDone, sending, sent, sentTo, }: { onSend: (email: string, message: string) => void; onClose: () => void; onDone: () => void; sending: boolean; sent: boolean; sentTo: string; }): JSX.Element { const [email, setEmail] = useState(''); const [message, setMessage] = useState(DEFAULT_INVITE_MESSAGE); const [error, setError] = useState(false); const [copied, setCopied] = useState(false); const emailRef = useRef(null); const copyTimer = useRef | null>(null); useEffect(() => { if (!sent) emailRef.current?.focus(); }, [sent]); useEffect( () => () => { if (copyTimer.current) clearTimeout(copyTimer.current); }, [] ); const send = (): void => { if (sending) return; if (!isValidEmail(email)) { setError(true); emailRef.current?.focus(); return; } setError(false); onSend(email.trim(), message); }; const copyMessage = (): void => { const done = (): void => { setCopied(true); if (copyTimer.current) clearTimeout(copyTimer.current); copyTimer.current = setTimeout(() => setCopied(false), 1600); }; navigator.clipboard?.writeText(message).then(done).catch(done); }; return ( {sent ? (

Invitation sent

We've emailed{' '} {sentTo}{' '} and cc'd our partner team so we can help them get set up.

) : ( <>

Invite your agency or expert

We'll email them everything they need to run your setup. When they take care of it, 10,000 extra credits land on your trial.

{ setEmail(event.target.value); if (error) setError(false); }} onKeyDown={event => { if (event.key === 'Enter') { event.preventDefault(); send(); } }} className={FIELD} /> {error && ( Enter a valid email )}