diff --git a/client/components/App.jsx b/client/components/App.jsx index 1a43da5d..60e251c7 100644 --- a/client/components/App.jsx +++ b/client/components/App.jsx @@ -8,72 +8,30 @@ 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 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) { 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('/'); @@ -87,144 +45,18 @@ class App extends Component { this.props.adminLogout(this.cb); }; - protectedAdminRoutes = () => { - return ( - <> - - ( - - )} - /> - - ( - - )} - /> - - ( - - )} - /> - ( - - )} - /> - - - ); - }; - - protectedStudentRoutes = () => { - return ( - <> - - ( - - )} - /> - - ( - - )} - /> - ( - - )} - /> - ( - - )} - /> - {/* */} - - - ); - }; - - nonProtectedRoutes = () => { - return ( - <> - - - - - - - - - - - - ); - }; - render() { - if (!this.state.user && localStorage.token) this.loginUser(); - // 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.state.user - ? this.nonProtectedRoutes() - : this.state.user.isAdmin - ? this.protectedAdminRoutes() - : this.protectedStudentRoutes()} - {/* */} + {this.props.adminReducer.isAdminLoggedIn ? ( + + ) : this.props.studentReducer.isStudentLoggedIn ? ( + + ) : ( + + )} ); } @@ -232,6 +64,7 @@ class App extends Component { const mapStateToProps = store => store; export default connect(mapStateToProps, { + verifyUser, studentLogin, studentLogout, adminLogout, 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/AdminSidebar.jsx b/client/components/adminDashboard/AdminSidebar.jsx deleted file mode 100644 index 18be70b1..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/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), +); diff --git a/client/components/adminDashboard/PendingApprovals.jsx b/client/components/adminDashboard/PendingApprovals.jsx index 2f0fee1d..8b048c17 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 + + + )} + /> + + +
+ )} +
+ ); } 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 ( -
-
- -
-
- - In Campus - -
-
-
- -
-
- - In Campus - -
-
-
- - -
-
- ); - } -} - -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 ( -
-
-
{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/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
- - - - - 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 + + + )} + /> + +
+
+ )} +
+
); } } 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
- - - - - Home - {/* Home (Stats) */} - - - - - - Submissions - - - - - - Content List - - - - - - Student List - - - - - - Pending Approvals - - - -
- -
-
- -

Exposure System

-
-
- -
-
-
- -
-

Student List

- - - - - {/* */} - { - return ( - {record.isInCampus ? 'Yes' : 'No'} - ); - }} - /> - { - return {record.isActive ? 'Yes' : 'No'}; - }} - /> - - ( - - {/* - */} - this.handleReject(record._id)}> - Delete - - - )} - /> - -
-
-
-
- Exposure System ©2018 Created by AltCampus -
-
-
- )} -
- ); - } -} - -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 {