1- import React , { useContext } from 'react'
1+ import React , { useContext , useEffect , useState } from 'react'
22
33import { Route , Switch , Redirect } from 'react-router-dom'
44import { AnimatePresence } from 'framer-motion'
@@ -16,43 +16,42 @@ import EventDetailContext, { EventDetailProvider } from './context'
1616const EventDetailRouter = ( ) => {
1717 const match = useRouteMatch ( )
1818 const location = useLocation ( )
19- const { eventLoading, eventError, isRegistrationOpen } =
20- useContext ( EventDetailContext )
21- // TODO FIX errortext and desc to be from eventErro
19+ const [ isPreview , setIsPreview ] = useState ( false )
20+ const { eventLoading, eventError, isRegistrationOpen } = useContext ( EventDetailContext )
21+
22+ // Monitor changes to the preview query parameter and update state accordingly
23+ useEffect ( ( ) => {
24+ const searchParams = new URLSearchParams ( location . search )
25+ setIsPreview ( searchParams . get ( 'preview' ) === 'true' )
26+ } , [ location . search ] )
27+
28+ // Conditional rendering for preview or non-preview mode
2229 return (
2330 < PageWrapper
2431 loading = { eventLoading }
2532 error = { ! ! eventError }
26- errorText = { `Oops, something went wrong` }
27- errorDesc = { `Please refresh the page to try again.` }
28- header = { ( ) => < GlobalNavBar /> }
29- footer = { ( ) => < EventFooter /> }
30- render = { ( ) => {
31- return (
32- < AnimatePresence >
33- < Switch location = { location } key = { location . pathname } >
34- < Route
35- exact
36- path = { `${ match . url } ` }
37- component = { EventDetail }
38- />
39- { isRegistrationOpen && (
40- < Route
41- exact
42- path = { `${ match . url } /register` }
43- component = { EventRegister }
44- />
45- ) }
46- < Route
47- exact
48- path = { `${ match . url } /finalist-voting` }
49- component = { FinalistVoting }
50- />
51- < Redirect to = { `${ match . url } ` } />
52- </ Switch >
53- </ AnimatePresence >
54- )
55- } }
33+ errorText = "Oops, something went wrong"
34+ errorDesc = "Please refresh the page to try again."
35+ header = { ! isPreview ? ( ) => < GlobalNavBar /> : undefined }
36+ footer = { ! isPreview ? ( ) => < EventFooter /> : undefined }
37+ render = { ( ) => (
38+ < AnimatePresence >
39+ < Switch location = { location } key = { location . pathname } >
40+ < Route
41+ exact
42+ path = { `${ match . url } ` }
43+ render = { ( props ) => < EventDetail { ...props } isPreview = { isPreview } /> }
44+ />
45+ { isRegistrationOpen && ! isPreview &&
46+ < Route exact path = { `${ match . url } /register` } component = { EventRegister } />
47+ }
48+ { ! isPreview &&
49+ < Route exact path = { `${ match . url } /finalist-voting` } component = { FinalistVoting } />
50+ }
51+ < Redirect to = { `${ match . url } ` } />
52+ </ Switch >
53+ </ AnimatePresence >
54+ ) }
5655 />
5756 )
5857}
@@ -63,4 +62,4 @@ export default () => {
6362 < EventDetailRouter />
6463 </ EventDetailProvider >
6564 )
66- }
65+ }
0 commit comments