@@ -2,7 +2,7 @@ import { useParams, useNavigate } from "react-router-dom";
22import { useQuery , useMutation , useQueryClient } from "@tanstack/react-query" ;
33import { motion } from "framer-motion" ;
44import { useState , useEffect } from "react" ;
5- import { useAuth } from "@clerk/clerk-react" ;
5+ import { useAuth , useUser } from "@clerk/clerk-react" ;
66import {
77 ArrowLeft ,
88 Calendar ,
@@ -26,8 +26,12 @@ import { getEventStatus, isEventNew } from "@/shared/lib/eventUtils";
2626import { Event } from "@/features/events/types/events" ;
2727import BadgeMask from "@/shared/components/ui/badge-mask" ;
2828
29- const fetchEvent = async ( eventId : string ) : Promise < Event > => {
30- const response = await fetch ( `${ API_BASE_URL } /events/${ eventId } ` ) ;
29+ const fetchEvent = async ( eventId : string , token ?: string | null ) : Promise < Event > => {
30+ const headers : HeadersInit = { } ;
31+ if ( token ) {
32+ headers . Authorization = `Bearer ${ token } ` ;
33+ }
34+ const response = await fetch ( `${ API_BASE_URL } /events/${ eventId } ` , { headers } ) ;
3135 if ( ! response . ok ) {
3236 throw new Error ( "Event not found" ) ;
3337 }
@@ -86,6 +90,8 @@ const OrganizationBadge = ({ event }: { event: Event }) => {
8690
8791function EventDetailPage ( ) {
8892 const { eventId } = useParams < { eventId : string } > ( ) ;
93+ const { user } = useUser ( ) ;
94+ const isAdmin = user ?. publicMetadata ?. role === 'admin' ;
8995 const navigate = useNavigate ( ) ;
9096 const { getToken } = useAuth ( ) ;
9197 const queryClient = useQueryClient ( ) ;
@@ -95,45 +101,19 @@ function EventDetailPage() {
95101
96102 const { data : event , isLoading, error } = useQuery ( {
97103 queryKey : [ "event" , eventId ] ,
98- queryFn : ( ) => fetchEvent ( eventId ! ) ,
99- enabled : ! ! eventId ,
100- } ) ;
101-
102- // Fetch submission info to check if user is submitter or admin
103- const { data : submissionInfo , isLoading : isSubmissionLoading } = useQuery ( {
104- queryKey : [ "event-submission" , eventId ] ,
105104 queryFn : async ( ) => {
106- try {
107- const token = await getToken ( ) ;
108- const headers : HeadersInit = { } ;
109- if ( token ) {
110- headers . Authorization = `Bearer ${ token } ` ;
111- }
112-
113- const response = await fetch ( `${ API_BASE_URL } /events/${ eventId } /submission/` , {
114- headers,
115- } ) ;
116- if ( ! response . ok ) throw new Error ( "Failed to fetch submission info" ) ;
117- return response . json ( ) ;
118- } catch ( error ) {
119- console . error ( "Error fetching submission info:" , error ) ;
120- return { is_submitter : false , is_admin : false } ;
121- }
105+ const token = await getToken ( ) ;
106+ return fetchEvent ( eventId ! , token ) ;
122107 } ,
123108 enabled : ! ! eventId ,
124109 } ) ;
125110
126111 // Initialize editedData when event loads for pending events or for admins
127- // Filter to only show user-editable fields
128112 useEffect ( ( ) => {
129- if ( event && ! editedData && submissionInfo ) {
130- const shouldEdit = ( event . status === "PENDING" && ( submissionInfo . is_submitter || submissionInfo . is_admin ) ) || submissionInfo . is_admin ;
113+ if ( event && ! editedData ) {
114+ const shouldEdit = ( event . status === "PENDING" && ( event as any ) . is_submitter ) || isAdmin ;
131115 if ( shouldEdit ) {
132- // Filter to only user-editable fields (same as submission form)
133- const allowedFields = new Set ( [
134- 'title' , 'dtstart' , 'dtend' , 'all_day' , 'location' ,
135- 'price' , 'food' , 'registration' , 'description'
136- ] ) ;
116+ const allowedFields = new Set ( [ 'title' , 'dtstart' , 'dtend' , 'all_day' , 'location' , 'price' , 'food' , 'registration' , 'description' ] ) ;
137117 const filteredData : any = { } ;
138118 for ( const field of Object . keys ( event ) ) {
139119 if ( allowedFields . has ( field ) ) {
@@ -143,7 +123,7 @@ function EventDetailPage() {
143123 setEditedData ( filteredData ) ;
144124 }
145125 }
146- } , [ event , submissionInfo , editedData ] ) ;
126+ } , [ event , editedData , isAdmin ] ) ;
147127
148128 // Mutation for updating event
149129 const updateEventMutation = useMutation ( {
@@ -200,14 +180,11 @@ function EventDetailPage() {
200180 setEditError ( null ) ;
201181 } ;
202182
203- // Determine if user can edit this event
204- const canEditEvent = submissionInfo ?. is_submitter || submissionInfo ?. is_admin ;
205-
206- // Check if event is pending and user cannot view it (only check after submissionInfo is loaded)
207- const isPendingAndUnauthorized = event ?. status === "PENDING" && ! canEditEvent && ! isSubmissionLoading ;
183+ const canEditEvent = ( event as any ) ?. is_submitter || isAdmin ;
184+ const isPendingAndUnauthorized = event ?. status === "PENDING" && ! canEditEvent ;
208185
209186 // Show loading while either query is loading
210- if ( isLoading || ( event ?. status === "PENDING" && isSubmissionLoading ) ) {
187+ if ( isLoading ) {
211188 return (
212189 < div className = "flex items-center justify-center min-h-[400px]" >
213190 < div className = "flex items-center space-x-2 text-gray-600 dark:text-gray-400" >
@@ -237,7 +214,7 @@ function EventDetailPage() {
237214 }
238215
239216 // Render edit mode for pending events when user has permission, OR for admins regardless of status
240- if ( ( event . status === "PENDING" && canEditEvent ) || submissionInfo ?. is_admin ) {
217+ if ( ( event . status === "PENDING" && canEditEvent ) || isAdmin ) {
241218 return (
242219 < div className = "max-w-4xl mx-auto" >
243220 < SEOHead
@@ -255,12 +232,12 @@ function EventDetailPage() {
255232 </ div >
256233
257234 { /* Original Screenshot (if available for submitter/admin) */ }
258- { submissionInfo ?. screenshot_url && (
235+ { ( event as any ) ?. screenshot_url && (
259236 < div className = "mb-6 bg-white dark:bg-gray-800 rounded-lg shadow-lg p-6" >
260237 < h2 className = "text-xl font-bold text-gray-900 dark:text-white mb-4" > Original Screenshot</ h2 >
261238 < div className = "relative w-full max-w-2xl mx-auto" >
262239 < img
263- src = { submissionInfo . screenshot_url }
240+ src = { ( event as any ) . screenshot_url }
264241 alt = "Original event screenshot"
265242 className = "w-full h-auto rounded-lg shadow-lg"
266243 />
@@ -581,20 +558,28 @@ function EventDetailPage() {
581558 </ p >
582559 </ div >
583560 </ div >
584- { /* Google Maps Embed */ }
585- < div className = "w-full h-64 rounded-lg overflow-hidden" >
586- < iframe
587- width = "100%"
588- height = "100%"
589- style = { { border : 0 } }
590- loading = "lazy"
591- allowFullScreen
592- referrerPolicy = "no-referrer-when-downgrade"
593- src = { `https://www.google.com/maps/embed/v1/place?key=${
594- import . meta. env . VITE_GOOGLE_MAPS_API_KEY || ""
595- } &q=${ encodeURIComponent ( `${ event . location } , ${ event . school || "" } ` ) } `}
596- > </ iframe >
597- </ div >
561+ { /* Google Maps Embed - Only show for physical locations */ }
562+ { ( ( ) => {
563+ const locationLower = event . location . toLowerCase ( ) ;
564+ const isVirtual = locationLower . includes ( "virtual" ) ||
565+ locationLower . includes ( "zoom" ) ||
566+ locationLower . includes ( "google meet" ) ;
567+ return ! isVirtual && (
568+ < div className = "w-full h-64 rounded-lg overflow-hidden" >
569+ < iframe
570+ width = "100%"
571+ height = "100%"
572+ style = { { border : 0 } }
573+ loading = "lazy"
574+ allowFullScreen
575+ referrerPolicy = "no-referrer-when-downgrade"
576+ src = { `https://www.google.com/maps/embed/v1/place?key=${
577+ import . meta. env . VITE_GOOGLE_MAPS_API_KEY || ""
578+ } &q=${ encodeURIComponent ( `${ event . location } , ${ event . school || "" } ` ) } `}
579+ > </ iframe >
580+ </ div >
581+ ) ;
582+ } ) ( ) }
598583 </ div >
599584 ) }
600585
@@ -708,7 +693,7 @@ function EventDetailPage() {
708693 </ motion . div >
709694
710695 { /* Original Screenshot (if available for submitter/admin) */ }
711- { canEditEvent && submissionInfo ?. screenshot_url && (
696+ { ( event as any ) ?. screenshot_url && (
712697 < motion . div
713698 initial = { { opacity : 0 , y : 20 } }
714699 animate = { { opacity : 1 , y : 0 } }
@@ -721,7 +706,7 @@ function EventDetailPage() {
721706 </ h3 >
722707 < div className = "relative w-full" >
723708 < img
724- src = { submissionInfo . screenshot_url }
709+ src = { ( event as any ) . screenshot_url }
725710 alt = "Original event screenshot"
726711 className = "w-full h-auto rounded-lg shadow-lg"
727712 />
0 commit comments