2023-05-23 08:52:27 +00:00
import { useCallback } from 'react' ;
2023-05-23 15:15:17 +00:00
2022-09-29 02:39:33 +00:00
import { FormattedMessage } from 'react-intl' ;
2023-05-23 15:15:17 +00:00
2022-10-26 17:35:55 +00:00
import { openModal } from 'mastodon/actions/modal' ;
2023-08-03 14:43:15 +00:00
import { registrationsOpen , sso _redirect } from 'mastodon/initial_state' ;
2023-05-23 15:15:17 +00:00
import { useAppDispatch , useAppSelector } from 'mastodon/store' ;
2022-09-29 02:39:33 +00:00
2022-10-26 17:35:55 +00:00
const SignInBanner = ( ) => {
2023-05-23 13:17:09 +00:00
const dispatch = useAppDispatch ( ) ;
2022-10-26 17:35:55 +00:00
const openClosedRegistrationsModal = useCallback (
2023-05-25 13:42:37 +00:00
( ) => dispatch ( openModal ( { modalType : 'CLOSED_REGISTRATIONS' } ) ) ,
2022-10-26 17:35:55 +00:00
[ dispatch ] ,
) ;
let signupButton ;
2023-08-07 15:58:29 +00:00
const signupUrl = useAppSelector ( ( state ) => state . getIn ( [ 'server' , 'server' , 'registrations' , 'url' ] , null ) || '/auth/sign_up' ) ;
2023-08-03 14:43:15 +00:00
2023-08-07 15:58:29 +00:00
if ( sso _redirect ) {
2023-08-03 14:43:15 +00:00
return (
< div className = 'sign-in-banner' >
< p > < FormattedMessage id = 'sign_in_banner.text' defaultMessage = 'Login to follow profiles or hashtags, favorite, share and reply to posts. You can also interact from your account on a different server.' / > < / p >
< a href = { sso _redirect } data - method = 'post' className = 'button button--block button-tertiary' > < FormattedMessage id = 'sign_in_banner.sso_redirect' defaultMessage = 'Login or Register' / > < / a >
< / div >
2023-10-09 11:38:29 +00:00
) ;
2023-08-03 14:43:15 +00:00
}
2023-05-23 13:17:09 +00:00
2022-10-26 17:35:55 +00:00
if ( registrationsOpen ) {
signupButton = (
2023-05-23 13:17:09 +00:00
< a href = { signupUrl } className = 'button button--block' >
2022-10-26 17:35:55 +00:00
< FormattedMessage id = 'sign_in_banner.create_account' defaultMessage = 'Create account' / >
< / a >
) ;
} else {
signupButton = (
2023-05-10 18:17:55 +00:00
< button className = 'button button--block' onClick = { openClosedRegistrationsModal } >
2022-10-26 17:35:55 +00:00
< FormattedMessage id = 'sign_in_banner.create_account' defaultMessage = 'Create account' / >
< / button >
) ;
}
return (
< div className = 'sign-in-banner' >
2023-07-21 17:09:13 +00:00
< p > < FormattedMessage id = 'sign_in_banner.text' defaultMessage = 'Login to follow profiles or hashtags, favorite, share and reply to posts. You can also interact from your account on a different server.' / > < / p >
2022-10-26 17:35:55 +00:00
{ signupButton }
2023-05-10 18:17:55 +00:00
< a href = '/auth/sign_in' className = 'button button--block button-tertiary' > < FormattedMessage id = 'sign_in_banner.sign_in' defaultMessage = 'Login' / > < / a >
2022-10-26 17:35:55 +00:00
< / div >
) ;
} ;
2022-09-29 02:39:33 +00:00
export default SignInBanner ;