mirasim's picture
Add the tasks, judges, harness, app under test, docs and report; merge the repository README into the card (part 5)
3eb5a0c verified
Raw History Blame Contribute Delete
1.41 kB
import { useState } from "react";
import { teamApi } from "../api/team";
import type { Invite } from "../types";
import { Modal } from "./Modal";
export function InviteDialog({ onInvited, onClose }: { onInvited: (invite: Invite) => void; onClose: () => void }) {
const [email, setEmail] = useState("");
const [error, setError] = useState<string | null>(null);
const [sending, setSending] = useState(false);
const send = async () => {
setSending(true);
setError(null);
try {
onInvited(await teamApi.invite(email.trim()));
onClose();
} catch (e) {
setError((e as Error).message);
} finally {
setSending(false);
}
};
return (
<Modal title="Invite a teammate" onClose={onClose}>
<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>
</Modal>
);
}