+
+ {this.props.adminReducer.isLoadingPendingStudentList ? (
+
+
+
+ ) : (
+
+ )}
+
+
>
);
}
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,
+);
diff --git a/client/components/auth/AdminProtectedRoutes.jsx b/client/components/auth/AdminProtectedRoutes.jsx
new file mode 100644
index 00000000..50cafb44
--- /dev/null
+++ b/client/components/auth/AdminProtectedRoutes.jsx
@@ -0,0 +1,64 @@
+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 '../adminDashboard/StudentList';
+import UpdateContentModal from '../content/UpdateContentModal';
+import PendingApprovals from '../adminDashboard/PendingApprovals';
+import AdminWrapper from '../adminDashboard/AdminWrapper';
+
+class AdminProtectedRoutes extends Component {
+ render() {
+ return (
+
+ (
+
+ )}
+ />
+
+
+ (
+
+ )}
+ />
+
+ (
+
+ )}
+ />
+ (
+
+ )}
+ />
+
+ );
+ }
+}
+
+export default AdminProtectedRoutes;
diff --git a/client/components/auth/NonProtectedRoutes.jsx b/client/components/auth/NonProtectedRoutes.jsx
new file mode 100644
index 00000000..bc3940ff
--- /dev/null
+++ b/client/components/auth/NonProtectedRoutes.jsx
@@ -0,0 +1,26 @@
+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 RegisterVerification from '../registerVerfication/RegisterVerification';
+import Page404 from '../Page404';
+
+class NonProtectedRoutes extends Component {
+ render() {
+ return (
+
+
+
+
+
+
+
+
+
+ );
+ }
+}
+
+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 (
-
- );
- }
-}
-
-const mapStateToProps = state => state;
-
-export default connect(mapStateToProps, { registerStudent })(Onboarding);
diff --git a/client/components/auth/StudentProtectedRoutes.jsx b/client/components/auth/StudentProtectedRoutes.jsx
new file mode 100644
index 00000000..01db8ed4
--- /dev/null
+++ b/client/components/auth/StudentProtectedRoutes.jsx
@@ -0,0 +1,63 @@
+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 () {
+ return (
+ <>
+
+ (
+
+ )}
+ />
+
+ (
+
+ )}
+ />
+ (
+
+ )}
+ />
+ (
+
+ )}
+ />
+ {/* */}
+
+ >
+ );
+ }
+}
+
+export default StudentProtectedRoutes;
\ No newline at end of file
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 (
-
-
-
- {/* //TODO navlink should redirect to individual content piece by passing
- contentid from props */}
-
- Read More >>>
-
-
- );
- }
-}
-
-export default ContentCard;
diff --git a/client/components/content/ContentList.jsx b/client/components/content/ContentList.jsx
index b5798e42..6d5671ac 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';
@@ -29,174 +30,86 @@ 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() {
// 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
-
-
-
-
-
-
- Exposure System
-
-
-
-
-
-
-
-
-
-
Content List
-
-
-
-
-
-
- {/* */}
-
-
- )}
-
+
+
+ {this.props.adminReducer.isLoadingContentList ? (
+
+
+
+ ) : (
+
+
+
Content List
+
+
+
+
+
+ )}
+
+
);
}
}
diff --git a/client/components/content/NewContentModal.jsx b/client/components/content/NewContentModal.jsx
index 0463802e..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/content/list');
+ console.log('done');
+ this.props.fetchContentList();
+ // this.props.history.push('/admin/contents');
};
showModal = () => {
@@ -124,4 +129,6 @@ class NewContentModal extends React.Component {
const mapStateToProps = state => {
return state;
};
-export default connect(mapStateToProps, { createContent })(withRouter(NewContentModal));
+export default connect(mapStateToProps, { createContent, fetchContentList })(
+ withRouter(NewContentModal),
+);
diff --git a/client/components/content/UpdateContentModal.jsx b/client/components/content/UpdateContentModal.jsx
index 650176a4..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/content/list');
+ 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,4 +154,6 @@ class UpdateContentModal extends React.Component {
const mapStateToProps = state => {
return state;
};
-export default connect(mapStateToProps, { updateContent })(withRouter(UpdateContentModal));
+export default connect(mapStateToProps, { updateContent, fetchContentList })(
+ withRouter(UpdateContentModal),
+);
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 506a8c5b..00000000
--- a/client/components/students/StudentList.jsx
+++ /dev/null
@@ -1,213 +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';
-
-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 ? (
-
-
-
- ) : (
-
- {
- console.log(broken);
- }}
- onCollapse={(collapsed, type) => {
- console.log(collapsed, type);
- }}
- >
- Exposure System
-
-
-
-
-
-
- Exposure System
-
-
-
-
-
-
-
-
-
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;
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/actions/verificationAction.js b/client/redux/actions/verificationAction.js
new file mode 100644
index 00000000..47173aaa
--- /dev/null
+++ b/client/redux/actions/verificationAction.js
@@ -0,0 +1,37 @@
+const verifyUser = () => dispatch => {
+ //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) {
+ dispatch({
+ type: 'ADMIN_LOGIN_SUCCESS',
+ data: 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 => {
+ dispatch({
+ type: 'STUDENT_LOGIN_SUCCESS',
+ data: student,
+ });
+ });
+ }
+ });
+ };
+
+
+ module.exports = { verifyUser };
\ No newline at end of file
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 {