mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-22 12:21:13 +00:00
Hide signup when registrations are closed or the instance is private
This commit is contained in:
parent
9fcd5ef54f
commit
85c4de91c0
4 changed files with 60 additions and 42 deletions
|
@ -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<AppProps, any> {
|
|||
<Navbar siteRes={siteRes} />
|
||||
<div className="mt-4 p-0 fl-1">
|
||||
<Switch>
|
||||
{routes.map(
|
||||
({ path, component: RouteComponent, fetchInitialData }) => (
|
||||
<Route
|
||||
key={path}
|
||||
path={path}
|
||||
exact
|
||||
component={routeProps => {
|
||||
if (!fetchInitialData) {
|
||||
FirstLoadService.falsify();
|
||||
}
|
||||
{routes
|
||||
.filter(
|
||||
({ path }) =>
|
||||
!(path === "/signup" && shouldHideSignup(siteRes)),
|
||||
)
|
||||
.map(
|
||||
({ path, component: RouteComponent, fetchInitialData }) => (
|
||||
<Route
|
||||
key={path}
|
||||
path={path}
|
||||
exact
|
||||
component={routeProps => {
|
||||
if (!fetchInitialData) {
|
||||
FirstLoadService.falsify();
|
||||
}
|
||||
|
||||
return (
|
||||
<ErrorGuard>
|
||||
<div tabIndex={-1}>
|
||||
{RouteComponent &&
|
||||
(isAuthPath(path ?? "") ? (
|
||||
<AuthGuard {...routeProps}>
|
||||
return (
|
||||
<ErrorGuard>
|
||||
<div tabIndex={-1}>
|
||||
{RouteComponent &&
|
||||
(isAuthPath(path ?? "") ? (
|
||||
<AuthGuard {...routeProps}>
|
||||
<RouteComponent {...routeProps} />
|
||||
</AuthGuard>
|
||||
) : isAnonymousPath(path ?? "") ? (
|
||||
<AnonymousGuard>
|
||||
<RouteComponent {...routeProps} />
|
||||
</AnonymousGuard>
|
||||
) : (
|
||||
<RouteComponent {...routeProps} />
|
||||
</AuthGuard>
|
||||
) : isAnonymousPath(path ?? "") ? (
|
||||
<AnonymousGuard>
|
||||
<RouteComponent {...routeProps} />
|
||||
</AnonymousGuard>
|
||||
) : (
|
||||
<RouteComponent {...routeProps} />
|
||||
))}
|
||||
</div>
|
||||
</ErrorGuard>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
),
|
||||
)}
|
||||
))}
|
||||
</div>
|
||||
</ErrorGuard>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
),
|
||||
)}
|
||||
<Route component={ErrorPage} />
|
||||
</Switch>
|
||||
</div>
|
||||
|
|
|
@ -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<NavbarProps, NavbarState> {
|
|||
{I18NextService.i18n.t("login")}
|
||||
</NavLink>
|
||||
</li>
|
||||
<li className="nav-item">
|
||||
<NavLink
|
||||
to="/signup"
|
||||
className="nav-link"
|
||||
title={I18NextService.i18n.t("sign_up")}
|
||||
onMouseUp={linkEvent(this, handleCollapseClick)}
|
||||
>
|
||||
{I18NextService.i18n.t("sign_up")}
|
||||
</NavLink>
|
||||
</li>
|
||||
{!shouldHideSignup(this.props.siteRes) && (
|
||||
<li className="nav-item">
|
||||
<NavLink
|
||||
to="/signup"
|
||||
className="nav-link"
|
||||
title={I18NextService.i18n.t("sign_up")}
|
||||
onMouseUp={linkEvent(this, handleCollapseClick)}
|
||||
>
|
||||
{I18NextService.i18n.t("sign_up")}
|
||||
</NavLink>
|
||||
</li>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</ul>
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
8
src/shared/utils/helpers/should-hide-signup.ts
Normal file
8
src/shared/utils/helpers/should-hide-signup.ts
Normal 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
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue