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,7 +65,12 @@ 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
.filter(
({ path }) =>
!(path === "/signup" && shouldHideSignup(siteRes)),
)
.map(
({ path, component: RouteComponent, fetchInitialData }) => ( ({ path, component: RouteComponent, fetchInitialData }) => (
<Route <Route
key={path} key={path}

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,6 +437,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
{I18NextService.i18n.t("login")} {I18NextService.i18n.t("login")}
</NavLink> </NavLink>
</li> </li>
{!shouldHideSignup(this.props.siteRes) && (
<li className="nav-item"> <li className="nav-item">
<NavLink <NavLink
to="/signup" to="/signup"
@ -447,6 +448,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
{I18NextService.i18n.t("sign_up")} {I18NextService.i18n.t("sign_up")}
</NavLink> </NavLink>
</li> </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
);
}