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 | 1x 5x 6x 6x 6x 3x 3x 3x | import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import PatSection from "main/components/Profile/PatSection";
import { hasRole, useCurrentUser } from "main/utils/currentUser";
const testIdPrefix = "UserProfilePage";
// Roles come back from the backend as e.g. "ROLE_ADMIN"; display them as "admin".
function friendlyRoleName(role: string): string {
return role.replace(/^ROLE_/, "").toLowerCase();
}
export default function UserProfilePage(): React.JSX.Element {
const currentUser = useCurrentUser();
const canSeePat =
hasRole(currentUser, "ROLE_ADMIN") ||
hasRole(currentUser, "ROLE_INSTRUCTOR");
if (!currentUser.loggedIn) {
return <BasicLayout>Loading...</BasicLayout>;
}
const { user, rolesList } = currentUser.root;
return (
<BasicLayout>
<div className="pt-2">
<h1 data-testid={`${testIdPrefix}-title`}>User Profile</h1>
<table className="table table-striped" style={{ maxWidth: "600px" }}>
<tbody>
<tr>
<th>Name</th>
<td data-testid={`${testIdPrefix}-name`}>
{user.fullName ?? "Not specified"}
</td>
</tr>
<tr>
<th>Email</th>
<td data-testid={`${testIdPrefix}-email`}>{user.email}</td>
</tr>
<tr>
<th>Roles</th>
<td data-testid={`${testIdPrefix}-roles`}>
{rolesList.map(friendlyRoleName).join(", ")}
</td>
</tr>
</tbody>
</table>
{canSeePat && (
<>
<PatSection
title="GitHub PAT"
endpoint="/api/pat/github"
testIdPrefix={`${testIdPrefix}-githubPat`}
/>
<div className="mt-4" />
<PatSection
title="PrairieLearn PAT"
endpoint="/api/pat/pl"
testIdPrefix={`${testIdPrefix}-plPat`}
/>
</>
)}
</div>
</BasicLayout>
);
}
|