All files / components/TabComponent AssignmentTabComponent.jsx

100% Statements 58/58
100% Branches 7/7
100% Functions 7/7
100% Lines 58/58

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 781x 1x 1x 1x 1x   1x 26x 2x 2x   26x 2x 2x   26x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x   26x 26x 26x     26x 2x 2x   26x 2x 2x 2x 2x 2x 2x 2x 2x 2x   26x 26x 26x     26x 2x 2x   26x 26x 26x 26x 26x 26x 26x       26x 26x 26x 26x 26x           26x  
import IndividualAssignmentForm from "main/components/Assignments/IndividualAssignmentForm";
import TeamRepositoryAssignmentForm from "main/components/Assignments/TeamRepositoryAssignmentForm";
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 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,
    },
  });
 
  const teamAssignmentMutation = useBackendMutation(
    objectToAxiosParamsTeamAssignment,
    { onSuccess: onSuccessTeamAssignment },
  );
 
  const postTeamAssignment = (teamAssignment) => {
    teamAssignmentMutation.mutate(teamAssignment);
  };
 
  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>
    </Row>
  );
}