import React, { useState } from 'react'; 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/mutations/use-login'; import { normalizeServerUrl } from '@/renderer/utils'; const Container = styled(Box)` width: 100%; background: var(--main-bg); `; export const LoginRoute = () => { 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 { mutate: handleLogin, isLoading, isError, } = useLogin( normalizeServerUrl(server), { password, username, }, { onError: (error) => { setErrorMessage(error?.response?.data?.error || error.message); }, } ); return (
{ e.preventDefault(); handleLogin(undefined, { onError: () => {}, onSuccess: () => {}, }); }} > Login to Feishin ) => setServer(e.currentTarget.value) } /> ) => setUsername(e.currentTarget.value) } /> ) => setPassword(e.currentTarget.value) } /> {isError && {errorMessage}}
); };