Skip to content

Commit

Permalink
Merge branch 'main' into update-upcoming-events-API
Browse files Browse the repository at this point in the history
  • Loading branch information
JiashuHarryHuang committed Nov 25, 2023
2 parents 5bd8e86 + 7ac598c commit 1f7d7f0
Show file tree
Hide file tree
Showing 17 changed files with 1,657 additions and 677 deletions.
7 changes: 6 additions & 1 deletion components/DesktopSidebar/UserIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import React from 'react';
import Image from 'next/image';
import { useEffect, useState } from 'react';
import { fetchData } from '@/utils/utils';
import {
ImageContainer,
Name,
UserIconContainer,
} from '@/styles/components/Sidebar/userIcon.styles';
import { Media } from '@/lib/media';
import { useSession } from 'next-auth/react';

export const UserIcon = () => {
const { data: session } = useSession();

return (
<UserIconContainer>
<ImageContainer>
Expand All @@ -20,7 +25,7 @@ export const UserIcon = () => {
<Image src="/bookem-logo.png" width="73" height="73" alt="" />
</Media>
</ImageContainer>
<Name>Linda S.</Name>
<Name>{session?.user && session.user.name}</Name>
</UserIconContainer>
);
};
76 changes: 43 additions & 33 deletions components/Home/MainDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Media } from '@/lib/media';
import Image from 'next/image';
import UpcomingEvents from '@/components/Home/UpcomingEvents';
import PastActivity from '@/components/Home/PastActivity';
import { Popover } from 'antd';
import {
Container,
DashboardLayout,
Expand All @@ -16,6 +17,8 @@ import {
MobilePastActivityContainer,
MobileHeader,
} from '@/styles/dashboard.styles';
import { formatDate } from '@/utils/utils';
import { QueriedUserData } from 'bookem-shared/src/types/database';

/**
* format main dashboard on home page
Expand All @@ -27,48 +30,58 @@ import {
* dollarsDonated: number;
* }
*/
const MainDashboard = ({ userData }: any) => {
const MainDashboard = ({ userData }: { userData: QueriedUserData | null }) => {
// state for showing mobile past activities
const [onMobilePastActivity, setOnMobilePastActivity] = useState(false);

const content = (
<div>
<p>This is the main dashboard for book&apos;em user</p>
</div>
);

return (
<>
{onMobilePastActivity ? (
{onMobilePastActivity && (
<>
{/* Display PastActivity when click on arrow button */}
<PastActivity userData={userData} />
</>
) : (
)}
{!onMobilePastActivity && (
<DashboardLayout>
<Container>
{/* Mobile Greeting and InfoIcon*/}
<Media lessThan="sm">
<Greeting>Hello, {userData.name}</Greeting>

<InfoIcon>
<Image
src="/home/info.png"
alt="Info icon"
width="19"
height="19"
/>
</InfoIcon>
<Greeting>Hello, {userData?.name}</Greeting>

<Popover content={content} title="Info">
<InfoIcon>
<Image
src="/home/info.png"
alt="Info icon"
width="19"
height="19"
/>
</InfoIcon>
</Popover>
</Media>

{/* Desktop Greeting and InfoIcon */}
<Media greaterThanOrEqual="sm">
<Greeting>
Hello {userData.name}, thanks for checking in!
Hello {userData?.name}, thanks for checking in!
</Greeting>

<InfoIcon>
<Image
src="/home/info.png"
alt="Info icon"
width="44"
height="44"
/>
</InfoIcon>
<Popover content={content} title="Info">
<InfoIcon>
<Image
src="/home/info.png"
alt="Info icon"
width="35"
height="35"
/>
</InfoIcon>
</Popover>
</Media>

<div>
Expand All @@ -84,18 +97,15 @@ const MainDashboard = ({ userData }: any) => {

<StatsFlex>
<FlexChild>
<StatsNumber>{userData.hoursVolunteered}</StatsNumber>
<StatsDescription>hours volunteered</StatsDescription>
</FlexChild>

<FlexChild>
<StatsNumber>{userData.booksShared}</StatsNumber>
<StatsDescription>books shared</StatsDescription>
<StatsNumber>{userData?.events.length}</StatsNumber>
<StatsDescription>Events attended</StatsDescription>
</FlexChild>

<FlexChild>
<StatsNumber>{userData.dollarsDonated}</StatsNumber>
<StatsDescription>dollars donated</StatsDescription>
<StatsNumber>
{formatDate(new Date(userData?.createdAt as Date))}
</StatsNumber>
<StatsDescription>Date joined</StatsDescription>
</FlexChild>
</StatsFlex>
</div>
Expand Down Expand Up @@ -133,7 +143,7 @@ const MainDashboard = ({ userData }: any) => {

{/* Desktop PastActivity is shown on the right side of main dashboard*/}
<Media greaterThanOrEqual="sm">
<PastActivity />
<PastActivity userData={userData} />
</Media>
</DashboardLayout>
)}
Expand Down
7 changes: 5 additions & 2 deletions components/Home/PastActivity.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React, { Suspense, useState } from 'react';
import mongoose from 'mongoose';
import { Media } from '@/lib/media';
import { QueriedVolunteerEventData } from 'bookem-shared/src/types/database';
import {
QueriedUserData,
QueriedVolunteerEventData,
} from 'bookem-shared/src/types/database';
import Image from 'next/image';
const EventCard = React.lazy(() => import('@/components/shared/EventCard')); // implement lazy loading
import MainDashboard from '@/components/Home/MainDashboard';
Expand Down Expand Up @@ -39,7 +42,7 @@ const dummyEventData: QueriedVolunteerEventData = {
};

// vertical list of sample PastEvents
const PastActivity = ({ userData }: any) => {
const PastActivity = ({ userData }: { userData: QueriedUserData | null }) => {
// state for hiding/showing mobile Past Activities
const [onMobileHide, setOnMobileHide] = useState(false);

Expand Down
21 changes: 12 additions & 9 deletions components/Volunteer/VolunteerDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ import {
import LogHoursPopupWindowForm from '@/components/Forms/LogHoursPopupWindowForm';
import { Media } from '@/lib/media';
import { BOOKEM_THEME } from '@/utils/constants';
import { QueriedUserData } from 'bookem-shared/src/types/database';
import { formatDate } from '@/utils/utils';

const VolunteerDashboard = ({ userData }: any) => {
const VolunteerDashboard = ({
userData,
}: {
userData: QueriedUserData | null;
}) => {
// set pop up window to false
const [showPopup, setShowPopup] = useState(false);

Expand Down Expand Up @@ -87,19 +93,16 @@ const VolunteerDashboard = ({ userData }: any) => {
<VolunteerStatsContainer>
<StatsFlex>
<FlexChild>
<StatsNumber>{userData.hoursVolunteered}</StatsNumber>
<StatsDescription>Hours volunteered</StatsDescription>
<StatsNumber>{userData?.events.length}</StatsNumber>
<StatsDescription>Events attended</StatsDescription>
</FlexChild>

<FlexChild>
<StatsNumber>{userData.booksDistributed}</StatsNumber>
<StatsNumber>
{formatDate(new Date(userData?.createdAt as Date))}
</StatsNumber>
<StatsDescription>Books distributed</StatsDescription>
</FlexChild>

<FlexChild>
<StatsNumber>{userData.eventsAssisted}</StatsNumber>
<StatsDescription>Events assisted</StatsDescription>
</FlexChild>
</StatsFlex>
</VolunteerStatsContainer>
</DashboardContainer>
Expand Down
19 changes: 19 additions & 0 deletions lib/useUserData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { fetchData } from '@/utils/utils';
import { QueriedUserData } from 'bookem-shared/src/types/database';
import { useEffect, useState } from 'react';

/**
* Custom hook to fetch user data and return
* @returns
*/
export const useUserData = () => {
const [userData, setUserData] = useState<QueriedUserData | null>(null);

useEffect(() => {
fetchData('/api/users/')
.then(data => setUserData(data))
.catch(err => console.error('Error fetching user data:', err));
}, []);

return userData;
};
Loading

0 comments on commit 1f7d7f0

Please sign in to comment.