Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2602d0e
added tokenServices file for fetching token
afterafx Oct 7, 2019
f9b162c
Read in token from Dashboard
rsanchez-dv Oct 10, 2019
90c1dbc
Set up basic dashboard with data read in from token
rsanchez-dv Oct 11, 2019
c4c19ba
Redirect finally works
rsanchez-dv Oct 11, 2019
89132f6
Pass fullName to tokenService
devmarantz Oct 14, 2019
be93e5f
Pass fullName to DashboardPage
devmarantz Oct 14, 2019
ae92898
Merge staging
devmarantz Oct 14, 2019
4fea825
Add dashboard menu component and dashboard.scss
devmarantz Oct 15, 2019
eab5093
Add stylings to dashboard and fix to stonehaven variables
devmarantz Oct 15, 2019
8d9f429
Fix Menu and Dashboard text and temporarily remove logout function
devmarantz Oct 15, 2019
b567e54
Add secondary font on Dashboard
devmarantz Oct 15, 2019
d6325ef
Add new fonts for all text on Dashboard
devmarantz Oct 15, 2019
c9eae04
Change menuHeader
devmarantz Oct 15, 2019
ce20f96
Merge remote-tracking branch 'origin/passFullName' into 3-authentication
rsanchez-dv Oct 16, 2019
a1c21e4
Updated the signup page and cleaned some code
rsanchez-dv Oct 16, 2019
1175be5
Add protected Dashboard Route
devmarantz Oct 16, 2019
0a13dc8
Add protectedDashboardRoute to the App
devmarantz Oct 16, 2019
3f57daa
Cleaned up some code to handle no network connection
rsanchez-dv Oct 16, 2019
36e7dd6
Add handler for login
devmarantz Oct 16, 2019
1cd3e5a
Make ProtectedDashboardRoute able to redirect with a link input
devmarantz Oct 16, 2019
a3ed588
Add General Protected Route in Utils
devmarantz Oct 16, 2019
1b9de24
Add protected route for login
devmarantz Oct 16, 2019
5a5595c
Handle redirect when logging in
devmarantz Oct 16, 2019
2a33105
Make a signup handler
devmarantz Oct 16, 2019
7c8f379
Delete protectedDashboardRoute
devmarantz Oct 16, 2019
96f3291
Add proptypes to signup
devmarantz Oct 16, 2019
b2aed34
Merge branch '3-authentication' into protectedDashboard
devmarantz Oct 16, 2019
615b732
Merge remote-tracking branch 'origin/protectedDashboard' into 3-authe…
rsanchez-dv Oct 16, 2019
78f0104
Add responsive navbar to display login or dashboard depending on if c…
devmarantz Oct 17, 2019
e6dc862
Merge remote-tracking branch 'origin/protectedDashboard' into 3-authe…
rsanchez-dv Oct 17, 2019
4257865
Added log off functionality
rsanchez-dv Oct 17, 2019
28d54e3
Fixed Eslint on my side
rsanchez-dv Oct 24, 2019
353af2c
Update nav bar, you can now logoff from mobile
rsanchez-dv Oct 25, 2019
c59ae6e
Fixed the mismatch color in mobile navbar for logoff
rsanchez-dv Oct 29, 2019
2085047
Merge branch 'staging' into 3-authentication
rsanchez-dv Oct 29, 2019
b0d4192
Fixed Stuff
rsanchez-dv Oct 29, 2019
9b3455d
Cleaned up code in signup.js
rsanchez-dv Oct 29, 2019
609d83e
Change protectedRoute isSomething to isAuthenticated
devmarantz Oct 30, 2019
c867e44
Merge pull request #83 from talent-path-pipeline/fix-something
devmarantz Oct 30, 2019
0a15a6c
Added real link for terms and agreement
rsanchez-dv Nov 1, 2019
0d8aad7
Used template strings for dashboard
rsanchez-dv Nov 1, 2019
01b9bc2
Fix isAuthenticated to not be mutated directly
devmarantz Nov 5, 2019
0fa6d3d
Remove isRequired for logout on DashboardMenu
devmarantz Nov 5, 2019
52d44a0
Remove navlink from HomePage
devmarantz Nov 5, 2019
3aeadf8
Prevent security vulnerabilities in SignUp
devmarantz Nov 5, 2019
361a0d5
Remove console logs on Registration page
devmarantz Nov 5, 2019
b8223fe
Remove console logs from NavBar when loggin out
devmarantz Nov 5, 2019
2743fb1
removed ToS, some ESlint minor refactors
samsaksfithian Nov 5, 2019
d69c744
added netlify.toml and more eslint fixes
samsaksfithian Nov 5, 2019
317afd0
re-add lesson page extra props
samsaksfithian Nov 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[redirects]]
from = "/*"
to = "/index.html"
status = 200

[context.production.environment]
REACT_APP_SVR_API = "https://stonehaven-academy.herokuapp.com/api"

[context.branch-deploy.environment]
REACT_APP_SVR_API = "https://stonehaven-server-staging.herokuapp.com/api"

[context.deploy-preview.environment]
REACT_APP_SVR_API = "https://stonehaven-server-staging.herokuapp.com/api"
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"axios": "^0.19.0",
"dotenv": "^8.1.0",
"isotope-layout": "^3.0.6",
"jwt-decode": "^2.2.0",
"node-sass": "^4.12.0",
"prop-types": "^15.7.2",
"react": "^16.8.6",
Expand Down Expand Up @@ -39,6 +40,7 @@
]
},
"devDependencies": {
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.4.0"
}
}
154 changes: 108 additions & 46 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import React from 'react';
import PropTypes from 'prop-types';
import { Switch, Route, Redirect } from 'react-router-dom';
import DUMMY_DATA from './DUMMY_DATA';
import { tokenServices, ProtectedRoute } from './utils';
import {
NavBar,
HomePage,
PathPage,
LessonPage,
CatalogPage,
// RegistrationPage,
// DashboardPage,
RegistrationPage,
DashboardPage,
SupportPage,
AboutPage,
ErrorPage,
Expand All @@ -27,54 +28,115 @@ const links = {
dashboard: '/dashboard',
};

function App() {
const { courses } = DUMMY_DATA;
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
user: null,
isAuthenticated: false,
};
}

return (
<div id="start-page">
<NavBar links={links} />
<Switch>
<Route exact path="/" component={HomePage} />
<Route
exact
path={links.path}
render={props => <PathPage {...props} path_data={DUMMY_DATA} />}
/>
<Route exact path={links.catalog} component={CatalogPage} />
{/* <Route exact path={links.login} component={RegistrationPage} /> */}
{/* <Route exact path={links.dashboard} component={DashboardPage} /> */}
<Route exact path={links.support} component={SupportPage} />
<Route exact path={links.about} component={AboutPage} />
// componentWillMount = () => {
// const { history, location } = this.props;
// console.log(history);
// console.log(location);
// }

/**
* get user data from database
*/
componentDidMount = () => {
const user = tokenServices.getToken();
if (user) {
this.setState({ isAuthenticated: true, user });
}
};

handleLogin = () => {
const user = tokenServices.getToken();
if (user) {
this.setState({ isAuthenticated: true, user });
} else {
this.setState({ isAuthenticated: null, user: null });
}
};

<Redirect exact from="/courses/:course" to="/courses/:course/0" />
<Route
path="/courses/:course/:order"
render={props => {
const courseObj = courses.find(
course => course.slug === props.match.params.course,
);
const prevCourse = courses.find(course => course.order === courseObj.order - 1);
const nextCourse = courses.find(course => course.order === courseObj.order + 1);
const order = parseInt(props.match.params.order, 10);
if (!courseObj || order >= courseObj.lessons.length) return <ErrorPage />;
return (
<LessonPage
{...props}
course_title={courseObj.title}
lessons={courseObj.lessons}
curr_lesson_num={order}
base_path={courseObj.slug}
prev_slug={prevCourse ? prevCourse.slug : undefined}
next_slug={nextCourse ? nextCourse.slug : undefined}
handleLogoff = () => {
tokenServices.removeToken();
this.setState({ isAuthenticated: false, user: null });
};

/>
);
}}
render() {
const { courses } = DUMMY_DATA;
const { user, isAuthenticated } = this.state;

return (
<div id="start-page">
<NavBar
links={links}
isAuthenticated={isAuthenticated}
handleLogoff={this.handleLogoff}
/>
<Route component={ErrorPage} />
</Switch>
</div>
);
<Switch>
<Route exact path="/" component={HomePage} />
<Route
exact
path={links.path}
render={props => <PathPage {...props} path_data={DUMMY_DATA} />}
/>
<Route exact path={links.catalog} component={CatalogPage} />
{/* Login Protected Route */}
<ProtectedRoute
path={links.login}
isAuthenticated={!isAuthenticated}
redirectLink={links.dashboard}
component={RegistrationPage}
handleLogin={this.handleLogin}
/>
{/* Dashboard Protected Route */}
<ProtectedRoute
path={links.dashboard}
isAuthenticated={isAuthenticated}
redirectLink={links.login}
component={DashboardPage}
/>
<Route exact path={links.support} component={SupportPage} />
<Route exact path={links.about} component={AboutPage} />

<Redirect exact from="/courses/:course" to="/courses/:course/0" />
<Route
path="/courses/:course/:order"
render={props => {
const courseObj = courses.find(
course => course.slug === props.match.params.course,
);
const prevCourse = courses.find(
course => course.order === courseObj.order - 1,
);
const nextCourse = courses.find(
course => course.order === courseObj.order + 1,
);
const order = parseInt(props.match.params.order, 10);
if (!courseObj || order >= courseObj.lessons.length) return <ErrorPage />;
return (
<LessonPage
{...props}
course_title={courseObj.title}
lessons={courseObj.lessons}
curr_lesson_num={order}
base_path={courseObj.slug}
prev_slug={prevCourse ? prevCourse.slug : undefined}
next_slug={nextCourse ? nextCourse.slug : undefined}
/>
);
}}
/>
<Route component={ErrorPage} />
</Switch>
</div>
);
}
}

App.propTypes = {
Expand Down
30 changes: 23 additions & 7 deletions src/components/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ class NavBar extends React.Component {

this.state = {
menuOpen: false,
isAuthenticated: false,
};
}

componentDidUpdate(prevProps, prevState) {
const { isAuthenticated } = this.props;
if (isAuthenticated !== prevState.isAuthenticated) {
this.setState({ isAuthenticated });
}
}

// This keeps your state in sync with the opening/closing of the menu
// via the default means, e.g. clicking the X, pressing the ESC key etc.
handleStateChange(state) {
Expand Down Expand Up @@ -61,14 +69,14 @@ class NavBar extends React.Component {
<li>
<NavLink to={links.catalog}>Catalog</NavLink>
</li>
{/* Commented out until implemented */}
<li>
<NavLink to={links.about}>About</NavLink>
</li>
<li><NavLink to={links.support}>Support</NavLink></li>
<li><a onClick={() => this.closeMenu()} target="_blank" rel="noopener noreferrer" href="https://forms.gle/2YMiTeQ4iuZByx4ZA">Feedback</a></li>
{/* <li><NavLink to={links.dashboard}>Dashboard</NavLink></li> */}
{/* <li><NavLink to={links.login}>Login</NavLink></li> */}
{this.state.isAuthenticated ? (<li><NavLink to={links.dashboard}>Dashboard</NavLink></li>) : null}
{this.state.isAuthenticated ? (<li><NavLink onClick={()=>{this.props.handleLogoff();}} to="/">Log Off</NavLink></li>) : (
<li><NavLink to={links.login}>Login</NavLink></li>)}
</ul>
<div className="mobile-nav">
<Menu
Expand All @@ -88,14 +96,21 @@ class NavBar extends React.Component {
<NavLink onClick={() => this.closeMenu()} to={links.about}>
About
</NavLink>
<NavLink onClick={() => this.closeMenu()} to={links.login}>
LogIn
</NavLink>
<NavLink onClick={() => this.closeMenu()} to={links.dashboard} />
<NavLink onClick={() => this.closeMenu()} to={links.support}>
Support
</NavLink>
<a onClick={() => this.closeMenu()} target="_blank" rel="noopener noreferrer" href="https://forms.gle/2YMiTeQ4iuZByx4ZA">Feedback</a>

{this.state.isAuthenticated ? (
<NavLink onClick={() => this.closeMenu()} to={links.dashboard}>
Dashboard
</NavLink>
) : (null
)}
{this.state.isAuthenticated ? (<NavLink onClick={()=>{ this.props.handleLogoff();}} to="/">Log Off</NavLink>) : (
<NavLink to={links.login}>Login</NavLink>)}


</Menu>
</div>
</div>
Expand All @@ -107,6 +122,7 @@ NavBar.propTypes = {
links: PropTypes.shape({
home: PropTypes.string,
}).isRequired,
isAuthenticated: PropTypes.bool,
};

export default NavBar;
50 changes: 50 additions & 0 deletions src/components/dashboard/DashboardMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import PropTypes from 'prop-types';

/**
* Dashboard navigation menu
* @param {Object} props Passed props
* @param {string} activeView Active navigation text
* @param {Function} showOverview Display function handler
* @param {Function} showSettings Display function handler
* @param {Function} logout Logout function handler
*/
const DashboardMenu = ({ activeView, showOverview, showSettings, logout }) => (
<div className="accountMenu">
<h1 className="menuHeader">My Dashboard</h1>
<ul>
<li>
{activeView === 'overview' ? (
<span className="activeView">Overview</span>
) : (
<button type="button" className="linkButton" onClick={() => showOverview()}>
Overview
</button>
)}
</li>
<li>
{activeView === 'settings' ? (
<span className="activeView">Account Settings</span>
) : (
<button type="button" className="linkButton" onClick={() => showSettings()}>
Account Settings
</button>
)}
</li>
{/* <li>
<button type="button" className="linkButton" onClick={() => logout()}>
Logout
</button>
</li> */}
</ul>
</div>
);

DashboardMenu.propTypes = {
activeView: PropTypes.string.isRequired,
showOverview: PropTypes.func.isRequired,
showSettings: PropTypes.func.isRequired,
logout: PropTypes.func,
};

export default DashboardMenu;
Loading