Skip to content

Commit c91b2a6

Browse files
authored
Merge pull request #243 from saitama-on/main
inital set up of admin page
2 parents e4548b2 + 209944e commit c91b2a6

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

pages/admin.jsx

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { Input } from '@mui/material'
2+
import {useState , useEffect} from 'react'
3+
4+
5+
6+
const Admin = () =>{
7+
8+
const [userInfo , setUserInfo] = useState({
9+
username:"",
10+
password:""
11+
});
12+
13+
const [checking , setChecking] = useState(false);
14+
15+
16+
useEffect(()=>{
17+
if(checking){
18+
//do wait for now
19+
console.log("checking")
20+
}
21+
},[checking])
22+
23+
24+
useEffect(()=>{
25+
setTimeout(()=>{
26+
window.location.href = window.location.origin
27+
}, 3000)
28+
})
29+
30+
const handleUserNameChange = (e) =>{
31+
// console.log(value)
32+
setUserInfo((prev)=> {
33+
return {...prev , username:e.target.value}
34+
})
35+
}
36+
37+
const handlePasswordChange = (e) =>{
38+
// console.log(value)
39+
setUserInfo((prev)=> {
40+
return {...prev , password:e.target.value}
41+
})
42+
}
43+
44+
const handleValidation = async()=>{
45+
if(!userInfo.username.trim() || !userInfo.password.trim()){
46+
alert("Fields cannot be empty!!")
47+
return
48+
}
49+
50+
setChecking(true);
51+
const username = userInfo.username.trim();
52+
const password = userInfo.password.trim();
53+
54+
const verfiyCred = await handleVerifyCred({username , password});
55+
56+
}
57+
58+
const handleVerifyCred = async ({username , password})=>{
59+
const response = await fetch('http://localhost:3001/api/v1/users/login',{
60+
method:'POST',
61+
headers:{
62+
'Content-Type' : 'application/json'
63+
},
64+
body:JSON.stringify({
65+
username:username,
66+
password:password
67+
})
68+
})
69+
70+
const data = await response.json();
71+
72+
if(!data.user){
73+
alert(data.message)
74+
return
75+
}
76+
77+
console.log(data.user.username)
78+
79+
//save info in local storage
80+
81+
// localStorage.setItem('username' , data.user.username);
82+
// localStorage.setItem('token', data.token);
83+
84+
// console.log(data)
85+
}
86+
87+
88+
89+
90+
return(
91+
<div>
92+
<h1>Work in progress....(Redirecting to home)</h1>
93+
{/* <div>
94+
<Input value={userInfo.username}
95+
onChange={handleUserNameChange}
96+
placeholder='enter username'
97+
required
98+
>Username</Input>
99+
<br></br>
100+
<Input value={userInfo.password}
101+
onChange={handlePasswordChange}
102+
placeholder='enter password'
103+
required
104+
>Username</Input>
105+
106+
<br></br>
107+
<button onClick={handleValidation} id="login-btn">Login</button>
108+
</div> */}
109+
</div>
110+
)
111+
}
112+
113+
114+
export default Admin

0 commit comments

Comments
 (0)