import { Flex, Box, FormControl, FormLabel, Input, InputGroup, InputRightElement, Stack, Button, Heading, Text, useColorModeValue, useToast, } from '@chakra-ui/react' import Link from 'next/link' import { useState } from 'react' import { ViewIcon, ViewOffIcon } from '@chakra-ui/icons' import { authService } from '../services/authService' export default function LoginPage() { const [showPassword, setShowPassword] = useState(false) const [loading, setLoading] = useState(false) const [otpSent, setOtpSent] = useState(false) const [resetSuccess, setResetSuccess] = useState(false) const [formData, setFormData] = useState({ email: '', otp: '', newPassword: '', }) const toast = useToast() const handleRequestResetPassword = async (e) => { setLoading(true) authService .requestPasswordReset(formData) .then((res) => { setOtpSent(true) toast({ title: 'OTP sent successfully', status: 'success', duration: 5000, isClosable: true, }) }) .catch((err) => { toast({ title: 'Error', description: err.response.data.message || 'Something went wrong', status: 'error', duration: 5000, isClosable: true, }) }) .finally(() => { setLoading(false) }) } const handleResetPassword = async (e) => { setLoading(true) authService .resetPassword(formData) .then((res) => { toast({ title: 'Password reset successfully', status: 'success', }) setResetSuccess(true) }) .catch((err) => { toast({ title: 'Error', description: err.response?.data?.message || 'Something went wrong', status: 'error', }) }) .finally(() => { setLoading(false) }) } const onChange = (e) => { setFormData({ ...formData, [e.target.name]: e.target.value, }) } if (resetSuccess) { return ( <> Password reset successfully ) } return ( Reset Password Email address {otpSent && ( <> OTP New Password )} Go back to login ) }