Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Admin] New hacker review logic and indicator #526

Merged
merged 10 commits into from
Dec 29, 2024
3 changes: 2 additions & 1 deletion apps/site/src/app/admin/applicants/[uid]/Applicant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function Applicant({ params }: ApplicantProps) {
);
}

const { first_name, last_name } = applicant;
const { first_name, last_name, application_data } = applicant;

return (
<ContentLayout
Expand All @@ -42,6 +42,7 @@ function Applicant({ params }: ApplicantProps) {
applicant.roles.includes(ParticipantRole.Hacker) ? (
<HackerApplicantActions
applicant={applicant._id}
reviews={application_data.reviews}
submitReview={submitReview}
/>
) : (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
import { useContext, useState } from "react";

import { Button, Input, SpaceBetween } from "@cloudscape-design/components";
import { submitReview } from "@/app/admin/applicants/hackers/useApplicant";
import {
Box,
Button,
Input,
SpaceBetween,
} from "@cloudscape-design/components";
import {
Review,
submitReview,
} from "@/app/admin/applicants/hackers/useApplicant";
import { Uid } from "@/lib/userRecord";
import UserContext from "@/lib/admin/UserContext";
import { isReviewer } from "@/lib/admin/authorization";

interface ApplicantActionsProps {
applicant: Uid;
reviews: Review[];
submitReview: submitReview;
}

function HackerApplicantActions({
applicant,
reviews,
submitReview,
}: ApplicantActionsProps) {
const { roles } = useContext(UserContext);
const { uid, roles } = useContext(UserContext);
const [value, setValue] = useState("");
// const canReview = either there are less than 2 reviewers or uid is in current reviews
const uniqueReviewers = new Set(reviews.map((review) => review[1]));
const canReview = uid
? uniqueReviewers.size < 2 || uniqueReviewers.has(uid)
: false;

if (!isReviewer(roles)) {
return null;
}

return (
return canReview ? (
<SpaceBetween direction="horizontal" size="xs">
<Input
onChange={({ detail }) => setValue(detail.value)}
Expand All @@ -31,16 +46,23 @@ function HackerApplicantActions({
inputMode="decimal"
placeholder="Applicant score"
step={0.5}
disabled={!canReview}
/>
<Button
onClick={() => {
submitReview(applicant, value);
setValue("");
}}
disabled={!canReview}
>
Submit
</Button>
</SpaceBetween>
) : (
<Box variant="awsui-key-label" color="text-status-warning">
Two reviewers have already submitted reviews. Log in as one of them to
submit a review.
</Box>
);
}

Expand Down
Loading