diff --git a/components/admin/DashboardTableTitle.tsx b/components/admin/DashboardTableTitle.tsx index c5d2ae8..d7d341a 100644 --- a/components/admin/DashboardTableTitle.tsx +++ b/components/admin/DashboardTableTitle.tsx @@ -1,12 +1,18 @@ -import React, { FC } from "react"; +import React, { FC, useState, createContext, useContext } from "react"; import Tabs from "@mui/material/Tabs"; import Tab from "@mui/material/Tab"; +import ExpandableRowTable from "./ExpandableRowTable"; +import { set } from "firebase/database"; interface TitleProps { numFirstChoiceEntries?: number; numSecondChoiceEntries?: number; setWhichChoiceTab: (tab: number) => void; whichChoiceTab?: number; + edit: boolean; + toggleEdit: () => void; + saved?: boolean; + toggleSaved: () => void; } interface TabDescriptionProps { title: string; @@ -26,18 +32,65 @@ const TabDescription: FC = ({ ); + + +export const EditButton = ({ edit, toggleEdit, saved, toggleSaved}: { edit: boolean, toggleEdit: () => void, saved: any, toggleSaved: () => void}) => { + const editButton = + "border-2 border-blue rounded-full text-blue text-center px-8 py-1 m-2 inline-block capitalize bg-white"; + + + // set saveFn to randomFn + // saveFn = randomFn; + + const onSave = () => { + toggleSaved(); + toggleEdit(); + } + + return ( + ( edit ? ( +
+ + +
+ ): ( + + ) + ) + ) +} + const TableTitle: FC = ({ numFirstChoiceEntries, numSecondChoiceEntries, setWhichChoiceTab, whichChoiceTab, + edit, + toggleEdit, + saved, + toggleSaved }) => { const pillStyle = "border-2 border-blue-100 text-blue rounded-full px-4 py-2 m-2 font-large inline-block"; - // const editButton = - // "border-2 border-blue rounded-full text-blue text-center px-8 py-1 m-2 inline-block capitalize bg-white"; - const handleChange = (event: React.SyntheticEvent, newValue: number) => { setWhichChoiceTab(newValue); }; @@ -71,21 +124,8 @@ const TableTitle: FC = ({ /> - {/* */} + + {/* */} ); }; diff --git a/components/admin/ExpandableRowTable.tsx b/components/admin/ExpandableRowTable.tsx index 6d09257..54731f2 100644 --- a/components/admin/ExpandableRowTable.tsx +++ b/components/admin/ExpandableRowTable.tsx @@ -1,5 +1,5 @@ // InnerTableComponent.tsx -import React from "react"; +import React, {useState, useEffect} from "react"; import MUIDataTable, { MUIDataTableColumn, MUIDataTableOptions, @@ -7,6 +7,9 @@ import MUIDataTable, { import { getExpandableRowMuiTheme } from "utils/muidatatable"; import { MuiThemeProvider } from "@material-ui/core"; import { SkillCategory } from "@utils/muidatatable"; +import { set } from "firebase/database"; +import { fetchGraphql } from "@utils/makegqlrequest"; +import { mutations } from "graphql/queries"; type ReviewerData = { reviewerName: string; @@ -21,9 +24,112 @@ type ReviewerData = { interface InnerTableProps { data: ReviewerData[]; columns: MUIDataTableColumn[]; + edit?: boolean; + toggleEdit?: () => void; + saved?: boolean; + toggleSaved: any; } -const ExpandableRowTable: React.FC = ({ data, columns }) => { +const ExpandableRowTable: React.FC = ({ data, columns, edit, saved, toggleSaved}) => { + + const initData1 = {"PFSG": data[0]["PFSG"], "team": data[0]["Team Player"], "D2L": data[0]["D2L"], "skill": data[0]["Skill"]} + const initData2 = {"PFSG": data[1]["PFSG"], "team": data[1]["Team Player"], "D2L": data[1]["D2L"], "skill": data[1]["Skill"]} + + const reviewerId1 = data[0]["ReviewerId"]; + const reviewerId2 = data[1]["ReviewerId"]; + + const [PFSG1, setPFSG1] = useState(initData1["PFSG"]) + const [team1, setTeam1] = useState(initData1["team"]) + const [D2L1, setD2L1] = useState(initData1["D2L"]) + const [skill1, setSkill1] = useState(initData1["skill"]) + + const [PFSG2, setPFSG2] = useState(initData2["PFSG"]) + const [team2, setTeam2] = useState(initData2["team"]) + const [D2L2, setD2L2] = useState(initData2["D2L"]) + const [skill2, setSkill2] = useState(initData2["skill"]) + + // Logic: When the state of saved is changed, the useEffect will run only if saved is true + useEffect(() => { + if (saved){ + fetchGraphql(mutations.changeRating, {id: reviewerId1, ratingToBeChanged: "passionFSG", newValue: PFSG1}).then( + (result) => { + if (result) { + console.log(result) + }}, + ) + fetchGraphql(mutations.changeRating, {id: reviewerId1, ratingToBeChanged: "teamPlayer", newValue: team1}).then( + (result) => { + if (result) { + console.log(result) + }}, + ) + fetchGraphql(mutations.changeRating, {id: reviewerId1, ratingToBeChanged: "desireToLearn", newValue: D2L1}).then( + (result) => { + if (result) { + console.log(result) + }}, + ) + fetchGraphql(mutations.changeRating, {id: reviewerId1, ratingToBeChanged: "skill", newValue: skill1}).then( + (result) => { + if (result) { + console.log(result) + }}, + ) + fetchGraphql(mutations.changeRating, {id: reviewerId2, ratingToBeChanged: "passionFSG", newValue: PFSG2}).then( + (result) => { + if (result) { + console.log(result) + }}, + ) + fetchGraphql(mutations.changeRating, {id: reviewerId2, ratingToBeChanged: "teamPlayer", newValue: team2}).then( + (result) => { + if (result) { + console.log(result) + }}, + ) + fetchGraphql(mutations.changeRating, {id: reviewerId2, ratingToBeChanged: "desireToLearn", newValue: D2L2}).then( + (result) => { + if (result) { + console.log(result) + }}, + ) + fetchGraphql(mutations.changeRating, {id: reviewerId2, ratingToBeChanged: "skill", newValue: skill2}).then( + (result) => { + if (result) { + console.log(result) + }}, + ) + toggleSaved(); + } + }, [saved]); + + const handleChange = (event: any, row: number) => { + const { id, value } = event.target; + + if(edit && row == 0) { + if (id == "PFSG"){ + setPFSG1(parseInt(value)) + } else if (id == "Team Player") { + setTeam1(parseInt(value)) + } else if (id == "D2L") { + setD2L1(parseInt(value)) + } else if (id == "Skill"){ + setSkill1(parseInt(value)) + } + } + if (edit && row == 1) { + if (id == "PFSG"){ + setPFSG2(parseInt(value)) + } else if (id == "Team Player") { + setTeam2(parseInt(value)) + } else if (id == "D2L") { + setD2L2(parseInt(value)) + } else if (id == "Skill"){ + setSkill2(parseInt(value)) + } + } + }; + const updatedColumns = columns.map((column) => { if (column.name === "Skill Category") { return { @@ -36,6 +142,61 @@ const ExpandableRowTable: React.FC = ({ data, columns }) => { }, }; } + const getValue = (value: number, column: MUIDataTableColumn, row: number) => { + if (edit && row == 0) { + if (column.name == "PFSG"){ + return PFSG1 + } else if (column.name == "Team Player") { + return team1 + } else if (column.name == "D2L") { + return D2L1 + } else if (column.name == "Skill"){ + return skill1 + } + } + else if (edit && row == 1) { + if (column.name == "PFSG"){ + return PFSG2 + } else if (column.name == "Team Player") { + return team2 + } else if (column.name == "D2L") { + return D2L2 + } else if (column.name == "Skill"){ + return skill2 + } + } + else { + return value + } + } + + // Add custom body render for the values when edit is true + if (edit) { + if (column.name === "PFSG" || column.name === "Team Player" || column.name === "D2L" || column.name === "Skill") { + return { + ...column, + options: { + ...column.options, + customBodyRender: (value: number, tableMeta: any) => { + return ( + handleChange(e, tableMeta.rowIndex)} + id={column.name} + style={{ + width: '40px', + padding: '5px', + border: '1px solid #ccc', + borderRadius: '4px' + }} + /> + ); + }, + }, + }; + } + } return column; }); diff --git a/components/admin/ReviewTable.tsx b/components/admin/ReviewTable.tsx index c186aed..aa66b61 100644 --- a/components/admin/ReviewTable.tsx +++ b/components/admin/ReviewTable.tsx @@ -16,6 +16,10 @@ interface TableProps { numFirstChoiceEntries?: number; setNumSecondChoiceEntries: (tab: number) => void; numSecondChoiceEntries?: number; + edit?: boolean; + toggleEdit?: () => void; + saved?: boolean; + toggleSaved?: () => void; } const ReviewTable: React.FC = ({ @@ -23,6 +27,10 @@ const ReviewTable: React.FC = ({ whichChoiceTab, setNumFirstChoiceEntries, setNumSecondChoiceEntries, + edit, + toggleEdit, + saved, + toggleSaved, }) => { const [firstChoiceApplications, setFirstChoiceApplications] = useState( [], @@ -91,26 +99,53 @@ const ReviewTable: React.FC = ({ return secondChoiceApplications.map(createStudentRow); }; - const generateMockInnerData = () => { - return [ + const generateInnerData = (dataindex: number): any => { + const reviewerScore = firstChoiceApplications[dataindex].reviewDashboards; + const reviewer = firstChoiceApplications[dataindex].reviewers; + + const firstScore = reviewerScore[0]; + const secondScore = reviewerScore[1]; + + const firstReviewer = reviewer[0]; + const secondReviewer = reviewer[1]; + + if (!firstReviewer || !secondReviewer) { + return [{},{}]; + } + + const collectedReviewers = [ { - "Reviewer Name": "John Doe", - PFSG: 4, - "Team Player": 3, - D2L: 6, - Skill: 5, - "Skill Category": "junior", - "Reviewer Comments": "Great work presenting your case study.", + "Reviewer Name": firstReviewer.firstName + " " + firstReviewer.lastName, + PFSG: firstScore.passionFSG, + "Team Player": firstScore.teamPlayer, + D2L: firstScore.desireToLearn, + Skill: firstScore.skill, + "Total Score": firstScore.passionFSG + firstScore.teamPlayer + firstScore.desireToLearn + firstScore.skill, + "Skill Category": firstScore.skillCategory, + "Reviewer Comments": firstScore.reviewerComments, + "ReviewerId": firstScore.reviewerId, }, - // Add as many objects as you want to simulate different rows - ]; + { + "Reviewer Name": secondReviewer.firstName + " " + secondReviewer.lastName, + PFSG: secondScore.passionFSG, + "Team Player": secondScore.teamPlayer, + D2L: secondScore.desireToLearn, + Skill: secondScore.skill, + "Total Score": secondScore.passionFSG + secondScore.teamPlayer + secondScore.desireToLearn + secondScore.skill, + "Skill Category": secondScore.skillCategory, + "Reviewer Comments": secondScore.reviewerComments, + "ReviewerId": secondScore.reviewerId, + }, + ] + + return (collectedReviewers); }; const renderExpandableRow = ( rowData: any, rowMeta: { dataIndex: number }, ) => { - const innerData = generateMockInnerData(); // Use mock data for testing + const reviewers = generateInnerData(rowMeta.dataIndex); const application = { secondChoiceRole: "Graphic Designer", recommendForSecondChoice: true, @@ -126,6 +161,10 @@ const ReviewTable: React.FC = ({ { name: "Team Player", options: { filter: false, sort: false } }, { name: "D2L", options: { filter: false, sort: false } }, { name: "Skill", options: { filter: false, sort: false } }, + { + name: "Total Score", + options: { filter: false, sort: false }, + }, { name: "Skill Category", options: { filter: false, sort: false }, @@ -142,7 +181,7 @@ const ReviewTable: React.FC = ({
- +
diff --git a/components/admin/Table.tsx b/components/admin/Table.tsx index 2f73e1e..8fb7e14 100644 --- a/components/admin/Table.tsx +++ b/components/admin/Table.tsx @@ -1,4 +1,4 @@ -import React, { FC } from "react"; +import React, { FC, useState } from "react"; import DropdownMenu from "./DropdownMenu"; import { Avatar } from "./Profile"; import Tabs from "./Tabs"; @@ -9,6 +9,7 @@ import TableTitle from "./DashboardTableTitle"; import ApplicationsTable from "./ApplicationsTable"; import ApplicantRole from "entities/applicationRole"; import ReviewTable from "./ReviewTable"; +import { set } from "firebase/database"; export enum OrganizationalArea { Engineering = "Engineering", @@ -35,6 +36,18 @@ const Table: FC = () => { const [selectedDropdownItem, setSelectedDropdownItem] = React.useState("Delegation Dashboard"); + const [edit, setEdit] = useState(false); + + const toggleEdit = () => { + setEdit(!edit); + } + + const [saved, setSaved] = useState(false); + + const toggleSaved = () => { + setSaved(!saved); + } + const handleDropdownChange = (selectedItem: string) => { setSelectedDropdownItem(selectedItem); }; @@ -80,6 +93,10 @@ const Table: FC = () => { numSecondChoiceEntries={numSecondChoiceEntries} setWhichChoiceTab={setWhichChoiceTab} whichChoiceTab={whichChoiceTab} + edit={edit} + toggleEdit={toggleEdit} + saved={saved} + toggleSaved={toggleSaved} /> {selectedDropdownItem === "Review Dashboard" && ( { numFirstChoiceEntries={numFirstChoiceEntries} setNumSecondChoiceEntries={setNumSecondChoiceEntries} numSecondChoiceEntries={numSecondChoiceEntries} + edit={edit} + toggleEdit={toggleEdit} + saved={saved} + toggleSaved={toggleSaved} /> )} {selectedDropdownItem === "Delegation Dashboard" && ( diff --git a/graphql/queries.ts b/graphql/queries.ts index 9a6bd37..075c789 100644 --- a/graphql/queries.ts +++ b/graphql/queries.ts @@ -17,6 +17,12 @@ export const mutations = { refresh(refreshToken: $refreshToken) } `, + changeRating: ` + mutation changeRating($id: Int!, $ratingToBeChanged: String!, $newValue: Int!) { + changeRating(id: $id, ratingToBeChanged: $ratingToBeChanged, newValue: $newValue) { + id + } + }`, }; // TODO: add functionaltiy to getRole in case accessToken expired and needs to be refreshed. @@ -79,10 +85,13 @@ export const applicationTableQueries = { lastName } reviewDashboards { + reviewerId passionFSG teamPlayer desireToLearn + skill skillCategory + reviewerComments } } }