From c81db8ae192c83f8e3f63353c15a54d78d1c5c74 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Thu, 9 Mar 2023 11:23:29 +0000 Subject: [PATCH] feat: disable non-cloud features --- .../web/src/components/LoginForm/index.tsx | 10 ++++--- packages/web/src/hooks/useCloud.ts | 15 +++++++++- packages/web/src/index.tsx | 30 ++++++++++--------- .../web/src/pages/ForgotPassword/index.ee.tsx | 4 +++ .../web/src/pages/ResetPassword/index.ee.tsx | 4 +++ packages/web/src/pages/SignUp/index.ee.tsx | 6 +++- 6 files changed, 49 insertions(+), 20 deletions(-) diff --git a/packages/web/src/components/LoginForm/index.tsx b/packages/web/src/components/LoginForm/index.tsx index 7070da10..1c30640a 100644 --- a/packages/web/src/components/LoginForm/index.tsx +++ b/packages/web/src/components/LoginForm/index.tsx @@ -7,6 +7,7 @@ import Typography from '@mui/material/Typography'; import LoadingButton from '@mui/lab/LoadingButton'; import useAuthentication from 'hooks/useAuthentication'; +import useCloud from 'hooks/useCloud'; import * as URLS from 'config/urls'; import { LOGIN } from 'graphql/mutations/login'; import Form from 'components/Form'; @@ -14,6 +15,7 @@ import TextField from 'components/TextField'; import useFormatMessage from 'hooks/useFormatMessage'; function LoginForm() { + const isCloud = useCloud(); const navigate = useNavigate(); const formatMessage = useFormatMessage(); const authentication = useAuthentication(); @@ -76,13 +78,13 @@ function LoginForm() { sx={{ mb: 1 }} /> - {formatMessage('loginForm.forgotPasswordText')} - + } - + {isCloud && {formatMessage('loginForm.noAccount')}   {formatMessage('loginForm.signUp')} - + } ); diff --git a/packages/web/src/hooks/useCloud.ts b/packages/web/src/hooks/useCloud.ts index 43c1360f..bb0226e7 100644 --- a/packages/web/src/hooks/useCloud.ts +++ b/packages/web/src/hooks/useCloud.ts @@ -1,7 +1,20 @@ +import { useNavigate } from 'react-router-dom'; + import useAutomatischInfo from './useAutomatischInfo'; -export default function useCloud(): boolean { +type UseCloudOptions = { + redirect?: boolean; +} + +export default function useCloud(options?: UseCloudOptions): boolean { + const redirect = options?.redirect || false; + const { isCloud } = useAutomatischInfo(); + const navigate = useNavigate(); + + if (isCloud === false && redirect) { + navigate('/'); + } return isCloud; } diff --git a/packages/web/src/index.tsx b/packages/web/src/index.tsx index 502bd72e..c2cd7099 100644 --- a/packages/web/src/index.tsx +++ b/packages/web/src/index.tsx @@ -12,21 +12,23 @@ import routes from 'routes'; import reportWebVitals from './reportWebVitals'; ReactDOM.render( - - - - - - - {routes} + + + + + + + + {routes} - - - - - - - , + + + + + + + + , document.getElementById('root') ); diff --git a/packages/web/src/pages/ForgotPassword/index.ee.tsx b/packages/web/src/pages/ForgotPassword/index.ee.tsx index 4b75e703..1c1a27cf 100644 --- a/packages/web/src/pages/ForgotPassword/index.ee.tsx +++ b/packages/web/src/pages/ForgotPassword/index.ee.tsx @@ -1,9 +1,13 @@ import * as React from 'react'; import Box from '@mui/material/Box'; + +import useCloud from 'hooks/useCloud'; import Container from 'components/Container'; import ForgotPasswordForm from 'components/ForgotPasswordForm/index.ee'; export default function ForgotPassword(): React.ReactElement { + useCloud({ redirect: true }); + return ( diff --git a/packages/web/src/pages/ResetPassword/index.ee.tsx b/packages/web/src/pages/ResetPassword/index.ee.tsx index eb41213e..8dfb0664 100644 --- a/packages/web/src/pages/ResetPassword/index.ee.tsx +++ b/packages/web/src/pages/ResetPassword/index.ee.tsx @@ -1,9 +1,13 @@ import * as React from 'react'; import Box from '@mui/material/Box'; + +import useCloud from 'hooks/useCloud'; import Container from 'components/Container'; import ResetPasswordForm from 'components/ResetPasswordForm/index.ee'; export default function ResetPassword(): React.ReactElement { + useCloud({ redirect: true }); + return ( diff --git a/packages/web/src/pages/SignUp/index.ee.tsx b/packages/web/src/pages/SignUp/index.ee.tsx index afe51ddb..7d314164 100644 --- a/packages/web/src/pages/SignUp/index.ee.tsx +++ b/packages/web/src/pages/SignUp/index.ee.tsx @@ -1,9 +1,13 @@ import * as React from 'react'; import Box from '@mui/material/Box'; + +import useCloud from 'hooks/useCloud'; import Container from 'components/Container'; import SignUpForm from 'components/SignUpForm/index.ee'; -export default function Login(): React.ReactElement { +export default function SignUp(): React.ReactElement { + useCloud({ redirect: true }); + return (