Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert login views to React #2250

Merged
merged 41 commits into from
May 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9367685
Initial component/container setup for sign in page
May 4, 2017
11df141
Replicate look of sign in form
May 4, 2017
6db218b
Replicate look of sign up form
May 5, 2017
b81c46e
Use composeWithTracker in signInContainer
May 5, 2017
ed87abc
Replicate look of forgot password form
May 5, 2017
0b63291
Create parent login container to hold general login for views
May 6, 2017
5b0d252
Add switching between views logic
May 6, 2017
f530967
Set up sign in form submission
May 8, 2017
094f88f
Set up sign up form submission
May 8, 2017
2ffafeb
Set up forgot password form submission
May 8, 2017
04e6c22
Handle sign in action and error message display
May 9, 2017
a63e503
Remove template methods
May 9, 2017
0677974
Remove template methods and alert message template
May 10, 2017
18d8895
Rewrite renderPasswordErrors method
May 10, 2017
b6af560
Render social buttons on login
May 10, 2017
96c4dd6
Add social login functionality
May 10, 2017
6b2b608
Remove unnecessary blaze templates
May 10, 2017
f8a9e8b
Move functions to React
May 10, 2017
274366f
Implement sign up functionality
May 10, 2017
2b02b47
Merge signin and signup containers
May 10, 2017
d02769b
Merge branch 'development' into kieha-login-views-to-react-2055
May 11, 2017
c6612e6
Put back helper methods needed by other templates
May 11, 2017
25d2ec7
Abstract loginFormMessaged into react container
May 11, 2017
2adcb2b
Add forgot password functionality (part1)
May 11, 2017
21a2f07
Remove unnecessary component in helper
May 11, 2017
44a58ab
Remove forgot password template
May 11, 2017
0becd93
Clean up folder structure
May 11, 2017
056ed04
Solve invariant violation browser error
May 11, 2017
1252d89
updatepasswordOverlay react component/container
May 15, 2017
fc15580
completed updayePasswordOverlay functionality
May 15, 2017
eb86610
Remove stopPropagation function
May 15, 2017
58a86a1
Capitalize social login name
May 15, 2017
ba11a69
Show loading spinner while processing button clicks
May 15, 2017
9fe3b4f
Solve onClick not working by removing 'event.stopPropagation()' on pa…
May 16, 2017
30e9895
Remove JQuery and use lodash
May 18, 2017
01c626f
Using 'event' instead of 'e' to reference event handlers
May 18, 2017
49c7a6e
Add validation for no email input on forgot password
May 18, 2017
4155170
Add error message on social login
May 18, 2017
98ae171
Move capitalize function to helper file
May 18, 2017
62fcb7d
Move capitalize function to helper file
May 18, 2017
938ecbc
Fix conflicts
May 18, 2017
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
3 changes: 3 additions & 0 deletions client/modules/accounts/components/auth/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export LoginButtons from "./loginButtons";
export SignIn from "./signIn";
export SignUp from "./signUp";
75 changes: 75 additions & 0 deletions client/modules/accounts/components/auth/loginButtons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React, { Component, PropTypes } from "react";
import {
Button
} from "/imports/plugins/core/ui/client/components";

class LoginButtons extends Component {

constructor(props) {
super(props);
}

renderLoginButtons() {
const enabledServices = this.props.loginServices().filter((service) =>{
return service.enabled;
});

return (
<div>
{this.props.loginServices &&
enabledServices.map((service) => (
<Button
key={service._id}
className={`btn-block provider-${service.name}`}
primary={true}
bezelStyle="solid"
type="button"
data-provider={`${service.name}`}
onClick={() => this.props.onSocialClick(service.name)}
>
<i className={`fa fa-${service.name}`} />

{this.props.currentView === "loginFormSignInView" &&
<span data-i18n="accountsUI.signInWith">Sign in with</span>}
{this.props.currentView === "loginFormSignUpView" &&
<span data-i18n="accountsUI.signUpWith">Sign up with</span>}

&nbsp;<span data-i18n={`social.${service.name}`}>{this.props.capitalizeName(service.name)}</span>
</Button>
))
}
</div>
);
}

renderSeparator() {
if (this.props.onSeparator()) {
return (
<div className="loginForm-seperator">
<span />
<span className="text" data-i18n="accountsUI.or">or</span>
<span />
</div>
);
}
}

render() {
return (
<div>
{this.renderLoginButtons()}
{this.renderSeparator()}
</div>
);
}
}

LoginButtons.propTypes = {
capitalizeName: PropTypes.func,
currentView: PropTypes.string,
loginServices: PropTypes.func,
onSeparator: PropTypes.func,
onSocialClick: PropTypes.func
};

export default LoginButtons;
186 changes: 186 additions & 0 deletions client/modules/accounts/components/auth/signIn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import React, { Component, PropTypes } from "react";
import classnames from "classnames";
import {
Button,
TextField,
Translation
} from "/imports/plugins/core/ui/client/components";

class SignIn extends Component {

constructor(props) {
super(props);

this.state = {
email: props.credentials.email,
password: props.credentials.password
};

this.handleFieldChange = this.handleFieldChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

handleFieldChange = (event, value, field) => {
this.setState({
[field]: value
});
}

handleSubmit = (event) => {
if (this.props.onFormSubmit) {
this.props.onFormSubmit(event, this.state.email, this.state.password);
}
}

renderEmailErrors() {
if (this.props.onError(this.props.messages.errors && this.props.messages.errors.email)) {
return (
<span className="help-block">
<Translation
defaultValue={this.props.messages.errors.email.reason}
i18nKey={this.props.messages.errors.email.i18nKeyReason}
/>
</span>
);
}
}

renderPasswordErrors() {
return (
<span className="help-block">
{this.props.onError(this.props.messages.errors && this.props.messages.errors.password) &&
this.props.messages.errors.password.map((error, i) => (
<Translation
key={i}
defaultValue={error.reason}
i18nKey={error.i18nKeyReason}
/>
))
}
</span>
);
}

renderFormMessages() {
if (this.props.loginFormMessages) {
return (
<div>
{this.props.loginFormMessages()}
</div>
);
}
}

renderSpinnerOnWait() {
if (this.props.isLoading === true) {
return (
<div style={{ textAlign: "center" }}>
<i className="fa fa-spinner fa-spin" />
</div>
);
}
return (
<Button
className="btn-block"
primary={true}
bezelStyle="solid"
i18nKeyLabel="accountsUI.signIn"
label="Sign In"
type="submit"
tabIndex="3"
eventAction="submitSignInForm"
/>
);
}

render() {
const emailClasses = classnames({
"form-group": true,
"form-group-email": true,
"has-error has-feedback": this.props.onError(this.props.messages.errors && this.props.messages.errors.email)
});

const passwordClasses = classnames({
"form-group": true,
"has-error has-feedback": this.props.onError(this.props.messages.errors && this.props.messages.errors.password)
});
return (
<div>
<div className="loginForm-title">
<h2 data-i18n="accountsUI.signIn">Sign In</h2>
</div>

<form className="login-form" onSubmit={this.handleSubmit} noValidate>

{this.renderFormMessages()}

<div className={emailClasses}>
<TextField
i18nKeyLabel="accountsUI.emailAddress"
label="Email"
name="email"
type="email"
tabIndex="1"
id={`email-${this.props.uniqueId}`}
value={this.state.email}
onChange={this.handleFieldChange}
/>
{this.renderEmailErrors()}
</div>

<div className={passwordClasses}>
<TextField
i18nKeyLabel="accountsUI.password"
label="Password"
name="password"
type="password"
tabIndex="2"
id={`password-${this.props.uniqueId}`}
value={this.state.password}
onChange={this.handleFieldChange}
/>
{this.renderPasswordErrors()}
</div>

<div className="form-group">
{this.renderSpinnerOnWait()}
</div>

<div className="form-group flex flex-justify-spaceBetween">
<a
href="#"
data-i18n="accountsUI.forgotPassword"
tabIndex="4"
onClick={this.props.onForgotPasswordClick}
>
Reset Password
</a>
<a
href="#"
data-i18n="accountsUI.signUp"
tabIndex="5"
onClick={this.props.onSignUpClick}
>
Register
</a>
</div>

</form>
</div>
);
}
}

SignIn.propTypes = {
credentials: PropTypes.object,
isLoading: PropTypes.bool,
loginFormMessages: PropTypes.func,
messages: PropTypes.object,
onError: PropTypes.func,
onForgotPasswordClick: PropTypes.func,
onFormSubmit: PropTypes.func,
onSignUpClick: PropTypes.func,
uniqueId: PropTypes.string
};

export default SignIn;
Loading