Skip to content

Commit

Permalink
Merge branch 'feat/user-profiles/frontend' of https://github.com/csmb…
Browse files Browse the repository at this point in the history
…erkeley/csm_web into feat/user-profiles/frontend
  • Loading branch information
jacovkim committed Oct 17, 2023
2 parents f904047 + 567d7b2 commit 171128e
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 4 deletions.
109 changes: 106 additions & 3 deletions csm_web/frontend/src/components/section/StudentSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Navigate, Route, Routes } from "react-router-dom";
import {
useDropUserMutation,
useStudentAttendances,
useStudentSubmitWordOfTheDayMutation
useStudentSubmitWordOfTheDayMutation,
useSectionStudents
} from "../../utils/queries/sections";
import { Mentor, Override, Spacetime } from "../../utils/types";
import Modal from "../Modal";
Expand Down Expand Up @@ -47,14 +48,16 @@ export default function StudentSection({
userRole={ROLES.STUDENT}
links={[
["Section", ""],
["Attendance", "attendance"]
["Attendance", "attendance"],
["Students", "students"]
]}
>
<Routes>
<Route
path="attendance"
element={<StudentSectionAttendance associatedProfileId={associatedProfileId} id={id} />}
/>
<Route path="students" element={<StudentList associatedProfileId={associatedProfileId} id={id} />} />
<Route
index
element={
Expand Down Expand Up @@ -87,9 +90,11 @@ function StudentSectionInfo({ mentor, spacetimes, override, associatedProfileId
{mentor && (
<InfoCard title="Mentor">
<h5>{mentor.name}</h5>
<a href={`mailto:${mentor.email}`}>{mentor.email}</a>
{/* <a href={`mailto:${mentor.email}`}>{mentor.email}</a> */}
<ProfileSection profileId={associatedProfileId} />
</InfoCard>
)}

{spacetimes.map(({ override, ...spacetime }, index) => (
<SectionSpacetime
manySpacetimes={spacetimes.length > 1}
Expand Down Expand Up @@ -155,6 +160,46 @@ function DropSection({ profileId }: DropSectionProps) {
}
}

interface ProfileSectionProps {
profileId: number;
}

enum ProfileSectionStage {
CLOSED = "CLOSED",
OPENED = "OPENED"
}

function ProfileSection({ profileId }: ProfileSectionProps) {

Check warning on line 172 in csm_web/frontend/src/components/section/StudentSection.tsx

View workflow job for this annotation

GitHub Actions / ESLint

csm_web/frontend/src/components/section/StudentSection.tsx#L172

'profileId' is defined but never used (@typescript-eslint/no-unused-vars)
// const studentDropMutation = useDropUserMutation(profileId);
const [stage, setStage] = useState<ProfileSectionStage>(ProfileSectionStage.CLOSED);

// const performDrop = () => {
// studentDropMutation.mutate(undefined, {
// onSuccess: () => {
// setStage(ProfileSectionStage.CLOSED);
// }
// });
// };

switch (stage) {
case ProfileSectionStage.CLOSED:
return (
<button className="primary-btn" onClick={() => setStage(ProfileSectionStage.OPENED)}>
Profile
</button>
);
case ProfileSectionStage.OPENED:
return (
<Modal closeModal={() => setStage(ProfileSectionStage.CLOSED)}>
<div className="profile-information">
<h5>Are you sure you want to drop?</h5>
<p>You are not guaranteed an available spot in another section!</p>
</div>
</Modal>
);
}
}

interface StudentSectionAttendanceProps {
associatedProfileId: number;
id: number;
Expand Down Expand Up @@ -358,3 +403,61 @@ function StudentSectionAttendance({ associatedProfileId, id }: StudentSectionAtt
<LoadingSpinner className="spinner-centered" />
);
}

interface StudentListProps {
associatedProfileId: number;
id: number;
}

// Need permission for student to load student list, or new backend point?
function StudentList({ associatedProfileId, id }: StudentListProps) {

Check warning on line 413 in csm_web/frontend/src/components/section/StudentSection.tsx

View workflow job for this annotation

GitHub Actions / ESLint

csm_web/frontend/src/components/section/StudentSection.tsx#L413

'id' is defined but never used (@typescript-eslint/no-unused-vars)
const {
data: studentList,
isSuccess: listLoaded,
isError: listLoadError,
refetch: refetchStudentList

Check warning on line 418 in csm_web/frontend/src/components/section/StudentSection.tsx

View workflow job for this annotation

GitHub Actions / ESLint

csm_web/frontend/src/components/section/StudentSection.tsx#L418

'refetchStudentList' is assigned a value but never used (@typescript-eslint/no-unused-vars)
} = useSectionStudents(associatedProfileId);

return listLoaded ? (
<React.Fragment>
<div id="word-of-the-day-card">
<h3 className="word-of-the-day-title">Submit Word of the Day</h3>
<div className="word-of-the-day-action-container">
<div className="word-of-the-day-submit-container"></div>
</div>
<div className="word-of-the-day-status-bar">
<div className="word-of-the-day-deadline-container"></div>
</div>
</div>
<table id="attendance-table" className="csm-table standalone">
<thead className="csm-table-head">
<tr className="csm-table-head-row">
<th className="csm-table-item">Name</th>
<th className="csm-table-item">Profile</th>
</tr>
</thead>
<tbody>
{studentList
// convert to a table row
.map(({ name, email }) => {
// const [label, cssSuffix] = ATTENDANCE_LABELS[presence];
// const attendanceColor = scssColors[`attendance-${cssSuffix}`];
// const attendanceFgColor = scssColors[`attendance-${cssSuffix}-fg`];
return (
<tr key={email} className="csm-table-row">
<td className="csm-table-item">{name}</td>
<td className="csm-table-item">
<div className="attendance-status">{email}</div>
</td>
</tr>
);
})}
</tbody>
</table>
</React.Fragment>
) : listLoadError ? (
<h3>Student List could not be loaded</h3>
) : (
<LoadingSpinner className="spinner-centered" />
);
}
25 changes: 24 additions & 1 deletion csm_web/frontend/src/utils/queries/sections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import { useMutation, UseMutationResult, useQuery, useQueryClient, UseQueryResult } from "@tanstack/react-query";
import { fetchNormalized, fetchWithMethod, HTTP_METHODS } from "../api";
import { Attendance, RawAttendance, Section, Spacetime, Student } from "../types";
import { Attendance, RawAttendance, Section, Spacetime, Student, UserInfo } from "../types";

Check warning on line 7 in csm_web/frontend/src/utils/queries/sections.tsx

View workflow job for this annotation

GitHub Actions / ESLint

csm_web/frontend/src/utils/queries/sections.tsx#L7

'UserInfo' is defined but never used (@typescript-eslint/no-unused-vars)
import { handleError, handlePermissionsError, handleRetry, PermissionError, ServerError } from "./helpers";

/* ===== Queries ===== */
Expand Down Expand Up @@ -112,6 +112,29 @@ export const useStudentAttendances = (studentId: number): UseQueryResult<Attenda
return queryResult;
};

// // Get all students attending this section. Need new backend entry points
// export const useStudentList = (studentId: number): UseQueryResult<Student[], ServerError> => {
// const queryResult = useQuery<Student[], Error>(
// ["students", studentId, "attendance"],
// async () => {
// if (isNaN(studentId)) {
// throw new PermissionError("Invalid student id");
// }
// const response = await fetchNormalized(`/students/${studentId}/attendances`);
// if (response.ok) {
// return await response.json();
// } else {
// handlePermissionsError(response.status);
// throw new ServerError(`Failed to fetch student ${studentId} attendances`);
// }
// },
// { retry: handleRetry }
// );
//
// handleError(queryResult);
// return queryResult;
// };

interface WordOfTheDayResponse {
id: number; // section occurrence id
wordOfTheDay: string;
Expand Down

0 comments on commit 171128e

Please sign in to comment.