Skip to content
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

UI for Student dashboard #33

Merged
merged 23 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3de8b6a
added student dashboard UI draft
home0712 Apr 1, 2024
ba1cb9a
added a dropdown icon for disclosure
home0712 Apr 1, 2024
ee86d55
dashboard draft chore
home0712 Apr 13, 2024
6493467
student dashboard draft with merged recent main
home0712 Apr 13, 2024
bb3c43e
student dashborad UI draft
home0712 Apr 21, 2024
0dfa7fb
Merge branch 'main' into student-dashboard
home0712 Apr 23, 2024
2560494
UI for student dashboard draft with useEffect incompeleted
home0712 Apr 25, 2024
3e2c030
UI for student dashboard final draft
home0712 Apr 26, 2024
07595ce
student dashboard final draft
home0712 Apr 26, 2024
2aa832c
deleted Home link
home0712 Apr 28, 2024
7badb0f
Merge branch 'main' into student-dashboard
home0712 Apr 28, 2024
c8a4fcb
disclosure error
home0712 Apr 28, 2024
59a89c6
deleted disclosure, and replaced it with a new code
home0712 Apr 28, 2024
8512708
deleted test code
home0712 Apr 28, 2024
475dd18
deleted test code and chores
home0712 Apr 28, 2024
12fac0a
added dropdown arrow icon functionality
nkanchinadam Apr 29, 2024
af01f00
changed icon alt
nkanchinadam Apr 29, 2024
cd850f2
made the dropdown appear more like the iframe is a part of the dropdo…
nkanchinadam Apr 29, 2024
6ad5df7
used correct auth object
nkanchinadam Apr 29, 2024
4349fac
modified return JSON of getSurveyByID and getUserByID routes
nkanchinadam Apr 29, 2024
a1f2f30
added formTitle field to Response type
nkanchinadam Apr 29, 2024
8646e30
modified data fetching of StudentDashboardPage
nkanchinadam Apr 29, 2024
e7c2cc7
fixed overlapping divs in Completed Surveys section
nkanchinadam Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
326 changes: 326 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@fortawesome/fontawesome-free": "^6.5.2",
"@google-cloud/pubsub": "^4.3.3",
"@googleapis/forms": "^2.0.5",
"@headlessui/react": "^1.7.18",
"@types/nodemailer": "^6.4.14",
"canvas": "^2.11.2",
"firebase": "^10.8.1",
Expand Down
File renamed without changes
Binary file added public/icons/down-arrow-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added public/icons/up-arrow-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/app/api/surveys/[surveyId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function GET(
const { surveyId } = params;
try {
const survey = await getSurveyByID(surveyId);
return NextResponse.json({ data: survey }, { status: 200 });
return NextResponse.json(survey, { status: 200 });
} catch (err) {
return NextResponse.json(
{ error: "error getting survey by id" },
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/users/[userId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export async function GET(
const userid = params.userId;

try {
const result = await getAccountById(userid);
return NextResponse.json({ result }, { status: 200 });
const user = await getAccountById(userid);
return NextResponse.json(user, { status: 200 });
} catch {
return NextResponse.json(
{ error: "Error with Getting the Account Via the Given ID" },
Expand Down
122 changes: 122 additions & 0 deletions src/app/student-dashboard/StudentDashboard.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
.container {
display: flex;
min-height: 100vh;
width: 100%;
box-sizing: border-box;
}

.sidebar {
flex: 0 0 22%;
display: flex;
background-color: #D0D12A;
flex-direction: column;
min-height: 100%;
position: relative;
min-width: 300px;
max-width: 300px;
}

.img {
height: 100px;
width: 300px;
display: block;
margin: 10% auto;
}

.info {
display: block;
margin-left: 10%;
margin-right: 10%;
text-decoration: none;
color: black;
font-size: 20px;
}

.settingButton {
background-color: #D9D9D9;
border: none;
border-radius: 15px;
text-align: center;
font-size: 20px;
display: block;
padding: 10px 15px;
margin-top: 10px;
margin-left: auto;
margin-right: auto;
}

.logOut {
text-decoration: none;
color: black;
font-size: 20px;
display: block;
margin: 0 10%;
margin-bottom: 10%;
position: absolute;
bottom: 0;
}

.mainContent {
flex: 1;
background-color: #295972;
min-width: 320px;
box-sizing: border-box;
padding: 20px 5%;
}

.surveyTitle {
color: white;
font-size: 30px;
margin-bottom: 5px;
}

.horizontalLine {
border: 1px solid white;
width: auto;
}

.surveyContainer {
background-color: white;
color: black;
border-radius: 25px;
padding: 0px;
margin-top: 10px;
display: flex;
flex-direction: column;
align-items: center;
}

.assignedSurveyButton, .completedSurveyButton {
border: none;
border-radius: 25px;
width: 100%;
padding: 10px;
padding-left: 25px;
display: inline-block;
font-size: 18px;
text-align: left;
position: relative;
}

.vector {
position: absolute;
right: 15px;
top: 50%;
transform: translateY(-50%);
}

.completedSurveyButton {
background-color: #D0D12A;
width: 96%;
margin-bottom: 10px;
}

.assignedSurveyPanel {
width: 100%;
}

.form {
margin-top: 1%;
width: 95%;
height: 600px;
}
105 changes: 105 additions & 0 deletions src/app/student-dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
'use client';

import styles from "./StudentDashboard.module.css";
import CompanyLogo from "@/../public/images/logo.svg";
import UpArrow from '@/../public/icons/up-arrow-icon.png'
import DownArrow from '@/../public/icons/down-arrow-icon.png'
import Image from "next/image"
import Link from "next/link"
import React, { useState, useEffect } from "react";
import { User } from "@/types/user-types";
import { Survey, Response } from '@/types/survey-types';
import { auth } from '@/lib/firebase/firebaseConfig';

export default function StudentDashboard() {
const [user, setUser] = useState<User | null>(null);
const [surveys, setSurveys] = useState<Survey[]>([]);
const [responses, setResponses] = useState<string[]>([]);
const [openSurvey, setOpenSurvey] = useState('');

const fetchCurrentUserData = async (userId: string) => {
try {
const res = await fetch(`/api/users/${userId}`);
const user: User = await res.json();
setUser(user);

Promise.all(user.assignedSurveys.map(surveyId => fetch(`/api/surveys/${surveyId}`))).then(responses => {
Promise.all(responses.map(res => res.json())).then((surveys: Survey[]) => {
setSurveys(surveys);
})
})

Promise.all(user.completedResponses.map(responseId => fetch(`/api/responses/${responseId}`))).then(responses => {
Promise.all(responses.map(res => res.json())).then((responses: Response[]) => {
setResponses(responses.map(response => response.formTitle))
})
})
} catch (error) {
console.error(error);
throw new Error('unable to fetch data for student dashboard');
}
}

useEffect(() => {
const user = auth.currentUser;
if (user) {
fetchCurrentUserData(user.uid);
} else {
console.log('no signed-in user');
}
}, []);

const handleSurveyButtonClick = (surveyId: string) => {
setOpenSurvey(surveyId === openSurvey ? '' : surveyId);
};

return (
<div className={styles.container}>
<div className={styles.sidebar}>
<Image src={CompanyLogo} alt="Company Logo" className={styles.img} />
<p className={styles.info}>
Student ID: {user?.id || "No user ID found"}
</p>
<button className={styles.settingButton}>Settings</button>
<Link href="/" className={styles.logOut}>
Log Out
</Link>
</div>
<div className={styles.mainContent}>
<p className={styles.surveyTitle}>Available Surveys</p>
<hr className={styles.horizontalLine} />
{surveys.map((survey) => (
<div key={survey.formId} className={styles.surveyContainer}>
<button
onClick={() => handleSurveyButtonClick(survey.formId)}
className={styles.assignedSurveyButton}
>
{survey.info.title}
<Image
src={openSurvey === survey.formId ? DownArrow : UpArrow}
alt={openSurvey === survey.formId ? "DownArrow" : "UpArrow"}
className={styles.vector}
/>
</button>
{openSurvey === survey.formId && (
<iframe
key={survey.formId}
src={survey.responderUri}
title={survey.info.title}
allowFullScreen={true}
className={styles.form}
/>
)}
</div>
))}
<p className={styles.surveyTitle}>Completed Surveys</p>
<hr className={styles.horizontalLine} />
{responses.map((response) => (
<span key={response} className={styles.completedSurveyButton}>
{response}
</span>
))}
</div>
</div>
);
}
1 change: 1 addition & 0 deletions src/types/survey-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface GoogleFormResponse {

export interface Response extends GoogleFormResponse {
userId: string;
formTitle: string;
}

// Info and settings
Expand Down
Loading