mirror of
https://github.com/stonith404/pingvin-share.git
synced 2024-11-15 11:50:34 +01:00
fix: get started button on home page not working when sign-up is disabled
* Redirect to sign in page if sign ups are disabled on an instance * Add a comment back, add a comment in * Remove english default Get Started text
This commit is contained in:
parent
f1f514dff7
commit
4924f76394
@ -10,12 +10,13 @@ import {
|
|||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { TbCheck } from "react-icons/tb";
|
import { TbCheck } from "react-icons/tb";
|
||||||
import { FormattedMessage } from "react-intl";
|
import { FormattedMessage } from "react-intl";
|
||||||
import Logo from "../components/Logo";
|
import Logo from "../components/Logo";
|
||||||
import Meta from "../components/Meta";
|
import Meta from "../components/Meta";
|
||||||
import useUser from "../hooks/user.hook";
|
import useUser from "../hooks/user.hook";
|
||||||
|
import useConfig from "../hooks/config.hook";
|
||||||
|
|
||||||
const useStyles = createStyles((theme) => ({
|
const useStyles = createStyles((theme) => ({
|
||||||
inner: {
|
inner: {
|
||||||
@ -73,15 +74,29 @@ export default function Home() {
|
|||||||
const { classes } = useStyles();
|
const { classes } = useStyles();
|
||||||
const { refreshUser } = useUser();
|
const { refreshUser } = useUser();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const config = useConfig();
|
||||||
|
const [signupEnabled, setSignupEnabled] = useState(true);
|
||||||
|
|
||||||
// If the user is already logged in, redirect to the upload page
|
// If user is already authenticated, redirect to the upload page
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refreshUser().then((user) => {
|
refreshUser().then((user) => {
|
||||||
if (user) {
|
if (user) {
|
||||||
router.replace("/upload");
|
router.replace("/upload");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, []);
|
|
||||||
|
// If registration is disabled, get started button should redirect to the sign in page
|
||||||
|
try {
|
||||||
|
const allowRegistration = config.get("share.allowRegistration");
|
||||||
|
setSignupEnabled(allowRegistration !== false);
|
||||||
|
} catch (error) {
|
||||||
|
setSignupEnabled(true);
|
||||||
|
}
|
||||||
|
}, [config]);
|
||||||
|
|
||||||
|
const getButtonHref = () => {
|
||||||
|
return signupEnabled ? "/auth/signUp" : "/auth/signIn";
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -142,12 +157,14 @@ export default function Home() {
|
|||||||
<Group mt={30}>
|
<Group mt={30}>
|
||||||
<Button
|
<Button
|
||||||
component={Link}
|
component={Link}
|
||||||
href="/auth/signUp"
|
href={getButtonHref()}
|
||||||
radius="xl"
|
radius="xl"
|
||||||
size="md"
|
size="md"
|
||||||
className={classes.control}
|
className={classes.control}
|
||||||
>
|
>
|
||||||
<FormattedMessage id="home.button.start" />
|
<FormattedMessage
|
||||||
|
id="home.button.start"
|
||||||
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
component={Link}
|
component={Link}
|
||||||
|
Loading…
Reference in New Issue
Block a user