Hide signup when registrations are closed or the instance is private

This commit is contained in:
SleeplessOne1917 2023-11-16 21:34:06 -05:00
parent 9fcd5ef54f
commit 85c4de91c0
4 changed files with 60 additions and 42 deletions

View file

@ -16,6 +16,7 @@ import "./styles.scss";
import { Theme } from "./theme"; import { Theme } from "./theme";
import AnonymousGuard from "../common/anonymous-guard"; import AnonymousGuard from "../common/anonymous-guard";
import { CodeTheme } from "./code-theme"; import { CodeTheme } from "./code-theme";
import { shouldHideSignup } from "@utils/helpers";
interface AppProps { interface AppProps {
user?: MyUserInfo; user?: MyUserInfo;
@ -64,39 +65,44 @@ export class App extends Component<AppProps, any> {
<Navbar siteRes={siteRes} /> <Navbar siteRes={siteRes} />
<div className="mt-4 p-0 fl-1"> <div className="mt-4 p-0 fl-1">
<Switch> <Switch>
{routes.map( {routes
({ path, component: RouteComponent, fetchInitialData }) => ( .filter(
<Route ({ path }) =>
key={path} !(path === "/signup" && shouldHideSignup(siteRes)),
path={path} )
exact .map(
component={routeProps => { ({ path, component: RouteComponent, fetchInitialData }) => (
if (!fetchInitialData) { <Route
FirstLoadService.falsify(); key={path}
} path={path}
exact
component={routeProps => {
if (!fetchInitialData) {
FirstLoadService.falsify();
}
return ( return (
<ErrorGuard> <ErrorGuard>
<div tabIndex={-1}> <div tabIndex={-1}>
{RouteComponent && {RouteComponent &&
(isAuthPath(path ?? "") ? ( (isAuthPath(path ?? "") ? (
<AuthGuard {...routeProps}> <AuthGuard {...routeProps}>
<RouteComponent {...routeProps} />
</AuthGuard>
) : isAnonymousPath(path ?? "") ? (
<AnonymousGuard>
<RouteComponent {...routeProps} />
</AnonymousGuard>
) : (
<RouteComponent {...routeProps} /> <RouteComponent {...routeProps} />
</AuthGuard> ))}
) : isAnonymousPath(path ?? "") ? ( </div>
<AnonymousGuard> </ErrorGuard>
<RouteComponent {...routeProps} /> );
</AnonymousGuard> }}
) : ( />
<RouteComponent {...routeProps} /> ),
))} )}
</div>
</ErrorGuard>
);
}}
/>
),
)}
<Route component={ErrorPage} /> <Route component={ErrorPage} />
</Switch> </Switch>
</div> </div>

View file

@ -1,6 +1,6 @@
import { showAvatars } from "@utils/app"; import { showAvatars } from "@utils/app";
import { isBrowser } from "@utils/browser"; import { isBrowser } from "@utils/browser";
import { numToSI } from "@utils/helpers"; import { numToSI, shouldHideSignup } from "@utils/helpers";
import { amAdmin, canCreateCommunity } from "@utils/roles"; import { amAdmin, canCreateCommunity } from "@utils/roles";
import { Component, createRef, linkEvent } from "inferno"; import { Component, createRef, linkEvent } from "inferno";
import { NavLink } from "inferno-router"; import { NavLink } from "inferno-router";
@ -437,16 +437,18 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
{I18NextService.i18n.t("login")} {I18NextService.i18n.t("login")}
</NavLink> </NavLink>
</li> </li>
<li className="nav-item"> {!shouldHideSignup(this.props.siteRes) && (
<NavLink <li className="nav-item">
to="/signup" <NavLink
className="nav-link" to="/signup"
title={I18NextService.i18n.t("sign_up")} className="nav-link"
onMouseUp={linkEvent(this, handleCollapseClick)} title={I18NextService.i18n.t("sign_up")}
> onMouseUp={linkEvent(this, handleCollapseClick)}
{I18NextService.i18n.t("sign_up")} >
</NavLink> {I18NextService.i18n.t("sign_up")}
</li> </NavLink>
</li>
)}
</> </>
)} )}
</ul> </ul>

View file

@ -23,6 +23,7 @@ import validInstanceTLD from "./valid-instance-tld";
import validTitle from "./valid-title"; import validTitle from "./valid-title";
import validURL from "./valid-url"; import validURL from "./valid-url";
import dedupByProperty from "./dedup-by-property"; import dedupByProperty from "./dedup-by-property";
import shouldHideSignup from "./should-hide-signup";
export { export {
capitalizeFirstLetter, capitalizeFirstLetter,
@ -50,4 +51,5 @@ export {
validTitle, validTitle,
validURL, validURL,
dedupByProperty, dedupByProperty,
shouldHideSignup,
}; };

View file

@ -0,0 +1,8 @@
import { GetSiteResponse } from "lemmy-js-client";
export default function shouldHideSignup(siteRes?: GetSiteResponse) {
return (
siteRes?.site_view.local_site.registration_mode === "Closed" ||
siteRes?.site_view.local_site.private_instance
);
}