refactor intro.jsx and navigation.jsx to use new navigation reducer single registration open request action

This commit is contained in:
Ben Wheeler 2019-10-07 16:18:49 -04:00
parent d4676ec990
commit baa4e0e2c3
2 changed files with 10 additions and 38 deletions

View file

@ -15,20 +15,12 @@ class Intro extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
bindAll(this, [ bindAll(this, [
'handleClickRegistration',
'handleShowVideo' 'handleShowVideo'
]); ]);
this.state = { this.state = {
videoOpen: false videoOpen: false
}; };
} }
handleClickRegistration (event) {
if (this.props.useScratch3Registration) {
this.props.navigateToRegistration(event);
} else {
this.props.handleOpenRegistration(event);
}
}
handleShowVideo () { handleShowVideo () {
this.setState({videoOpen: true}); this.setState({videoOpen: true});
} }
@ -52,7 +44,7 @@ class Intro extends React.Component {
<a <a
className="intro-button join-button button" className="intro-button join-button button"
href="#" href="#"
onClick={this.handleClickRegistration} onClick={this.props.handleClickRegistration}
> >
{this.props.messages['intro.join']} {this.props.messages['intro.join']}
</a> </a>
@ -115,7 +107,7 @@ class Intro extends React.Component {
} }
Intro.propTypes = { Intro.propTypes = {
handleOpenRegistration: PropTypes.func, handleClickRegistration: PropTypes.func,
messages: PropTypes.shape({ messages: PropTypes.shape({
'intro.aboutScratch': PropTypes.string, 'intro.aboutScratch': PropTypes.string,
'intro.forEducators': PropTypes.string, 'intro.forEducators': PropTypes.string,
@ -125,9 +117,7 @@ Intro.propTypes = {
'intro.tagLine1': PropTypes.string, 'intro.tagLine1': PropTypes.string,
'intro.tagLine2': PropTypes.string, 'intro.tagLine2': PropTypes.string,
'intro.watchVideo': PropTypes.string 'intro.watchVideo': PropTypes.string
}), })
navigateToRegistration: PropTypes.func,
useScratch3Registration: PropTypes.bool
}; };
Intro.defaultProps = { Intro.defaultProps = {
@ -145,18 +135,13 @@ Intro.defaultProps = {
}; };
const mapStateToProps = state => ({ const mapStateToProps = state => ({
session: state.session, session: state.session
useScratch3Registration: state.navigation.useScratch3Registration
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
handleOpenRegistration: event => { handleClickRegistration: event => {
event.preventDefault(); event.preventDefault();
dispatch(navigationActions.setRegistrationOpen(true)); dispatch(navigationActions.handleRegistrationRequested());
},
navigateToRegistration: event => {
event.preventDefault();
navigationActions.navigateToRegistration();
} }
}); });

View file

@ -27,7 +27,6 @@ class Navigation extends React.Component {
super(props); super(props);
bindAll(this, [ bindAll(this, [
'getProfileUrl', 'getProfileUrl',
'handleClickRegistration',
'handleSearchSubmit' 'handleSearchSubmit'
]); ]);
this.state = { this.state = {
@ -78,13 +77,6 @@ class Navigation extends React.Component {
if (!this.props.user) return; if (!this.props.user) return;
return `/users/${this.props.user.username}/`; return `/users/${this.props.user.username}/`;
} }
handleClickRegistration (event) {
if (this.props.useScratch3Registration) {
this.props.navigateToRegistration(event);
} else {
this.props.handleOpenRegistration(event);
}
}
handleSearchSubmit (formData) { handleSearchSubmit (formData) {
let targetUrl = '/search/projects'; let targetUrl = '/search/projects';
if (formData.q) { if (formData.q) {
@ -201,7 +193,7 @@ class Navigation extends React.Component {
<a <a
className="registrationLink" className="registrationLink"
href="#" href="#"
onClick={this.handleClickRegistration} onClick={this.props.handleClickRegistration}
> >
<FormattedMessage id="general.joinScratch" /> <FormattedMessage id="general.joinScratch" />
</a> </a>
@ -239,13 +231,12 @@ class Navigation extends React.Component {
Navigation.propTypes = { Navigation.propTypes = {
accountNavOpen: PropTypes.bool, accountNavOpen: PropTypes.bool,
getMessageCount: PropTypes.func, getMessageCount: PropTypes.func,
handleClickRegistration: PropTypes.func,
handleCloseAccountNav: PropTypes.func, handleCloseAccountNav: PropTypes.func,
handleLogOut: PropTypes.func, handleLogOut: PropTypes.func,
handleOpenRegistration: PropTypes.func,
handleToggleAccountNav: PropTypes.func, handleToggleAccountNav: PropTypes.func,
handleToggleLoginOpen: PropTypes.func, handleToggleLoginOpen: PropTypes.func,
intl: intlShape, intl: intlShape,
navigateToRegistration: PropTypes.func,
permissions: PropTypes.shape({ permissions: PropTypes.shape({
admin: PropTypes.bool, admin: PropTypes.bool,
social: PropTypes.bool, social: PropTypes.bool,
@ -296,9 +287,9 @@ const mapDispatchToProps = dispatch => ({
handleCloseAccountNav: () => { handleCloseAccountNav: () => {
dispatch(navigationActions.setAccountNavOpen(false)); dispatch(navigationActions.setAccountNavOpen(false));
}, },
handleOpenRegistration: event => { handleClickRegistration: event => {
event.preventDefault(); event.preventDefault();
dispatch(navigationActions.setRegistrationOpen(true)); dispatch(navigationActions.handleRegistrationRequested());
}, },
handleLogOut: event => { handleLogOut: event => {
event.preventDefault(); event.preventDefault();
@ -308,10 +299,6 @@ const mapDispatchToProps = dispatch => ({
event.preventDefault(); event.preventDefault();
dispatch(navigationActions.toggleLoginOpen()); dispatch(navigationActions.toggleLoginOpen());
}, },
navigateToRegistration: event => {
event.preventDefault();
navigationActions.navigateToRegistration();
},
setMessageCount: newCount => { setMessageCount: newCount => {
dispatch(messageCountActions.setCount(newCount)); dispatch(messageCountActions.setCount(newCount));
} }