From 4a9534160d6c9e10a95a3650a007c1c1b3a59e8e Mon Sep 17 00:00:00 2001 From: Tristan Teufel Date: Tue, 2 Jan 2024 07:16:44 +0100 Subject: [PATCH] add error handling for login --- src/app/ChannelsForType.tsx | 9 ++++----- src/app/Login.tsx | 9 ++++++++- src/app/controls/DoorControl.tsx | 9 ++++----- src/i18n/utils.ts | 4 ++++ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/app/ChannelsForType.tsx b/src/app/ChannelsForType.tsx index e4fcd55..2e2d5f9 100644 --- a/src/app/ChannelsForType.tsx +++ b/src/app/ChannelsForType.tsx @@ -18,15 +18,14 @@ import { Icon } from '@iconify/react'; import { Channel, ChannelType } from './../types/types'; import { RainDetectionControl } from './controls/RainDetectionControl'; import { DoorControl } from './controls/DoorControl'; -import { styledWithForward } from './../styled'; interface ExpandMoreProps { - isExpanded: boolean; + expanded: string; } -const ExpandMore = styledWithForward(Icon)(({ isExpanded }) => ({ - transform: isExpanded ? 'rotate(180deg)' : 'rotate(0deg)', +const ExpandMore = styled(Icon)(({ expanded }) => ({ + transform: expanded === 'true' ? 'rotate(180deg)' : 'rotate(0deg)', marginLeft: 'auto', transition: 'transform 150ms cubic-bezier(0.4, 0, 0.2, 1) 0ms', fontSize: '25px', @@ -114,7 +113,7 @@ export const ChannelsForType: React.FC = ({ > {t(channelType)} - + {hasTransitionExited ? : null} diff --git a/src/app/Login.tsx b/src/app/Login.tsx index 20c2020..ef25c93 100644 --- a/src/app/Login.tsx +++ b/src/app/Login.tsx @@ -1,12 +1,15 @@ -import { Box, Button, TextField } from '@mui/material'; +import { Alert, Box, Button, TextField, Typography } from '@mui/material'; import { Container } from '@mui/system'; import { FormEvent } from 'react'; import { useLogin } from '../hooks/useApi'; import { useRedirectToRooms } from '../hooks/useCheckSession'; +import { useTranslations } from './../i18n/utils'; export const Login = () => { const loginMutation = useLogin(); + const t = useTranslations(); + const { navigateRooms } = useRedirectToRooms(); const Login = async (d: FormEvent) => { @@ -21,6 +24,10 @@ export const Login = () => { return ( + + {t('signInTitle')} + + {loginMutation.isError && {t('errorOccuredWhileLogin')}}
(({ isUncertain }) => ({ - display: isUncertain ? 'block' : 'none', + const StyledTypography = styled(Typography)(({ uncertain }) => ({ + display: uncertain === 'true' ? 'block' : 'none', })); interface DoorControlProps { @@ -92,7 +91,7 @@ export const DoorControl: React.FC = ({ channel, refetch }) => /> Door state is uncertain diff --git a/src/i18n/utils.ts b/src/i18n/utils.ts index badc2c1..28147d5 100644 --- a/src/i18n/utils.ts +++ b/src/i18n/utils.ts @@ -16,6 +16,8 @@ export const ui = { CLIMATECONTROL_FLOOR_TRANSCEIVER: 'Floor', RAIN_DETECTION_TRANSMITTER: 'Rain', KEYMATIC: 'Keymatic', + errorOccuredWhileLogin: 'Error occured while login', + signInTitle: 'Sign in', }, de: { SWITCH_VIRTUAL_RECEIVER: 'Schalter', @@ -24,6 +26,8 @@ export const ui = { CLIMATECONTROL_FLOOR_TRANSCEIVER: 'Fußboden', RAIN_DETECTION_TRANSMITTER: 'Regen', KEYMATIC: 'Keymatic', + errorOccuredWhileLogin: 'Fehler beim Login', + signInTitle: 'Anmelden', }, } as const;