@@ -3,30 +3,29 @@ import { faExclamationCircle } from '@fortawesome/free-solid-svg-icons';
33import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
44import Link from 'next/link' ;
55import { useRouter } from 'next/navigation' ;
6+ import { FC , useState } from 'react' ;
67import { useForm } from 'react-hook-form' ;
78
89import { ErrorBalloon } from '@web/src/modules/shared/components/client/ErrorBalloon' ;
910
11+ import axios from 'axios' ;
12+
1013import {
1114 Input ,
1215 SubmitButton ,
1316} from '../../../shared/components/client/FormElements' ;
1417
15- type LoginFormProps = {
16- isLoading ?: boolean ;
17- isLocked ?: boolean ;
18- } ;
19-
2018type LoginFormData = {
2119 email : string ;
22- password : string ;
2320} ;
2421
22+ const backendURL = process . env . NEXT_PUBLIC_API_URL ;
23+
2524// TODO: Implement login logic
26- export const LoginForm = ( {
27- isLoading = false ,
28- isLocked = false ,
29- } : LoginFormProps ) => {
25+ export const LoginForm : FC = ( ) => {
26+ const [ isLoading , setIsLoading ] = useState ( false ) ;
27+ const [ isLocked , setIsLocked ] = useState ( false ) ;
28+
3029 const {
3130 register,
3231 handleSubmit,
@@ -35,9 +34,29 @@ export const LoginForm = ({
3534
3635 const router = useRouter ( ) ;
3736
38- const onSubmit = async ( data : LoginFormData ) => {
39- // Handle login logic here
40- console . log ( data ) ;
37+ const onSubmit = async ( { email } : LoginFormData ) => {
38+ try {
39+ setIsLoading ( true ) ;
40+ const url = `${ backendURL } /auth/login/email` ;
41+
42+ const response = await axios . post (
43+ url ,
44+ {
45+ destination : email ,
46+ } ,
47+ {
48+ headers : {
49+ 'Content-Type' : 'application/json' ,
50+ } ,
51+ } ,
52+ ) ;
53+
54+ console . log ( response . data ) ;
55+ } catch ( error ) {
56+ console . error ( error ) ;
57+ } finally {
58+ setIsLoading ( false ) ;
59+ }
4160 } ;
4261
4362 return (
@@ -76,46 +95,12 @@ export const LoginForm = ({
7695 />
7796 </ div >
7897
79- { /* Password */ }
80- < div >
81- < Input
82- id = 'password'
83- label = 'Password*'
84- type = 'password'
85- tooltip = {
86- < >
87- < p > Enter your password to log in.</ p >
88- </ >
89- }
90- isLoading = { isLoading }
91- disabled = { isLocked }
92- errorMessage = { errors . password ?. message }
93- { ...register ( 'password' , { required : 'Password is required' } ) }
94- />
95- </ div >
96-
9798 { errors . email && < ErrorBalloon message = { errors . email . message } /> }
98- { errors . password && (
99- < ErrorBalloon message = { errors . password . message } />
100- ) }
10199
102100 < div className = 'flex flex-row items-center justify-end gap-8' >
103101 { /* Submit button */ }
104102 < SubmitButton isDisabled = { isLoading } />
105103 </ div >
106-
107- { /* Link to registration page */ }
108- < div className = 'flex items-center justify-center gap-2 my-3' >
109- < p >
110- Don't have an account?{ ' ' }
111- < Link
112- href = '/register'
113- className = 'text-blue-400 hover:text-blue-300 hover:underline'
114- >
115- Register here
116- </ Link >
117- </ p >
118- </ div >
119104 </ div >
120105 </ form >
121106 </ >
0 commit comments