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

GH-2206: Onboarding - Step 1 - Create Account #639

Merged
merged 36 commits into from Dec 7, 2020
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
834bb52
Make form
benstrumeyer Dec 1, 2020
3300d83
Add skip and learn more links
benstrumeyer Dec 1, 2020
5911f47
Set arrow up/down depending on expanded state
benstrumeyer Dec 1, 2020
a56094f
Make FAQ
benstrumeyer Dec 1, 2020
f623f22
Make list responsive
benstrumeyer Dec 1, 2020
9d641f9
Adjust padding of FAQContainer to scroll onto nice spot
benstrumeyer Dec 1, 2020
f9ad55e
Make sure promoString checkbox text does not wrap
benstrumeyer Dec 1, 2020
13d10ee
Add privacy policy link
benstrumeyer Dec 1, 2020
11f908c
Make privacy policy link more responsive
benstrumeyer Dec 1, 2020
6cfcdce
Make BrowserLogInForm and style responsively
benstrumeyer Dec 2, 2020
9f024a5
Refactor Create Account form into a component
benstrumeyer Dec 2, 2020
0371513
Create BrowserCreateAccountFormContainer and add handlers
benstrumeyer Dec 2, 2020
7a04bd3
Add error handling to legal consent label
benstrumeyer Dec 2, 2020
31b8e8e
Remove privacy policy link if learn more is not expanded
benstrumeyer Dec 2, 2020
2071175
Add handlers for log in view and replace strings
benstrumeyer Dec 2, 2020
74b0a41
Add handlers for forgot password and throttle it
benstrumeyer Dec 2, 2020
7d9bd47
Lower throttle time in case user enters a wrong email
benstrumeyer Dec 2, 2020
ba6f3c9
Make updates checkbox work
benstrumeyer Dec 2, 2020
c098331
Add signed in view
benstrumeyer Dec 2, 2020
1087c46
Change spacing of title and subtitle for small screens
benstrumeyer Dec 2, 2020
b8c2629
Update create account design for small screens
benstrumeyer Dec 2, 2020
e187609
Center skip link on small screens
benstrumeyer Dec 2, 2020
a6e9257
Decrease spacing for small sreens on already have account/create acco…
benstrumeyer Dec 2, 2020
f715cf7
Decrease width of faqDescription items and privacy policy link
benstrumeyer Dec 2, 2020
8b6838d
Open privacy policy link in new tab
benstrumeyer Dec 2, 2020
817ce0b
Add confirm password functionality
benstrumeyer Dec 4, 2020
dfc6ec9
Update passwords not match string
benstrumeyer Dec 4, 2020
7ff259f
Add global email preferences to user object on account creation success
benstrumeyer Dec 4, 2020
143cce8
Hold input fields in place when error messages appear
benstrumeyer Dec 4, 2020
136ef0d
Merge branch 'ghostery-browser-intro-hub' into GH-2206
benstrumeyer Dec 4, 2020
eda38ca
Rename components
benstrumeyer Dec 4, 2020
91badf5
Add propTypes
benstrumeyer Dec 5, 2020
1b24823
Update comments
benstrumeyer Dec 5, 2020
6ce6eca
Remove newline
benstrumeyer Dec 5, 2020
44518ad
Update confirm password string
benstrumeyer Dec 5, 2020
6ff20ca
Add comments and minor refactors
benstrumeyer Dec 5, 2020
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

Add handlers for log in view and replace strings

  • Loading branch information
benstrumeyer committed Dec 2, 2020
commit 2071175ca78125829d7ea8b39006c66d72058ad6
@@ -30,13 +30,17 @@
color: red;
}
.BrowserCreateAccountForm__promoString {
font-size: 14px;
margin-top: 15px;
@include breakpoint(small down) {
margin-top: 0;
}
}
.BrowserCreateAccountForm__legalConsentCheckedLabel {
font-size: 14px;
@include breakpoint(small down) {
width: 258px;
}

&.error {
color: red;
@@ -71,7 +71,7 @@ const renderFAQListItem = (icon, label, description) => (
*/
const BrowserCreateAccountView = () => {
const [expanded, setExpanded] = useState(false);
const [view, setView] = useState(CREATE_ACCOUNT);
const [view, setView] = useState(SIGN_IN);

const arrowClassNames = ClassNames('BrowserCreateAccountView__arrow', {
up: expanded,
@@ -90,7 +90,12 @@ const BrowserCreateAccountView = () => {

return (
<div className="BrowserCreateAccountView">
<div className="BrowserCreateAccountView__title">{ t('hub_browser_create_a_ghostery_account') }</div>
{view === CREATE_ACCOUNT && (
<div className="BrowserCreateAccountView__title">{t('hub_browser_create_a_ghostery_account')}</div>
)}
{view === SIGN_IN && (
<div className="BrowserCreateAccountView__title">{t('sign_in')}</div>
)}
<div className="BrowserCreateAccountView__subtitle">{ t('hub_browser_sync_settings') }</div>
<div className="row align-center-middle">
{view === CREATE_ACCOUNT && (
@@ -94,7 +94,7 @@ const BrowserLogInForm = (props) => {
</div>
</div>
<div className="BrowserLogInForm__ctaButtonContainer">
<button type="submit" className="BrowserLogInForm__ctaButton">{t('create_account')}</button>
<button type="submit" className="BrowserLogInForm__ctaButton">{t('sign_in')}</button>
</div>
<div className="row align-center-middle">
<div className="columns small-10 medium-5" />
@@ -0,0 +1,160 @@
/**
* Browser Log In Form Container
*
* Ghostery Browser Extension
* https://www.ghostery.com/
*
* Copyright 2019 Ghostery, Inc. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0
*/

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { validateEmail } from '../../../panel/utils/utils';
import BrowserLogInForm from './BrowserLogInForm';
import SignedInView from '../SignedInView';
/**
* @class Implement the Browser Log In Form for the Ghostery Hub
* @extends Component
* @memberof HubContainers
*/
class BrowserLogInFormContainer extends Component {
constructor(props) {
super(props);
this.state = {
email: '',
password: '',
emailError: false,
passwordError: false,
validateInput: false,
};

const { actions } = this.props;
actions.setToast({
toastMessage: '',
toastClass: '',
});
}

/**
* Update input values by updating state.
* @param {Object} event the 'change' event
*/
_handleInputChange = (event) => {
const { name, value } = event.target;
this.setState({ [name]: value });

const { validateInput } = this.state;
if (!validateInput) {
return;
}

switch (name) {
case 'email': {
const emailIsValid = value && validateEmail(value);
this.setState({
emailError: !emailIsValid,
});
break;
}
case 'password': {
this.setState({
passwordError: !value,
});
break;
}
default: break;
}
}

/**
* Handle logging in, but validate the data first.
* @param {Object} event the 'submit' event
*/
_handleLoginAttempt = (event) => {
event.preventDefault();
const { email, password } = this.state;
const emailIsValid = email && validateEmail(email);

this.setState({
emailError: !emailIsValid,
passwordError: !password,
validateInput: true,
});

if (!emailIsValid || !password) {
return;
}

const { actions, history } = this.props;
actions.setToast({
toastMessage: '',
toastClass: ''
});
actions.login(email, password).then((success) => {
if (success) {
const { origin, pathname, hash } = window.location;
window.history.pushState({}, '', `${origin}${pathname}${hash}`);

actions.getUser();
actions.getUserSettings()
.then((settings) => {
const { current_theme } = settings;
return actions.getTheme(current_theme);
});
actions.setToast({
toastMessage: t('hub_login_toast_success'),
toastClass: 'success'
});
// Move to second screen
} else {
actions.setToast({
toastMessage: t('no_such_email_password_combo'),
toastClass: 'alert'
});
}
});
}

/**
* React's required render function. Returns JSX
* @return {JSX} JSX for rendering the Log In View of the Hub app
*/
render() {
const { loggedIn, user } = this.props;
const {
email,
password,
emailError,
passwordError,
} = this.state;

return loggedIn ? (
<SignedInView email={(user && user.email) || 'email'} />
) : (
<BrowserLogInForm
email={email}
password={password}
emailError={emailError}
passwordError={passwordError}
handleInputChange={this._handleInputChange}
handleSubmit={this._handleLoginAttempt}
/>
);
}
}

// PropTypes ensure we pass required props of the correct type
BrowserLogInFormContainer.propTypes = {
actions: PropTypes.shape({
setToast: PropTypes.func.isRequired,
login: PropTypes.func.isRequired,
getUser: PropTypes.func.isRequired,
getUserSettings: PropTypes.func.isRequired,
}).isRequired,
};

export default BrowserLogInFormContainer;
@@ -1,3 +1,46 @@
import BrowserLoginForm from './BrowserLogInForm';
/**
* Point of entry index.js file for Browser Log In Form
*
* Ghostery Browser Extension
* https://www.ghostery.com/
*
* Copyright 2019 Ghostery, Inc. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0
*/

export default BrowserLoginForm;
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';

import BrowserLogInFormContainer from './BrowserLogInFormContainer';
import { login, getUser, getUserSettings } from '../../../Account/AccountActions';
import { getTheme } from '../../../panel/actions/PanelActions';
import { setToast } from '../AppView/AppViewActions';

/**
* Map redux store state properties to the component's own properties.
* @param {Object} state entire Redux store's state
* @return {function} this function returns a plain object, which will be merged into the component's props
* @memberof HubContainers
*/
const mapStateToProps = state => ({ ...state.account });

/**
* Bind the component's action creators using Redux's bindActionCreators.
* @param {function} dispatch redux store method which dispatches actions
* @return {function} to be used as an argument in redux connect call
* @memberof SetupContainers
*/
const mapDispatchToProps = dispatch => ({
actions: bindActionCreators({
setToast,
login,
getUser,
getUserSettings,
getTheme
}, dispatch),
});

export default connect(mapStateToProps, mapDispatchToProps)(BrowserLogInFormContainer);
ProTip! Use n and p to navigate between commits in a pull request.