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 | 1x 1x 1x 1x 1x 1x 9x 9x 9x 9x 9x 9x 2x 2x 2x 2x 2x 2x 2x 2x 9x 1x 1x 1x 9x 9x 9x 9x 1x 1x 9x 3x 3x 6x 6x 6x 6x 6x 9x 9x 9x 9x 9x | import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import CourseForm from "main/components/Courses/CourseForm";
import { useBackend, useBackendMutation } from "main/utils/useBackend";
import { Navigate, useParams } from "react-router";
import { toast } from "react-toastify";
export default function AdminCoursesEditPage() {
const { id } = useParams();
const { data: course } = useBackend([`/api/course/${id}`], {
method: "GET",
url: `/api/course/${id}`,
});
const objectToAxiosParams = (updatedCourse) => ({
url: `/api/course/${updatedCourse.id}`,
method: "PUT",
data: {
code: updatedCourse.code,
name: updatedCourse.name,
term: updatedCourse.term,
},
});
const onSuccess = (_, updatedCourse) => {
toast(
`Course updated - id: ${updatedCourse.id} code: ${updatedCourse.code}`,
);
};
const mutation = useBackendMutation(objectToAxiosParams, { onSuccess }, [
`/api/course/${id}`,
]);
const submitAction = async (data) => {
mutation.mutate(data);
};
if (mutation.isSuccess) {
return <Navigate to="/admin/listcourses" />;
}
return (
<BasicLayout>
<div className="pt-2">
<h1>Edit Course</h1>
{course && (
<CourseForm
initialCourse={course}
submitAction={submitAction}
buttonLabel="Update"
/>
)}
</div>
</BasicLayout>
);
}
|