From d23ac73e37f1ffa526380f60a96410791aa04fc0 Mon Sep 17 00:00:00 2001 From: SB1019 Date: Mon, 8 Apr 2024 12:03:31 -0700 Subject: [PATCH 1/6] Writing Architecture for api/user --- backend/src/controllers/user.ts | 9 +++++++++ backend/src/routes/user.ts | 3 ++- frontend/src/api/Users.ts | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/backend/src/controllers/user.ts b/backend/src/controllers/user.ts index 1ff74a2..cbabb41 100644 --- a/backend/src/controllers/user.ts +++ b/backend/src/controllers/user.ts @@ -20,3 +20,12 @@ export const getWhoAmI: RequestHandler = async (req: PAPRequest, res, next) => { next(error); } }; + +export const getUsers: RequestHandler = async (req: PAPRequest, res, next) => { + try { + const users = await UserModel.find(); + res.status(200).send(users); + } catch (error) { + next(error); + } +}; diff --git a/backend/src/routes/user.ts b/backend/src/routes/user.ts index efd4171..be41f9f 100644 --- a/backend/src/routes/user.ts +++ b/backend/src/routes/user.ts @@ -1,10 +1,11 @@ import express from "express"; -import { requireSignedIn } from "src/middleware/auth"; +import { requireSignedIn, requireAdmin } from "src/middleware/auth"; import * as UserController from "src/controllers/user"; const router = express.Router(); router.get("/whoami", requireSignedIn, UserController.getWhoAmI); +router.get("/", requireSignedIn, requireAdmin, UserController.getUsers); export default router; diff --git a/frontend/src/api/Users.ts b/frontend/src/api/Users.ts index 64e76b7..f0819f3 100644 --- a/frontend/src/api/Users.ts +++ b/frontend/src/api/Users.ts @@ -19,3 +19,13 @@ export const getWhoAmI = async (firebaseToken: string): Promise> return handleAPIError(error); } }; + +export const getUsers = async (firebaseToken: string): Promise> => { + try { + const response = await get("/api/user", createAuthHeader(firebaseToken)); + const json = (await response.json()) as User[]; + return { success: true, data: json }; + } catch (error) { + return handleAPIError(error); + } +}; From 760646a32d59b40b7522d6a19a9717d8ba91e589 Mon Sep 17 00:00:00 2001 From: sydneyzhang18 <114766656+sydneyzhang18@users.noreply.github.com> Date: Mon, 8 Apr 2024 12:40:51 -0700 Subject: [PATCH 2/6] profile page frontend progress --- frontend/public/ic_settings.svg | 5 ++ .../src/app/staff/profile/page.module.css | 34 ++++++++++++ frontend/src/app/staff/profile/page.tsx | 53 +++++++++++++++++++ frontend/src/components/UserProfile/index.tsx | 36 +++++++++++++ .../components/UserProfile/styles.module.css | 44 +++++++++++++++ 5 files changed, 172 insertions(+) create mode 100644 frontend/public/ic_settings.svg create mode 100644 frontend/src/app/staff/profile/page.module.css create mode 100644 frontend/src/app/staff/profile/page.tsx create mode 100644 frontend/src/components/UserProfile/index.tsx create mode 100644 frontend/src/components/UserProfile/styles.module.css diff --git a/frontend/public/ic_settings.svg b/frontend/public/ic_settings.svg new file mode 100644 index 0000000..fed6907 --- /dev/null +++ b/frontend/public/ic_settings.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/frontend/src/app/staff/profile/page.module.css b/frontend/src/app/staff/profile/page.module.css new file mode 100644 index 0000000..b2d4309 --- /dev/null +++ b/frontend/src/app/staff/profile/page.module.css @@ -0,0 +1,34 @@ +.main { + padding: 64px; + padding-top: 128px; + background-color: var(--color-background); + display: flex; + flex-direction: column; + color: var(--Accent-Blue-1, #102d5f); + text-align: left; + + /* justify-content: center; */ + margin: 105px 120px 0; + gap: 40px; + + gap: 32px; + /* Desktop/H1 */ + font-family: Lora; + /* font-size: 20px; */ + font-style: normal; + font-weight: 700; + line-height: normal; +} + +.row { + display: flex; + flex-direction: row; +} + +.title { + font-size: 40px; +} + +.subtitle { + font-size: 24px; +} diff --git a/frontend/src/app/staff/profile/page.tsx b/frontend/src/app/staff/profile/page.tsx new file mode 100644 index 0000000..f0c331f --- /dev/null +++ b/frontend/src/app/staff/profile/page.tsx @@ -0,0 +1,53 @@ +"use client"; + +import styles from "@/app/staff/profile/page.module.css"; +import VSRTable from "@/components/VSRTable/VSRTable"; +import SearchKeyword from "@/components/VSRTable/SearchKeyword"; +import PageTitle from "@/components/VSRTable/PageTitle"; +import HeaderBar from "@/components/shared/HeaderBar"; +import Image from "next/image"; +import React, { useContext, useEffect, useState } from "react"; +import { StatusDropdown } from "@/components/shared/StatusDropdown"; +import { useMediaQuery } from "@mui/material"; +import { useRedirectToLoginIfNotSignedIn } from "@/hooks/useRedirection"; +import { UserContext } from "@/contexts/userContext"; +import { DeleteVSRsModal } from "@/components/shared/DeleteVSRsModal"; +import { VSR, getAllVSRs } from "@/api/VSRs"; +import { VSRErrorModal } from "@/components/VSRForm/VSRErrorModal"; +import { useScreenSizes } from "@/hooks/useScreenSizes"; +import { LoadingScreen } from "@/components/shared/LoadingScreen"; +import { Button } from "@/components/shared/Button"; +import { UserProfile } from "@/components/UserProfile"; +import { User } from "firebase/auth"; + +export default function Profile() { + const { isMobile, isTablet } = useScreenSizes(); + + // useRedirectToLoginIfNotSignedIn(); + + return ( +
+ +
+

Account

+

User Profile

+ {/* ACCOUNT INFO */} + +
+

Manage Users

+
+ + +
+
+ ); +} diff --git a/frontend/src/components/UserProfile/index.tsx b/frontend/src/components/UserProfile/index.tsx new file mode 100644 index 0000000..bf0754d --- /dev/null +++ b/frontend/src/components/UserProfile/index.tsx @@ -0,0 +1,36 @@ +import React from "react"; +import styles from "@/components/UserProfile/styles.module.css"; +import Image from "next/image"; +import { User } from "firebase/auth"; + +export interface UserProps { + name: string; + email: string; +} +export function UserProfile({ name, email }: UserProps) { + return ( +
+ {/*
*/} + Internal Error + {/*
*/} +
+

{name}

+

{email}

+
+ Internal Error +
+ ); +} diff --git a/frontend/src/components/UserProfile/styles.module.css b/frontend/src/components/UserProfile/styles.module.css new file mode 100644 index 0000000..4b52fb1 --- /dev/null +++ b/frontend/src/components/UserProfile/styles.module.css @@ -0,0 +1,44 @@ +.user { + display: flex; + flex-direction: row; + border-radius: 6px; + background: var(--Functional-Background, #f9f9f9); + + display: flex; + padding: 26px 34px; + align-items: flex-start; + gap: 10px; + align-self: stretch; + margin-bottom: 32px; +} + +.info { + display: flex; + flex-direction: column; +} + +.name { + color: var(--Accent-Blue-1, #102d5f); + + /* Desktop/H2 */ + font-family: Lora; + font-size: 24px; + font-style: normal; + font-weight: 700; + line-height: normal; +} + +.email { + color: var(--Neutral-Gray6, #484848); + + /* Desktop/Body 2 */ + font-family: "Open Sans"; + font-size: 16px; + font-style: normal; + font-weight: 400; + line-height: normal; +} + +.pfp { + border-radius: 50%; +} From 35dce850c8ce4e9df23625e597ddd8495ec78eaa Mon Sep 17 00:00:00 2001 From: sydneyzhang18 <114766656+sydneyzhang18@users.noreply.github.com> Date: Mon, 8 Apr 2024 23:50:54 -0700 Subject: [PATCH 3/6] admin info progress, will fix alignment issues --- .../src/app/staff/profile/page.module.css | 26 ++++++- frontend/src/app/staff/profile/page.tsx | 6 +- .../components/Profile/AdminProfile/index.tsx | 45 ++++++++++++ .../Profile/AdminProfile/styles.module.css | 68 +++++++++++++++++++ .../{ => Profile}/UserProfile/index.tsx | 2 +- .../UserProfile/styles.module.css | 3 + 6 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 frontend/src/components/Profile/AdminProfile/index.tsx create mode 100644 frontend/src/components/Profile/AdminProfile/styles.module.css rename frontend/src/components/{ => Profile}/UserProfile/index.tsx (92%) rename frontend/src/components/{ => Profile}/UserProfile/styles.module.css (91%) diff --git a/frontend/src/app/staff/profile/page.module.css b/frontend/src/app/staff/profile/page.module.css index b2d4309..59b63c3 100644 --- a/frontend/src/app/staff/profile/page.module.css +++ b/frontend/src/app/staff/profile/page.module.css @@ -1,6 +1,9 @@ +.page { + background-color: var(--color-background); +} .main { padding: 64px; - padding-top: 128px; + /* padding-top: 105px; */ background-color: var(--color-background); display: flex; flex-direction: column; @@ -11,7 +14,7 @@ margin: 105px 120px 0; gap: 40px; - gap: 32px; + /* gap: 32px; */ /* Desktop/H1 */ font-family: Lora; /* font-size: 20px; */ @@ -20,11 +23,30 @@ line-height: normal; } +.admin { + display: flex; + flex-direction: row; + border-radius: 6px; + background: var(--Functional-Background, #f9f9f9); + + display: flex; + padding: 26px 34px; + align-items: flex-start; + gap: 10px; + align-self: stretch; + margin-bottom: 32px; +} + .row { display: flex; flex-direction: row; } +.column { + display: flex; + flex-direction: column; +} + .title { font-size: 40px; } diff --git a/frontend/src/app/staff/profile/page.tsx b/frontend/src/app/staff/profile/page.tsx index f0c331f..76b40db 100644 --- a/frontend/src/app/staff/profile/page.tsx +++ b/frontend/src/app/staff/profile/page.tsx @@ -17,8 +17,9 @@ import { VSRErrorModal } from "@/components/VSRForm/VSRErrorModal"; import { useScreenSizes } from "@/hooks/useScreenSizes"; import { LoadingScreen } from "@/components/shared/LoadingScreen"; import { Button } from "@/components/shared/Button"; -import { UserProfile } from "@/components/UserProfile"; +import { UserProfile } from "@/components/Profile/UserProfile"; import { User } from "firebase/auth"; +import { AdminProfile } from "@/components/Profile/AdminProfile"; export default function Profile() { const { isMobile, isTablet } = useScreenSizes(); @@ -32,6 +33,7 @@ export default function Profile() {

Account

User Profile

{/* ACCOUNT INFO */} +

Manage Users

@@ -46,7 +48,7 @@ export default function Profile() { />
- + ); diff --git a/frontend/src/components/Profile/AdminProfile/index.tsx b/frontend/src/components/Profile/AdminProfile/index.tsx new file mode 100644 index 0000000..8d0f7e5 --- /dev/null +++ b/frontend/src/components/Profile/AdminProfile/index.tsx @@ -0,0 +1,45 @@ +import React from "react"; +import styles from "@/components/Profile/AdminProfile/styles.module.css"; +import Image from "next/image"; +import { User } from "firebase/auth"; + +export interface AdminProps { + name: string; + email: string; +} +export function AdminProfile({ name, email }: AdminProps) { + return ( +
+
+
+

Account Information

+ Internal Error{" "} +
+
+ Internal Error +
+

Name

+

{name}

+
+
+

Email Account

+

{email}

+
+
+
+
+ ); +} diff --git a/frontend/src/components/Profile/AdminProfile/styles.module.css b/frontend/src/components/Profile/AdminProfile/styles.module.css new file mode 100644 index 0000000..d2ea2e2 --- /dev/null +++ b/frontend/src/components/Profile/AdminProfile/styles.module.css @@ -0,0 +1,68 @@ +.admin { + display: flex; + flex-direction: row; + border-radius: 6px; + background: var(--Functional-Background, #f9f9f9); + + display: flex; + padding: 32px; + align-items: flex-start; + gap: 10px; + align-self: stretch; + margin-bottom: 64px; +} + +.row { + display: flex; + flex-direction: row; +} + +.column { + display: flex; + flex-direction: column; + gap: 32px; +} + +.info_column { + display: flex; + flex-direction: column; + gap: 16px; +} + +.info_column_right { + display: flex; + flex-direction: column; + gap: 16px; + margin-left: 96px; +} + +.pfp { + border-radius: 50%; + margin-right: 64px; +} + +.subtitle { + font-size: 24px; +} + +.info_type { + color: var(--Dark-Gray, #484848); + + /* Desktop/Body 2 */ + font-family: "Open Sans"; + font-size: 16px; + font-style: normal; + font-weight: 400; + line-height: normal; +} + +.info { + color: var(--Primary-Background-Dark, #232220); + + /* Desktop/Body 1 */ + font-family: "Open Sans"; + font-size: 20px; + font-style: normal; + font-weight: 400; + line-height: normal; +} diff --git a/frontend/src/components/UserProfile/index.tsx b/frontend/src/components/Profile/UserProfile/index.tsx similarity index 92% rename from frontend/src/components/UserProfile/index.tsx rename to frontend/src/components/Profile/UserProfile/index.tsx index bf0754d..e0892ad 100644 --- a/frontend/src/components/UserProfile/index.tsx +++ b/frontend/src/components/Profile/UserProfile/index.tsx @@ -1,5 +1,5 @@ import React from "react"; -import styles from "@/components/UserProfile/styles.module.css"; +import styles from "@/components/Profile/UserProfile/styles.module.css"; import Image from "next/image"; import { User } from "firebase/auth"; diff --git a/frontend/src/components/UserProfile/styles.module.css b/frontend/src/components/Profile/UserProfile/styles.module.css similarity index 91% rename from frontend/src/components/UserProfile/styles.module.css rename to frontend/src/components/Profile/UserProfile/styles.module.css index 4b52fb1..bb70858 100644 --- a/frontend/src/components/UserProfile/styles.module.css +++ b/frontend/src/components/Profile/UserProfile/styles.module.css @@ -15,6 +15,7 @@ .info { display: flex; flex-direction: column; + margin-left: 41px; } .name { @@ -26,6 +27,7 @@ font-style: normal; font-weight: 700; line-height: normal; + margin-bottom: 14px; } .email { @@ -41,4 +43,5 @@ .pfp { border-radius: 50%; + margin-left: 22px; } From a0251909b3baa5d18ec5962205a1f19c23fd154b Mon Sep 17 00:00:00 2001 From: sydneyzhang18 <114766656+sydneyzhang18@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:24:17 -0700 Subject: [PATCH 4/6] more frontend, waiting on designer clarification to finalize --- .../src/app/staff/profile/page.module.css | 3 ++- frontend/src/app/staff/profile/page.tsx | 2 +- .../components/Profile/AdminProfile/index.tsx | 2 +- .../Profile/AdminProfile/styles.module.css | 11 +++++++-- .../components/Profile/UserProfile/index.tsx | 24 ++++++++++--------- .../Profile/UserProfile/styles.module.css | 10 ++++++-- 6 files changed, 34 insertions(+), 18 deletions(-) diff --git a/frontend/src/app/staff/profile/page.module.css b/frontend/src/app/staff/profile/page.module.css index 59b63c3..13977ff 100644 --- a/frontend/src/app/staff/profile/page.module.css +++ b/frontend/src/app/staff/profile/page.module.css @@ -16,7 +16,7 @@ /* gap: 32px; */ /* Desktop/H1 */ - font-family: Lora; + font-family: var(--font-title); /* font-size: 20px; */ font-style: normal; font-weight: 700; @@ -40,6 +40,7 @@ .row { display: flex; flex-direction: row; + justify-content: space-between; } .column { diff --git a/frontend/src/app/staff/profile/page.tsx b/frontend/src/app/staff/profile/page.tsx index 76b40db..5b85d14 100644 --- a/frontend/src/app/staff/profile/page.tsx +++ b/frontend/src/app/staff/profile/page.tsx @@ -33,7 +33,7 @@ export default function Profile() {

Account

User Profile

{/* ACCOUNT INFO */} - +

Manage Users

diff --git a/frontend/src/components/Profile/AdminProfile/index.tsx b/frontend/src/components/Profile/AdminProfile/index.tsx index 8d0f7e5..013ec8d 100644 --- a/frontend/src/components/Profile/AdminProfile/index.tsx +++ b/frontend/src/components/Profile/AdminProfile/index.tsx @@ -11,7 +11,7 @@ export function AdminProfile({ name, email }: AdminProps) { return (
-
+

Account Information

{/*
*/} -
-

{name}

-

{email}

+
+
+

{name}

+

{email}

+
+ Internal Error
- Internal Error
); } diff --git a/frontend/src/components/Profile/UserProfile/styles.module.css b/frontend/src/components/Profile/UserProfile/styles.module.css index bb70858..a7b2ed2 100644 --- a/frontend/src/components/Profile/UserProfile/styles.module.css +++ b/frontend/src/components/Profile/UserProfile/styles.module.css @@ -22,7 +22,7 @@ color: var(--Accent-Blue-1, #102d5f); /* Desktop/H2 */ - font-family: Lora; + font-family: var(--font-title); font-size: 24px; font-style: normal; font-weight: 700; @@ -34,7 +34,7 @@ color: var(--Neutral-Gray6, #484848); /* Desktop/Body 2 */ - font-family: "Open Sans"; + font-family: var(--font-open-sans); font-size: 16px; font-style: normal; font-weight: 400; @@ -45,3 +45,9 @@ border-radius: 50%; margin-left: 22px; } + +.row_justify { + display: flex; + flex-direction: row; + justify-content: space-between; +} From 29a3df16ce3977d56049991f7cf6643141776591 Mon Sep 17 00:00:00 2001 From: sydneyzhang18 <114766656+sydneyzhang18@users.noreply.github.com> Date: Sat, 13 Apr 2024 17:30:11 -0700 Subject: [PATCH 5/6] fixed frontend alignment issue --- .../src/app/staff/profile/page.module.css | 26 +++---------- frontend/src/app/staff/profile/page.tsx | 2 +- .../components/Profile/UserProfile/index.tsx | 38 +++++++++---------- .../Profile/UserProfile/styles.module.css | 19 +++++++--- 4 files changed, 39 insertions(+), 46 deletions(-) diff --git a/frontend/src/app/staff/profile/page.module.css b/frontend/src/app/staff/profile/page.module.css index 13977ff..4571975 100644 --- a/frontend/src/app/staff/profile/page.module.css +++ b/frontend/src/app/staff/profile/page.module.css @@ -1,42 +1,28 @@ -.page { +/* .page { background-color: var(--color-background); -} + padding-bottom: 67px; + min-height: 100vh; +} */ .main { padding: 64px; - /* padding-top: 105px; */ + padding-top: 105px; background-color: var(--color-background); display: flex; flex-direction: column; color: var(--Accent-Blue-1, #102d5f); text-align: left; - /* justify-content: center; */ - margin: 105px 120px 0; + padding: 105px 120px 0; gap: 40px; /* gap: 32px; */ /* Desktop/H1 */ font-family: var(--font-title); - /* font-size: 20px; */ font-style: normal; font-weight: 700; line-height: normal; } -.admin { - display: flex; - flex-direction: row; - border-radius: 6px; - background: var(--Functional-Background, #f9f9f9); - - display: flex; - padding: 26px 34px; - align-items: flex-start; - gap: 10px; - align-self: stretch; - margin-bottom: 32px; -} - .row { display: flex; flex-direction: row; diff --git a/frontend/src/app/staff/profile/page.tsx b/frontend/src/app/staff/profile/page.tsx index 5b85d14..e8bf85f 100644 --- a/frontend/src/app/staff/profile/page.tsx +++ b/frontend/src/app/staff/profile/page.tsx @@ -27,7 +27,7 @@ export default function Profile() { // useRedirectToLoginIfNotSignedIn(); return ( -
+

Account

diff --git a/frontend/src/components/Profile/UserProfile/index.tsx b/frontend/src/components/Profile/UserProfile/index.tsx index b16e68b..4a0ce41 100644 --- a/frontend/src/components/Profile/UserProfile/index.tsx +++ b/frontend/src/components/Profile/UserProfile/index.tsx @@ -10,29 +10,29 @@ export interface UserProps { export function UserProfile({ name, email }: UserProps) { return (
- {/*
*/} - Internal Error - {/*
*/} -
-
-

{name}

-

{email}

-
+
Internal Error
+
+
+

{name}

+ Internal Error +
+

{email}

+
); } diff --git a/frontend/src/components/Profile/UserProfile/styles.module.css b/frontend/src/components/Profile/UserProfile/styles.module.css index a7b2ed2..332d5fc 100644 --- a/frontend/src/components/Profile/UserProfile/styles.module.css +++ b/frontend/src/components/Profile/UserProfile/styles.module.css @@ -12,12 +12,6 @@ margin-bottom: 32px; } -.info { - display: flex; - flex-direction: column; - margin-left: 41px; -} - .name { color: var(--Accent-Blue-1, #102d5f); @@ -50,4 +44,17 @@ display: flex; flex-direction: row; justify-content: space-between; + width: 100%; +} + +.column { + display: flex; + flex-direction: column; +} + +.column_right { + display: flex; + flex-direction: column; + width: 100%; + margin-left: 41px; } From db289d51ca850cd007876e2b6d7a5cf01a1f77f9 Mon Sep 17 00:00:00 2001 From: SB1019 Date: Fri, 3 May 2024 19:02:20 -0700 Subject: [PATCH 6/6] Adding Profile Picture and Firebase Profile WIP --- backend/src/controllers/user.ts | 28 +++++++++- backend/src/models/user.ts | 9 ++++ backend/src/routes/user.ts | 2 +- frontend/src/api/Users.ts | 12 ++++- frontend/src/app/staff/profile/page.tsx | 51 ++++++++++++------- .../components/Profile/UserProfile/index.tsx | 11 ++-- 6 files changed, 83 insertions(+), 30 deletions(-) diff --git a/backend/src/controllers/user.ts b/backend/src/controllers/user.ts index cbabb41..13930c9 100644 --- a/backend/src/controllers/user.ts +++ b/backend/src/controllers/user.ts @@ -1,6 +1,7 @@ import { RequestHandler } from "express"; import { PAPRequest } from "src/middleware/auth"; -import UserModel from "src/models/user"; +import { firebaseAuth } from "src/services/firebase"; +import UserModel, { DisplayUser } from "src/models/user"; /** * Retrieves data about the current user (their MongoDB ID, Firebase UID, and role). @@ -24,7 +25,30 @@ export const getWhoAmI: RequestHandler = async (req: PAPRequest, res, next) => { export const getUsers: RequestHandler = async (req: PAPRequest, res, next) => { try { const users = await UserModel.find(); - res.status(200).send(users); + const displayUsers = []; + for (const user of users) { + const { uid, _id } = user; + + try { + // const userRecord = await firebaseAuth.getUser(uid); + + await firebaseAuth.updateUser(uid, { + displayName: "Samvrit Srinath", + photoURL: + "https://www.google.com/url?sa=i&url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F42893664%2Ffirebase-photourl-from-a-google-auth-provider-returns-a-jpg-with-colors-inverted&psig=AOvVaw1rsKyabxOup86UrqGbfpsp&ust=1714873347675000&source=images&cd=vfe&opi=89978449&ved=0CBIQjRxqFwoTCIDx4Jjv8oUDFQAAAAAdAAAAABAD", + }); + + const newUser = await firebaseAuth.getUser(uid); + const { displayName, email, photoURL } = newUser!; + + const displayUser = { _id, uid, displayName, email, photoURL }; + displayUsers.push(displayUser); + } catch (error) { + next(error); + } + } + + res.status(200).json(displayUsers as DisplayUser[]); } catch (error) { next(error); } diff --git a/backend/src/models/user.ts b/backend/src/models/user.ts index 566df40..c31de5a 100644 --- a/backend/src/models/user.ts +++ b/backend/src/models/user.ts @@ -1,3 +1,4 @@ +import { ObjectId } from "mongodb"; import { InferSchemaType, Schema, model } from "mongoose"; /** @@ -28,6 +29,14 @@ export enum UserRole { ADMIN = "admin", } +export interface DisplayUser { + _id: ObjectId; + uid: string; + email: string; + displayName: string; + photoURL: string; +} + type User = InferSchemaType; export default model("User", userSchema); diff --git a/backend/src/routes/user.ts b/backend/src/routes/user.ts index be41f9f..adcc607 100644 --- a/backend/src/routes/user.ts +++ b/backend/src/routes/user.ts @@ -1,6 +1,6 @@ import express from "express"; -import { requireSignedIn, requireAdmin } from "src/middleware/auth"; +import { requireAdmin, requireSignedIn } from "src/middleware/auth"; import * as UserController from "src/controllers/user"; const router = express.Router(); diff --git a/frontend/src/api/Users.ts b/frontend/src/api/Users.ts index f0819f3..5d0ce73 100644 --- a/frontend/src/api/Users.ts +++ b/frontend/src/api/Users.ts @@ -6,6 +6,14 @@ export interface User { role: string; } +export interface DisplayUser { + _id: string; + uid: string; + email: string; + displayName: string; + photoURL: string; +} + export const createAuthHeader = (firebaseToken: string) => ({ Authorization: `Bearer ${firebaseToken}`, }); @@ -20,10 +28,10 @@ export const getWhoAmI = async (firebaseToken: string): Promise> } }; -export const getUsers = async (firebaseToken: string): Promise> => { +export const getAllUsers = async (firebaseToken: string): Promise> => { try { const response = await get("/api/user", createAuthHeader(firebaseToken)); - const json = (await response.json()) as User[]; + const json = (await response.json()) as DisplayUser[]; return { success: true, data: json }; } catch (error) { return handleAPIError(error); diff --git a/frontend/src/app/staff/profile/page.tsx b/frontend/src/app/staff/profile/page.tsx index e8bf85f..5ff7d16 100644 --- a/frontend/src/app/staff/profile/page.tsx +++ b/frontend/src/app/staff/profile/page.tsx @@ -1,28 +1,37 @@ "use client"; import styles from "@/app/staff/profile/page.module.css"; -import VSRTable from "@/components/VSRTable/VSRTable"; -import SearchKeyword from "@/components/VSRTable/SearchKeyword"; -import PageTitle from "@/components/VSRTable/PageTitle"; import HeaderBar from "@/components/shared/HeaderBar"; -import Image from "next/image"; -import React, { useContext, useEffect, useState } from "react"; -import { StatusDropdown } from "@/components/shared/StatusDropdown"; -import { useMediaQuery } from "@mui/material"; -import { useRedirectToLoginIfNotSignedIn } from "@/hooks/useRedirection"; -import { UserContext } from "@/contexts/userContext"; -import { DeleteVSRsModal } from "@/components/shared/DeleteVSRsModal"; -import { VSR, getAllVSRs } from "@/api/VSRs"; -import { VSRErrorModal } from "@/components/VSRForm/VSRErrorModal"; +import React, { useContext, useState } from "react"; import { useScreenSizes } from "@/hooks/useScreenSizes"; -import { LoadingScreen } from "@/components/shared/LoadingScreen"; import { Button } from "@/components/shared/Button"; import { UserProfile } from "@/components/Profile/UserProfile"; -import { User } from "firebase/auth"; import { AdminProfile } from "@/components/Profile/AdminProfile"; +import { DisplayUser, getAllUsers } from "@/api/Users"; +import { UserContext } from "@/contexts/userContext"; +enum AllUsersError { + CANNOT_FETCH_USERS_NO_INTERNET, + CANNOT_FETCH_USERS_INTERNAL, + NONE, +} export default function Profile() { const { isMobile, isTablet } = useScreenSizes(); + const { firebaseUser, papUser } = useContext(UserContext); + const [users, setUsers] = useState([]); + // const [userError, setUserError] = useState(AllUsersError.NONE); + + firebaseUser?.getIdToken().then((firebaseToken) => { + getAllUsers(firebaseToken).then((result) => { + if (result.success) { + setUsers(result.data); + console.log(result.data); + } else { + // setUserError(AllUsersError.CANNOT_FETCH_USERS_INTERNAL); + // console.log(userError); + } + }); + }); // useRedirectToLoginIfNotSignedIn(); @@ -34,7 +43,6 @@ export default function Profile() {

User Profile

{/* ACCOUNT INFO */} -

Manage Users

- - + {/* */} + {users.map((user, index) => + user.uid != firebaseUser?.uid ? ( + + ) : null, + )}
); diff --git a/frontend/src/components/Profile/UserProfile/index.tsx b/frontend/src/components/Profile/UserProfile/index.tsx index 4a0ce41..5794f26 100644 --- a/frontend/src/components/Profile/UserProfile/index.tsx +++ b/frontend/src/components/Profile/UserProfile/index.tsx @@ -6,18 +6,13 @@ import { User } from "firebase/auth"; export interface UserProps { name: string; email: string; + photoURL: string; } -export function UserProfile({ name, email }: UserProps) { +export function UserProfile({ name, email, photoURL }: UserProps) { return (
- Internal Error + Internal Error