Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

Commit

Permalink
show error message on homepage in case there is a problem with api co…
Browse files Browse the repository at this point in the history
…nnection
  • Loading branch information
wodka committed May 2, 2021
1 parent c6cf678 commit 8ee1e0f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- ability to change user passwords
- add default page background
- add environment list in [doc](doc/environment.md)
- show error message on homepage in case there is a problem with api connection

### Changed

Expand Down
20 changes: 20 additions & 0 deletions graphql/query/status.query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { QueryHookOptions, QueryResult, useQuery } from '@apollo/client'
import { gql } from '@apollo/client/core'

interface Data {
status: {
version: string
}
}

const QUERY = gql`
query status {
status {
version
}
}
`

export const useStatusQuery = (
options?: QueryHookOptions<Data, unknown>
): QueryResult<Data, unknown> => useQuery<Data, unknown>(QUERY, options)
9 changes: 7 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Layout } from 'antd'
import { Alert, Layout } from 'antd'
import { AuthFooter } from 'components/auth/footer'
import { GetStaticProps, NextPage } from 'next'
import { NextPage } from 'next'
import getConfig from 'next/config'
import { useRouter } from 'next/router'
import React, { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { LoadingPage } from '../components/loading.page'
import { Omf } from '../components/omf'
import { useStatusQuery } from '../graphql/query/status.query'
import { NextConfigType } from '../next.config.type'

const { publicRuntimeConfig } = getConfig() as NextConfigType
Expand All @@ -17,6 +18,7 @@ const Index: NextPage = () => {
const [loading, setLoading] = useState<boolean>(
publicRuntimeConfig.spa || (process.browser && router.pathname !== window.location.pathname)
)
const status = useStatusQuery()

useEffect(() => {
if (router.pathname !== window.location.pathname) {
Expand Down Expand Up @@ -67,6 +69,9 @@ const Index: NextPage = () => {
src={require('../assets/images/logo_white.png') as string}
/>

{status.error && (
<Alert message={`There is an error with your API connection: ${status.error.message}`} />
)}
<AuthFooter />
</Layout>
)
Expand Down

0 comments on commit 8ee1e0f

Please sign in to comment.