Skip to content

Commit

Permalink
Added Private Route and 404 page
Browse files Browse the repository at this point in the history
  • Loading branch information
upendradhamaladev committed Apr 17, 2022
1 parent b0f79b4 commit 6b7e681
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 50 deletions.
23 changes: 2 additions & 21 deletions backend/seeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const importData = async () => {
const createdUsers = await Admin.insertMany(users)
console.log('inserted users')
const adminUser = createdUsers[0]._id
//the following code will insert admin user in each of the student data

const sampleStudents = students.map((student) => {
return { ...student, user: adminUser }
Expand All @@ -29,8 +28,6 @@ const importData = async () => {
await Dashboard.insertMany(items)
await Student.insertMany(sampleStudents)

//among all the inserted students by the above code of line
//we will select the first

console.log('Data imported.')
process.exit()
Expand All @@ -40,36 +37,20 @@ const importData = async () => {
}
}

//following is for deleting the data from the database of mongodb
const exportData = async () => {
try {
await Student.deleteMany()
await Dashboard.deleteMany()
await Admin.deleteMany()
// const createdUsers = await Admin.insertMany(users)
// const adminUser = createdUsers[0]._id
// //the following code will insert admin user in each of the student data

// const sampleStudents = students.map((student) => {
// return { ...student, user: adminUser }
// })
// await Student.insertMany(sampleStudents)

// //among all the inserted students by the above code of line
// //we will select the first

// await Dashboard.insertMany(items)

console.log('Data destroyed.')
process.exit()
} catch (error) {
console.log(error)
process.exit(1)
}
}
//following line of code looks into the command
//passed into the terminal
//if the two index is '-d', then the destroy function is called
//otherwise import function is called.

if (process.argv[2] === '-d') {
destroyData()
} else {
Expand Down
Binary file added frontend/public/images/notFound.webp
Binary file not shown.
64 changes: 40 additions & 24 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,93 +23,109 @@ import AllTeachers from './screens/AllTeachers'
import AllStaffs from './screens/AllStaffs'
import StaffRegister from './screens/StaffRegister'
import IncomeScreen from './screens/IncomeScreen'
import NotFound from './screens/NotFound'

import ExpenseScreen from './screens/ExpenseScreen'
import underConstruction from './components/underConstruction'
import { studentAttendances } from './actions/studentActions'
import PrivateRoute from '../src/utils/PrivateRoute'
// import ExpenseScreen from './screens/ExpenseScreen'

const App = () => {
return (
<Router>
<div>
<Switch>
<Route path='/' component={Landing} exact />
<PrivateRoute path='/' component={Landing} exact />
<Route path='/login' component={Login} exact />
<Route path='/student-register' component={StudentRegister} />
<Route path='/student-fee' component={StudentFees} />
<Route path='/student_details' component={StudentDetails} exact />
<Route
<PrivateRoute path='/student-register' component={StudentRegister} />
<PrivateRoute path='/student-fee' component={StudentFees} />
<PrivateRoute
path='/student_details'
component={StudentDetails}
exact
/>
<PrivateRoute
path='/student_details/details/:id'
component={StudentDeepDetails}
exact
/>
{/* <Route
{/* <PrivateRoute
path='/student-attendance'
component={underConstruction}
exact
/> */}
<Route
<PrivateRoute
path='/teacher_attendance'
component={underConstruction}
exact
/>
<Route
<PrivateRoute
path='/non-teaching_staff_attendance'
component={underConstruction}
exact
/>
<Route
<PrivateRoute
path='/student-attendance/:class'
component={StudentDeepAttendance}
exact
/>
<Route path='/students' component={AllStudents} exact />
<Route path='/admit_card' component={StudentAdmitCard} exact />
<Route
<PrivateRoute path='/students' component={AllStudents} exact />
<PrivateRoute path='/admit_card' component={StudentAdmitCard} exact />
<PrivateRoute
path='/admit_card/allstudents'
component={AllStudentsAdmitCard}
exact
/>
<Route
<PrivateRoute
path='/admit_card/classes'
component={StudentClassAdmitCard}
exact
/>
<Route
<PrivateRoute
path='/admit_card/classes/:id'
component={StudentClassAdmitCardDeep}
exact
/>
<Route
<PrivateRoute
path='/admit_card/student'
component={ParticularStudentAdmitCard}
exact
/>
<Route path='/teacher_salary' component={TeacherSalary} exact />
<Route path='/teacher_register' component={TeacherRegister} exact />
<Route path='/teacher_details' component={AllTeachers} exact />
<Route
<PrivateRoute
path='/teacher_salary'
component={TeacherSalary}
exact
/>
<PrivateRoute
path='/teacher_register'
component={TeacherRegister}
exact
/>
<PrivateRoute path='/teacher_details' component={AllTeachers} exact />
<PrivateRoute
path='/non-teaching_staff_details'
component={AllStaffs}
exact
/>
<Route
<PrivateRoute
path='/non-teaching_staff_register'
component={StaffRegister}
exact
/>
<Route
<PrivateRoute
path='/non-teaching_staff_salary'
component={StaffSalary}
exact
/>
<Route path='/income' component={IncomeScreen} exact />
<Route path='/salary' component={ExpenseScreen} exact />
<Route
<PrivateRoute path='/income' component={IncomeScreen} exact />
<PrivateRoute path='/salary' component={ExpenseScreen} exact />
<PrivateRoute
path='/student-attendance'
component={StudentAttendance}
exact
/>
<Route component={NotFound} />
</Switch>
</div>
</Router>
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@
display: block;
} */
/* // style={{ marginTop: '10px', maxWidth: '30%', display: 'block' }} */

.notFound{

height: 100vh;
/* border: 1px solid red; */
overflow: hidden;
width: 100%;


}
.notFound img{
/* border: 1px solid red; */
height: 100vh;
margin: auto;
display: block;

}
6 changes: 1 addition & 5 deletions frontend/src/screens/Landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ const Landing = ({ history }) => {
const closeSidebar = () => {
setsidebarOpen(false)
}
useEffect(() => {
if (!userCred) {
history.push('/login')
}
}, [userCred, history])

return (
<div className='containers'>
<Header sidebarOpen={sidebarOpen} openSidebar={openSidebar} />
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/screens/NotFound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
const NotFound = () => {
return (
<div className='notFound'>
<img src='./images/notFound.webp' alt='' />
</div>
)
}

export default NotFound
16 changes: 16 additions & 0 deletions frontend/src/utils/PrivateRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import { Route, Redirect } from 'react-router-dom'

const PrivateRoute = ({ component: Component, ...rest }) => {
const isLoggedIn = localStorage.getItem('userCred')
return (
<Route
{...rest}
render={(props) =>
isLoggedIn ? <Component {...props} /> : <Redirect to='/login' />
}
/>
)
}

export default PrivateRoute

0 comments on commit 6b7e681

Please sign in to comment.