diff --git a/CHANGELOG.md b/CHANGELOG.md index 2732609..efdabdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added +- Fetch Server Settings to determine if signup is available - `SPA` env variable to have static page with loading spinner before redirect - `de`, `fr`, `es`, `it`, `cn` base folders for translations - finish translating `de` and `en` diff --git a/components/auth/footer.tsx b/components/auth/footer.tsx index 61509c3..21f8d10 100644 --- a/components/auth/footer.tsx +++ b/components/auth/footer.tsx @@ -1,9 +1,11 @@ import {UpOutlined} from '@ant-design/icons/lib' +import {useQuery} from '@apollo/react-hooks' import {Button, Menu, Select} from 'antd' import Link from 'next/link' import {useRouter} from 'next/router' import React from 'react' import {useTranslation} from 'react-i18next' +import {SETTINGS_QUERY, SettingsQueryData} from '../../graphql/query/settings.query' import {languages} from '../../i18n' import {clearAuth, withAuth} from '../with.auth' @@ -17,6 +19,7 @@ interface Props { const AuthFooterInner: React.FC = props => { const { t, i18n } = useTranslation() const router = useRouter() + const {data} = useQuery(SETTINGS_QUERY) const logout = () => { clearAuth() @@ -70,6 +73,7 @@ const AuthFooterInner: React.FC = props => { diff --git a/graphql/query/settings.query.ts b/graphql/query/settings.query.ts new file mode 100644 index 0000000..f21fffd --- /dev/null +++ b/graphql/query/settings.query.ts @@ -0,0 +1,15 @@ +import {gql} from 'apollo-boost' + +export interface SettingsQueryData { + disabledSignUp: { + value: boolean + } +} + +export const SETTINGS_QUERY = gql` + query { + disabledSignUp: getByKey (key: "SIGNUP_DISABLED") { + value: isTrue + } + } +` diff --git a/pages/register.tsx b/pages/register.tsx index 28a2780..71f2cbd 100644 --- a/pages/register.tsx +++ b/pages/register.tsx @@ -1,4 +1,4 @@ -import {useMutation} from '@apollo/react-hooks' +import {useMutation, useQuery} from '@apollo/react-hooks' import {Button, Form, Input, message} from 'antd' import {useForm} from 'antd/lib/form/Form' import {AuthFooter} from 'components/auth/footer' @@ -10,12 +10,15 @@ import Link from 'next/link' import {useRouter} from 'next/router' import React, {useState} from 'react' import {useTranslation} from 'react-i18next' +import {ErrorPage} from '../components/error.page' +import {SETTINGS_QUERY, SettingsQueryData} from '../graphql/query/settings.query' const Register: NextPage = () => { const { t } = useTranslation() const [form] = useForm() const router = useRouter() const [loading, setLoading] = useState(false) + const {data} = useQuery(SETTINGS_QUERY) const [register] = useMutation(REGISTER_MUTATION) @@ -47,6 +50,12 @@ const Register: NextPage = () => { message.error(t('validation:mandatoryFieldsMissing')) } + if (data && data.disabledSignUp.value) { + return ( + + ) + } + return (