Skip to content

Commit

Permalink
profilepage
Browse files Browse the repository at this point in the history
  • Loading branch information
charlestang06 committed Jan 14, 2024
1 parent bc25690 commit 9825bc1
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 34 deletions.
49 changes: 24 additions & 25 deletions src/components/Dashboard/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ function Dashboard() {
let [major, setMajor] = useState("");


console.log(user)
// console.log(user)
useEffect(() => {
console.log(logoutUser)
// console.log(logoutUser)
if (user == null && logoutUser) {
navigate("/");
setLogout(false);
}

}, [user]);


Expand Down Expand Up @@ -237,7 +237,6 @@ function Dashboard() {
setSignup(true);
}
});

});

const services = [
Expand Down Expand Up @@ -372,24 +371,23 @@ function Dashboard() {

const getUserInfo = () => {
try {
RequestUtils.get('/retrieve?id=' + user.uid).then((response) => response.json())
.then((data) => {
console.log(data.status)
if (data.status == 200) {
setFirst(data.data.name);
setLast(data.data.last);
setYear(data.data.year);
setMajor(data.data.major);
}
if(data.status == 404) {
console.log(data.status)
setSignup(true);
}
});
} catch {

}

RequestUtils.get('/retrieve?id=' + user.uid).then((response) => response.json())
.then((data) => {
console.log(data.status)
if (data.status == 200) {
setFirst(data.data.name);
setLast(data.data.last);
setYear(data.data.year);
setMajor(data.data.major);
}
if (data.status == 404) {
console.log(data.status)
setSignup(true);
}
});
} catch {
console.log("Error in retrieving user info.")
}
}


Expand Down Expand Up @@ -478,8 +476,8 @@ function Dashboard() {
onClick: () => {
logout();
setLogout(true);


}

}
Expand Down Expand Up @@ -515,7 +513,8 @@ function Dashboard() {
<Table />
) : (
<>
<Profile first={first} setFirst={setFirst} last={last} setLast={setLast} year={year} setYear={setYear} major={major} setMajor={setMajor} />
<Profile />
{/*first={first} setFirst={setFirst} last={last} setLast={setLast} year={year} setYear={setYear} major={major} setMajor={setMajor} */}
</>
)}
</Content>
Expand Down
65 changes: 56 additions & 9 deletions src/components/Dashboard/Profile.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,79 @@
import { useState, useEffect, useLayoutEffect } from "react";
import { useNavigate } from "react-router";
import { Button, Form, Input, Select } from "antd";
import RequestUtils from "../../Utils/RequestUtils.js";
import { auth, logout } from "../../Firebase.js";
import { useAuthState } from "react-firebase-hooks/auth";

function Profile({ first, setFirst, last, setLast, year, setYear, major, setMajor }) {

function Profile({ }) {
// first, setFirst, last, setLast, year, setYear, major, setMajor
const { Option } = Select;
let [user, loading] = useAuthState(auth);

let [first, setFirst] = useState("");
let [last, setLast] = useState("");
let [year, setYear] = useState("");
let [major, setMajor] = useState("");

const signupyayslay = () => {
let reqbody = {
first: first,
last: last,
email: user.email,
year: year,
major: major,
}
RequestUtils.post('/user?id=' + user.uid, reqbody)
}

useEffect(() => {
if (user != null) {
getUserInfo();
}

}, [user]);

const getUserInfo = () => {
try {
RequestUtils.get('/retrieve?id=' + user.uid).then((response) => response.json())
.then((data) => {
console.log(data.status)
if (data.status == 200) {
setFirst(data.data.name);
setLast(data.data.last);
setYear(data.data.year);
setMajor(data.data.major);
}
if (data.status == 404) {
console.log(data.status)
}
});
} catch {
console.log("Error in retrieving user info.")
}
}

return (
<>
<br>
</br>
<br></br>
<>
<br>
</br>
<br></br>
<h1>Profile</h1>

<Form layout='vertical'>
<Form.Item label="First Name" style={{
width: "50%",
marginBottom: "10px"
}}>
<Input size="medium" width={200} onChange={(e) => {
<Input disabled size="medium" value={first} width={200} onChange={(e) => {
setFirst(e.target.value)
}}></Input>
</Form.Item>
<Form.Item label="Last Name" style={{
<Form.Item disabled label="Last Name" style={{
width: "50%",
marginBottom: "10px"
}}>
<Input size="medium" width={200} onChange={(e) => {
<Input size="medium" disabled value={last} width={200} onChange={(e) => {
setLast(e.target.value)
}}
/>
Expand Down

0 comments on commit 9825bc1

Please sign in to comment.