diff --git a/components/Settings/SettingsDashboard.tsx b/components/Settings/SettingsDashboard.tsx new file mode 100644 index 0000000..cbf9e8f --- /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 0000000..5b0c425 --- /dev/null +++ b/components/Settings/UserProfile/index.tsx @@ -0,0 +1,41 @@ +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/api/applications.ts b/pages/api/applications.ts index 90336ee..509c017 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({ diff --git a/pages/api/volunteer-logs/index.ts b/pages/api/volunteer-logs/index.ts index 3fc066e..bebba63 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, diff --git a/pages/settings.tsx b/pages/settings.tsx index 91caa01..ea1116a 100644 --- a/pages/settings.tsx +++ b/pages/settings.tsx @@ -1,18 +1,9 @@ -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 0000000..5ca2888 --- /dev/null +++ b/styles/settings.style.tsx @@ -0,0 +1,10 @@ +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; +`;