77 ShieldCheck ,
88 ChevronDown ,
99 ChevronUp ,
10+ MessageSquare ,
1011} from "lucide-react" ;
1112import {
1213 Collapsible ,
@@ -18,6 +19,51 @@ import LoadingScreen from "../Loading/LoadingScreen";
1819import { fetchAuthSession } from "aws-amplify/auth" ;
1920import Session from "../history/Session" ;
2021
22+ const EmptyFeedbackView = ( { role } ) => {
23+ const getRoleIcon = ( role ) => {
24+ switch ( role ) {
25+ case "public" :
26+ return < Users className = "mr-2" /> ;
27+ case "educator" :
28+ return < GraduationCap className = "mr-2" /> ;
29+ case "admin" :
30+ return < ShieldCheck className = "mr-2" /> ;
31+ default :
32+ return null ;
33+ }
34+ } ;
35+
36+ const getRoleLabel = ( role ) => {
37+ switch ( role ) {
38+ case "public" :
39+ return "Student/General Public" ;
40+ case "educator" :
41+ return "Educator/Educational Designer" ;
42+ case "admin" :
43+ return "Post-Secondary Institution Admin/Leader" ;
44+ default :
45+ return role ;
46+ }
47+ } ;
48+
49+ return (
50+ < div className = "w-full" >
51+ < div className = "flex items-center space-x-4 px-4 py-3 bg-gray-50 rounded-t-lg" >
52+ < div className = "flex items-center" >
53+ { getRoleIcon ( role ) }
54+ < h2 className = "text-lg font-semibold capitalize" >
55+ { getRoleLabel ( role ) } Feedback
56+ </ h2 >
57+ < span className = "ml-2 text-gray-500" > (Avg Rating: 0, Total: 0)</ span >
58+ </ div >
59+ </ div >
60+ < div className = "p-8 text-center border-b border-x rounded-b-lg bg-white" >
61+ < p className = "text-gray-500" > No feedback available for this role yet</ p >
62+ </ div >
63+ </ div >
64+ ) ;
65+ } ;
66+
2167const FeedbackView = ( { role, feedbackData, onFeedbackClick } ) => {
2268 const [ isOpen , setIsOpen ] = useState ( true ) ;
2369
@@ -51,6 +97,13 @@ const FeedbackView = ({ role, feedbackData, onFeedbackClick }) => {
5197 return new Date ( dateString ) . toLocaleString ( ) ;
5298 } ;
5399
100+ if (
101+ ! feedbackData . feedback_details ||
102+ feedbackData . feedback_details . length === 0
103+ ) {
104+ return < EmptyFeedbackView role = { role } /> ;
105+ }
106+
54107 return (
55108 < Collapsible open = { isOpen } onOpenChange = { setIsOpen } className = "w-full" >
56109 < CollapsibleTrigger asChild className = "hover:cursor-pointer" >
@@ -133,21 +186,15 @@ const Feedback = () => {
133186
134187 function sortFeedbackByTimestamp ( data ) {
135188 return data . map ( ( roleData ) => {
136- // Create a new object to avoid mutating the original
137189 const sortedData = { ...roleData } ;
138-
139- // Sort feedback_details in descending order (recent first)
140190 if (
141191 sortedData . feedback_details &&
142192 Array . isArray ( sortedData . feedback_details )
143193 ) {
144194 sortedData . feedback_details = sortedData . feedback_details . sort (
145- ( a , b ) => {
146- return new Date ( b . feedback_time ) - new Date ( a . feedback_time ) ;
147- }
195+ ( a , b ) => new Date ( b . feedback_time ) - new Date ( a . feedback_time )
148196 ) ;
149197 }
150-
151198 return sortedData ;
152199 } ) ;
153200 }
@@ -173,7 +220,6 @@ const Feedback = () => {
173220 }
174221
175222 const data = await response . json ( ) ;
176- console . log ( data ) ;
177223 const sortedData = sortFeedbackByTimestamp ( data ) ;
178224 setFeedbackData ( sortedData ) ;
179225 } catch ( error ) {
@@ -187,7 +233,6 @@ const Feedback = () => {
187233 } , [ ] ) ;
188234
189235 const handleSessionClick = ( sessionId ) => {
190- // Find the session object with the matching session_id
191236 for ( const roleData of feedbackData ) {
192237 const session = roleData . feedback_details . find (
193238 ( feedback ) => feedback . session_id === sessionId
@@ -217,6 +262,21 @@ const Feedback = () => {
217262 ) ;
218263 }
219264
265+ if ( ! feedbackData || feedbackData . length === 0 ) {
266+ return (
267+ < div className = "w-full h-[50vh] flex flex-col items-center justify-center p-4 space-y-4" >
268+ < MessageSquare className = "w-16 h-16 text-gray-300" />
269+ < h2 className = "text-xl font-semibold text-gray-600" >
270+ No Feedback Available
271+ </ h2 >
272+ < p className = "text-gray-500 text-center max-w-md" >
273+ There is currently no feedback from any user roles. Feedback will
274+ appear here once users start providing it.
275+ </ p >
276+ </ div >
277+ ) ;
278+ }
279+
220280 return (
221281 < div className = "w-full mx-auto space-y-4 p-4 overflow-y-auto mb-8" >
222282 { feedbackData . map ( ( roleData , index ) => (
0 commit comments