Skip to content

Commit

Permalink
Adding the logic for courses enrollment admin activitys
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Ramadan1 committed May 4, 2024
1 parent 1803e9f commit cfab40c
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 438 deletions.
6 changes: 6 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Users,
Reservations,
Settings,
CreateCourses
} from "./pages";
import ViewCourses from "./pages/ViewCourses";
import DetailsCourse from "./pages/DetailsCourse";
Expand Down Expand Up @@ -113,7 +114,12 @@ const router = createBrowserRouter([
{
path: "paidCourses",
element: <PaiedCourses />,
},{
path:"createCourses",
element:<CreateCourses/>
},


{
path: "users",
element: <Users />,
Expand Down
14 changes: 7 additions & 7 deletions src/components/Admin/SideBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function SideBar() {
d="M4 6h16M4 10h16M4 14h16M4 18h16"
/>
</svg>
<a href="/admin/dashboard">Statics</a>
<p>Statics</p>
</div>
</Link>
{/* free courses management link */}
Expand All @@ -63,13 +63,13 @@ function SideBar() {
<line x1="15.41" y1="6.51" x2="8.59" y2="10.49" />
</svg>

<a href="/admin/courses">Free Courses</a>
<p>Free Courses</p>
</div>
</Link>
{/* paied Courses */}
<Link
className="hover:bg-gray-800 p-3 rounded mt-3 text-white"
to={"/dashboard/paiedCourses"}
to={"/dashboard/paidCourses"}
>
{/* icons and link and arrow*/}
<div className="flex gap-5">
Expand All @@ -88,7 +88,7 @@ function SideBar() {
/>
</svg>

<a href="/admin/paied-courses">Paied Courses</a>
<p>Paied Courses</p>
</div>
</Link>
{/* manage users link */}
Expand All @@ -113,7 +113,7 @@ function SideBar() {
/>
</svg>

<a href="/admin/users">Users</a>
<p>Users</p>
</div>
</Link>
{/* reseved courses */}
Expand All @@ -137,7 +137,7 @@ function SideBar() {
<polyline points="12 6 12 12 16 14" />
</svg>

<a href="/admin/reserved-courses">Reserved Courses</a>
<p href="/admin/reserved-courses">Reserved Courses</p>
</div>
</Link>
{/* settings */}
Expand All @@ -161,7 +161,7 @@ function SideBar() {
<path d="M12 5v2m0 10v2m-6-6h2m10 0h2m-8.485 8.485l1.414-1.414m-1.414 1.414l-1.414-1.414" />
</svg>

<a href="/admin/settings">Settings</a>
<p href="/dashboard/settings">Settings</p>
</div>
</Link>
</div>
Expand Down
106 changes: 106 additions & 0 deletions src/layout/dashboard/EnrollmentElement.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import axios from "axios";
import { useDispatch, useSelector } from "react-redux";
import { toast } from "react-toastify";
import { deleteEnrollment } from "../../store/courseEnrollmentsSlice";

const baseUrl =
"https://graduation-project-backend-5vtx.onrender.com/api/v1/admin";

const EnrollmentElement = ({ enrollment, index, token }) => {
const dispatch = useDispatch();

const { _id, price, createdAt, paid, updatedAt, enrollmentStatus } =
enrollment;
const { title, description, duration } = enrollment.course;
const { name, email } = enrollment.user;

const isPaid = paid ? "Paid" : "Not Paid";
const createdAtDate = new Date(createdAt).toLocaleDateString();
const updatedAtDate = new Date(updatedAt).toLocaleDateString();

const handelDeleteEnrollment = async () => {
dispatch(deleteEnrollment(_id));
toast.success("Enrollment deleted successfully");
};

const handelApproveEnrollment = async () => {
try {
await axios.patch(
`${baseUrl}/approveEnrollment/${_id}`,
{},
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
toast.success("Enrollment approved successfully");
} catch (error) {
console.log(error);
toast.error("Error approving enrollment");
}
};
const handelCancelledEnrollment = async () => {
try {
await axios.patch(
`${baseUrl}/cancelEnrollment/${_id}`,
{},
{
headers: {
Authorization: `Bearer ${token}`,
},
}
);
toast.success("Enrollment approved successfully");
} catch (error) {
console.log(error);
toast.error("Error approving enrollment");
}
};

return (
<tbody>
<tr>
<td className="p-3 text-center">{index}</td>
<td className="p-3 text-center">{title}</td>
<td className="p-3 text-center">{name}</td>
<td className="p-3 text-center">{email}</td>
<td className="p-3 text-center">{isPaid}</td>
<td className="p-3 text-center">{createdAtDate}</td>
<td className="p-3 text-center">{duration} h</td>
<td className="p-3 text-center">{price} $</td>
<td className="p-3 text-center">{updatedAtDate}</td>
<td className="p-3 text-center">{enrollmentStatus}</td>

{/* pop up menue for delete update active buttons */}
<td className="p-3 text-center">
<div className="flex gap-5 text-center">
<button
type="button"
onClick={handelDeleteEnrollment}
className="bg-red-500 text-white p-1.5 rounded"
>
Delete
</button>
<button
type="button"
onClick={handelCancelledEnrollment}
className="bg-blue-500 text-white p-1.5 rounded"
>
Cancel
</button>
<button
type="button"
onClick={handelApproveEnrollment}
className="bg-green-500 text-white p-1.5 rounded"
>
approve
</button>
</div>
</td>
</tr>
</tbody>
);
};

export default EnrollmentElement;
21 changes: 21 additions & 0 deletions src/layout/dashboard/EnrollmentHeader.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const EnrollmentHeader = () => {
return (
<thead>
<tr className="border-b">
<td className="p-3 text-center">Index</td>
<td className="p-3 text-center">Course Title</td>
<td className="p-3 text-center">User Name</td>
<td className="p-3 text-center">User Email</td>
<td className="p-3 text-center">Paid Status</td>
<td className="p-3 text-center">crated At</td>
<td className="p-3 text-center">Duration</td>
<td className="p-3 text-center">Price</td>
<td className="p-3 text-center">Updated At</td>
<td className="p-3 text-center">Enrollment Status</td>
<td className="p-3 text-center">Options</td>
</tr>
</thead>
);
};

export default EnrollmentHeader;
11 changes: 11 additions & 0 deletions src/layout/dashboard/EnrollmentsContainer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const EnrollmentsContainer = ({ children }) => {
return (
<div class="rounded-lg mt-10 shadow rounded-sm border border-stroke bg-white px-5 pt-6 pb-2.5 shadow-default dark:border-strokedark dark:bg-boxdark sm:px-7.5 xl:pb-1">
<h1 className="text-2xl font-semibold">Courses Enrollments</h1>

<table className="w-full mt-5">{children}</table>
</div>
);
};

export default EnrollmentsContainer;
77 changes: 77 additions & 0 deletions src/pages/CreateCourses.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React from "react";

function CreateCourses() {
return (
<div>
<div className="p-5">
<h1 className="text-2xl font-semibold">
Dashboard / <span className="text-blue-600">Create Courses</span>{" "}
</h1>
<form action="">
<input type="text" placeholder="Title" className="p-3 w-full mt-5" />
<input
type="text"
placeholder="Description"
className="p-3 w-full mt-5"
/>
<input
type="text"
placeholder="Duration"
className="p-3 w-full mt-5"
/>
<input
type="text"
placeholder="Instructors"
className="p-3 w-full mt-5"
/>
<div class="flex-1 items-center max-w-screen-sm mx-auto mb-3 space-y-4 sm:flex sm:space-y-0 my-5">
<div class="relative w-full">
<div class="items-center justify-center max-w-xl mx-auto">
<label
class="flex justify-center w-full h-32 px-4 transition bg-white border-2 border-gray-300 border-dashed rounded-md appearance-none cursor-pointer hover:border-gray-400 focus:outline-none"
id="drop"
>
<span class="flex items-center space-x-2">
<svg
xmlns="http://www.w3.org/2000/svg"
class="w-6 h-6 text-gray-600"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
stroke-width="2"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"
></path>
</svg>
<span class="font-medium text-gray-600">
Drop files to Attach, or
<span class="text-blue-600 underline ml-[4px]">
browse
</span>
</span>
</span>
<input
type="file"
name="file_upload"
class="hidden"
accept="image/png,image/jpeg"
id="input"
/>
</label>
</div>
</div>
</div>

<button className="bg-blue-600 text-white p-3 rounded-lg mt-5 w-full">
Save
</button>
</form>
</div>
</div>
);
}

export default CreateCourses;
8 changes: 5 additions & 3 deletions src/pages/FreeCourses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useSelector } from "react-redux";
import CoursesHeader from "../layout/dashboard/CoursesHeader";
import CourseContainer from "../layout/dashboard/CourseContainer";
import CourseElement from "../layout/dashboard/CourseElement";
import { Link } from "react-router-dom";
function FreeCourses() {
const { token } = useSelector((state) => state.userReducers);
const [courses, setCourses] = useState(null);
Expand Down Expand Up @@ -37,9 +38,10 @@ function FreeCourses() {
return (
<>
<div className="p-5">
<h1 className="text-2xl font-semibold">
Dashboard / <span className="text-blue-600">free courses</span>{" "}
</h1>
<h1 className="text-2xl font-semibold md-3">
Dashboard / <span className="text-blue-600" >free courses</span>{" "}
</h1> <br/>
<Link className="bg-blue-500 text-white p-2 rounded mt-5" to={"/dashboard/createCourses"}> add new course</Link>
{/* table manage table courses table */}
<CourseContainer tableHeader={"Free Courses"}>
<CoursesHeader />
Expand Down
Loading

0 comments on commit cfab40c

Please sign in to comment.