-
Notifications
You must be signed in to change notification settings - Fork 0
/
Register.jsx
70 lines (57 loc) · 2.27 KB
/
Register.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React, { useEffect, useState } from 'react';
import registerLoginImage from '../images/registerLoginImage.png';
import RegisterForm from '../components/RegisterForm';
import Logo from '../constants/icons/Logo';
import { useAuth } from '../context/AuthProviderContext';
import { Link, useNavigate } from 'react-router-dom';
import { getRegister } from '../services/userService';
import useDisplayErrorMess from '../hooks/useDisplayErrorMess';
import useDisplaySuccessMess from '../hooks/useDisplaySuccessMes';
function Register() {
const navigator = useNavigate();
const { auth, setAuth } = useAuth();
const [loading, setLoading] = useState(false);
useEffect(() => {
//if there is authtoken in authContext that will be navigate to home.
// token && navigator('/');
auth?.authToken && navigator('/');
}, []);
const getRegisterFunc = async (auth) => {
setLoading(true);
//api has username,email and password. but we dont get username from user. so use username as email.
const res = await getRegister(auth.email, auth.email, auth.password);
if (res.status === 400) {
console.log(res.message);
useDisplayErrorMess('E-posta daha önceden alındı.');
setLoading(false);
}
else {
setAuth({ id: res.data?.user?.id, email: auth.email, authToken: res.data?.jwt });
document.cookie = `Auth_Token=${res.data?.jwt}`;
setLoading(false);
useDisplaySuccessMess('Registered successfully.');
setTimeout(() => {
navigator('/');
}, 3000);
}
};
return (
<div className='register'>
<div className='registerLeftSide'>
<img src={registerLoginImage} alt="ikinci el" />
</div>
<div className='registerRightSide'>
<div className='logo'><Link to='/'><Logo width={224} height={73} /> </Link></div>
<div className='registerInfoDiv'>
<div className='title'>Üye Ol</div>
<div className='subTitle'>Fırsatlardan yararlanmak için üye ol!</div>
<RegisterForm getRegisterFunc={getRegisterFunc} loading={loading} buttonText={'Üye Ol'} />
<div className='footer'>
Hesabın mı var? <span><Link to='/login'>Giriş Yap</Link></span>
</div>
</div>
</div>
</div>
);
}
export default Register;