Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 77 additions & 5 deletions app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
loadAdmissionRSVP,
loadProfile,
loadQRCode,
updateProfile
updateProfile,
getUserInfo,
webSignOutUser
} from "@/util/api";
import Loading from "@/components/Loading/Loading";
import ErrorSnackbar from "@/components/ErrorSnackbar/ErrorSnackbar";
Expand Down Expand Up @@ -46,6 +48,8 @@ export default function Profile() {
const [showQR, setShowQR] = useState(false);
const [qrInfo, setQrInfo] = useState("");
const [qrLoading, setQrLoading] = useState(false);
const [userId, setUserId] = useState<string | null>(null);
const [signOutPopupActive, setSignOutPopupActive] = useState(false);

const avatarUrl = `${base}/${avatarId}.png`;

Expand Down Expand Up @@ -105,8 +109,34 @@ export default function Profile() {
};

useEffect(() => {
// TODO: Remove this redirect once the rest of RSVP is finished.
// redirect("/");
const loadUserInfo = async () => {
try {
const userInfo = await getUserInfo();
console.log(userInfo);

// if (
// RSVPInfo.response !== "ACCEPTED" ||
// RSVPInfo.status !== "ACCEPTED"
// ) {
// router.push("/profile-unavailable");
// return;
// }
// const profile = await loadProfile();
// setAvatarId(
// profile.avatarUrl.split("/").pop()!.replace(".png", "")
// );
setUserId(userInfo.userId);

setLoading(false);
} catch (error: any) {
console.error("Error loading user data:", error);
setLoading(false);
}
};
loadUserInfo();
}, []);

useEffect(() => {
const loadData = async () => {
try {
const RSVPInfo = await loadAdmissionRSVP();
Expand Down Expand Up @@ -418,7 +448,6 @@ export default function Profile() {
>
{name}
</Typography>

<Typography
sx={{
color: "#FFF",
Expand Down Expand Up @@ -451,7 +480,6 @@ export default function Profile() {
>
{track}
</Typography>

<Box
sx={{
mt: "auto",
Expand Down Expand Up @@ -491,6 +519,28 @@ export default function Profile() {
</Box>
</Box>
</Box>
<Typography
position="absolute"
onClick={() => {
if (signOutPopupActive) {
sessionStorage.removeItem("token");
webSignOutUser().then(() =>
window.location.reload()
);
}
if (userId) setSignOutPopupActive(true);
}}
sx={{
bottom: "4px",
right: "40px",
fontSize: "12px",
color: "#7bff616b"
}}
>
{signOutPopupActive
? "sign out?"
: (userId ?? "not signed in")}
</Typography>
</Box>
<Box
sx={{
Expand Down Expand Up @@ -526,6 +576,28 @@ export default function Profile() {
>
SHOW QR
</Box>
<Typography
position="absolute"
onClick={() => {
if (signOutPopupActive) {
sessionStorage.removeItem("token");
webSignOutUser().then(() =>
window.location.reload()
);
}
if (userId) setSignOutPopupActive(true);
}}
sx={{
bottom: "50px",
right: "10px",
fontSize: "12px",
color: "#7bff616b"
}}
>
{signOutPopupActive
? "sign out?"
: (userId ?? "not signed in")}
</Typography>
</Box>
</Box>
) : (
Expand Down
12 changes: 11 additions & 1 deletion util/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
RSVPInfo,
EventType,
MentorProfile,
JudgeProfile
JudgeProfile,
UserInfo
} from "./types";

const APIv2 = "https://adonix.hackillinois.org";
Expand Down Expand Up @@ -206,6 +207,10 @@ export async function postAuthRefresh(): Promise<void> {
await requestv2("POST", "/auth/refresh", {});
}

export async function webSignOutUser(): Promise<void> {
await requestv2("POST", "/auth/logout", {});
}

export async function getEvents(): Promise<EventType[]> {
const res = await requestv2("GET", "/event").catch(handleError);
return res.events as EventType[];
Expand All @@ -227,3 +232,8 @@ export async function getJudges(): Promise<JudgeProfile[]> {
const res = await requestv2("GET", "/judge/info/").catch(handleError);
return res as JudgeProfile[];
}

export async function getUserInfo(): Promise<UserInfo> {
const res = await requestv2("GET", "/user").catch(handleError);
return res as UserInfo;
}
6 changes: 6 additions & 0 deletions util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,9 @@ export type JudgeProfile = {
description: string;
imageUrl: string;
};

export type UserInfo = {
userId: string;
name: string;
email: string;
};