diff --git a/src/renderer/features/auth/routes/login-route.tsx b/src/renderer/features/auth/routes/login-route.tsx index 80ee7305b..844f76215 100644 --- a/src/renderer/features/auth/routes/login-route.tsx +++ b/src/renderer/features/auth/routes/login-route.tsx @@ -1,122 +1,130 @@ import React, { useState } from 'react'; -import { - TextInput, - PasswordInput, - Button, - Stack, - Title, - Loader, - Alert, - Box, -} from '@mantine/core'; -import { useDebouncedValue } from '@mantine/hooks'; -import { useTranslation } from 'react-i18next'; -import { RiCheckboxCircleFill } from 'react-icons/ri'; +import { Stack, Alert, Box, Center, Group } from '@mantine/core'; +import { ErrorBoundary } from 'react-error-boundary'; import { useSearchParams } from 'react-router-dom'; import styled from 'styled-components'; +import { Button, PasswordInput, Text, TextInput } from '@/renderer/components'; +import { ErrorFallback } from '@/renderer/features/action-required'; import { useLogin } from '@/renderer/features/auth/queries/use-login'; -import { usePingServer } from '@/renderer/features/auth/queries/use-ping-server'; import { normalizeServerUrl } from '@/renderer/utils'; const Container = styled(Box)` - min-width: 400px; - max-width: 50%; - margin: auto; - padding: 3rem; - background: rgba(50, 50, 50, 40%); - border-radius: 5px; + width: 100%; + background: var(--main-bg); `; export const LoginRoute = () => { - const { t } = useTranslation(); const [searchParams] = useSearchParams(); + const [errorMessage, setErrorMessage] = useState(''); const [username, setUsername] = useState(searchParams.get('username') || ''); const [password, setPassword] = useState(searchParams.get('password') || ''); const [server, setServer] = useState( searchParams.get('server') || 'http://localhost:8843' ); - const [debouncedServer] = useDebouncedValue(server, 500); const { mutate: handleLogin, isLoading, isError, - } = useLogin(normalizeServerUrl(server), { - password, - username, - }); - - const { - isLoading: isCheckingServer, - isSuccess: isValidServer, - isFetched, - } = usePingServer(normalizeServerUrl(debouncedServer)); + } = useLogin( + normalizeServerUrl(server), + { + password, + username, + }, + { + onError: (error) => { + setErrorMessage(error?.response?.data?.error || error.message); + }, + } + ); return ( - {t('auth.login')} -
{ - e.preventDefault(); - handleLogin(undefined, { - onError: () => {}, - onSuccess: () => {}, - }); - }} - > - - - ) : isValidServer ? ( - - ) : null - } - value={server} - variant="default" - onChange={(e: React.ChangeEvent) => - setServer(e.currentTarget.value) - } - /> - ) => - setUsername(e.currentTarget.value) - } - /> - ) => - setPassword(e.currentTarget.value) - } - /> - - {isError && ( - - {t('Invalid username or password.')} - - )} +
+ + + + { + e.preventDefault(); + handleLogin(undefined, { + onError: () => {}, + onSuccess: () => {}, + }); + }} + > + + + Login to Feishin + + ) => + setServer(e.currentTarget.value) + } + /> + ) => + setUsername(e.currentTarget.value) + } + /> + ) => + setPassword(e.currentTarget.value) + } + /> + + {isError && {errorMessage}} + + + + - +
); };