Skip to content

Commit

Permalink
refactor sending requests based on new end points of server .
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Ramadan1 committed Jun 4, 2024
1 parent d70ad4e commit dc66267
Show file tree
Hide file tree
Showing 19 changed files with 47 additions and 49 deletions.
6 changes: 3 additions & 3 deletions src/components/dashboard/BlogELement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const BlogELement = ({ blog, setIsChanged }) => {
onClick={() => {
deleteOperationRequests(
"Are you sure you want to delete?",
`admin/deleteBlog/${_id}`,
`blogs/blogsPosts/${_id}`,
"Blog deleted successfully",
"Error deleting blog",
setIsChanged
Expand All @@ -42,7 +42,7 @@ const BlogELement = ({ blog, setIsChanged }) => {
onClick={() => {
handelOperationRequest(
"Are you sure you want to publish?",
`admin/unPublishBlog/${_id}`,
`/blogs/${_id}/notPublished`,
"Blog un-published successfully",
"Error un-publishing blog",
setIsChanged
Expand All @@ -57,7 +57,7 @@ const BlogELement = ({ blog, setIsChanged }) => {
onClick={() => {
handelOperationRequest(
"Are you sure you want to un-publish?",
`admin/publishBlog/${_id}`,
`/blogs/${_id}/published`,
"Blog published successfully",
"Error publishing blog",
setIsChanged
Expand Down
4 changes: 2 additions & 2 deletions src/components/dashboard/EnrollmentElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const EnrollmentElement = ({ enrollment, setIsChanged }) => {
onClick={() => {
handelOperationRequest(
"Are you sure you want to cancel?",
`admin/cancelEnrollment/${_id}`,
`/enrolls/${_id}/cancel`,
"Enrollment cancelled successfully",
"Error cancelling enrollment",
setIsChanged
Expand All @@ -72,7 +72,7 @@ const EnrollmentElement = ({ enrollment, setIsChanged }) => {
onClick={() => {
handelOperationRequest(
"Are you sure you want to approve?",
`admin/approveEnrollment/${_id}`,
`/enrolls/${_id}/approve`,
"Enrollment approved successfully",
"Error approving enrollment",
setIsChanged
Expand Down
6 changes: 3 additions & 3 deletions src/components/dashboard/FinancialAidRequestElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const FinancialAidRequestElement = ({ request, token, setIsChanged }) => {
onClick={() => {
deleteOperationRequests(
"Are you sure you want to delete?",
`admin/deleteFinancialAidRequest/${_id}`,
`financialAidRequests/deleteRequest/${_id}`,
"Financial Aid request deleted successfully",
"Error deleting financial aid request",
setIsChanged
Expand All @@ -52,7 +52,7 @@ const FinancialAidRequestElement = ({ request, token, setIsChanged }) => {
onClick={() => {
handelOperationRequest(
"Are you sure you want to reject this financial aid request?",
`admin/rejectFinancialAidRequest/${_id}`,
`/financialAidRequests/${_id}/reject`,
"Financial Aid application rejected successfully",
"Error rejecting financial aid request",
setIsChanged
Expand All @@ -67,7 +67,7 @@ const FinancialAidRequestElement = ({ request, token, setIsChanged }) => {
onClick={() => {
handelOperationRequest(
"Are you sure you want to approve this financial aid request?",
`admin/approveFinancialAidRequest/${_id}`,
`/financialAidRequests/${_id}/approve`,
"Financial application approved successfully",
"Error approving financial aid request",
setIsChanged
Expand Down
10 changes: 5 additions & 5 deletions src/components/dashboard/InstructorElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const InstructorElement = ({ instructor, setIsChanged }) => {
onClick={() => {
deleteOperationRequests(
"Are you sure you want to delete?",
`admin/deleteInstructor/${_id}`,
`/instructors/${_id}`,
"Instructor deleted successfully",
"Error deleting instructor",
setIsChanged
Expand All @@ -49,9 +49,9 @@ const InstructorElement = ({ instructor, setIsChanged }) => {
<ActionButton
onClick={() => {
handelOperationRequest(
"Are you sure you want to unactivate this instructor?",
`admin/deactivateInstructor/${_id}`,
"Instructor unactivated successfully",
"Are you sure you want to un-activate this instructor?",
`/instructors/${_id}/inactive`,
"Instructor un-activated successfully",
"Error unactivating instructor",
setIsChanged
);
Expand All @@ -65,7 +65,7 @@ const InstructorElement = ({ instructor, setIsChanged }) => {
onClick={() => {
handelOperationRequest(
"Are you sure you want to activate this instructor?",
`admin/activateInstructor/${_id}`,
`/instructors/${_id}/active`,
"Instructor activated successfully",
"Error activating instructor",
setIsChanged
Expand Down
8 changes: 4 additions & 4 deletions src/components/dashboard/UserELement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const UserELement = ({ user, setIsChanged }) => {
onClick={() => {
deleteOperationRequests(
"Are you sure you want to delete?",
`admin/deleteUser/${_id}`,
`/users/${_id}`,
"User deleted successfully",
"Error deleting user",
setIsChanged
Expand All @@ -45,7 +45,7 @@ const UserELement = ({ user, setIsChanged }) => {
onClick={() => {
handelOperationRequest(
"Are you sure you want to unActivate?",
`admin/unActivateUser/${_id}`,
`/users/${_id}/inactive`,
"User unActivated successfully",
"Error unActivated user",
setIsChanged
Expand All @@ -59,7 +59,7 @@ const UserELement = ({ user, setIsChanged }) => {
onClick={() => {
handelOperationRequest(
"Are you sure you want to activate?",
`admin/activateUser/${_id}`,
`/users/${_id}/active`,
"User activated successfully",
"Error activating user",
setIsChanged
Expand All @@ -74,7 +74,7 @@ const UserELement = ({ user, setIsChanged }) => {
onClick={() => {
handelOperationRequest(
"Are you sure you want to verify?",
`admin/verifyUser/${_id}`,
`/users/${_id}/verify`,
"User email verified successfully",
"Error verified email ",
setIsChanged
Expand Down
25 changes: 8 additions & 17 deletions src/layout/header/HeaderPhone.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,26 @@ export default function HeaderPhone() {
className="fixed menuList overflow-y-scroll w-full h-full transition ease-out top-0 flex gap-7 flex-col items-start bg-[#fff] p-[20px] z-10"
style={{ left: `${menuListLeft}px` }}
>
<div className="w-full flex items-center gap-[10px] ">
<div className="w-full flex items-center gap-[10px] justify-between ">
{user && (
<div className="w-[200px]">
<div className="profile w-full flex flex-row-reverse justify-between items-center gap-[15px]">
<div> </div>
<div className="flex gap-3 items-center justify-center">
<Link
to={"/profile/wishlist"}
to={"/profile"}
onClick={() => setMenuListLeft(-1000)}
>
<div className="mt-2 ml-3 w-[40px]">
<HeartHeader />
</div>
<img
src={user?.photo}
alt=""
className="w-[80px] h-[80px] rounded-[12px] ml-5"
/>
</Link>
</div>

<img src={user?.photo} alt="" className="w-[80px] h-[80px]" />
</div>
</div>
)}
<div className="inputSearch relative w-full h-[45px]">
<SearchIcon />
<input
type="search"
name=""
id=""
placeholder="What do you want learn..."
className="w-full h-full py-[10px] px-[40px] outline-none border-[1px] border-[#E9EAF0] "
/>
</div>

<div
className="exit cursor-pointer w-[45px] h-[45px] flex items-center justify-center bg-red-500"
Expand Down
1 change: 1 addition & 0 deletions src/pages/dashboard/CreateCourses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const action = async ({ request }) => {
});

toast.success("Course created Successfully");

return res;
} catch (error) {
toast.error(error?.response?.data?.message);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dashboard/CreateInstructorAccount.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const CreateInstructorAccount = () => {
validationSchema={createInstructorsSchema}
onSubmit={(values, actions) => {
sendPostRequest(
"admin/createInstructor",
"instructors",
values,
"Instructor Account Created Successfully",
"Instructor Account Created Failed",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dashboard/CreateUserAccount.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const CreateUserAccount = () => {
validationSchema={createUsersSchema}
onSubmit={(values, actions) => {
sendPostRequest(
"admin/createUser",
"users",
values,
"User Account Created Successfully",
"Error Creating User Account",
Expand Down
3 changes: 2 additions & 1 deletion src/pages/dashboard/FreeCourses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function FreeCourses() {
const [currentPage, setCurrentPage] = useState(1);
const [isChanged, setIsChanged] = useState(false);
const { data, loading, error, isMorePages, fetchData } = useFetchData(
"/admin/freeCourses",
"/courses/free",
{
headers: {
Authorization: `Bearer ${token}`,
Expand Down Expand Up @@ -48,6 +48,7 @@ function FreeCourses() {
{loading && <LoadingWhile />}

{!loading &&
!error &&
data.length > 0 &&
data.map((course, index) => (
<CourseElement
Expand Down
6 changes: 3 additions & 3 deletions src/pages/dashboard/Instructors.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useState, useEffect } from "react";
import { useSelector } from "react-redux";
import { customFetch } from "../../utils/customFetch";

import {
PageIntro,
Expand All @@ -20,7 +19,7 @@ const Instructors = () => {
const [currentPage, setCurrentPage] = useState(1);
const [isChanged, setIsChanged] = useState(false);
const { data, loading, error, isMorePages, fetchData } = useFetchData(
"/admin/getAllInstructors",
"/instructors",
{
headers: {
Authorization: `Bearer ${token}`,
Expand All @@ -46,8 +45,9 @@ const Instructors = () => {
{loading && <LoadingWhile />}

{!loading &&
!error &&
data.length > 0 &&
data.map((instructor, index) => (
data.map((instructor) => (
<InstructorElement
key={instructor._id}
instructor={instructor}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/dashboard/ManageBlogs.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect, useState } from "react";
import { useSelector } from "react-redux";
import { customFetch } from "../../utils/customFetch";

import {
PageIntro,
Expand All @@ -20,7 +19,7 @@ const ManageBlogs = () => {
const [currentPage, setCurrentPage] = useState(1);
const [isChanged, setIsChanged] = useState(false);
const { data, loading, error, isMorePages, fetchData } = useFetchData(
"/admin/getAllBlogs",
"/blogs/allBlogsPosts",
{
headers: {
Authorization: `Bearer ${token}`,
Expand All @@ -45,6 +44,7 @@ const ManageBlogs = () => {
<BlogsTableHeader />
{loading && <LoadingWhile />}
{!loading &&
!error &&
data.length > 0 &&
data.map((blog, index) => (
<BlogELement
Expand Down
1 change: 1 addition & 0 deletions src/pages/dashboard/ManageInstructorsRequests.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const ManageInstructorsRequests = () => {
{loading && <LoadingWhile />}

{!loading &&
!error &&
data.length > 0 &&
data.map((instructor, index) => (
<InstructorsApplicationElement
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dashboard/ManagePayments.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useState, useEffect } from "react";
import { useSelector } from "react-redux";
import { customFetch } from "../../utils/customFetch";

import {
PageIntro,
Expand Down Expand Up @@ -45,6 +44,7 @@ const ManagePayments = () => {
{loading && <LoadingWhile />}

{!loading &&
!error &&
data.length > 0 &&
data.map((payment, index) => (
<PaymentRecordELements
Expand Down
3 changes: 2 additions & 1 deletion src/pages/dashboard/MangeFinancialAidRequests.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const MangeFinancialAidRequests = () => {
const [currentPage, setCurrentPage] = useState(1);
const [isChanged, setIsChanged] = useState(false);
const { data, loading, error, isMorePages, fetchData } = useFetchData(
"admin/getAllFinancialAidRequests",
"/financialAidRequests/allRequests",
{
headers: {
Authorization: `Bearer ${token}`,
Expand All @@ -45,6 +45,7 @@ const MangeFinancialAidRequests = () => {
{loading && <LoadingWhile />}

{!loading &&
!error &&
data &&
data.map((request) => (
<FinancialAidRequestElement
Expand Down
8 changes: 5 additions & 3 deletions src/pages/dashboard/PaiedCourses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function PaiedCourses() {
const [isChanged, setIsChanged] = useState(false);

const { data, loading, error, isMorePages, fetchData } = useFetchData(
"/admin/paidCourses",
"/courses/paid",
{
headers: {
Authorization: `Bearer ${token}`,
Expand All @@ -44,8 +44,10 @@ function PaiedCourses() {
{/* table manage table courses table */}
<PageContainer tableHeader={"Paid Courses"}>
<CoursesHeader />
{data &&
data.map((course, index) => (
{!loading &&
!error &&
data &&
data.map((course) => (
<CourseElement
key={course._id}
course={course}
Expand Down
1 change: 1 addition & 0 deletions src/pages/dashboard/Reservations.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const Reservations = () => {
{loading && <LoadingWhile />}

{!loading &&
!error &&
data.length > 0 &&
data.map((enrollment, index) => (
<EnrollmentElement
Expand Down
3 changes: 2 additions & 1 deletion src/pages/dashboard/Users.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Users = () => {
const [currentPage, setCurrentPage] = useState(1);
const [isChanged, setIsChanged] = useState(false);
const { data, loading, error, isMorePages, fetchData } = useFetchData(
"/admin/getAllUsers",
"/users",
{
headers: {
Authorization: `Bearer ${token}`,
Expand All @@ -44,6 +44,7 @@ const Users = () => {
<UserTableHeader />
{loading && <LoadingWhile />}
{!loading &&
!error &&
data &&
data.map((user, index) => (
<UserElement
Expand Down
1 change: 0 additions & 1 deletion src/pages/userProfile/MyEnrolledCourses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const MyEnrolledCourses = () => {
fetchData();
}, [currentPage, itemsPerPage, token]);

console.log(data);
return (
<>
<ProfilePageContainer>
Expand Down

0 comments on commit dc66267

Please sign in to comment.