diff --git a/packages/web/src/contexts/AutomatischInfo.tsx b/packages/web/src/contexts/AutomatischInfo.tsx new file mode 100644 index 00000000..9223ffa3 --- /dev/null +++ b/packages/web/src/contexts/AutomatischInfo.tsx @@ -0,0 +1,38 @@ +import * as React from 'react'; +import { useQuery } from '@apollo/client'; + +import { GET_AUTOMATISCH_INFO } from 'graphql/queries/get-automatisch-info'; + +export type AutomatischInfoContextParams = { + isCloud: boolean; +}; + +export const AutomatischInfoContext = + React.createContext({ + isCloud: false, + }); + +type AutomatischInfoProviderProps = { + children: React.ReactNode; +}; + +export const AutomatischInfoProvider = ( + props: AutomatischInfoProviderProps +): React.ReactElement => { + const { children } = props; + const { data } = useQuery(GET_AUTOMATISCH_INFO); + + const isCloud = data?.getAutomatischInfo?.isCloud || false; + + const value = React.useMemo(() => { + return { + isCloud, + }; + }, [isCloud]); + + return ( + + {children} + + ); +}; diff --git a/packages/web/src/graphql/queries/get-automatisch-info.ts b/packages/web/src/graphql/queries/get-automatisch-info.ts new file mode 100644 index 00000000..e8dcdd90 --- /dev/null +++ b/packages/web/src/graphql/queries/get-automatisch-info.ts @@ -0,0 +1,10 @@ +import { gql } from '@apollo/client'; + +export const GET_AUTOMATISCH_INFO = gql` + query GetAutomatischInfo { + getAutomatischInfo { + isCloud + } + } +`; + diff --git a/packages/web/src/hooks/useAutomatischInfo.ts b/packages/web/src/hooks/useAutomatischInfo.ts new file mode 100644 index 00000000..8c33f38b --- /dev/null +++ b/packages/web/src/hooks/useAutomatischInfo.ts @@ -0,0 +1,14 @@ +import * as React from 'react'; +import { AutomatischInfoContext } from 'contexts/AutomatischInfo'; + +type UseAutomatischInfoReturn = { + isCloud: boolean; +}; + +export default function useAutomatischInfo(): UseAutomatischInfoReturn { + const automatischInfoContext = React.useContext(AutomatischInfoContext); + + return { + isCloud: automatischInfoContext.isCloud, + }; +} diff --git a/packages/web/src/hooks/useCloud.ts b/packages/web/src/hooks/useCloud.ts new file mode 100644 index 00000000..43c1360f --- /dev/null +++ b/packages/web/src/hooks/useCloud.ts @@ -0,0 +1,7 @@ +import useAutomatischInfo from './useAutomatischInfo'; + +export default function useCloud(): boolean { + const { isCloud } = useAutomatischInfo(); + + return isCloud; +} diff --git a/packages/web/src/index.tsx b/packages/web/src/index.tsx index bb89e0a5..946c4beb 100644 --- a/packages/web/src/index.tsx +++ b/packages/web/src/index.tsx @@ -5,6 +5,7 @@ import IntlProvider from 'components/IntlProvider'; import ApolloProvider from 'components/ApolloProvider'; import SnackbarProvider from 'components/SnackbarProvider'; import { AuthenticationProvider } from 'contexts/Authentication'; +import { AutomatischInfoProvider } from 'contexts/AutomatischInfo'; import Router from 'components/Router'; import routes from 'routes'; import reportWebVitals from './reportWebVitals'; @@ -13,11 +14,13 @@ ReactDOM.render( - - - {routes} - - + + + + {routes} + + + ,