import React, { FC, useState } from 'react' import styled from 'styled-components' import { Modal, ModalProps } from 'components/Modal' import { Title, Paragraph, Link } from 'components/Typography' import { Form } from 'antd' import { Button } from 'components/Button' import { Input, Password, ErrorMessage, LabelWithTooltip, Captcha } from 'components/FormControl' import Image from './images/password@2x.png' type Props = Pick & { onClose?: () => void } const StyledWrapper = styled.div` display: flex; align-items: center; flex-direction: column; min-height: 366px; ${props => props.theme.breakpoints.up('s')} { justify-content: center; } ` const StyledMain = styled.div` width: 100%; ${props => props.theme.breakpoints.up('s')} { width: 350px; } ${props => props.theme.breakpoints.down('s')} { padding-top: 37px; } .ant-form-item-required { width: 100%; } ` const StyledTitle = styled(Title)` margin-bottom: 2px !important; ${props => props.theme.breakpoints.down('s')} { margin-bottom: 5px !important; } ` const StyledCaptchaHint = styled(Paragraph)` margin-top: 30px; ` const TitleCopies = [ 'Forgot Password', 'Reset Password', 'Reset Password', 'Password Reset' ] const DescriptionCopies = [ 'Enter your email address to reset your password.', 'A 6-digit code has been sent to John.smith@gmail.com', ] export const ForgetPasswordModal: FC = ({ onClose, ...props }) => { const [step, setStep] = useState(0) const [email, setEmail] = useState('') const [captcha, setCaptcha] = useState('') const [expiration, setExpiration] = useState('9:45') const handleFinishEmail = ({ email }: { email: string }) => { setEmail(email) setStep(1) } const handleFinishCaptcha = ({ captcha }: { captcha: string }) => { setCaptcha(captcha) setStep(2) } const handleSendAgain = () => { // TODO: Update expiration } const handleConfirm = (data: { password: string }) => { console.log(data) setStep(3) } const handleClose = () => { setStep(0) setEmail('') setCaptcha('') onClose && onClose() } const handleLogin = () => { // TODO: login } return ( {TitleCopies[step]} {step < 2 && {DescriptionCopies[step]}} {step === 0 ? (
}, { type: 'email', message: } ]} >
) : null} {step === 1 ? (
}, { len: 6, validateTrigger: 'onSubmit', message: }, ]} > The code will expire in {expiration}
Didn’t receive the code? Send again
) : null} {step === 2 ? (
Please enter a new password } name="password" rules={[ { required: true, message: }, { pattern: /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/, message: } ]} > }, ({ getFieldValue }) => ({ validator(_, value) { if (!value || getFieldValue('password') === value) { return Promise.resolve(); } return Promise.reject(new Error('The two passwords that you entered do not match')); }, }), ]} >
) : null} {step === 3 ? ( <> Your password has just been reset, please log in to continue. ) : null}
) }