Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | 321x 321x 321x 3x 3x 2x 1x 321x 3x 642x | import React, { useState } from "react";
import { Accordion, Button, Form } from "react-bootstrap";
import { toast } from "react-toastify";
import { useBackend } from "main/utils/useBackend";
import {
EMAIL_FORMATS,
courseEmailsQueryKey,
} from "main/utils/courseEmailsUtils";
/**
* A card, open by default, that shows the email addresses of the people of
* the given type (STUDENTS, STAFF or ALL) in a course, in a read only text
* area with a button to copy them.
*/
export default function CourseEmailsCard({
courseId,
type,
testIdPrefix = "CourseEmailsCard",
}) {
const [format, setFormat] = useState(EMAIL_FORMATS[0].value);
const { data: emails } = useBackend(
[courseEmailsQueryKey(courseId), type, format],
{
// Stryker disable next-line StringLiteral : GET and empty string are equivalent
method: "GET",
url: "/api/courses/emails",
params: { courseId, type, format },
},
"",
true,
);
const copyEmails = async () => {
try {
await navigator.clipboard.writeText(emails);
toast("Emails copied to the clipboard.");
} catch {
toast("Unable to copy the emails to the clipboard.");
}
};
return (
<div className="card mt-4" data-testid={`${testIdPrefix}-card`}>
<Accordion flush defaultActiveKey="emails">
<Accordion.Item eventKey="emails">
<Accordion.Header>Emails</Accordion.Header>
<Accordion.Body>
<Form.Group className="mb-3" controlId={`${testIdPrefix}-format`}>
<Form.Label>Format</Form.Label>
<Form.Select
value={format}
onChange={(e) => setFormat(e.target.value)}
data-testid={`${testIdPrefix}-format`}
>
{EMAIL_FORMATS.map((f) => (
<option key={f.value} value={f.value}>
{f.label}
</option>
))}
</Form.Select>
</Form.Group>
<Form.Control
as="textarea"
rows={8}
readOnly
value={emails}
aria-label="Emails"
data-testid={`${testIdPrefix}-emails`}
style={{
fontFamily: "monospace",
backgroundColor: "black",
color: "white",
}}
/>
<Button
className="mt-3"
onClick={copyEmails}
disabled={emails === ""}
data-testid={`${testIdPrefix}-copy`}
>
Copy
</Button>
</Accordion.Body>
</Accordion.Item>
</Accordion>
</div>
);
}
|