Skip to content

Commit

Permalink
Fix “Sign up” button with closed registrations not opening modal on m…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and Nonexistent committed Jan 11, 2023
1 parent 4667901 commit a52e1f0
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions app/javascript/mastodon/features/ui/components/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { registrationsOpen, me } from 'mastodon/initial_state';
import Avatar from 'mastodon/components/avatar';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { openModal } from 'mastodon/actions/modal';

const Account = connect(state => ({
account: state.getIn(['accounts', me]),
Expand All @@ -15,20 +16,28 @@ const Account = connect(state => ({
</Link>
));

export default @withRouter
const mapDispatchToProps = (dispatch) => ({
openClosedRegistrationsModal() {
dispatch(openModal('CLOSED_REGISTRATIONS'));
},
});

export default @connect(null, mapDispatchToProps)
@withRouter
class Header extends React.PureComponent {

static contextTypes = {
identity: PropTypes.object,
};

static propTypes = {
openClosedRegistrationsModal: PropTypes.func,
location: PropTypes.object,
};

render () {
const { signedIn } = this.context.identity;
const { location } = this.props;
const { location, openClosedRegistrationsModal } = this.props;

let content;

Expand All @@ -40,10 +49,26 @@ class Header extends React.PureComponent {
</>
);
} else {
let signupButton;

if (registrationsOpen) {
signupButton = (
<a href='/auth/sign_up' className='button button-tertiary'>
<FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
</a>
);
} else {
signupButton = (
<button className='button button-tertiary' onClick={openClosedRegistrationsModal}>
<FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' />
</button>
);
}

content = (
<>
<a href='/auth/sign_in' className='button'><FormattedMessage id='sign_in_banner.sign_in' defaultMessage='Sign in' /></a>
<a href={registrationsOpen ? '/auth/sign_up' : 'https://joinmastodon.org/servers'} className='button button-tertiary'><FormattedMessage id='sign_in_banner.create_account' defaultMessage='Create account' /></a>
{signupButton}
</>
);
}
Expand Down

0 comments on commit a52e1f0

Please sign in to comment.