From e509a6007cd9fc04c21b68afe53dbbb45ba34906 Mon Sep 17 00:00:00 2001 From: David Huang Date: Fri, 26 Apr 2024 00:53:33 -0500 Subject: [PATCH 1/4] feature/simple-settings-with-profile-and-sign-out --- components/Settings/SettingsDashboard.tsx | 49 +++++++++++++++++++++++ components/Settings/UserProfile/index.tsx | 40 ++++++++++++++++++ pages/settings.tsx | 16 ++------ styles/settings.style.tsx | 11 +++++ 4 files changed, 104 insertions(+), 12 deletions(-) create mode 100644 components/Settings/SettingsDashboard.tsx create mode 100644 components/Settings/UserProfile/index.tsx create mode 100644 styles/settings.style.tsx diff --git a/components/Settings/SettingsDashboard.tsx b/components/Settings/SettingsDashboard.tsx new file mode 100644 index 00000000..cbf9e8f7 --- /dev/null +++ b/components/Settings/SettingsDashboard.tsx @@ -0,0 +1,49 @@ +import { signOut } from 'next-auth/react'; +import React, { useState, useEffect } from 'react'; +import { QueriedUserData } from 'bookem-shared/src/types/database'; +import UserProfile from './UserProfile'; +import { DashboardContainer } from '@/styles/volunteerDashboard.styles'; +import { CenteringContainer } from '@/styles/settings.style'; +import { Button } from 'antd'; +import { LogoutOutlined } from '@ant-design/icons'; + +export default function SettingsDashboard() { + const [userData, setUserData] = useState(null); + + useEffect(() => { + // fetch user data + const fetchUserData = async () => { + const res = await fetch('/api/users'); + const data = await res.json(); + setUserData(data); + + console.log(data); + }; + fetchUserData(); + }, []); + + if (!userData) return
Loading...
; + + return ( + + + + + + + + ); +} diff --git a/components/Settings/UserProfile/index.tsx b/components/Settings/UserProfile/index.tsx new file mode 100644 index 00000000..01fe6890 --- /dev/null +++ b/components/Settings/UserProfile/index.tsx @@ -0,0 +1,40 @@ +import { QueriedUserData } from 'bookem-shared/src/types/database'; +import { Card } from 'antd'; + +const renderBackgroundCheckStatus = (backgroundCheck: any) => { + if (backgroundCheck) { + if (backgroundCheck.passed) { + return ( + <> +

Background check status: Passed

+

+ Background check expiration date: + {new Date(backgroundCheck.expirationDate).toLocaleDateString()} +

+ + ); + } else { + return

Background check status: Not pased

; + } + } else { + return

Background check status: Not available

; + } +}; + +export default function UserProfile({ user }: { user: QueriedUserData }) { + const { backgroundCheck } = user; + + return ( + +

Name: {user.name}

+

Email: {user.email}

+

Phone: {user.phone}

+ {renderBackgroundCheckStatus(backgroundCheck)} +
+ ); +} diff --git a/pages/settings.tsx b/pages/settings.tsx index 91caa012..04a09b5c 100644 --- a/pages/settings.tsx +++ b/pages/settings.tsx @@ -1,18 +1,10 @@ -import { signOut, useSession } from 'next-auth/react'; -import React from 'react'; - +import SettingsDashboard from '@/components/Settings/SettingsDashboard'; const SettingsPage = () => { - const { data: session } = useSession(); return ( -
- {session && ( - <> -
You have signed in as {session.user?.email}
- - - )} -
+ <> + + ); }; diff --git a/styles/settings.style.tsx b/styles/settings.style.tsx new file mode 100644 index 00000000..0811cd96 --- /dev/null +++ b/styles/settings.style.tsx @@ -0,0 +1,11 @@ +import styled from "styled-components"; + + +// a container for centering the content +export const CenteringContainer = styled.div` + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + height: 100vh; +`; \ No newline at end of file From a043aa32fcbf0261d612235ef8b5c40c91947c7b Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Sat, 27 Apr 2024 00:21:21 -0500 Subject: [PATCH 2/4] Prettier --- components/Settings/UserProfile/index.tsx | 7 ++++--- pages/settings.tsx | 1 - styles/settings.style.tsx | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/components/Settings/UserProfile/index.tsx b/components/Settings/UserProfile/index.tsx index 01fe6890..5b0c425a 100644 --- a/components/Settings/UserProfile/index.tsx +++ b/components/Settings/UserProfile/index.tsx @@ -25,12 +25,13 @@ export default function UserProfile({ user }: { user: QueriedUserData }) { const { backgroundCheck } = user; return ( - + }}>

Name: {user.name}

Email: {user.email}

Phone: {user.phone}

diff --git a/pages/settings.tsx b/pages/settings.tsx index 04a09b5c..ea1116ac 100644 --- a/pages/settings.tsx +++ b/pages/settings.tsx @@ -1,6 +1,5 @@ import SettingsDashboard from '@/components/Settings/SettingsDashboard'; const SettingsPage = () => { - return ( <> diff --git a/styles/settings.style.tsx b/styles/settings.style.tsx index 0811cd96..5ca28880 100644 --- a/styles/settings.style.tsx +++ b/styles/settings.style.tsx @@ -1,5 +1,4 @@ -import styled from "styled-components"; - +import styled from 'styled-components'; // a container for centering the content export const CenteringContainer = styled.div` @@ -8,4 +7,4 @@ export const CenteringContainer = styled.div` justify-content: center; align-items: center; height: 100vh; -`; \ No newline at end of file +`; From 1e65731d709c7abfe05ad2692e2cf3f9133167c3 Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Sat, 27 Apr 2024 00:26:07 -0500 Subject: [PATCH 3/4] Make sure Events are registered --- pages/api/volunteer-logs/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pages/api/volunteer-logs/index.ts b/pages/api/volunteer-logs/index.ts index 3fc066ef..bebba63a 100644 --- a/pages/api/volunteer-logs/index.ts +++ b/pages/api/volunteer-logs/index.ts @@ -11,6 +11,7 @@ import { getSession } from 'next-auth/react'; import VolunteerLogs from 'bookem-shared/src/models/VolunteerLogs'; import Users from 'bookem-shared/src/models/Users'; import { QueriedUserData } from 'bookem-shared/src/types/database'; +import VolunteerEvents from 'bookem-shared/src/models/VolunteerEvents'; /** * /api/VolunteerLogs/: @@ -58,6 +59,7 @@ export default async function handler( const usersId = user._id; + await VolunteerEvents.findOne(); // get all volunteerEvents from collection that match the user's Id const volunteerLogs = await VolunteerLogs.find({ userId: usersId, From 9023b2dd6223d81d7655fddb934d8d9663b0e6f9 Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Sat, 27 Apr 2024 00:26:52 -0500 Subject: [PATCH 4/4] Optimize query a little --- pages/api/applications.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/api/applications.ts b/pages/api/applications.ts index 90336ee6..509c0176 100644 --- a/pages/api/applications.ts +++ b/pages/api/applications.ts @@ -34,7 +34,7 @@ export default async function handler( case 'GET': try { await dbConnect(); - await VolunteerEvents.find({}); + await VolunteerEvents.findOne({}); // query volunteerApplication by event id attributes const applicationResponses = await ApplicationResponse.find({