From 85c4de91c06cfe78b86cc63ed80a51c42b0890de Mon Sep 17 00:00:00 2001 From: SleeplessOne1917 Date: Thu, 16 Nov 2023 21:34:06 -0500 Subject: [PATCH] Hide signup when registrations are closed or the instance is private --- src/shared/components/app/app.tsx | 68 ++++++++++--------- src/shared/components/app/navbar.tsx | 24 ++++--- src/shared/utils/helpers/index.ts | 2 + .../utils/helpers/should-hide-signup.ts | 8 +++ 4 files changed, 60 insertions(+), 42 deletions(-) create mode 100644 src/shared/utils/helpers/should-hide-signup.ts diff --git a/src/shared/components/app/app.tsx b/src/shared/components/app/app.tsx index c573ea41..0027a1d9 100644 --- a/src/shared/components/app/app.tsx +++ b/src/shared/components/app/app.tsx @@ -16,6 +16,7 @@ import "./styles.scss"; import { Theme } from "./theme"; import AnonymousGuard from "../common/anonymous-guard"; import { CodeTheme } from "./code-theme"; +import { shouldHideSignup } from "@utils/helpers"; interface AppProps { user?: MyUserInfo; @@ -64,39 +65,44 @@ export class App extends Component {
- {routes.map( - ({ path, component: RouteComponent, fetchInitialData }) => ( - { - if (!fetchInitialData) { - FirstLoadService.falsify(); - } + {routes + .filter( + ({ path }) => + !(path === "/signup" && shouldHideSignup(siteRes)), + ) + .map( + ({ path, component: RouteComponent, fetchInitialData }) => ( + { + if (!fetchInitialData) { + FirstLoadService.falsify(); + } - return ( - -
- {RouteComponent && - (isAuthPath(path ?? "") ? ( - + return ( + +
+ {RouteComponent && + (isAuthPath(path ?? "") ? ( + + + + ) : isAnonymousPath(path ?? "") ? ( + + + + ) : ( - - ) : isAnonymousPath(path ?? "") ? ( - - - - ) : ( - - ))} -
-
- ); - }} - /> - ), - )} + ))} +
+
+ ); + }} + /> + ), + )}
diff --git a/src/shared/components/app/navbar.tsx b/src/shared/components/app/navbar.tsx index 900a12ec..9f5d756c 100644 --- a/src/shared/components/app/navbar.tsx +++ b/src/shared/components/app/navbar.tsx @@ -1,6 +1,6 @@ import { showAvatars } from "@utils/app"; import { isBrowser } from "@utils/browser"; -import { numToSI } from "@utils/helpers"; +import { numToSI, shouldHideSignup } from "@utils/helpers"; import { amAdmin, canCreateCommunity } from "@utils/roles"; import { Component, createRef, linkEvent } from "inferno"; import { NavLink } from "inferno-router"; @@ -437,16 +437,18 @@ export class Navbar extends Component { {I18NextService.i18n.t("login")} -
  • - - {I18NextService.i18n.t("sign_up")} - -
  • + {!shouldHideSignup(this.props.siteRes) && ( +
  • + + {I18NextService.i18n.t("sign_up")} + +
  • + )} )} diff --git a/src/shared/utils/helpers/index.ts b/src/shared/utils/helpers/index.ts index c519bfc1..4873c411 100644 --- a/src/shared/utils/helpers/index.ts +++ b/src/shared/utils/helpers/index.ts @@ -23,6 +23,7 @@ import validInstanceTLD from "./valid-instance-tld"; import validTitle from "./valid-title"; import validURL from "./valid-url"; import dedupByProperty from "./dedup-by-property"; +import shouldHideSignup from "./should-hide-signup"; export { capitalizeFirstLetter, @@ -50,4 +51,5 @@ export { validTitle, validURL, dedupByProperty, + shouldHideSignup, }; diff --git a/src/shared/utils/helpers/should-hide-signup.ts b/src/shared/utils/helpers/should-hide-signup.ts new file mode 100644 index 00000000..59f97846 --- /dev/null +++ b/src/shared/utils/helpers/should-hide-signup.ts @@ -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 + ); +}