File size: 1,628 Bytes
714ed7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | import { useState } from "react";
import { createPortal } from "react-dom";
import { useTeam } from "../store/TeamContext";
export function InviteDialog({ onClose }: { onClose: () => void }) {
const { sendInvite } = useTeam();
const [email, setEmail] = useState("");
const [error, setError] = useState<string | null>(null);
const [sending, setSending] = useState(false);
const send = async () => {
setSending(true);
setError(null);
try {
await sendInvite(email);
onClose();
} catch (e) {
setError((e as Error).message);
} finally {
setSending(false);
}
};
return createPortal(
<div className="overlay" onClick={(e) => e.target === e.currentTarget && onClose()}>
<section className="sheet" role="dialog" aria-modal="true" aria-labelledby="invite-title">
<h2 id="invite-title">Invite a teammate</h2>
<form
onSubmit={(e) => {
e.preventDefault();
void send();
}}
>
<label className="field">
Email
<input type="email" value={email} onChange={(e) => setEmail(e.target.value)} placeholder="name@company.com" autoFocus />
</label>
{error && <p className="form-error">{error}</p>}
<div className="actions">
<button type="button" onClick={onClose}>
Cancel
</button>
<button type="submit" className="primary" disabled={!email.trim() || sending}>
Send invite
</button>
</div>
</form>
</section>
</div>,
document.body,
);
}
|