// Copyright (C) 2020-2022 Intel Corporation // Copyright (C) 2022 CVAT.ai Corporation // // SPDX-License-Identifier: MIT import React, { useCallback, useState } from 'react'; import Form from 'antd/lib/form'; import Button from 'antd/lib/button'; import Input from 'antd/lib/input'; import Icon from '@ant-design/icons'; import { BackArrowIcon, ClearIcon, } from 'icons'; import { Col, Row } from 'antd/lib/grid'; import Title from 'antd/lib/typography/Title'; import Text from 'antd/lib/typography/Text'; import { Link } from 'react-router-dom'; export interface LoginData { credential: string; password: string; } interface Props { renderResetPassword: boolean; fetching: boolean; socialAuthentication: JSX.Element | null; onSubmit(loginData: LoginData): void; } function LoginFormComponent(props: Props): JSX.Element { const { fetching, onSubmit, renderResetPassword, socialAuthentication, } = props; const [form] = Form.useForm(); const [credential, setCredential] = useState(''); const inputReset = useCallback((name: string):void => { form.setFieldsValue({ [name]: '' }); }, [form]); const forgotPasswordLink = ( Forgot password? ); return (
{ credential && ( { setCredential(''); form.setFieldsValue({ credential: '' }); }} /> ) } { !credential && ( New user?  Create an account ) } { renderResetPassword && forgotPasswordLink } Sign in
{ onSubmit(loginData); }} > Email or username} suffix={( credential && ( { setCredential(''); inputReset('credential'); }} /> ) )} onChange={(event) => { const { value } = event.target; setCredential(value); if (!value) inputReset('credential'); }} /> { credential && ( Password } /> ) } { credential || !socialAuthentication ? ( ) : socialAuthentication }
); } export default React.memo(LoginFormComponent);