Skip to content

Commit

Permalink
Merge pull request #108 from GSG-G8/107-logout-AddEditForm
Browse files Browse the repository at this point in the history
Pass logout props to Admin Container
  • Loading branch information
ranasobeid95 authored Jun 2, 2020
2 parents efc2fb7 + 5452b73 commit 4241afa
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 50 deletions.
5 changes: 5 additions & 0 deletions client/src/Contexts/LogoutContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createContext } from 'react';

const LogoutContext = createContext();

export default LogoutContext;
29 changes: 9 additions & 20 deletions client/src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import axios from 'axios';

import * as ROUTES from '../constants/routes';
import LogoutContext from '../Contexts/LogoutContext';
import LoginPage from '../containers/loginPage';
import CohortPage from '../containers/CohortPage';
import StudentPage from '../containers/StudentPage';
Expand Down Expand Up @@ -82,33 +83,21 @@ class App extends Component {
}
/>
{isAuth ? (
<>
<Route
exact
path={ROUTES.HOME_PAGE}
render={(props) => (
<Statistics {...props} logout={this.logout} />
)}
/>
<Route
path={ROUTES.COHORT_PAGE}
exact
render={() => <CohortPage logout={this.logout} />}
/>
<LogoutContext.Provider value={{ logout: this.logout }}>
<Route exact path={ROUTES.HOME_PAGE} component={Statistics} />

<Route path={ROUTES.COHORT_PAGE} exact component={CohortPage} />

<Route
path={ROUTES.COHORT_STUDENTS_PAGE}
exact
render={(props) => (
<StudentPage {...props} logout={this.logout} />
)}
component={StudentPage}
/>

<Route
path={ROUTES.COHORT_PROJECTS_PAGE}
exact
render={(props) => (
<AdminProject {...props} logout={this.logout} />
)}
component={AdminProject}
/>

<Route
Expand Down Expand Up @@ -186,7 +175,7 @@ class App extends Component {
/>
)}
/>
</>
</LogoutContext.Provider>
) : redirect ? (
<Route render={() => <Redirect to={ROUTES.LOGIN_PAGE} />} />
) : null}
Expand Down
24 changes: 13 additions & 11 deletions client/src/components/AdminContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import PropTypes from 'prop-types';
import { Layout, Button } from 'antd';
import logo from '../../assets/images/logo.png';
import './style.css';
import LogoutContext from '../../Contexts/LogoutContext';

const { Header } = Layout;

const AdminContainer = ({ children, buttonContent, buttonRoute, logout }) => {
const AdminContainer = ({ children, buttonContent, buttonRoute }) => {
return (
<>
<Layout>
Expand Down Expand Up @@ -48,15 +49,17 @@ const AdminContainer = ({ children, buttonContent, buttonRoute, logout }) => {
</li>
</ul>
<div className="admin-side-btn">
<Button
className="logout-btn"
type="primary"
onClick={() => {
logout();
}}
>
Logout
</Button>
<LogoutContext.Consumer>
{({ logout }) => (
<Button
className="logout-btn"
type="primary"
onClick={logout}
>
Logout
</Button>
)}
</LogoutContext.Consumer>
</div>
</div>
</div>
Expand All @@ -76,7 +79,6 @@ AdminContainer.propTypes = {
buttonContent: PropTypes.string,
buttonRoute: PropTypes.string,
children: PropTypes.node.isRequired,
logout: PropTypes.func.isRequired,
};

export default AdminContainer;
3 changes: 0 additions & 3 deletions client/src/containers/AdminProjectPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class AdminProject extends Component {

render() {
const { data, total, startPage, endPage } = this.state;
const { logout } = this.props;
const {
match: {
params: { cohortId },
Expand All @@ -97,7 +96,6 @@ class AdminProject extends Component {
<AdminContainer
buttonContent="Add Project"
buttonRoute={`/admin/cohorts/${cohortId}/projects/add`}
logout={logout}
>
{data.length === 0 ? (
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} className="empty" />
Expand Down Expand Up @@ -144,7 +142,6 @@ AdminProject.propTypes = {
cohortId: PropTypes.number.isRequired,
match: PropTypes.func.isRequired,
location: PropTypes.func.isRequired,
logout: PropTypes.func.isRequired,
};

export default AdminProject;
6 changes: 0 additions & 6 deletions client/src/containers/CohortPage/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import axios from 'axios';
import { notification, Modal, Empty, List, Pagination } from 'antd';
import { ExclamationCircleOutlined } from '@ant-design/icons';
Expand Down Expand Up @@ -72,14 +71,12 @@ class Cohort extends Component {

render() {
const { data, startPage, endPage, total } = this.state;
const { logout } = this.props;
const list = data.slice(startPage, endPage);
return (
<div>
<AdminContainer
buttonContent="Add Cohort"
buttonRoute="/admin/cohorts/add"
logout={logout}
>
{data.length === 0 ? (
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} className="empty" />
Expand Down Expand Up @@ -124,8 +121,5 @@ class Cohort extends Component {
);
}
}
Cohort.propTypes = {
logout: PropTypes.func.isRequired,
};

export default Cohort;
3 changes: 0 additions & 3 deletions client/src/containers/StudentPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,12 @@ class Student extends Component {
},
} = this.props;
const { data, startPage, endPage, total } = this.state;
const { logout } = this.props;
const list = data.slice(startPage, endPage);
return (
<div>
<AdminContainer
buttonContent="Add Student"
buttonRoute={`/admin/cohorts/${cohortId}/students/add`}
logout={logout}
>
{data.length === 0 ? (
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} className="empty" />
Expand Down Expand Up @@ -141,7 +139,6 @@ Student.defaultProps = {
};

Student.propTypes = {
logout: PropTypes.func.isRequired,
cohortId: PropTypes.number,
match: PropTypes.node,
params: PropTypes.node,
Expand Down
8 changes: 1 addition & 7 deletions client/src/containers/statisticsPage/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { Component } from 'react';
import { Progress, notification } from 'antd';
import axios from 'axios';
import PropTypes from 'prop-types';

import AdminContainer from '../../components/AdminContainer';
import Chart from '../../components/Charts';
Expand Down Expand Up @@ -40,10 +39,9 @@ class Statistics extends Component {

render() {
const { cohortsCount, studentsCount, projectsCount } = this.state;
const { logout } = this.props;
return (
<div>
<AdminContainer logout={logout}>
<AdminContainer>
<div className="state-container">
<Chart />
<div className="state">
Expand Down Expand Up @@ -71,8 +69,4 @@ class Statistics extends Component {
}
}

Statistics.propTypes = {
logout: PropTypes.func.isRequired,
};

export default Statistics;

0 comments on commit 4241afa

Please sign in to comment.