From 8503470880ffd8bae86d94e32711b9b8d9a87f26 Mon Sep 17 00:00:00 2001 From: yjspoder Date: Mon, 27 Jan 2020 13:30:20 +0530 Subject: [PATCH 01/11] add Verification action --- client/components/App.jsx | 62 +++---------------- .../components/auth/AdminProtectedRoutes.jsx | 56 +++++++++++++++++ client/components/auth/NonProtectedRoutes.jsx | 23 +++++++ .../auth/StudentProtectedRoutes.jsx | 58 +++++++++++++++++ client/redux/actions/verificationAction.js | 35 +++++++++++ 5 files changed, 181 insertions(+), 53 deletions(-) create mode 100644 client/components/auth/AdminProtectedRoutes.jsx create mode 100644 client/components/auth/NonProtectedRoutes.jsx create mode 100644 client/components/auth/StudentProtectedRoutes.jsx create mode 100644 client/redux/actions/verificationAction.js diff --git a/client/components/App.jsx b/client/components/App.jsx index 1a43da5d..20ecdfd6 100644 --- a/client/components/App.jsx +++ b/client/components/App.jsx @@ -22,9 +22,13 @@ import UpdateContentModal from './content/UpdateContentModal'; import AdminFeed from './adminDashboard/AdminFeed'; import StudentList from './students/StudentList'; import RegisterVerification from './registerVerfication/RegisterVerification'; +import StudentProfile from './students/StudentProfile'; +import AdminProtectedRoutes from './auth/AdminProtectedRoutes'; +import StudentProtectedRoutes from './auth/StudentProtectedRoutes'; +import NonProtectedRoutes from './auth/NonProtectedRoutes'; +import { verifyUser } from '../redux/actions/verificationAction'; import { studentLogin, studentLogout } from '../redux/actions/studentAction'; import { adminLogout } from '../redux/actions/adminAction'; -import StudentProfile from './students/StudentProfile'; class App extends Component { constructor(props) { @@ -88,56 +92,7 @@ class App extends Component { }; protectedAdminRoutes = () => { - return ( - <> - - ( - - )} - /> - - ( - - )} - /> - - ( - - )} - /> - ( - - )} - /> - - - ); + }; protectedStudentRoutes = () => { @@ -222,8 +177,8 @@ class App extends Component { {!this.state.user ? this.nonProtectedRoutes() : this.state.user.isAdmin - ? this.protectedAdminRoutes() - : this.protectedStudentRoutes()} + ? + : } {/* */} ); @@ -232,6 +187,7 @@ class App extends Component { const mapStateToProps = store => store; export default connect(mapStateToProps, { + verifyUser, studentLogin, studentLogout, adminLogout, diff --git a/client/components/auth/AdminProtectedRoutes.jsx b/client/components/auth/AdminProtectedRoutes.jsx new file mode 100644 index 00000000..b5c19a28 --- /dev/null +++ b/client/components/auth/AdminProtectedRoutes.jsx @@ -0,0 +1,56 @@ +import React,{Component} from 'react'; + +class AdminProtectedRoutes extends Component { + render () { + return ( + + ( + + )} + /> + + ( + + )} + /> + + ( + + )} + /> + ( + + )} + /> + + ); + } +} + +export default AdminProtectedRoutes; \ No newline at end of file diff --git a/client/components/auth/NonProtectedRoutes.jsx b/client/components/auth/NonProtectedRoutes.jsx new file mode 100644 index 00000000..2d56ddde --- /dev/null +++ b/client/components/auth/NonProtectedRoutes.jsx @@ -0,0 +1,23 @@ +import React, { Component } from 'react'; + + +class NonProtectedRoutes extends Component { + render () { + return ( + + + + + + + + + + + ); + } +} \ No newline at end of file diff --git a/client/components/auth/StudentProtectedRoutes.jsx b/client/components/auth/StudentProtectedRoutes.jsx new file mode 100644 index 00000000..fcafd4c1 --- /dev/null +++ b/client/components/auth/StudentProtectedRoutes.jsx @@ -0,0 +1,58 @@ +import React, {Component} from 'react'; + +class StudentProtectedRoutes extends Component{ + render () { + return ( + <> + + ( + + )} + /> + + ( + + )} + /> + ( + + )} + /> + ( + + )} + /> + {/* */} + + + ); + } +} + +export default StudentProtectedRoutes; \ No newline at end of file diff --git a/client/redux/actions/verificationAction.js b/client/redux/actions/verificationAction.js new file mode 100644 index 00000000..52750c4b --- /dev/null +++ b/client/redux/actions/verificationAction.js @@ -0,0 +1,35 @@ +verifyUser = () => { + //TODO Store user/admin in reducer + fetch('http://localhost:3000/api/v1/admin/me', { + method: 'GET', + headers: { + authorization: localStorage.token, + 'content-Type': 'application/json', + }, + }) + .then(res => res.json()) + .then(admin => { + if (admin) { + this.setState({ + user: admin, + }); + } else { + fetch('http://localhost:3000/api/v1/students/me', { + method: 'GET', + headers: { + authorization: localStorage.token, + 'content-Type': 'application/json', + }, + }) + .then(res => res.json()) + .then(student => { + this.setState({ + user: student, + }); + }); + } + }); + }; + + + module.export = {verifyUser}; \ No newline at end of file From dbb26474f5b34bb1da2c548c49d39868e7a3c6fa Mon Sep 17 00:00:00 2001 From: yjspoder Date: Mon, 27 Jan 2020 14:52:08 +0530 Subject: [PATCH 02/11] refactor App.jsx --- client/components/App.jsx | 131 ++------------------- client/redux/actions/verificationAction.js | 12 +- 2 files changed, 17 insertions(+), 126 deletions(-) diff --git a/client/components/App.jsx b/client/components/App.jsx index 20ecdfd6..28d27c77 100644 --- a/client/components/App.jsx +++ b/client/components/App.jsx @@ -34,50 +34,17 @@ class App extends Component { constructor(props) { super(props); - this.state = { - user: null, - }; + // this.state = { + // user: null, + // }; } componentDidMount() { if (localStorage.token) { - this.loginUser(); + this.props.verifyUser(); } } - loginUser = () => { - //TODO Store user/admin in reducer - fetch('http://localhost:3000/api/v1/admin/me', { - method: 'GET', - headers: { - authorization: localStorage.token, - 'content-Type': 'application/json', - }, - }) - .then(res => res.json()) - .then(admin => { - if (admin) { - this.setState({ - user: admin, - }); - } else { - fetch('http://localhost:3000/api/v1/students/me', { - method: 'GET', - headers: { - authorization: localStorage.token, - 'content-Type': 'application/json', - }, - }) - .then(res => res.json()) - .then(student => { - this.setState({ - user: student, - }); - }); - } - }); - }; - cb = () => { this.setState({ user: null }, () => { this.props.history.push('/'); @@ -91,95 +58,17 @@ class App extends Component { this.props.adminLogout(this.cb); }; - protectedAdminRoutes = () => { - - }; - - protectedStudentRoutes = () => { - return ( - <> - - ( - - )} - /> - - ( - - )} - /> - ( - - )} - /> - ( - - )} - /> - {/* */} - - - ); - }; - - nonProtectedRoutes = () => { - return ( - <> - - - - - - - - - - - - ); - }; - render() { - if (!this.state.user && localStorage.token) this.loginUser(); + if ((!this.props.adminReducer.isAdminLoggedIn || !this.props.isStudentLoggedIn ) && localStorage.token) this.props.verifyUser(); // console.log('app render...', this.state.user); return ( <> - {!this.state.user - ? this.nonProtectedRoutes() - : this.state.user.isAdmin + {this.props.adminReducer.isAdminLoggedIn ? - : } - {/* */} + : this.props.studentReducer.isStudentLoggedIn + ? + : + } ); } diff --git a/client/redux/actions/verificationAction.js b/client/redux/actions/verificationAction.js index 52750c4b..877a84b9 100644 --- a/client/redux/actions/verificationAction.js +++ b/client/redux/actions/verificationAction.js @@ -1,4 +1,4 @@ -verifyUser = () => { +const verifyUser = () => dispatch => { //TODO Store user/admin in reducer fetch('http://localhost:3000/api/v1/admin/me', { method: 'GET', @@ -10,8 +10,9 @@ verifyUser = () => { .then(res => res.json()) .then(admin => { if (admin) { - this.setState({ - user: admin, + dispatch({ + type: 'ADMIN_LOGIN_SUCCESS', + data: admin, }); } else { fetch('http://localhost:3000/api/v1/students/me', { @@ -23,8 +24,9 @@ verifyUser = () => { }) .then(res => res.json()) .then(student => { - this.setState({ - user: student, + dispatch({ + type: 'STUDENT_LOGIN_SUCCESS', + data: student, }); }); } From 15fd27bd0f65389e7ea567ed262651b3ff3fb9a5 Mon Sep 17 00:00:00 2001 From: yjspoder Date: Tue, 28 Jan 2020 16:15:36 +0530 Subject: [PATCH 03/11] add protected and non protected routes components --- client/components/App.jsx | 4 ++-- client/components/auth/AdminProtectedRoutes.jsx | 6 ++++++ client/components/auth/NonProtectedRoutes.jsx | 12 +++++++++++- client/components/auth/StudentProtectedRoutes.jsx | 5 +++++ client/redux/actions/verificationAction.js | 2 +- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/client/components/App.jsx b/client/components/App.jsx index 28d27c77..f1e39dc2 100644 --- a/client/components/App.jsx +++ b/client/components/App.jsx @@ -59,8 +59,8 @@ class App extends Component { }; render() { - if ((!this.props.adminReducer.isAdminLoggedIn || !this.props.isStudentLoggedIn ) && localStorage.token) this.props.verifyUser(); - // console.log('app render...', this.state.user); + // if ((!this.props.adminReducer.isAdminLoggedIn || !this.props.isStudentLoggedIn ) && localStorage.token) this.props.verifyUser(); + // console.log('app render...', this.props); return ( <> {this.props.adminReducer.isAdminLoggedIn diff --git a/client/components/auth/AdminProtectedRoutes.jsx b/client/components/auth/AdminProtectedRoutes.jsx index b5c19a28..5c651a97 100644 --- a/client/components/auth/AdminProtectedRoutes.jsx +++ b/client/components/auth/AdminProtectedRoutes.jsx @@ -1,4 +1,10 @@ import React,{Component} from 'react'; +import { Switch , Route } from 'react-router-dom'; +import AdminFeed from '../adminDashboard/AdminFeed'; +import ContentList from '../content/ContentList'; +import StudentList from '../students/StudentList'; +import UpdateContentModal from '../content/UpdateContentModal'; +import PendingApprovals from '../adminDashboard/PendingApprovals'; class AdminProtectedRoutes extends Component { render () { diff --git a/client/components/auth/NonProtectedRoutes.jsx b/client/components/auth/NonProtectedRoutes.jsx index 2d56ddde..d6a88cd3 100644 --- a/client/components/auth/NonProtectedRoutes.jsx +++ b/client/components/auth/NonProtectedRoutes.jsx @@ -1,4 +1,12 @@ import React, { Component } from 'react'; +import { Switch , Route } from 'react-router-dom'; +import Home from '../home/Home'; +import RegisterUser from './RegisterUser'; +import LoginUser from './LoginUser'; +import AdminLogin from './AdminLogin'; +import Onboarding from './Onboarding'; +import RegisterVerification from '../registerVerfication/RegisterVerification'; +import Page404 from '../Page404'; class NonProtectedRoutes extends Component { @@ -20,4 +28,6 @@ class NonProtectedRoutes extends Component { ); } -} \ No newline at end of file +} + +export default NonProtectedRoutes; \ No newline at end of file diff --git a/client/components/auth/StudentProtectedRoutes.jsx b/client/components/auth/StudentProtectedRoutes.jsx index fcafd4c1..01db8ed4 100644 --- a/client/components/auth/StudentProtectedRoutes.jsx +++ b/client/components/auth/StudentProtectedRoutes.jsx @@ -1,4 +1,9 @@ import React, {Component} from 'react'; +import { Switch , Route } from 'react-router-dom'; +import ContentSubmission from '../content/ContentSubmission'; +import RegisterVerification from '../registerVerfication/RegisterVerification'; +import StudentDashboard from '../students/studentDashboard/StudentDashboard'; +import StudentProfile from '../students/StudentProfile'; class StudentProtectedRoutes extends Component{ render () { diff --git a/client/redux/actions/verificationAction.js b/client/redux/actions/verificationAction.js index 877a84b9..47173aaa 100644 --- a/client/redux/actions/verificationAction.js +++ b/client/redux/actions/verificationAction.js @@ -34,4 +34,4 @@ const verifyUser = () => dispatch => { }; - module.export = {verifyUser}; \ No newline at end of file + module.exports = { verifyUser }; \ No newline at end of file From 8bee7250d552a474d1f3e9acf49f7beb9e83fbee Mon Sep 17 00:00:00 2001 From: BadBrahmin Date: Wed, 29 Jan 2020 17:21:24 +0530 Subject: [PATCH 04/11] fix: wrong redirect on add content --- client/components/adminDashboard/AdminSidebar.jsx | 2 +- client/components/content/NewContentModal.jsx | 6 ++++-- client/components/content/UpdateContentModal.jsx | 6 ++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/client/components/adminDashboard/AdminSidebar.jsx b/client/components/adminDashboard/AdminSidebar.jsx index 18be70b1..f11f1791 100644 --- a/client/components/adminDashboard/AdminSidebar.jsx +++ b/client/components/adminDashboard/AdminSidebar.jsx @@ -34,7 +34,7 @@ function AdminSidebar() { - + Content List diff --git a/client/components/content/NewContentModal.jsx b/client/components/content/NewContentModal.jsx index 0463802e..7cc33fdb 100644 --- a/client/components/content/NewContentModal.jsx +++ b/client/components/content/NewContentModal.jsx @@ -72,7 +72,7 @@ class NewContentModal extends React.Component { }; cb = () => { - this.props.history.push('/admin/content/list'); + this.props.history.push('/admin/contents'); }; showModal = () => { @@ -124,4 +124,6 @@ class NewContentModal extends React.Component { const mapStateToProps = state => { return state; }; -export default connect(mapStateToProps, { createContent })(withRouter(NewContentModal)); +export default connect(mapStateToProps, { createContent })( + withRouter(NewContentModal), +); diff --git a/client/components/content/UpdateContentModal.jsx b/client/components/content/UpdateContentModal.jsx index 650176a4..887ed585 100644 --- a/client/components/content/UpdateContentModal.jsx +++ b/client/components/content/UpdateContentModal.jsx @@ -101,7 +101,7 @@ class UpdateContentModal extends React.Component { } cb = () => { - this.props.history.push('/admin/content/list'); + this.props.history.push('/admin/contents'); }; showModal = () => { @@ -152,4 +152,6 @@ class UpdateContentModal extends React.Component { const mapStateToProps = state => { return state; }; -export default connect(mapStateToProps, { updateContent })(withRouter(UpdateContentModal)); +export default connect(mapStateToProps, { updateContent })( + withRouter(UpdateContentModal), +); From 6c5183e4ad64d5d561a2269eeea358c60a05eb1e Mon Sep 17 00:00:00 2001 From: BadBrahmin Date: Wed, 29 Jan 2020 21:02:23 +0530 Subject: [PATCH 05/11] add: AdminWrapper component --- .../adminDashboard/AdminWrapper.jsx | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 client/components/adminDashboard/AdminWrapper.jsx diff --git a/client/components/adminDashboard/AdminWrapper.jsx b/client/components/adminDashboard/AdminWrapper.jsx new file mode 100644 index 00000000..1907f8de --- /dev/null +++ b/client/components/adminDashboard/AdminWrapper.jsx @@ -0,0 +1,129 @@ +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { Link, withRouter } from 'react-router-dom'; + +import { adminLogout } from '../../redux/actions/adminAction'; + +import { Layout, Menu, Icon, Table, Divider, Spin, Button } from 'antd'; +const { Column, ColumnGroup } = Table; +const { Header, Content, Footer, Sider } = Layout; + +class AdminWrapper extends Component { + constructor(props) { + super(props); + } + + render() { + console.log(this.props); + + return ( + <> + + { + console.log(broken); + }} + onCollapse={(collapsed, type) => { + console.log(collapsed, type); + }} + > +
Exposure System
+ + + + + Stats + + + + + + Submissions + + + + + + Content List + + + + + + Student List + + + + + + Pending Approvals + + + +
+ +
+
+ +

Exposure System

+ +
+ +
+
+
+ + {/*

Submission List

*/} + {this.props.children} +
+
+
+ + ); + } +} + +const mapStateToProps = store => store; + +export default connect(mapStateToProps, { adminLogout })( + withRouter(AdminWrapper), +); From aa04ba39bf42c2902a61a4440e8a690354fc8afe Mon Sep 17 00:00:00 2001 From: BadBrahmin Date: Wed, 29 Jan 2020 21:04:37 +0530 Subject: [PATCH 06/11] update: AdminFeed, PendingApprovals with wrapper --- .../components/adminDashboard/AdminFeed.jsx | 191 ++++----------- .../adminDashboard/PendingApprovals.jsx | 225 +++++------------- 2 files changed, 110 insertions(+), 306 deletions(-) diff --git a/client/components/adminDashboard/AdminFeed.jsx b/client/components/adminDashboard/AdminFeed.jsx index 90bc6276..13ca9bd3 100644 --- a/client/components/adminDashboard/AdminFeed.jsx +++ b/client/components/adminDashboard/AdminFeed.jsx @@ -4,6 +4,7 @@ import { NavLink } from 'react-router-dom'; import { fetchSubmissionList } from '../../redux/actions/submissonAction'; import { Layout, Menu, Icon, Table, Divider, Spin, Button } from 'antd'; +import AdminWrapper from './AdminWrapper'; const { Column, ColumnGroup } = Table; const { Header, Content, Footer, Sider } = Layout; @@ -23,153 +24,55 @@ class AdminFeed extends Component { this.props.submissionReducer.submissionList && this.props.submissionReducer.submissionList.submissions.reverse(); return ( - <> +
-
- {this.props.submissionReducer.isLoadingSubmissionList ? ( -
-
- -
-

- We're pulling up submissions to show you right now... -

+ {this.props.submissionReducer.isLoadingSubmissionList ? ( +
+
+
- ) : ( -
- - { - console.log(broken); - }} - onCollapse={(collapsed, type) => { - console.log(collapsed, type); - }} - > -
Exposure System
- - - - - Home - {/* Home (Stats) */} - - - - - - Submissions - - - - - - Content List - - - - - - Student List - - - - - - Pending Approvals - - - -
- -
-
- -

Exposure System

-
-
- -
-
-
- -

Submission List

- - - - - - - -
{' '} -
- {/*
- Exposure System ©2018 Created by AltCampus -
*/} -
-
-
- )} -
+

+ We're pulling up submissions to show you right now... +

+
+ ) : ( +
+

Submission List

+ + + + + + + +
{' '} +
+ )}
- + ); } } diff --git a/client/components/adminDashboard/PendingApprovals.jsx b/client/components/adminDashboard/PendingApprovals.jsx index 2f0fee1d..b7f8e1e8 100644 --- a/client/components/adminDashboard/PendingApprovals.jsx +++ b/client/components/adminDashboard/PendingApprovals.jsx @@ -2,13 +2,12 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { NavLink } from 'react-router-dom'; +import AdminWrapper from '../adminDashboard/AdminWrapper'; import { fetchPendingApprovalList } from '../../redux/actions/adminAction'; import { approveStudent, removeStudent } from '../../redux/actions/adminAction'; -import { Table, Divider, Layout, Menu, Icon, Button } from 'antd'; -import { Spin } from 'antd'; +import { Table, Divider, Layout, Menu, Icon, Button, Spin } from 'antd'; const { Header, Content, Footer, Sider } = Layout; - const { Column, ColumnGroup } = Table; class PendingApprovals extends Component { @@ -39,166 +38,68 @@ class PendingApprovals extends Component { return ( <> -
- {this.props.adminReducer.isLoadingPendingStudentList ? ( -
- -
- ) : ( -
- - { - console.log(broken); - }} - onCollapse={(collapsed, type) => { - console.log(collapsed, type); - }} - > -
Exposure System
- - - - - Home - {/* Home (Stats) */} - - - - - - Submissions - - - - - - Content List - - - - - - Student List - - - - - - Pending Approvals - - - -
- -
-
+
+ {this.props.adminReducer.isLoadingPendingStudentList ? ( +
+ +
+ ) : ( +
+ {/*

Pending Approvals

*/} + + + + + { + return {record.isInCampus ? 'Yes' : 'No'}; + }} + /> + { + return {record.isActive ? 'Yes' : 'No'}; }} - > - -

Exposure System

-
-
- -
- - - -

Pending Approvals

-
- - - - { - return ( - {record.isInCampus ? 'Yes' : 'No'} - ); - }} - /> - { - return ( - {record.isActive ? 'Yes' : 'No'} - ); - }} - /> - ( - - this.handleApprove(record._id)}> - Approve - - - this.handleReject(record._id)}> - Reject - - - )} - /> - -
{' '} - -
- Exposure System ©2018 Created by AltCampus -
- - -
- )} -
+ /> + ( + + this.handleApprove(record._id)}> + Approve + + + this.handleReject(record._id)}> + Reject + + + )} + /> + + +
+ )} +
+ ); } From bc8cb23fb42f32c1b6be65d6c106e05efa2753d9 Mon Sep 17 00:00:00 2001 From: BadBrahmin Date: Wed, 29 Jan 2020 21:31:52 +0530 Subject: [PATCH 07/11] update: StudentList with wrapper --- .../adminDashboard/PendingApprovals.jsx | 2 +- client/components/students/StudentList.jsx | 219 +++++------------- 2 files changed, 63 insertions(+), 158 deletions(-) diff --git a/client/components/adminDashboard/PendingApprovals.jsx b/client/components/adminDashboard/PendingApprovals.jsx index b7f8e1e8..8b048c17 100644 --- a/client/components/adminDashboard/PendingApprovals.jsx +++ b/client/components/adminDashboard/PendingApprovals.jsx @@ -46,7 +46,7 @@ class PendingApprovals extends Component {
) : (
- {/*

Pending Approvals

*/} +

Pending Approvals

- {this.props.adminReducer.isLoadingStudentList ? ( -
- -
- ) : ( - - { - console.log(broken); - }} - onCollapse={(collapsed, type) => { - console.log(collapsed, type); - }} - > -
Exposure System
- - - - - Home - {/* Home (Stats) */} - - - - - - Submissions - - - - - - Content List - - - - - - Student List - - - - - - Pending Approvals - - - -
- -
-
- -

Exposure System

-
-
- -
-
-
- -
-

Student List

-
- - - - {/* +
+ {this.props.adminReducer.isLoadingStudentList ? ( +
+ +
+ ) : ( +
+

Student List

+
+ + + + {/* */} - { - return ( - {record.isInCampus ? 'Yes' : 'No'} - ); - }} - /> - { - return {record.isActive ? 'Yes' : 'No'}; - }} - /> + { + return {record.isInCampus ? 'Yes' : 'No'}; + }} + /> + { + return {record.isActive ? 'Yes' : 'No'}; + }} + /> - ( - - {/* + ( + + {/* */} - this.handleReject(record._id)}> - Delete - - - )} - /> - -
-
- -
- Exposure System ©2018 Created by AltCampus -
- - - )} -
+ this.handleReject(record._id)}> + Delete + + + )} + /> + + + + )} + +
); } } From 2bf1b48e6041114b4232984842485d802bdf2a70 Mon Sep 17 00:00:00 2001 From: BadBrahmin Date: Wed, 29 Jan 2020 21:44:03 +0530 Subject: [PATCH 08/11] update: moved under admin --- .../components/adminDashboard/StudentList.jsx | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 client/components/adminDashboard/StudentList.jsx diff --git a/client/components/adminDashboard/StudentList.jsx b/client/components/adminDashboard/StudentList.jsx new file mode 100644 index 00000000..3eb5a029 --- /dev/null +++ b/client/components/adminDashboard/StudentList.jsx @@ -0,0 +1,118 @@ +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { NavLink } from 'react-router-dom'; + +import { fetchStudentList } from '../../redux/actions/adminAction'; +import { removeStudent } from '../../redux/actions/adminAction'; + +import { Table, Divider, Layout, Menu, Icon, Button, Spin } from 'antd'; +import AdminWrapper from './AdminWrapper'; + +const { Header, Content, Footer, Sider } = Layout; + +const { Column, ColumnGroup } = Table; + +class StudentList extends Component { + constructor(props) { + super(props); + this.state = { + studentList: this.props.adminReducer.studentList, + }; + } + + cb = () => { + this.componentDidMount(); + }; + + handleReject = id => { + this.props.removeStudent(id, this.cb); + }; + + componentDidMount() { + this.props.fetchStudentList(); + } + + render() { + const studentList = + this.props.adminReducer.studentList && + this.props.adminReducer.studentList.students.reverse(); + console.log(studentList, 'inside student list component'); + return ( + +
+ {this.props.adminReducer.isLoadingStudentList ? ( +
+ +
+ ) : ( +
+

Student List

+ + + + + {/* */} + { + return {record.isInCampus ? 'Yes' : 'No'}; + }} + /> + { + return {record.isActive ? 'Yes' : 'No'}; + }} + /> + + ( + + {/* + */} + this.handleReject(record._id)}> + Delete + + + )} + /> + +
+
+ )} +
+
+ ); + } +} + +const mapStateToProps = store => { + return store; +}; +export default connect(mapStateToProps, { fetchStudentList, removeStudent })( + StudentList, +); From 1a59de6fab7629cf454989aa91b4a63610b25548 Mon Sep 17 00:00:00 2001 From: BadBrahmin Date: Wed, 29 Jan 2020 21:45:26 +0530 Subject: [PATCH 09/11] update: ContentList with wrapper --- client/components/content/ContentList.jsx | 223 +++++++--------------- 1 file changed, 65 insertions(+), 158 deletions(-) diff --git a/client/components/content/ContentList.jsx b/client/components/content/ContentList.jsx index b5798e42..c60c1035 100644 --- a/client/components/content/ContentList.jsx +++ b/client/components/content/ContentList.jsx @@ -7,6 +7,7 @@ import { deleteContent, } from '../../redux/actions/contentAction'; import NewContentModal from './NewContentModal'; +import AdminWrapper from '../adminDashboard/AdminWrapper'; import { Table, Divider, Spin, Layout, Menu, Icon, Button } from 'antd/lib'; import UpdateContentModal from './UpdateContentModal'; @@ -37,166 +38,72 @@ class ContentList extends Component { // console.log(this.props); const contentList = this.props.adminReducer.contentList && - this.props.adminReducer.contentList.contents.reverse(); + this.props.adminReducer.contentList.contents; return ( -
- {this.props.adminReducer.isLoadingContentList ? ( -
- -
- ) : ( - - { - console.log(broken); - }} - onCollapse={(collapsed, type) => { - console.log(collapsed, type); - }} - > -
Exposure System
- - - - - Home - {/* Home (Stats) */} - - - - - - Submissions - - - - - - Content List - - - - - - Student List - - - - - - Pending Approvals - - - -
- -
-
- -

Exposure System

-
-
- -
-
-
- -
-
-

Content List

- -

-
- - - - - - ( - - - Link - - - - - this.handleDelete(record._id)}> - Delete - - - )} - /> - -
-
-
- {/*
- Exposure System ©2018 Created by AltCampus -
*/} -
-
- )} -
+ +
+ {this.props.adminReducer.isLoadingContentList ? ( +
+ +
+ ) : ( +
+
+

Content List

+ +

+
+ + + + + + ( + + + Link + + + + + this.handleDelete(record._id)}> + Delete + + + )} + /> + +
+
+ )} +
+
); } } From 4ca079ff4bca3c5fb07b45883116897a2ee9faaf Mon Sep 17 00:00:00 2001 From: BadBrahmin Date: Wed, 29 Jan 2020 22:07:50 +0530 Subject: [PATCH 10/11] fix: redirects --- client/components/content/ContentList.jsx | 8 ++++- client/components/content/NewContentModal.jsx | 11 +++++-- .../components/content/UpdateContentModal.jsx | 10 ++++--- client/redux/actions/contentAction.js | 30 +++++-------------- client/redux/reducers/adminReducer.js | 4 ++- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/client/components/content/ContentList.jsx b/client/components/content/ContentList.jsx index c60c1035..6d5671ac 100644 --- a/client/components/content/ContentList.jsx +++ b/client/components/content/ContentList.jsx @@ -30,8 +30,14 @@ class ContentList extends Component { this.setState({ [e.target.name]: e.target.value }); } + // cb = () => { + // console.log('done'); + // this.props.fetchContentList(); + // // this.props.history.push('/admin/contents'); + // }; + handleDelete = id => { - this.props.deleteContent(id, this.componentDidMount); + this.props.deleteContent(id, this.componentDidMount()); }; render() { diff --git a/client/components/content/NewContentModal.jsx b/client/components/content/NewContentModal.jsx index 7cc33fdb..fc07f6b5 100644 --- a/client/components/content/NewContentModal.jsx +++ b/client/components/content/NewContentModal.jsx @@ -1,5 +1,8 @@ import React from 'react'; -import { createContent } from '../../redux/actions/contentAction'; +import { + createContent, + fetchContentList, +} from '../../redux/actions/contentAction'; import { connect } from 'react-redux'; import { withRouter } from 'react-router-dom'; import { Button, Modal, Form, Input, Radio } from 'antd'; @@ -72,7 +75,9 @@ class NewContentModal extends React.Component { }; cb = () => { - this.props.history.push('/admin/contents'); + console.log('done'); + this.props.fetchContentList(); + // this.props.history.push('/admin/contents'); }; showModal = () => { @@ -124,6 +129,6 @@ class NewContentModal extends React.Component { const mapStateToProps = state => { return state; }; -export default connect(mapStateToProps, { createContent })( +export default connect(mapStateToProps, { createContent, fetchContentList })( withRouter(NewContentModal), ); diff --git a/client/components/content/UpdateContentModal.jsx b/client/components/content/UpdateContentModal.jsx index 887ed585..950fd0c2 100644 --- a/client/components/content/UpdateContentModal.jsx +++ b/client/components/content/UpdateContentModal.jsx @@ -1,7 +1,10 @@ import React from 'react'; import { connect } from 'react-redux'; import { withRouter } from 'react-router-dom'; -import { updateContent } from '../../redux/actions/contentAction'; +import { + updateContent, + fetchContentList, +} from '../../redux/actions/contentAction'; import { Button, Modal, Form, Input, Radio } from 'antd'; @@ -101,7 +104,7 @@ class UpdateContentModal extends React.Component { } cb = () => { - this.props.history.push('/admin/contents'); + this.props.fetchContentList(); }; showModal = () => { @@ -121,7 +124,6 @@ class UpdateContentModal extends React.Component { console.log('Received values of form: ', values); this.props.updateContent(values, this.cb); - // form.resetFields(); }); this.setState({ visible: false }); }; @@ -152,6 +154,6 @@ class UpdateContentModal extends React.Component { const mapStateToProps = state => { return state; }; -export default connect(mapStateToProps, { updateContent })( +export default connect(mapStateToProps, { updateContent, fetchContentList })( withRouter(UpdateContentModal), ); diff --git a/client/redux/actions/contentAction.js b/client/redux/actions/contentAction.js index 723fc297..ce70a194 100644 --- a/client/redux/actions/contentAction.js +++ b/client/redux/actions/contentAction.js @@ -52,7 +52,7 @@ const updateContent = (data, cb) => { cb(); }; -const deleteContent = (id, cb) => dispatch => { +const deleteContent = id => dispatch => { console.log(id, 'in action'); const url = `http://localhost:3000/api/v1/content/delete/${id}`; fetch(url, { @@ -62,34 +62,18 @@ const deleteContent = (id, cb) => dispatch => { 'Content-Type': 'application/json', }, }) + .then(res => res.json()) .then(res => { console.log(res, 'res in action'); - // swal({ - // title: 'Content has been', - // text: 'Deleted', - // icon: 'success', - // }); + swal({ + title: 'Content has been deleted', + text: 'Deleted!', + icon: 'success', + }); }) .catch(err => alert(err)); - cb(); }; -// const deleteContent = (id, cb) => dispatch => { -// fetch(`/api/v1/content/delete/${id}`, { -// method: 'DELETE', -// headers: { -// 'Content-Type': 'application/json', -// }, -// }).then(removedContent => { -// console.log(removedContent, 'content removed'); -// swal({ -// title: 'Content Removed', -// icon: 'success', -// }); -// }); -// cb(); -// }; - module.exports = { createContent, fetchContentList, diff --git a/client/redux/reducers/adminReducer.js b/client/redux/reducers/adminReducer.js index 9262f99f..b4b94e66 100644 --- a/client/redux/reducers/adminReducer.js +++ b/client/redux/reducers/adminReducer.js @@ -47,7 +47,9 @@ function adminReducer(state = INITIAL_STATE, action) { return { ...state, isLoadingContentList: false, - contentList: action.data, + contentList: {...action.data, + contents: action.data.contents.reverse() + }, }; case 'FETCHING_STUDENT_LIST_START': return { From 67e808fb0c1bc9d18a5785f6ef88a8d782604077 Mon Sep 17 00:00:00 2001 From: BadBrahmin Date: Wed, 29 Jan 2020 22:12:51 +0530 Subject: [PATCH 11/11] cleanup --- client/components/App.jsx | 30 ++--- .../adminDashboard/AdminSidebar.jsx | 74 ----------- .../components/auth/AdminProtectedRoutes.jsx | 108 ++++++++-------- client/components/auth/NonProtectedRoutes.jsx | 37 +++--- client/components/auth/Onboarding.jsx | 103 --------------- client/components/content/ContentCard.jsx | 36 ------ client/components/students/StudentCard.jsx | 36 ------ client/components/students/StudentList.jsx | 118 ------------------ .../StudentSubmissionCard.jsx | 29 ----- 9 files changed, 79 insertions(+), 492 deletions(-) delete mode 100644 client/components/adminDashboard/AdminSidebar.jsx delete mode 100644 client/components/auth/Onboarding.jsx delete mode 100644 client/components/content/ContentCard.jsx delete mode 100644 client/components/students/StudentCard.jsx delete mode 100644 client/components/students/StudentList.jsx delete mode 100644 client/components/students/studentDashboard/StudentSubmissionCard.jsx diff --git a/client/components/App.jsx b/client/components/App.jsx index f1e39dc2..60e251c7 100644 --- a/client/components/App.jsx +++ b/client/components/App.jsx @@ -8,24 +8,11 @@ import { BrowserRouter as Router, } from 'react-router-dom'; import { connect } from 'react-redux'; -import Home from './home/Home'; -import RegisterUser from './auth/RegisterUser'; -import LoginUser from './auth/LoginUser'; -import AdminLogin from './auth/AdminLogin'; -import Page404 from './Page404'; -import ContentList from './content/ContentList'; -import PendingApprovals from './adminDashboard/PendingApprovals'; -import ContentSubmission from './content/ContentSubmission'; -import Onboarding from './auth/Onboarding'; -import StudentDashboard from './students/studentDashboard/StudentDashboard'; -import UpdateContentModal from './content/UpdateContentModal'; -import AdminFeed from './adminDashboard/AdminFeed'; -import StudentList from './students/StudentList'; -import RegisterVerification from './registerVerfication/RegisterVerification'; -import StudentProfile from './students/StudentProfile'; + import AdminProtectedRoutes from './auth/AdminProtectedRoutes'; import StudentProtectedRoutes from './auth/StudentProtectedRoutes'; import NonProtectedRoutes from './auth/NonProtectedRoutes'; + import { verifyUser } from '../redux/actions/verificationAction'; import { studentLogin, studentLogout } from '../redux/actions/studentAction'; import { adminLogout } from '../redux/actions/adminAction'; @@ -63,12 +50,13 @@ class App extends Component { // console.log('app render...', this.props); return ( <> - {this.props.adminReducer.isAdminLoggedIn - ? - : this.props.studentReducer.isStudentLoggedIn - ? - : - } + {this.props.adminReducer.isAdminLoggedIn ? ( + + ) : this.props.studentReducer.isStudentLoggedIn ? ( + + ) : ( + + )} ); } diff --git a/client/components/adminDashboard/AdminSidebar.jsx b/client/components/adminDashboard/AdminSidebar.jsx deleted file mode 100644 index f11f1791..00000000 --- a/client/components/adminDashboard/AdminSidebar.jsx +++ /dev/null @@ -1,74 +0,0 @@ -import React from 'react'; -import { NavLink } from 'react-router-dom'; -import { Layout, Menu, Icon } from 'antd'; -const { Header, Content, Footer, Sider } = Layout; - -function AdminSidebar() { - return ( - <> - - -
- Exposure System -
- - - - - Home - {/* Home (Stats) */} - - - - - - Submissions - - - - - - Content List - - - - - - Student List - - - - - - Pending Approvals - - - -
- - {/*
- -
- ... -
-
*/} - {/*
- Ant Design ©2018 Created by Ant UED -
*/} - - - - ); -} - -export default AdminSidebar; diff --git a/client/components/auth/AdminProtectedRoutes.jsx b/client/components/auth/AdminProtectedRoutes.jsx index 5c651a97..50cafb44 100644 --- a/client/components/auth/AdminProtectedRoutes.jsx +++ b/client/components/auth/AdminProtectedRoutes.jsx @@ -1,62 +1,64 @@ -import React,{Component} from 'react'; -import { Switch , Route } from 'react-router-dom'; +import React, { Component } from 'react'; +import { Switch, Route } from 'react-router-dom'; import AdminFeed from '../adminDashboard/AdminFeed'; import ContentList from '../content/ContentList'; -import StudentList from '../students/StudentList'; +import StudentList from '../adminDashboard/StudentList'; import UpdateContentModal from '../content/UpdateContentModal'; import PendingApprovals from '../adminDashboard/PendingApprovals'; +import AdminWrapper from '../adminDashboard/AdminWrapper'; class AdminProtectedRoutes extends Component { - render () { + render() { return ( - - ( - - )} - /> - - ( - - )} - /> - - ( - - )} - /> - ( - - )} - /> - - ); - } + + ( + + )} + /> + + + ( + + )} + /> + + ( + + )} + /> + ( + + )} + /> + + ); + } } -export default AdminProtectedRoutes; \ No newline at end of file +export default AdminProtectedRoutes; diff --git a/client/components/auth/NonProtectedRoutes.jsx b/client/components/auth/NonProtectedRoutes.jsx index d6a88cd3..bc3940ff 100644 --- a/client/components/auth/NonProtectedRoutes.jsx +++ b/client/components/auth/NonProtectedRoutes.jsx @@ -1,33 +1,26 @@ import React, { Component } from 'react'; -import { Switch , Route } from 'react-router-dom'; +import { Switch, Route } from 'react-router-dom'; import Home from '../home/Home'; import RegisterUser from './RegisterUser'; import LoginUser from './LoginUser'; import AdminLogin from './AdminLogin'; -import Onboarding from './Onboarding'; import RegisterVerification from '../registerVerfication/RegisterVerification'; import Page404 from '../Page404'; - class NonProtectedRoutes extends Component { - render () { - return ( - - - - - - - - - - - ); - } + render() { + return ( + + + + + + + + + + ); + } } -export default NonProtectedRoutes; \ No newline at end of file +export default NonProtectedRoutes; diff --git a/client/components/auth/Onboarding.jsx b/client/components/auth/Onboarding.jsx deleted file mode 100644 index f41b476f..00000000 --- a/client/components/auth/Onboarding.jsx +++ /dev/null @@ -1,103 +0,0 @@ -/* eslint-disable react/jsx-indent */ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; -import registerStudent from '../../redux/actions/registerAction'; -import { Button, Checkbox } from 'antd'; -import swal from 'sweetalert'; - -class Onboarding extends Component { - constructor(props) { - super(props); - } - state = { - username: this.props.registerFormReducer.studentUsername, - email: this.props.registerFormReducer.studentEmail, - password: this.props.registerFormReducer.studentPassword, - isInCampus: false, - isActive: false, - }; - cb = () => { - this.props.history.push('/await-approval'); - }; - - handleChange = e => { - this.setState({ - [e.target.name]: e.target.value, - }); - }; - - onCheckChange1 = e => { - this.setState({ - isInCampus: e.target.checked, - }); - }; - - onCheckChange2 = e => { - this.setState({ - isActive: e.target.checked, - }); - }; - handleSubmit = e => { - e.preventDefault(); - console.log('submit called', this.state); - const studentData = { - username: this.state.username, - password: this.state.password, - email: this.state.email, - isInCampus: this.state.isInCampus, - isActive: this.state.isActive, - }; - registerStudent(studentData, this.cb); - - swal({ - title: 'Registered! ', - icon: 'success', - timer: 3000, - }); - }; - - render() { - return ( -
-
- -
-
- - In Campus - -
-
-
- -
-
- - In Campus - -
-
-
- - -
-
- ); - } -} - -const mapStateToProps = state => state; - -export default connect(mapStateToProps, { registerStudent })(Onboarding); diff --git a/client/components/content/ContentCard.jsx b/client/components/content/ContentCard.jsx deleted file mode 100644 index 9235a84f..00000000 --- a/client/components/content/ContentCard.jsx +++ /dev/null @@ -1,36 +0,0 @@ -import React, { Component } from 'react'; -import { NavLink } from 'react-router-dom'; - -class ContentCard extends Component { - constructor(props) { - super(props); - } - - render() { - const { type, title, description } = this.props.content; - return ( -
-
-
{type}
-
{title}
-
-
-
{description}
-
- {/* //TODO navlink should redirect to individual content piece by passing - contentid from props */} - - Read More >>> - -
- ); - } -} - -export default ContentCard; diff --git a/client/components/students/StudentCard.jsx b/client/components/students/StudentCard.jsx deleted file mode 100644 index c3fedb37..00000000 --- a/client/components/students/StudentCard.jsx +++ /dev/null @@ -1,36 +0,0 @@ -/* eslint-disable no-useless-constructor */ -import React, { Component } from 'react'; - -class Student extends Component { - constructor(props) { - super(props); - } - - render() { - const {username, email, isActive, isInCampus, isAdmin, createdAt } = this.props.student; - return ( -
-
{username}
-
-
-
-
-
- Details: - {email} - {isInCampus} - {isActive} - {isAdmin} -
-
-
-Created at: - {createdAt} - {' '} -
-
- ); - } -} - -export default Student; diff --git a/client/components/students/StudentList.jsx b/client/components/students/StudentList.jsx deleted file mode 100644 index a1d412c5..00000000 --- a/client/components/students/StudentList.jsx +++ /dev/null @@ -1,118 +0,0 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; -import { NavLink } from 'react-router-dom'; - -import { fetchStudentList } from '../../redux/actions/adminAction'; -import { removeStudent } from '../../redux/actions/adminAction'; - -import { Table, Divider, Layout, Menu, Icon, Button, Spin } from 'antd'; -import AdminWrapper from '../adminDashboard/AdminWrapper'; - -const { Header, Content, Footer, Sider } = Layout; - -const { Column, ColumnGroup } = Table; - -class StudentList extends Component { - constructor(props) { - super(props); - this.state = { - studentList: this.props.adminReducer.studentList, - }; - } - - cb = () => { - this.componentDidMount(); - }; - - handleReject = id => { - this.props.removeStudent(id, this.cb); - }; - - componentDidMount() { - this.props.fetchStudentList(); - } - - render() { - const studentList = - this.props.adminReducer.studentList && - this.props.adminReducer.studentList.students.reverse(); - console.log(studentList, 'inside student list component'); - return ( - -
- {this.props.adminReducer.isLoadingStudentList ? ( -
- -
- ) : ( -
-

Student List

- - - - - {/* */} - { - return {record.isInCampus ? 'Yes' : 'No'}; - }} - /> - { - return {record.isActive ? 'Yes' : 'No'}; - }} - /> - - ( - - {/* - */} - this.handleReject(record._id)}> - Delete - - - )} - /> - -
-
- )} -
-
- ); - } -} - -const mapStateToProps = store => { - return store; -}; -export default connect(mapStateToProps, { fetchStudentList, removeStudent })( - StudentList, -); diff --git a/client/components/students/studentDashboard/StudentSubmissionCard.jsx b/client/components/students/studentDashboard/StudentSubmissionCard.jsx deleted file mode 100644 index 70e58700..00000000 --- a/client/components/students/studentDashboard/StudentSubmissionCard.jsx +++ /dev/null @@ -1,29 +0,0 @@ -import React, { Component } from 'react'; -import { NavLink } from 'react-router-dom'; -// TODO : MAKE IT AS WHEN CLICKED ON THE CARD IT OPENS THE ORIGINAL ARTICLE + SUBMISSION (GET) -class StudentSubmissionCard extends Component { - constructor(props) { - super(props); - } - - render() { - // const { title, contentSummary } = this.props.submission; - return ( - // -
-
-
- Title : This is the title -
-
Submitted Summary:
-

This is the summary of the submission

-
Created at: 01/01/2020
-
-
- //
- ); - } -} - -const mapStateToProps = state => state; -export default StudentSubmissionCard;