|
1 |
| -import { generateClient } from "aws-amplify/data"; |
2 |
| -import Image from "next/image"; |
3 |
| -import { useState } from "react"; |
| 1 | +import Greetings from "@/components/Dashboard/Greetings"; |
| 2 | +import client from "@/components/_Amplify/AmplifyBackendClient"; |
4 | 3 |
|
5 |
| -import { type Schema } from "@/amplify/data/resource"; |
6 |
| -import LoadingRing from "@/components/LoadingRing"; |
7 |
| -import { useUser } from "@/components/contexts/UserContext"; |
8 |
| -import ModalPopup from "@/components/judging/ModalPopup"; |
9 |
| -import ScoresTable from "@/components/judging/ScoresTable"; |
10 |
| -import StatsPanel from "@/components/judging/StatsPanel"; |
11 |
| -import { useQuery } from "@tanstack/react-query"; |
| 4 | +import JudgingTable from "./JudgingTable"; |
12 | 5 |
|
13 |
| -const pink_underlines = "/svgs/judging/pink_underline.svg"; |
14 |
| - |
15 |
| -const LOADING_SCREEN_STYLES = |
16 |
| - "flex h-screen w-full items-center justify-center bg-pastel-pink"; |
17 |
| - |
18 |
| -const JUDGE_DASHBOARD_PAGE_STYLES = |
19 |
| - "flex justify-center text-blackish h-screen"; |
20 |
| -const JUDGE_DASHBOARD_CONTENT_STYLES = "w-full max-w-[1500px] p-6"; |
21 |
| - |
22 |
| -const JUDGE_DASHBOARD_HELLO_TILE_STYLES = |
23 |
| - "mb-6 flex rounded-lg bg-white p-8 pb-6 text-4xl font-semibold drop-shadow-md"; |
24 |
| - |
25 |
| -const SUBHEADER_TEXT_STYLES = "mb-4 text-xl font-semibold"; |
26 |
| - |
27 |
| -const client = generateClient<Schema>(); |
28 |
| - |
29 |
| -const JudgingDashboard = () => { |
30 |
| - const [selectedTeam, setSelectedTeamId] = useState(""); |
31 |
| - |
32 |
| - const { currentUser } = useUser(); |
33 |
| - |
34 |
| - const { data: roomData, isFetching: roomIsFetching } = useQuery({ |
35 |
| - queryKey: ["RoomForJudge", currentUser.JUDGE_roomId], |
36 |
| - queryFn: async () => { |
37 |
| - const { data, errors } = await client.models.Room.get({ |
38 |
| - id: currentUser.JUDGE_roomId, |
39 |
| - }); |
40 |
| - console.log(currentUser); |
41 |
| - console.log(data); |
42 |
| - if (errors) throw Error(errors[0].message); |
43 |
| - |
44 |
| - return data; |
45 |
| - }, |
46 |
| - }); |
47 |
| - |
48 |
| - const { data: hackathonData, isFetching: hackathonIsFetching } = useQuery({ |
49 |
| - queryKey: ["Hackathon"], |
50 |
| - queryFn: async () => { |
51 |
| - const { data, errors } = await client.models.Hackathon.list(); |
52 |
| - if (errors) throw Error(errors[0].message); |
53 |
| - |
54 |
| - return data[0]; |
55 |
| - }, |
56 |
| - }); |
57 |
| - |
58 |
| - const { data: teamsForRoomData, isFetching: teamsForRoomIsFetching } = |
59 |
| - useQuery({ |
60 |
| - queryKey: ["TeamsForRoom", roomData?.id], |
61 |
| - queryFn: async () => { |
62 |
| - const teamRooms = (await roomData?.teamRoom())?.data; |
63 |
| - if (!teamRooms) return []; |
64 |
| - const teams = await Promise.all( |
65 |
| - teamRooms.map(async (teamRoom) => (await teamRoom.team()).data), |
66 |
| - ); |
67 |
| - if (!teams) return []; |
68 |
| - |
69 |
| - return teams; |
70 |
| - }, |
71 |
| - }); |
72 |
| - |
73 |
| - if (!hackathonData || !teamsForRoomData || !roomData) return; |
74 |
| - |
75 |
| - const tableHeaders = [ |
76 |
| - { columnHeader: "Team Name", className: "w-1/3 rounded-tl-lg" }, |
77 |
| - ...hackathonData.scoringComponents.map((component) => ({ |
78 |
| - columnHeader: component.friendlyName, |
79 |
| - className: "w-fit", |
80 |
| - })), |
81 |
| - ...hackathonData.scoringSidepots.map((component) => ({ |
82 |
| - columnHeader: ( |
83 |
| - <div className="flex flex-col"> |
84 |
| - <p>Sidepot:</p> |
85 |
| - {component.friendlyName} |
86 |
| - </div> |
87 |
| - ), |
88 |
| - className: "w-fit bg-pastel-pink", |
89 |
| - })), |
90 |
| - ]; |
91 |
| - |
92 |
| - const panelData = [ |
93 |
| - { |
94 |
| - icon: "/svgs/judging/team_icon.svg", |
95 |
| - alt: "Teams assigned icon", |
96 |
| - stat: teamsForRoomData.length, |
97 |
| - text: `Teams Assigned to ${roomData.name}`, |
98 |
| - }, |
99 |
| - { |
100 |
| - icon: "/svgs/judging/teams_left.svg", |
101 |
| - alt: "Teams left icon", |
102 |
| - stat: teamsForRoomData.filter( |
103 |
| - async (team) => |
104 |
| - (await team?.scores())?.data.filter( |
105 |
| - (score) => score.judgeId === currentUser.username, |
106 |
| - ).length === 0, |
107 |
| - ).length, |
108 |
| - text: "Teams Left To Score", |
109 |
| - }, |
110 |
| - ]; |
111 |
| - |
112 |
| - const isFetching = |
113 |
| - roomIsFetching || hackathonIsFetching || teamsForRoomIsFetching; |
114 |
| - |
115 |
| - const handleCreateScoreClick = (teamId: string) => { |
116 |
| - setSelectedTeamId(teamId); |
117 |
| - }; |
118 |
| - |
119 |
| - const handleEditScoreClick = (teamId: string) => { |
120 |
| - setSelectedTeamId(teamId); |
121 |
| - }; |
122 |
| - |
123 |
| - const closeModal = () => { |
124 |
| - setSelectedTeamId(""); |
| 6 | +export default async function JudgingDashboard() { |
| 7 | + const { data: hackathons } = await client.models.Hackathon.list(); |
| 8 | + const hackathonData = { |
| 9 | + scoringComponents: hackathons[0].scoringComponents, |
| 10 | + scoringSidepots: hackathons[0].scoringSidepots, |
| 11 | + id: hackathons[0].id, |
125 | 12 | };
|
126 | 13 |
|
127 | 14 | return (
|
128 |
| - <> |
129 |
| - {isFetching ? ( |
130 |
| - <div className={LOADING_SCREEN_STYLES}> |
131 |
| - <LoadingRing /> |
132 |
| - </div> |
133 |
| - ) : ( |
134 |
| - <div className={JUDGE_DASHBOARD_PAGE_STYLES}> |
135 |
| - <div className={JUDGE_DASHBOARD_CONTENT_STYLES}> |
136 |
| - <div className={JUDGE_DASHBOARD_HELLO_TILE_STYLES}> |
137 |
| - <h1>Hello,</h1> |
138 |
| - <div className="ml-2"> |
139 |
| - <h1 className="text-dark-pink"> |
140 |
| - <i>Judge!</i> |
141 |
| - </h1> |
142 |
| - <div className="mt-2 flex justify-center"> |
143 |
| - <Image |
144 |
| - src={pink_underlines} |
145 |
| - height={100} |
146 |
| - width={80} |
147 |
| - alt="Pink underlines" |
148 |
| - /> |
149 |
| - </div> |
150 |
| - </div> |
151 |
| - </div> |
152 |
| - <h2 className={SUBHEADER_TEXT_STYLES}>Assigned Teams</h2> |
153 |
| - <div className="mb-4 flex"> |
154 |
| - <div className="mr-4 flex w-1/4 flex-col space-y-4"> |
155 |
| - {panelData.map((item, index) => ( |
156 |
| - <div key={index} className="h-1/2"> |
157 |
| - <StatsPanel |
158 |
| - icon={item.icon} |
159 |
| - alt={item.alt} |
160 |
| - stat={item.stat} |
161 |
| - subheader={item.text} |
162 |
| - /> |
163 |
| - </div> |
164 |
| - ))} |
165 |
| - </div> |
166 |
| - <div className="w-3/4"> |
167 |
| - <ScoresTable |
168 |
| - tableHeaders={tableHeaders} |
169 |
| - tableData={teamsForRoomData as Schema["Team"]["type"][]} |
170 |
| - onCreateScoreClick={handleCreateScoreClick} |
171 |
| - onEditScoreClick={handleEditScoreClick} |
172 |
| - colorScheme="pink" |
173 |
| - entriesPerPage={150} |
174 |
| - /> |
175 |
| - </div> |
176 |
| - </div> |
177 |
| - </div> |
178 |
| - {selectedTeam !== "" && ( |
179 |
| - <ModalPopup |
180 |
| - hackathon={hackathonData} |
181 |
| - onClose={closeModal} |
182 |
| - teamId={selectedTeam} |
183 |
| - /> |
184 |
| - )} |
185 |
| - </div> |
186 |
| - )} |
187 |
| - </> |
| 15 | + <div className="flex w-full flex-1 flex-col items-center p-6 text-blackish"> |
| 16 | + <Greetings accentColor="text-dark-pink" /> |
| 17 | + <h2 className="flex w-full py-4 text-xl font-semibold">Assigned Teams</h2> |
| 18 | + <JudgingTable hackathonData={hackathonData} /> |
| 19 | + </div> |
188 | 20 | );
|
189 |
| -}; |
190 |
| - |
191 |
| -export default JudgingDashboard; |
| 21 | +} |
0 commit comments