Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
axellorreyne committed May 22, 2024
2 parents b6b9aa4 + d58d6af commit a1647d9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
38 changes: 34 additions & 4 deletions frontend/app/[locale]/components/EditCourseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, {useEffect, useState} from "react";
import {useTranslation} from "react-i18next";
import {getCourse, getImage, postData, updateCourse} from "@lib/api";
import Typography from "@mui/material/Typography";
import {Box, Button, Input, LinearProgress, MenuItem, Select, TextField} from "@mui/material";
import {Box, Button, Input, LinearProgress, MenuItem, Select, TextField, Dialog, DialogActions, DialogTitle} from "@mui/material";
import {LocalizationProvider} from "@mui/x-date-pickers/LocalizationProvider";
import {AdapterDayjs} from "@mui/x-date-pickers/AdapterDayjs";
import {DatePicker} from '@mui/x-date-pickers/DatePicker';
Expand All @@ -24,6 +24,8 @@ const EditCourseForm = ({courseId}: EditCourseFormProps) => {
const [selectedImage, setSelectedImage] = useState<File | null>(null);
const [selectedImageURL, setSelectedImageURL] = useState<string>("");
const [loading, setLoading] = useState(true);
const [openConfirmation, setOpenConfirmation] = useState(false); // State for confirmation dialog


useEffect(() => {
const fetchCourseData = async () => {
Expand Down Expand Up @@ -57,6 +59,15 @@ const EditCourseForm = ({courseId}: EditCourseFormProps) => {

const handleSubmit = async (event: any) => {
event.preventDefault();
setOpenConfirmation(true); // Open confirmation dialog
};

const handleConfirmationClose = () => {
setOpenConfirmation(false);
};

const handleConfirmationYes = async () => {
setOpenConfirmation(false);
const formData = new FormData();
formData.append('name', name);
formData.append('description', description);
Expand All @@ -66,13 +77,16 @@ const EditCourseForm = ({courseId}: EditCourseFormProps) => {
fileReader.onload = async function () {
const arrayBuffer = this.result;
if (arrayBuffer !== null) {
formData.append('banner', new Blob([arrayBuffer], {type: 'image/png'}));
formData.append('banner', new Blob([arrayBuffer], { type: 'image/png' }));
await updateCourse(courseId, formData).then((response) => {
window.location.href = `/course/${courseId}/`;
});
}
await updateCourse(courseId, formData);
window.location.href = `/course/${courseId}/`;
}
if (selectedImage) fileReader.readAsArrayBuffer(selectedImage);
};


const handleImageUpload = (event: any) => {
const imageFile = event.target.files[0];
setSelectedImage(imageFile);
Expand Down Expand Up @@ -253,6 +267,22 @@ const EditCourseForm = ({courseId}: EditCourseFormProps) => {
{t("cancel")}
</Button>
</Box>
<Dialog
open={openConfirmation}
onClose={handleConfirmationClose}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
<DialogTitle id="alert-dialog-title">{t("Are you sure you want to submit this course?")}</DialogTitle>
<DialogActions>
<Button onClick={handleConfirmationClose} color="primary">
{t("cancel")}
</Button>
<Button onClick={handleConfirmationYes} color="primary" autoFocus>
{t("edit course")}
</Button>
</DialogActions>
</Dialog>
</Box>
);
}
Expand Down
1 change: 1 addition & 0 deletions frontend/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"role": "Role",
"save changes": "Save changes",
"save course": "Save course",
"edit course": "Edit course",
"save": "Save",
"save_changes": "Save Changes",
"score_required": "Score is required",
Expand Down
1 change: 1 addition & 0 deletions frontend/locales/nl/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"role": "Rol",
"save changes": "Wijzigingen opslaan",
"save course": "Cursus opslaan",
"edit course": "Cursus bewerken",
"save": "Opslaan",
"save_changes": "Wijzigingen Opslaan",
"score_required": "Score is verplicht",
Expand Down

0 comments on commit a1647d9

Please sign in to comment.