From 214f04f04beb74a010f24c51f6538b39195a0017 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 23 May 2023 15:17:09 +0200 Subject: [PATCH] [Glitch] Add support for custom sign-up URLs Port 4d631fcfb779dbe07675fa3948c2adcd5337932c to glitch-soc Signed-off-by: Claire --- .../glitch/features/interaction_modal/index.jsx | 6 ++++-- .../flavours/glitch/features/ui/components/header.jsx | 11 ++++++++--- .../glitch/features/ui/components/sign_in_banner.jsx | 8 +++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/javascript/flavours/glitch/features/interaction_modal/index.jsx b/app/javascript/flavours/glitch/features/interaction_modal/index.jsx index 2ef26f65f4..dd6a60b438 100644 --- a/app/javascript/flavours/glitch/features/interaction_modal/index.jsx +++ b/app/javascript/flavours/glitch/features/interaction_modal/index.jsx @@ -9,6 +9,7 @@ import { openModal, closeModal } from 'flavours/glitch/actions/modal'; const mapStateToProps = (state, { accountId }) => ({ displayNameHtml: state.getIn(['accounts', accountId, 'display_name_html']), + signupUrl: state.getIn(['server', 'server', 'registrations', 'url'], '/auth/sign_up'), }); const mapDispatchToProps = (dispatch) => ({ @@ -81,6 +82,7 @@ class InteractionModal extends PureComponent { url: PropTypes.string, type: PropTypes.oneOf(['reply', 'reblog', 'favourite', 'follow']), onSignupClick: PropTypes.func.isRequired, + signupUrl: PropTypes.string.isRequired, }; handleSignupClick = () => { @@ -88,7 +90,7 @@ class InteractionModal extends PureComponent { }; render () { - const { url, type, displayNameHtml } = this.props; + const { url, type, displayNameHtml, signupUrl } = this.props; const name = ; @@ -121,7 +123,7 @@ class InteractionModal extends PureComponent { if (registrationsOpen) { signupButton = ( - + ); diff --git a/app/javascript/flavours/glitch/features/ui/components/header.jsx b/app/javascript/flavours/glitch/features/ui/components/header.jsx index 78cef87271..5098781e02 100644 --- a/app/javascript/flavours/glitch/features/ui/components/header.jsx +++ b/app/javascript/flavours/glitch/features/ui/components/header.jsx @@ -17,6 +17,10 @@ const Account = connect(state => ({ )); +const mapStateToProps = (state) => ({ + signupUrl: state.getIn(['server', 'server', 'registrations', 'url'], '/auth/sign_up'), +}); + const mapDispatchToProps = (dispatch) => ({ openClosedRegistrationsModal() { dispatch(openModal('CLOSED_REGISTRATIONS')); @@ -32,11 +36,12 @@ class Header extends PureComponent { static propTypes = { openClosedRegistrationsModal: PropTypes.func, location: PropTypes.object, + signupUrl: PropTypes.string.isRequired, }; render () { const { signedIn } = this.context.identity; - const { location, openClosedRegistrationsModal } = this.props; + const { location, openClosedRegistrationsModal, signupUrl } = this.props; let content; @@ -52,7 +57,7 @@ class Header extends PureComponent { if (registrationsOpen) { signupButton = ( - + ); @@ -88,4 +93,4 @@ class Header extends PureComponent { } -export default withRouter(connect(null, mapDispatchToProps)(Header)); +export default withRouter(connect(mapStateToProps, mapDispatchToProps)(Header)); diff --git a/app/javascript/flavours/glitch/features/ui/components/sign_in_banner.jsx b/app/javascript/flavours/glitch/features/ui/components/sign_in_banner.jsx index cefcebfcbc..bdb3af7659 100644 --- a/app/javascript/flavours/glitch/features/ui/components/sign_in_banner.jsx +++ b/app/javascript/flavours/glitch/features/ui/components/sign_in_banner.jsx @@ -1,11 +1,11 @@ import { useCallback } from 'react'; import { FormattedMessage } from 'react-intl'; -import { useDispatch } from 'react-redux'; +import { useAppDispatch, useAppSelector } from 'flavours/glitch/store'; import { registrationsOpen } from 'flavours/glitch/initial_state'; import { openModal } from 'flavours/glitch/actions/modal'; const SignInBanner = () => { - const dispatch = useDispatch(); + const dispatch = useAppDispatch(); const openClosedRegistrationsModal = useCallback( () => dispatch(openModal('CLOSED_REGISTRATIONS')), @@ -14,9 +14,11 @@ const SignInBanner = () => { let signupButton; + const signupUrl = useAppSelector((state) => state.getIn(['server', 'server', 'registrations', 'url'], '/auth/sign_up')); + if (registrationsOpen) { signupButton = ( - + );