-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dashboard fix #65
Merged
Merged
Dashboard fix #65
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d4d6f48
replaced all fake data with real user data
Josephine0110 e74a4ca
fixed the usericon file
Josephine0110 f32c6fe
Merge branch 'main' into dashboard-fix
JiashuHarryHuang ed7d9b0
Make the info icon clickable in main dashboard
Josephine0110 71861ac
Fix compilation and prettier
JiashuHarryHuang 93870e6
Use proper type
JiashuHarryHuang 057d57c
Use session data for sidebar. No need for another query
JiashuHarryHuang 8fe91f8
Move fetch user data logic and format date out
JiashuHarryHuang 07fdf94
Refactor and add similar logic in volunteer page
JiashuHarryHuang 5039667
Rename to events attended'
JiashuHarryHuang df3a636
Add comments
JiashuHarryHuang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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 | ||
|
@@ -27,48 +30,58 @@ import { | |
* dollarsDonated: number; | ||
* } | ||
*/ | ||
const MainDashboard = ({ userData }: any) => { | ||
const MainDashboard = ({ userData }: { userData: QueriedUserData | null }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using "any" type |
||
// state for showing mobile past activities | ||
const [onMobilePastActivity, setOnMobilePastActivity] = useState(false); | ||
|
||
const content = ( | ||
<div> | ||
<p>This is the main dashboard for book'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> | ||
|
@@ -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> | ||
|
@@ -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> | ||
)} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { fetchData } from '@/utils/utils'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a custom hook to avoid duplicate code. |
||
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; | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need username here so using session data would be enough