All files / components/TabComponent AssignmentTabComponent.jsx

100% Statements 32/32
100% Branches 4/4
100% Functions 4/4
100% Lines 32/32

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 421x 1x 1x 1x   1x 24x 2x 2x   24x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x   24x 24x 24x     24x 2x 2x 24x 24x 24x 24x 24x 24x         24x  
import IndividualAssignmentForm from "main/components/Assignments/IndividualAssignmentForm";
import { Card, Row } 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 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);
  };
  return (
    <Row md={2} data-testid={"AssignmentTabComponent"}>
      <Card>
        <Card.Header>Individual Assignment</Card.Header>
        <Card.Body>
          <IndividualAssignmentForm submitAction={postIndividualAssignment} />
        </Card.Body>
      </Card>
    </Row>
  );
}