All files / components/TabComponent AssignmentTabComponent.jsx

100% Statements 22/22
100% Branches 0/0
100% Functions 10/10
100% Lines 19/19

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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110                60x 2x     60x 3x     60x 1x     60x                       60x         60x 2x     60x                       60x         60x 3x     60x                 60x         60x 1x     60x                                                          
import IndividualAssignmentForm from "main/components/Assignments/IndividualAssignmentForm";
import TeamRepositoryAssignmentForm from "main/components/Assignments/TeamRepositoryAssignmentForm";
import DeleteRepoForm from "main/components/Assignments/DeleteRepoForm";
import { Card, Row, Col } from "react-bootstrap";
import { useBackendMutation } from "main/utils/useBackend";
import { toast } from "react-toastify";
 
export default function AssignmentTabComponent({ courseId }) {
  const onSuccessAssignment = () => {
    toast("Repository creation successfully started.");
  };
 
  const onSuccessTeamAssignment = () => {
    toast("Team repository creation successfully started.");
  };
 
  const onSuccessRepoDeletion = () => {
    toast("Repo deletion successfully started.");
  };
 
  const objectToAxiosParamsIndividualAssignment = (assignment) => ({
    url: `/api/repos/createRepos`,
    method: "POST",
    params: {
      courseId: courseId,
      repoPrefix: assignment.repoPrefix,
      isPrivate: assignment.assignmentPrivacy,
      permissions: assignment.permissions,
      creationOption: assignment.creationOption,
    },
  });
 
  const indvidiualAssignmentMutation = useBackendMutation(
    objectToAxiosParamsIndividualAssignment,
    { onSuccess: onSuccessAssignment },
  );
 
  const postIndividualAssignment = (assignment) => {
    indvidiualAssignmentMutation.mutate(assignment);
  };
 
  const objectToAxiosParamsTeamAssignment = (teamAssignment) => ({
    url: `/api/repos/createTeamRepos`,
    method: "POST",
    params: {
      courseId: courseId,
      repoPrefix: teamAssignment.repoPrefix,
      isPrivate: teamAssignment.assignmentPrivacy,
      permissions: teamAssignment.permissions,
      teamRegex: teamAssignment.teamRegex,
    },
  });
 
  const teamAssignmentMutation = useBackendMutation(
    objectToAxiosParamsTeamAssignment,
    { onSuccess: onSuccessTeamAssignment },
  );
 
  const postTeamAssignment = (teamAssignment) => {
    teamAssignmentMutation.mutate(teamAssignment);
  };
 
  const objectToAxiosParamsRepoDeletion = (repoDeletion) => ({
    url: `/api/repos`,
    method: "DELETE",
    params: {
      courseId: courseId,
      prefix: repoDeletion.repoPrefix,
    },
  });
 
  const repoDeletionMutation = useBackendMutation(
    objectToAxiosParamsRepoDeletion,
    { onSuccess: onSuccessRepoDeletion },
  );
 
  const deleteRepo = (repoDeletion) => {
    repoDeletionMutation.mutate(repoDeletion);
  };
 
  return (
    <Row md={2} className="g-2 mb-2" data-testid={"AssignmentTabComponent"}>
      <Col md={6}>
        <Card className="h-100">
          <Card.Header>Individual Repository Assignment</Card.Header>
          <Card.Body>
            <IndividualAssignmentForm submitAction={postIndividualAssignment} />
          </Card.Body>
        </Card>
      </Col>
      <Col md={6}>
        <Card className="h-100">
          <Card.Header>Team Repository Assignment</Card.Header>
          <Card.Body>
            <TeamRepositoryAssignmentForm submitAction={postTeamAssignment} />
          </Card.Body>
        </Card>
      </Col>
      <Col md={6}>
        <Card className="h-100">
          <Card.Header>Delete Empty Repos</Card.Header>
          <Card.Body>
            <DeleteRepoForm submitAction={deleteRepo} />
          </Card.Body>
        </Card>
      </Col>
    </Row>
  );
}