add cloud_mode

This commit is contained in:
Brian Cao 2022-10-12 15:35:33 -07:00
parent 9147415761
commit db1ae3f2c7
13 changed files with 103 additions and 25 deletions

View File

@ -14,7 +14,7 @@ import useUser from 'hooks/useUser';
import Logo from 'assets/logo.svg';
import styles from './Header.module.css';
export default function Header() {
export default function Header({ settingsDisabled }) {
const { user } = useUser();
const { pathname } = useRouter();
const { updatesDisabled } = useConfig();
@ -38,15 +38,17 @@ export default function Header() {
<Link href="/realtime">
<FormattedMessage id="label.realtime" defaultMessage="Realtime" />
</Link>
{!settingsDisabled && (
<Link href="/settings">
<FormattedMessage id="label.settings" defaultMessage="Settings" />
</Link>
)}
</div>
)}
<div className={styles.buttons}>
<ThemeButton />
<LanguageButton menuAlign="right" />
{user && <UserButton />}
{user && <UserButton settingsDisabled={settingsDisabled} />}
</div>
</header>
</>

View File

@ -4,7 +4,13 @@ import Header from 'components/layout/Header';
import Footer from 'components/layout/Footer';
import useLocale from 'hooks/useLocale';
export default function Layout({ title, children, header = true, footer = true }) {
export default function Layout({
title,
children,
header = true,
footer = true,
settingsDisabled = false,
}) {
const { dir } = useLocale();
return (
@ -13,7 +19,7 @@ export default function Layout({ title, children, header = true, footer = true }
<title>umami{title && ` - ${title}`}</title>
</Head>
{header && <Header />}
{header && <Header settingsDisabled={settingsDisabled} />}
<main>{children}</main>
{footer && <Footer />}
<div id="__modals" dir={dir} />

View File

@ -9,7 +9,7 @@ import styles from './UserButton.module.css';
import { AUTH_TOKEN } from 'lib/constants';
import useUser from 'hooks/useUser';
export default function UserButton() {
export default function UserButton({ settingsDisabled }) {
const { user } = useUser();
const router = useRouter();
@ -25,7 +25,11 @@ export default function UserButton() {
value: 'username',
className: styles.username,
},
{ label: <FormattedMessage id="label.profile" defaultMessage="Profile" />, value: 'profile' },
{
label: <FormattedMessage id="label.profile" defaultMessage="Profile" />,
value: 'profile',
hidden: settingsDisabled,
},
{ label: <FormattedMessage id="label.logout" defaultMessage="Logout" />, value: 'logout' },
];

View File

@ -2,9 +2,9 @@ import React from 'react';
import Layout from 'components/layout/Layout';
import { FormattedMessage } from 'react-intl';
export default function Custom404() {
export default function Custom404({ settingsDisabled }) {
return (
<Layout>
<Layout settingsDisabled={settingsDisabled}>
<div className="row justify-content-center">
<h1>
<FormattedMessage id="message.page-not-found" defaultMessage="Page not found" />
@ -13,3 +13,11 @@ export default function Custom404() {
</Layout>
);
}
export async function getServerSideProps() {
return {
props: {
settingsDisabled: !!process.env.CLOUD_MODE,
},
};
}

View File

@ -4,7 +4,7 @@ import TestConsole from 'components/pages/TestConsole';
import useRequireLogin from 'hooks/useRequireLogin';
import useUser from 'hooks/useUser';
export default function ConsolePage({ enabled }) {
export default function ConsolePage({ enabled, settingsDisabled }) {
const { loading } = useRequireLogin();
const { user } = useUser();
@ -13,7 +13,7 @@ export default function ConsolePage({ enabled }) {
}
return (
<Layout>
<Layout settingsDisabled={settingsDisabled}>
<TestConsole />
</Layout>
);

View File

@ -3,7 +3,7 @@ import Layout from 'components/layout/Layout';
import Dashboard from 'components/pages/Dashboard';
import useRequireLogin from 'hooks/useRequireLogin';
export default function DashboardPage() {
export default function DashboardPage({ settingsDisabled }) {
const { loading } = useRequireLogin();
if (loading) {
@ -11,8 +11,16 @@ export default function DashboardPage() {
}
return (
<Layout>
<Layout settingsDisabled={settingsDisabled}>
<Dashboard />
</Layout>
);
}
export async function getServerSideProps() {
return {
props: {
settingsDisabled: !!process.env.CLOUD_MODE,
},
};
}

View File

@ -16,6 +16,6 @@ export default function LoginPage({ loginDisabled }) {
export async function getServerSideProps() {
return {
props: { loginDisabled: !!process.env.DISABLE_LOGIN },
props: { loginDisabled: !!process.env.DISABLE_LOGIN || process.env.CLOUD_MODE },
};
}

View File

@ -3,7 +3,7 @@ import Layout from 'components/layout/Layout';
import RealtimeDashboard from 'components/pages/RealtimeDashboard';
import useRequireLogin from 'hooks/useRequireLogin';
export default function RealtimePage() {
export default function RealtimePage({ settingsDisabled }) {
const { loading } = useRequireLogin();
if (loading) {
@ -11,8 +11,16 @@ export default function RealtimePage() {
}
return (
<Layout>
<Layout settingsDisabled={settingsDisabled}>
<RealtimeDashboard />
</Layout>
);
}
export async function getServerSideProps() {
return {
props: {
settingsDisabled: !!process.env.CLOUD_MODE,
},
};
}

View File

@ -1,3 +1,11 @@
import Index from './index';
export default Index;
export async function getServerSideProps() {
return {
props: {
settingsDisabled: !!process.env.CLOUD_MODE,
},
};
}

View File

@ -3,16 +3,26 @@ import Layout from 'components/layout/Layout';
import Settings from 'components/pages/Settings';
import useRequireLogin from 'hooks/useRequireLogin';
export default function SettingsPage() {
export default function SettingsPage({ settingsDisabled }) {
const { loading } = useRequireLogin();
if (loading) {
if (settingsDisabled || loading) {
return null;
}
return (
<Layout>
<Layout settingsDisabled={settingsDisabled}>
TEST TEST TEST
{settingsDisabled}
<Settings />
</Layout>
);
}
export async function getServerSideProps() {
return {
props: {
settingsDisabled: !!process.env.CLOUD_MODE,
},
};
}

View File

@ -1,3 +1,11 @@
import Index from './index';
export default Index;
export async function getServerSideProps() {
return {
props: {
settingsDisabled: !!process.env.CLOUD_MODE,
},
};
}

View File

@ -4,7 +4,7 @@ import Layout from 'components/layout/Layout';
import WebsiteDetails from 'components/pages/WebsiteDetails';
import useShareToken from 'hooks/useShareToken';
export default function SharePage() {
export default function SharePage({ settingsDisabled }) {
const router = useRouter();
const { id } = router.query;
const shareId = id?.[0];
@ -17,8 +17,16 @@ export default function SharePage() {
const { websiteId } = shareToken;
return (
<Layout>
<Layout settingsDisabled={settingsDisabled}>
<WebsiteDetails websiteId={websiteId} />
</Layout>
);
}
export async function getServerSideProps() {
return {
props: {
settingsDisabled: !!process.env.CLOUD_MODE,
},
};
}

View File

@ -4,7 +4,7 @@ import Layout from 'components/layout/Layout';
import WebsiteDetails from 'components/pages/WebsiteDetails';
import useRequireLogin from 'hooks/useRequireLogin';
export default function DetailsPage() {
export default function DetailsPage({ settingsDisabled }) {
const { loading } = useRequireLogin();
const router = useRouter();
const { id } = router.query;
@ -16,8 +16,16 @@ export default function DetailsPage() {
const [websiteId] = id;
return (
<Layout>
<Layout settingsDisabled={settingsDisabled}>
<WebsiteDetails websiteId={websiteId} />
</Layout>
);
}
export async function getServerSideProps() {
return {
props: {
settingsDisabled: !!process.env.CLOUD_MODE,
},
};
}