-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the logic for courses enrollment admin activitys
- Loading branch information
1 parent
1803e9f
commit cfab40c
Showing
9 changed files
with
267 additions
and
438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.