Skip to content

Commit

Permalink
feat(login): login page and progress on login form
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickocoffeyo committed May 18, 2018
1 parent 7e350d4 commit 53729e2
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 47 deletions.
7 changes: 5 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import React, { Fragment } from 'react';
import { HashRouter as Router, Route } from 'react-router-dom';
import { CssBaseline } from '@material-ui/core';

import { Home } from './pages';
import { Home, Login } from './pages';

const App = () => (
<Fragment>
<CssBaseline />
<Router>
<Route exact path="/" component={Home} />
<Fragment>
<Route exact path="/" component={Home} />
<Route path="/login" component={Login} />
</Fragment>
</Router>
</Fragment>
);
Expand Down
83 changes: 83 additions & 0 deletions src/components/LoginForm/LoginForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* @file LoginForm.js
* Exports a component that allows users to log into EditVR.
*/

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { TextField, Button, withStyles } from '@material-ui/core';

import LoginFormStyles from './LoginForm.style';

class LoginForm extends Component {
static propTypes = {
classes: PropTypes.shape({
textField: PropTypes.string.isRequired,
button: PropTypes.string.isRequired
}).isRequired
};

state = {
username: null,
password: null,
apiLoading: false,
apiMessage: null
};

/**
* Handles field update action.
*
* @param {object} event - Field update event.
*/
handleFieldUpdate = event => {
const state = {};
state[event.target.id] = event.target.value;
this.setState(state);
};

/**
* Handles a login form submit action.
*
* @param {object} event - Submit event object.
*/
handleSubmit = event => {};

/**
* {@inheretdoc}
*/
render() {
const { classes } = this.props;
const { apiLoading, apiMessage } = this.state;

return (
<form onSubmit={this.handleSubmit}>
<TextField
id="username"
label="Username"
type="text"
required
onChange={this.handleFieldUpdate}
className={classes.textField}
/>
<TextField
id="password"
label="Password"
type="password"
required
onChange={this.handleFieldUpdate}
className={classes.textField}
/>
<Button
variant="raised"
color="primary"
type="submit"
className={classes.button}
>
Log In
</Button>
</form>
);
}
}

export default withStyles(LoginFormStyles)(LoginForm);
15 changes: 15 additions & 0 deletions src/components/LoginForm/LoginForm.style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @file LoginForm.style.js
* Exports LoginForm component styles.
*/

export default theme => ({
textField: {
width: '100%',
marginTop: `${theme.spacing.unit * 2}px`
},
button: {
marginTop: `${theme.spacing.unit * 3}px`,
marginRight: theme.spacing.unit
}
});
8 changes: 8 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @file index.js
* Exports all components.
*/

import LoginForm from './LoginForm/LoginForm';

export { LoginForm };
13 changes: 9 additions & 4 deletions src/layouts/Footer.style.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ export default () => ({
position: 'relative'
},
logo: {
width: '230px'
maxWidth: '230px',
width: '100%'
},
text: {
color: 'rgba(255,255,255,.5)',
left: '86px',
top: '-1px',
position: 'absolute'
marginBottom: '10px'
},
'@media (min-width: 380px)': {
text: {
marginLeft: '86px',
marginBottom: '-20px'
}
}
});
2 changes: 1 addition & 1 deletion src/layouts/Layout.style.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default theme => ({
position: 'absolute',
overflowX: 'scroll'
},
centerColumn: {
thinWrapper: {
padding: '0 1rem',
maxWidth: 600,
margin: '0 auto',
Expand Down
18 changes: 8 additions & 10 deletions src/layouts/HomeLayout.js → src/layouts/ThinLayout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file Home.js
* Exports a React component that renders EditVR's home page layout.
* @file ThinLayout.js
* Exports a React component that renders EditVR's thin layout.
*/

import React from 'react';
Expand All @@ -12,28 +12,26 @@ import Footer from './Footer';
import Header from './Header';
import LayoutStyles from './Layout.style';

const Home = ({ children, classes }) => (
const ThinLayout = ({ children, classes }) => (
<div id="layout__wrapper" className={classes.wrapper}>
<div id="layout__center" className={classes.centerColumn}>
<div id="layout__thin-wrapper" className={classes.thinWrapper}>
<Header />
{children}
<Footer />
</div>
</div>
);

Home.propTypes = {
ThinLayout.propTypes = {
children: PropTypes.node,
classes: PropTypes.shape({
wrapper: PropTypes.string.isRequired,
centerColumn: PropTypes.string.isRequired
thinWrapper: PropTypes.string.isRequired
}).isRequired
};

Home.defaultProps = {
ThinLayout.defaultProps = {
children: null
};

const HomeLayout = ThemeProvider(withStyles(LayoutStyles)(Home));

export { HomeLayout };
export default ThemeProvider(withStyles(LayoutStyles)(ThinLayout));
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/**
* @file HomeLayout.test.js
* Contains tests for HomeLayout.js.
* @file ThinLayout.test.js
* Contains tests for ThinLayout.js.
*/

import React from 'react';
import renderer from 'react-test-renderer';

import { HomeLayout } from './index';
import { ThinLayout } from './index';

describe('<HomeLayout />', () => {
describe('<ThinLayout />', () => {
it('Matches its snapshot', () => {
expect(
renderer
.create(
<HomeLayout>
<ThinLayout>
<div>child</div>
</HomeLayout>
</ThinLayout>
)
.toJSON()
).toMatchSnapshot();
Expand Down
49 changes: 49 additions & 0 deletions src/layouts/__snapshots__/ThinLayout.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<ThinLayout /> Matches its snapshot 1`] = `
<div
className="ThinLayout-wrapper-1"
id="layout__wrapper"
>
<div
className={undefined}
id="layout__thin-wrapper"
>
<header
className="Header-wrapper-3"
>
<img
alt="EditVR logo"
className="Header-logo-4"
src="editvr-logo.svg"
/>
</header>
<div>
child
</div>
<footer
className="Footer-wrapper-5"
>
<div
className="Footer-elements-6"
>
<a
href="https://fourkitchens.com"
>
<p
className="MuiTypography-root-9 MuiTypography-body1-18 Footer-text-8"
type="body1"
>
EditVR is a product of
</p>
<img
alt="Four Kitchens"
className="Footer-logo-7"
src="4k-logo-reversed.svg"
/>
</a>
</div>
</footer>
</div>
</div>
`;
4 changes: 3 additions & 1 deletion src/layouts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
* Exports all layout components.
*/

export * from './HomeLayout';
import ThinLayout from './ThinLayout';

export { ThinLayout };
22 changes: 0 additions & 22 deletions src/pages/Home.js

This file was deleted.

42 changes: 42 additions & 0 deletions src/pages/Home/Home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @file Home.js
* Exports a React component that renders EditVR's home page.
*/

import React from 'react';
import PropTypes from 'prop-types';
import { Typography, Button, withStyles } from '@material-ui/core';
import { NavLink } from 'react-router-dom';

import { ThinLayout } from '../../layouts';
import HomeStyles from './Home.style';

const Home = ({ classes }) => (
<ThinLayout>
<Typography type="body1">
<b>EditVR is a free, open-source WebVR editor</b> that lets you produce
interactive and affordable 360 tours and VR stories. EditVR makes
immersive experiences available to everyone using devices they already
own. Nothing to buy, download, or install!
</Typography>

<NavLink to="/login">
<Button className={classes.button} variant="raised" color="primary">
Login
</Button>
</NavLink>
<NavLink to="/register">
<Button className={classes.button} variant="raised" color="primary">
Register
</Button>
</NavLink>
</ThinLayout>
);

Home.propTypes = {
classes: PropTypes.shape({
button: PropTypes.string.isRequired
}).isRequired
};

export default withStyles(HomeStyles)(Home);
11 changes: 11 additions & 0 deletions src/pages/Home/Home.style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @file Home.style.js
* Exports Home component styles.
*/

export default theme => ({
button: {
marginTop: `${theme.spacing.unit * 3}px`,
marginRight: theme.spacing.unit
}
});
19 changes: 19 additions & 0 deletions src/pages/Login/Login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file Login.js
* Exports a React component that renders EditVR's login.
*/

import React from 'react';
import { Typography } from '@material-ui/core';

import { LoginForm } from '../../components';
import { ThinLayout } from '../../layouts';

const Login = () => (
<ThinLayout>
<Typography variant="headline">Log into EditVR</Typography>
<LoginForm />
</ThinLayout>
);

export default Login;
5 changes: 4 additions & 1 deletion src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
* Exports all page components.
*/

export * from './Home';
import Home from './Home/Home';
import Login from './Login/Login';

export { Home, Login };
Loading

0 comments on commit 53729e2

Please sign in to comment.