-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.jsx
162 lines (155 loc) · 5.1 KB
/
App.jsx
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { useEffect } from "react"
import "./App.css"
// Redux
import { useDispatch, useSelector } from "react-redux"
// React Router
import { Route, Routes, useNavigate } from "react-router-dom"
// Components
import Navbar from "./components/Common/Navbar"
import OpenRoute from "./components/core/Auth/OpenRoute"
import PrivateRoute from "./components/core/Auth/PrivateRoute"
import AddCourse from "./components/core/Dashboard/AddCourse"
import Cart from "./components/core/Dashboard/Cart"
import EditCourse from "./components/core/Dashboard/EditCourse"
import EnrolledCourses from "./components/core/Dashboard/EnrolledCourses"
import Instructor from "./components/core/Dashboard/Instructor"
import MyCourses from "./components/core/Dashboard/MyCourses"
import MyProfile from "./components/core/Dashboard/MyProfile"
import Settings from "./components/core/Dashboard/Settings"
import VideoDetails from "./components/core/ViewCourse/VideoDetails"
import About from "./pages/About"
import Catalog from "./pages/Catalog"
import Contact from "./pages/Contact"
import CourseDetails from "./pages/CourseDetails"
import Dashboard from "./pages/Dashboard"
import Error from "./pages/Error"
import ForgotPassword from "./pages/ForgotPassword"
// Pages
import Home from "./pages/Home"
import Login from "./pages/Login"
import Signup from "./pages/Signup"
import UpdatePassword from "./pages/UpdatePassword"
import VerifyEmail from "./pages/VerifyEmail"
import ViewCourse from "./pages/ViewCourse"
import { getUserDetails } from "./services/operations/profileAPI"
import { ACCOUNT_TYPE } from "./utils/constants"
function App() {
const dispatch = useDispatch()
const navigate = useNavigate()
const { user } = useSelector((state) => state.profile)
useEffect(() => {
if (localStorage.getItem("token")) {
const token = JSON.parse(localStorage.getItem("token"))
dispatch(getUserDetails(token, navigate))
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return (
<div className="flex min-h-screen w-screen flex-col bg-richblack-900 font-inter">
<Navbar />
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/contact" element={<Contact />} />
<Route path="courses/:courseId" element={<CourseDetails />} />
<Route path="catalog/:catalogName" element={<Catalog />} />
{/* Open Route - for Only Non Logged in User */}
<Route
path="login"
element={
<OpenRoute>
<Login />
</OpenRoute>
}
/>
<Route
path="forgot-password"
element={
<OpenRoute>
<ForgotPassword />
</OpenRoute>
}
/>
<Route
path="update-password/:id"
element={
<OpenRoute>
<UpdatePassword />
</OpenRoute>
}
/>
<Route
path="signup"
element={
<OpenRoute>
<Signup />
</OpenRoute>
}
/>
<Route
path="verify-email"
element={
<OpenRoute>
<VerifyEmail />
</OpenRoute>
}
/>
{/* Private Route - for Only Logged in User */}
<Route
element={
<PrivateRoute>
<Dashboard />
</PrivateRoute>
}
>
{/* Route for all users */}
<Route path="dashboard/my-profile" element={<MyProfile />} />
<Route path="dashboard/Settings" element={<Settings />} />
{/* Route only for Instructors */}
{user?.accountType === ACCOUNT_TYPE.INSTRUCTOR && (
<>
<Route path="dashboard/instructor" element={<Instructor />} />
<Route path="dashboard/my-courses" element={<MyCourses />} />
<Route path="dashboard/add-course" element={<AddCourse />} />
<Route
path="dashboard/edit-course/:courseId"
element={<EditCourse />}
/>
</>
)}
{/* Route only for Students */}
{user?.accountType === ACCOUNT_TYPE.STUDENT && (
<>
<Route
path="dashboard/enrolled-courses"
element={<EnrolledCourses />}
/>
<Route path="/dashboard/cart" element={<Cart />} />
</>
)}
<Route path="dashboard/settings" element={<Settings />} />
</Route>
{/* For the watching course lectures */}
<Route
element={
<PrivateRoute>
<ViewCourse />
</PrivateRoute>
}
>
{user?.accountType === ACCOUNT_TYPE.STUDENT && (
<>
<Route
path="view-course/:courseId/section/:sectionId/sub-section/:subSectionId"
element={<VideoDetails />}
/>
</>
)}
</Route>
{/* 404 Page */}
<Route path="*" element={<Error />} />
</Routes>
</div>
)
}
export default App