diff --git a/csm_web/frontend/src/components/section/MentorSectionInfo.tsx b/csm_web/frontend/src/components/section/MentorSectionInfo.tsx index 582ee38f..e9c26c59 100644 --- a/csm_web/frontend/src/components/section/MentorSectionInfo.tsx +++ b/csm_web/frontend/src/components/section/MentorSectionInfo.tsx @@ -101,7 +101,9 @@ export default function MentorSectionInfo({ > View - {showModal === ModalStates.SPACETIME_EDIT && } + {showModal === ModalStates.SPACETIME_EDIT && ( + + )} ) diff --git a/csm_web/frontend/src/components/section/ProfileModal.tsx b/csm_web/frontend/src/components/section/ProfileModal.tsx index 1e16cf86..56a8155b 100644 --- a/csm_web/frontend/src/components/section/ProfileModal.tsx +++ b/csm_web/frontend/src/components/section/ProfileModal.tsx @@ -2,14 +2,21 @@ import React, { useState } from "react"; import LoadingSpinner from "../LoadingSpinner"; import Modal from "../Modal"; import { useUserInfo } from "../../utils/queries/base"; +import { UseUserInfoWithId } from "../../utils/queries/profiles"; import { UserInfo } from "../../utils/types"; +import { useSectionStudents } from "../../utils/queries/sections"; interface ProfileModalProps { + id: number; closeModal: () => void; } -const ProfileModal = ({ closeModal }: ProfileModalProps): React.ReactElement => { - const { data: jsonUserInfo, isSuccess: userInfoLoaded } = useUserInfo(); +const ProfileModal = ({ id, closeModal }: ProfileModalProps): React.ReactElement => { + // const { data: jsonUserInfo, isSuccess: userInfoLoaded } = UseUserInfoWithId(id); + const { data: jsonUserInfo, isSuccess: userInfoLoaded } = useSectionStudents(id); + console.log(id); + console.log(); + console.log(jsonUserInfo); let userInfo: UserInfo | null; if (userInfoLoaded) { diff --git a/csm_web/frontend/src/utils/queries/profiles.tsx b/csm_web/frontend/src/utils/queries/profiles.tsx index f80df167..726157b7 100644 --- a/csm_web/frontend/src/utils/queries/profiles.tsx +++ b/csm_web/frontend/src/utils/queries/profiles.tsx @@ -6,6 +6,7 @@ import { useMutation, UseMutationResult, useQuery, useQueryClient, UseQueryResul import { fetchNormalized, fetchWithMethod, HTTP_METHODS } from "../api"; import { handleError, handlePermissionsError, handleRetry, PermissionError, ServerError } from "./helpers"; import { DateTime } from "luxon"; +import { RawUserInfo } from "../types"; /* ===== Mutation ===== */ /** @@ -22,6 +23,28 @@ export interface UpdateUserInfo { pronouns: string; } +/** + * Hook to get the user's info. + */ +export const useStudentsInfo = (): UseQueryResult => { + const queryResult = useQuery( + ["students"], + async () => { + const response = await fetchNormalized("/students"); + if (response.ok) { + return await response.json(); + } else { + handlePermissionsError(response.status); + throw new ServerError("Failed to fetch user info"); + } + }, + { retry: handleRetry } + ); + + handleError(queryResult); + return queryResult; +}; + export const useUserInfoUpdateMutation = (userId: number): UseMutationResult => { const queryClient = useQueryClient(); const mutationResult = useMutation( @@ -29,12 +52,12 @@ export const useUserInfoUpdateMutation = (userId: number): UseMutationResult => { + const queryResult = useQuery( + ["userinfo", id], + async () => { + const response = await fetchNormalized("/userinfo"); + if (response.ok) { + return await response.json(); + } else { + handlePermissionsError(response.status); + throw new ServerError("Failed to fetch user info"); + } + }, + { retry: handleRetry } + ); + + handleError(queryResult); + return queryResult; +};