From 04b0e3f6e91e0c476a78bcbf330a114469c122d1 Mon Sep 17 00:00:00 2001 From: spaenleh Date: Wed, 20 Mar 2024 07:57:54 +0100 Subject: [PATCH 1/5] fix: wip --- package.json | 1 + src/components/APIChecker.tsx | 48 ++++++++++++++++++++++++++ src/components/FullscreenContainer.tsx | 12 ++++--- src/components/SignIn.tsx | 2 +- src/config/queryClient.ts | 2 ++ src/langs/constants.ts | 4 +++ src/langs/en.json | 6 +++- yarn.lock | 19 ++++++++++ 8 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 src/components/APIChecker.tsx diff --git a/package.json b/package.json index 8e8a24f3..d9965c3a 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@mui/lab": "5.0.0-alpha.169", "@mui/material": "5.15.14", "@sentry/react": "7.108.0", + "@tanstack/react-query": "5.28.4", "http-status-codes": "2.3.0", "i18next": "23.10.1", "react": "18.2.0", diff --git a/src/components/APIChecker.tsx b/src/components/APIChecker.tsx new file mode 100644 index 00000000..3e9d163f --- /dev/null +++ b/src/components/APIChecker.tsx @@ -0,0 +1,48 @@ +import { useQuery } from '@tanstack/react-query'; + +import { Replay } from '@mui/icons-material'; +import { + Alert, + AlertTitle, + Box, + Button, + Stack, + Typography, +} from '@mui/material'; + +import { API_HOST } from '../config/env'; +import { useAuthTranslation } from '../config/i18n'; +import { axios } from '../config/queryClient'; +import { AUTH } from '../langs/constants'; + +const APIChecker = (): JSX.Element | null => { + const { t } = useAuthTranslation(); + + const { isError, isSuccess } = useQuery({ + queryKey: ['apiStatus'], + queryFn: () => axios.get(`${API_HOST}/status`).then(({ data }) => data), + }); + + if (isSuccess) { + return null; + } + + if (isError) { + return ( + + + {t(AUTH.API_UNAVAILABLE_TITLE)} + + {t(AUTH.API_UNAVAILABLE_EXPLANATION)} + {t(AUTH.API_UNAVAILABLE_INSTRUCTIONS)} + + + + + ); + } + return null; +}; +export default APIChecker; diff --git a/src/components/FullscreenContainer.tsx b/src/components/FullscreenContainer.tsx index 5640ead7..b7135998 100644 --- a/src/components/FullscreenContainer.tsx +++ b/src/components/FullscreenContainer.tsx @@ -1,5 +1,6 @@ -import { Box } from '@mui/material'; +import { Box, Stack } from '@mui/material'; +import APIChecker from './APIChecker'; import Footer from './Footer'; type Props = { @@ -7,10 +8,9 @@ type Props = { }; const FullscreenContainer = ({ children }: Props): JSX.Element => ( - ( backgroundImage: `url("data:image/svg+xml,%3Csvg width='100' height='20' viewBox='0 0 100 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21.184 20c.357-.13.72-.264 1.088-.402l1.768-.661C33.64 15.347 39.647 14 50 14c10.271 0 15.362 1.222 24.629 4.928.955.383 1.869.74 2.75 1.072h6.225c-2.51-.73-5.139-1.691-8.233-2.928C65.888 13.278 60.562 12 50 12c-10.626 0-16.855 1.397-26.66 5.063l-1.767.662c-2.475.923-4.66 1.674-6.724 2.275h6.335zm0-20C13.258 2.892 8.077 4 0 4V2c5.744 0 9.951-.574 14.85-2h6.334zM77.38 0C85.239 2.966 90.502 4 100 4V2c-6.842 0-11.386-.542-16.396-2h-6.225zM0 14c8.44 0 13.718-1.21 22.272-4.402l1.768-.661C33.64 5.347 39.647 4 50 4c10.271 0 15.362 1.222 24.629 4.928C84.112 12.722 89.438 14 100 14v-2c-10.271 0-15.362-1.222-24.629-4.928C65.888 3.278 60.562 2 50 2 39.374 2 33.145 3.397 23.34 7.063l-1.767.662C13.223 10.84 8.163 12 0 12v2z' fill='%23f2f2ff' fill-opacity='0.82' fill-rule='evenodd'/%3E%3C/svg%3E")`, }} > + ( {children}