Add useRegistrationStatus hook
This commit is contained in:
parent
29bf78d09b
commit
82981efe9a
|
@ -4,7 +4,7 @@ import { Link, Redirect, Route, Switch, useHistory, useLocation } from 'react-ro
|
||||||
|
|
||||||
import LandingGradient from 'soapbox/components/landing-gradient';
|
import LandingGradient from 'soapbox/components/landing-gradient';
|
||||||
import SiteLogo from 'soapbox/components/site-logo';
|
import SiteLogo from 'soapbox/components/site-logo';
|
||||||
import { useAppSelector, useFeatures, useSoapboxConfig, useOwnAccount, useInstance } from 'soapbox/hooks';
|
import { useOwnAccount, useInstance, useRegistrationStatus } from 'soapbox/hooks';
|
||||||
|
|
||||||
import { Button, Card, CardBody } from '../../components/ui';
|
import { Button, Card, CardBody } from '../../components/ui';
|
||||||
import LoginPage from '../auth-login/components/login-page';
|
import LoginPage from '../auth-login/components/login-page';
|
||||||
|
@ -28,14 +28,8 @@ const AuthLayout = () => {
|
||||||
|
|
||||||
const account = useOwnAccount();
|
const account = useOwnAccount();
|
||||||
const instance = useInstance();
|
const instance = useInstance();
|
||||||
const features = useFeatures();
|
const { isOpen } = useRegistrationStatus();
|
||||||
const soapboxConfig = useSoapboxConfig();
|
|
||||||
|
|
||||||
const pepeEnabled = soapboxConfig.getIn(['extensions', 'pepe', 'enabled']) === true;
|
|
||||||
const isOpen = features.accountCreation && instance.registrations;
|
|
||||||
const pepeOpen = useAppSelector(state => state.verification.instance.get('registrations') === true);
|
|
||||||
const isLoginPage = history.location.pathname === '/login';
|
const isLoginPage = history.location.pathname === '/login';
|
||||||
const shouldShowRegisterLink = (isLoginPage && (isOpen || (pepeEnabled && pepeOpen)));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='h-full'>
|
<div className='h-full'>
|
||||||
|
@ -50,7 +44,7 @@ const AuthLayout = () => {
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{shouldShowRegisterLink && (
|
{(isLoginPage && isOpen) && (
|
||||||
<div className='relative z-10 ml-auto flex items-center'>
|
<div className='relative z-10 ml-auto flex items-center'>
|
||||||
<Button
|
<Button
|
||||||
theme='tertiary'
|
theme='tertiary'
|
||||||
|
|
|
@ -6,17 +6,15 @@ import Markup from 'soapbox/components/markup';
|
||||||
import { Button, Card, CardBody, Stack, Text } from 'soapbox/components/ui';
|
import { Button, Card, CardBody, Stack, Text } from 'soapbox/components/ui';
|
||||||
import VerificationBadge from 'soapbox/components/verification-badge';
|
import VerificationBadge from 'soapbox/components/verification-badge';
|
||||||
import RegistrationForm from 'soapbox/features/auth-login/components/registration-form';
|
import RegistrationForm from 'soapbox/features/auth-login/components/registration-form';
|
||||||
import { useAppDispatch, useAppSelector, useFeatures, useInstance, useSoapboxConfig } from 'soapbox/hooks';
|
import { useAppDispatch, useFeatures, useInstance, useRegistrationStatus, useSoapboxConfig } from 'soapbox/hooks';
|
||||||
import { capitalize } from 'soapbox/utils/strings';
|
import { capitalize } from 'soapbox/utils/strings';
|
||||||
|
|
||||||
const LandingPage = () => {
|
const LandingPage = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const features = useFeatures();
|
const features = useFeatures();
|
||||||
const soapboxConfig = useSoapboxConfig();
|
const soapboxConfig = useSoapboxConfig();
|
||||||
const pepeEnabled = soapboxConfig.getIn(['extensions', 'pepe', 'enabled']) === true;
|
const { pepeEnabled, pepeOpen } = useRegistrationStatus();
|
||||||
|
|
||||||
const instance = useInstance();
|
const instance = useInstance();
|
||||||
const pepeOpen = useAppSelector(state => state.verification.instance.get('registrations') === true);
|
|
||||||
|
|
||||||
/** Registrations are closed */
|
/** Registrations are closed */
|
||||||
const renderClosed = () => {
|
const renderClosed = () => {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { fetchInstance } from 'soapbox/actions/instance';
|
||||||
import { openModal } from 'soapbox/actions/modals';
|
import { openModal } from 'soapbox/actions/modals';
|
||||||
import SiteLogo from 'soapbox/components/site-logo';
|
import SiteLogo from 'soapbox/components/site-logo';
|
||||||
import { Button, Form, HStack, IconButton, Input, Tooltip } from 'soapbox/components/ui';
|
import { Button, Form, HStack, IconButton, Input, Tooltip } from 'soapbox/components/ui';
|
||||||
import { useAppSelector, useFeatures, useSoapboxConfig, useOwnAccount, useInstance, useAppDispatch } from 'soapbox/hooks';
|
import { useSoapboxConfig, useOwnAccount, useAppDispatch, useRegistrationStatus } from 'soapbox/hooks';
|
||||||
|
|
||||||
import Sonar from './sonar';
|
import Sonar from './sonar';
|
||||||
|
|
||||||
|
@ -29,14 +29,9 @@ const Header = () => {
|
||||||
|
|
||||||
const account = useOwnAccount();
|
const account = useOwnAccount();
|
||||||
const soapboxConfig = useSoapboxConfig();
|
const soapboxConfig = useSoapboxConfig();
|
||||||
const pepeEnabled = soapboxConfig.getIn(['extensions', 'pepe', 'enabled']) === true;
|
const { isOpen } = useRegistrationStatus();
|
||||||
const { links } = soapboxConfig;
|
const { links } = soapboxConfig;
|
||||||
|
|
||||||
const features = useFeatures();
|
|
||||||
const instance = useInstance();
|
|
||||||
const isOpen = features.accountCreation && instance.registrations;
|
|
||||||
const pepeOpen = useAppSelector(state => state.verification.instance.get('registrations') === true);
|
|
||||||
|
|
||||||
const [isLoading, setLoading] = React.useState(false);
|
const [isLoading, setLoading] = React.useState(false);
|
||||||
const [username, setUsername] = React.useState('');
|
const [username, setUsername] = React.useState('');
|
||||||
const [password, setPassword] = React.useState('');
|
const [password, setPassword] = React.useState('');
|
||||||
|
@ -111,7 +106,7 @@ const Header = () => {
|
||||||
{intl.formatMessage(messages.login)}
|
{intl.formatMessage(messages.login)}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
{(isOpen || pepeEnabled && pepeOpen) && (
|
{isOpen && (
|
||||||
<Button
|
<Button
|
||||||
to='/signup'
|
to='/signup'
|
||||||
theme='primary'
|
theme='primary'
|
||||||
|
|
|
@ -2,14 +2,15 @@ import React from 'react';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
|
||||||
import { Banner, Button, HStack, Stack, Text } from 'soapbox/components/ui';
|
import { Banner, Button, HStack, Stack, Text } from 'soapbox/components/ui';
|
||||||
import { useAppSelector, useInstance, useSoapboxConfig } from 'soapbox/hooks';
|
import { useAppSelector, useInstance, useRegistrationStatus, useSoapboxConfig } from 'soapbox/hooks';
|
||||||
|
|
||||||
const CtaBanner = () => {
|
const CtaBanner = () => {
|
||||||
const instance = useInstance();
|
const instance = useInstance();
|
||||||
|
const { isOpen } = useRegistrationStatus();
|
||||||
const { displayCta } = useSoapboxConfig();
|
const { displayCta } = useSoapboxConfig();
|
||||||
const me = useAppSelector((state) => state.me);
|
const me = useAppSelector((state) => state.me);
|
||||||
|
|
||||||
if (me || !displayCta || !instance.registrations) return null;
|
if (me || !displayCta || !isOpen) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div data-testid='cta-banner' className='hidden lg:block'>
|
<div data-testid='cta-banner' className='hidden lg:block'>
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { defineMessages, useIntl } from 'react-intl';
|
||||||
|
|
||||||
import SiteLogo from 'soapbox/components/site-logo';
|
import SiteLogo from 'soapbox/components/site-logo';
|
||||||
import { Text, Button, Icon, Modal } from 'soapbox/components/ui';
|
import { Text, Button, Icon, Modal } from 'soapbox/components/ui';
|
||||||
import { useAppSelector, useFeatures, useInstance, useSoapboxConfig } from 'soapbox/hooks';
|
import { useRegistrationStatus, useSoapboxConfig } from 'soapbox/hooks';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
download: { id: 'landing_page_modal.download', defaultMessage: 'Download' },
|
download: { id: 'landing_page_modal.download', defaultMessage: 'Download' },
|
||||||
|
@ -22,15 +22,9 @@ const LandingPageModal: React.FC<ILandingPageModal> = ({ onClose }) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
const soapboxConfig = useSoapboxConfig();
|
const soapboxConfig = useSoapboxConfig();
|
||||||
const pepeEnabled = soapboxConfig.getIn(['extensions', 'pepe', 'enabled']) === true;
|
const { isOpen } = useRegistrationStatus();
|
||||||
const { links } = soapboxConfig;
|
const { links } = soapboxConfig;
|
||||||
|
|
||||||
const instance = useInstance();
|
|
||||||
const features = useFeatures();
|
|
||||||
|
|
||||||
const isOpen = features.accountCreation && instance.registrations;
|
|
||||||
const pepeOpen = useAppSelector(state => state.verification.instance.get('registrations') === true);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
title={<SiteLogo alt='Logo' className='h-6 w-auto cursor-pointer' />}
|
title={<SiteLogo alt='Logo' className='h-6 w-auto cursor-pointer' />}
|
||||||
|
@ -63,7 +57,7 @@ const LandingPageModal: React.FC<ILandingPageModal> = ({ onClose }) => {
|
||||||
{intl.formatMessage(messages.login)}
|
{intl.formatMessage(messages.login)}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
{(isOpen || pepeEnabled && pepeOpen) && (
|
{isOpen && (
|
||||||
<Button to='/signup' theme='primary' block>
|
<Button to='/signup' theme='primary' block>
|
||||||
{intl.formatMessage(messages.register)}
|
{intl.formatMessage(messages.register)}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { openSidebar } from 'soapbox/actions/sidebar';
|
||||||
import SiteLogo from 'soapbox/components/site-logo';
|
import SiteLogo from 'soapbox/components/site-logo';
|
||||||
import { Avatar, Button, Form, HStack, IconButton, Input, Tooltip } from 'soapbox/components/ui';
|
import { Avatar, Button, Form, HStack, IconButton, Input, Tooltip } from 'soapbox/components/ui';
|
||||||
import Search from 'soapbox/features/compose/components/search';
|
import Search from 'soapbox/features/compose/components/search';
|
||||||
import { useAppDispatch, useInstance, useOwnAccount } from 'soapbox/hooks';
|
import { useAppDispatch, useOwnAccount, useRegistrationStatus } from 'soapbox/hooks';
|
||||||
|
|
||||||
import ProfileDropdown from './profile-dropdown';
|
import ProfileDropdown from './profile-dropdown';
|
||||||
|
|
||||||
|
@ -25,11 +25,9 @@ const messages = defineMessages({
|
||||||
const Navbar = () => {
|
const Navbar = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const { isOpen } = useRegistrationStatus();
|
||||||
const node = useRef(null);
|
|
||||||
|
|
||||||
const account = useOwnAccount();
|
const account = useOwnAccount();
|
||||||
const instance = useInstance();
|
const node = useRef(null);
|
||||||
|
|
||||||
const [isLoading, setLoading] = useState<boolean>(false);
|
const [isLoading, setLoading] = useState<boolean>(false);
|
||||||
const [username, setUsername] = useState<string>('');
|
const [username, setUsername] = useState<string>('');
|
||||||
|
@ -150,7 +148,7 @@ const Navbar = () => {
|
||||||
<FormattedMessage id='account.login' defaultMessage='Log In' />
|
<FormattedMessage id='account.login' defaultMessage='Log In' />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
{!instance.registrations && (
|
{!isOpen && (
|
||||||
<Button theme='primary' to='/signup' size='sm'>
|
<Button theme='primary' to='/signup' size='sm'>
|
||||||
<FormattedMessage id='account.register' defaultMessage='Sign up' />
|
<FormattedMessage id='account.register' defaultMessage='Sign up' />
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
@ -2,13 +2,14 @@ import React from 'react';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
|
|
||||||
import { Button, Stack, Text } from 'soapbox/components/ui';
|
import { Button, Stack, Text } from 'soapbox/components/ui';
|
||||||
import { useAppSelector, useInstance } from 'soapbox/hooks';
|
import { useAppSelector, useInstance, useRegistrationStatus } from 'soapbox/hooks';
|
||||||
|
|
||||||
const SignUpPanel = () => {
|
const SignUpPanel = () => {
|
||||||
const instance = useInstance();
|
const instance = useInstance();
|
||||||
|
const { isOpen } = useRegistrationStatus();
|
||||||
const me = useAppSelector((state) => state.me);
|
const me = useAppSelector((state) => state.me);
|
||||||
|
|
||||||
if (me || !instance.registrations) return null;
|
if (me || !isOpen) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack space={2}>
|
<Stack space={2}>
|
||||||
|
|
|
@ -12,6 +12,7 @@ export { useOnScreen } from './useOnScreen';
|
||||||
export { useOwnAccount } from './useOwnAccount';
|
export { useOwnAccount } from './useOwnAccount';
|
||||||
export { usePrevious } from './usePrevious';
|
export { usePrevious } from './usePrevious';
|
||||||
export { useRefEventHandler } from './useRefEventHandler';
|
export { useRefEventHandler } from './useRefEventHandler';
|
||||||
|
export { useRegistrationStatus } from './useRegistrationStatus';
|
||||||
export { useSettings } from './useSettings';
|
export { useSettings } from './useSettings';
|
||||||
export { useSoapboxConfig } from './useSoapboxConfig';
|
export { useSoapboxConfig } from './useSoapboxConfig';
|
||||||
export { useSystemTheme } from './useSystemTheme';
|
export { useSystemTheme } from './useSystemTheme';
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { useAppSelector } from './useAppSelector';
|
||||||
|
import { useFeatures } from './useFeatures';
|
||||||
|
import { useInstance } from './useInstance';
|
||||||
|
import { useSoapboxConfig } from './useSoapboxConfig';
|
||||||
|
|
||||||
|
export const useRegistrationStatus = () => {
|
||||||
|
const instance = useInstance();
|
||||||
|
const features = useFeatures();
|
||||||
|
const soapboxConfig = useSoapboxConfig();
|
||||||
|
|
||||||
|
const pepeOpen = useAppSelector(state => state.verification.instance.get('registrations') === true);
|
||||||
|
const pepeEnabled = soapboxConfig.getIn(['extensions', 'pepe', 'enabled']) === true;
|
||||||
|
|
||||||
|
return {
|
||||||
|
/** Registrations are open, either through Pepe or traditional account creation. */
|
||||||
|
isOpen: (features.accountCreation && instance.registrations) || (pepeEnabled && pepeOpen),
|
||||||
|
/** Whether Pepe is open. */
|
||||||
|
pepeOpen,
|
||||||
|
/** Whether Pepe is enabled. */
|
||||||
|
pepeEnabled,
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue