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

Redirecting when creation of project is succesful or showing error message on failure #313

Merged
merged 3 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion frontend/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@
"noFilesPlaceholder": "No assignment files given yet",
"noRegexPlaceholder": "No regex added yet",
"clearSelected": "Clear Selection",
"faultySubmission": "Some fields were left open or there is no valid runner/file combination"
"faultySubmission": "Some fields were left open or there is no valid runner/file combination",
"unauthorized": "You are unauthorized to upload a project for this course",
"submissionError": "Submission failed, please try again"
},
"student" : {
"myProjects": "My Projects",
Expand Down
4 changes: 3 additions & 1 deletion frontend/public/locales/nl/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@
"uploadError": "Project is niet goed geformatteerd",
"noDeadlinesPlaceholder": "Nog geen opgegeven deadlines",
"noFilesPlaceholder": "Nog geen opgave bestanden geupload",
"noRegexPlaceholder": "Nog geen regex toegevoegd"
"noRegexPlaceholder": "Nog geen regex toegevoegd",
"unauthorized": "U heeft niet de juiste rechten om een project aan te maken voor dit vak",
"submissionError": "Er is een fout opgetreden bij het indienen van uw project, probeer het later opnieuw."
},
"projectView": {
"submitNetworkError": "Er is iets mislopen bij het opslaan van uw indiening. Probeer het later opnieuw.",
Expand Down
29 changes: 26 additions & 3 deletions frontend/src/components/ProjectForm/ProjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import DeleteIcon from "@mui/icons-material/Delete";
import DeadlineCalender from "../Calender/DeadlineCalender.tsx";
import { Deadline } from "../../types/deadline";
import {InfoOutlined} from "@mui/icons-material";
import {Link, useLoaderData, useLocation} from "react-router-dom";
import {Link, useLoaderData, useLocation, useNavigate} from "react-router-dom";
import FolderDragDrop from "../FolderUpload/FolderUpload.tsx";
import TabPanel from "@mui/lab/TabPanel";
import {TabContext} from "@mui/lab";
import FileStuctureForm from "./FileStructureForm.tsx";
import AdvancedRegex from "./AdvancedRegex.tsx";
import RunnerSelecter from "./RunnerSelecter.tsx";
import { authenticatedFetch } from "../../utils/authenticated-fetch.ts";
import i18next from "i18next";

interface Course {
course_id: string;
Expand Down Expand Up @@ -77,13 +78,16 @@ export default function ProjectForm() {
const [runner, setRunner] = useState<string>('');
const [validRunner, setValidRunner] = useState(true);
const [validSubmission, setValidSubmission] = useState(true);
const [errorMessage, setErrorMessage] = useState('');

const courses = useLoaderData() as Course[]

const [courseId, setCourseId] = useState<string>('');
const [courseName, setCourseName] = useState<string>('');
const location = useLocation();

const navigate = useNavigate();

useEffect(() =>{
const urlParams = new URLSearchParams(location.search);
const initialCourseId = urlParams.get('course_id') || '';
Expand Down Expand Up @@ -142,9 +146,15 @@ export default function ProjectForm() {

if (runner === "CUSTOM") {
setValidRunner(constainsDocker);
if (!constainsDocker) {
setErrorMessage(t("faultySubmission"));
}
setValidSubmission(constainsDocker);
} else {
setValidRunner(containsRuntest);
if(!containsRuntest) {
setErrorMessage(t("faultySubmission"));
}
setValidSubmission(containsRuntest);
}
}
Expand Down Expand Up @@ -177,6 +187,7 @@ export default function ProjectForm() {

if (!assignmentFile || !validRunner) {
setValidSubmission(false);
setErrorMessage(t("faultySubmission"));
return;
}

Expand Down Expand Up @@ -212,8 +223,20 @@ export default function ProjectForm() {
})

if (!response.ok) {
throw new Error(t("uploadError"));
setValidSubmission(false);
if (response.status === 403) {
setErrorMessage(t("unauthorized"));
}
else {
setErrorMessage(t("submissionError"));
}
return;
}

response.json().then((data) => {
const projectData = data.data;
navigate(`/${i18next.language}/projects/${projectData.project_id}`);
})
}

const handleCourseChange = (e: SelectChangeEvent<string>) => {
Expand Down Expand Up @@ -422,7 +445,7 @@ export default function ProjectForm() {
{
!validSubmission && (
<Typography style={{color: 'red', paddingTop: "20px" }}>
{t("faultySubmission")} ⚠️
{errorMessage} ⚠️
</Typography>
)
}
Expand Down