11'use client' ;
22import { Column , Grid , Row , useTheme } from '@umami/react-zen' ;
3- import { useRouter } from 'next/navigation' ;
3+ import { usePathname , useRouter } from 'next/navigation' ;
44import { useEffect , useMemo } from 'react' ;
55import { AttributionPage } from '@/app/(main)/websites/[websiteId]/(reports)/attribution/AttributionPage' ;
66import { BreakdownPage } from '@/app/(main)/websites/[websiteId]/(reports)/breakdown/BreakdownPage' ;
@@ -18,10 +18,8 @@ import { WebsiteHeader } from '@/app/(main)/websites/[websiteId]/WebsiteHeader';
1818import { WebsitePage } from '@/app/(main)/websites/[websiteId]/WebsitePage' ;
1919import { WebsiteProvider } from '@/app/(main)/websites/WebsiteProvider' ;
2020import { PageBody } from '@/components/common/PageBody' ;
21- import { useShareTokenQuery } from '@/components/hooks' ;
21+ import { useShare } from '@/components/hooks' ;
2222import { MobileMenuButton } from '@/components/input/MobileMenuButton' ;
23- import { ShareFooter } from './ShareFooter' ;
24- import { ShareHeader } from './ShareHeader' ;
2523import { ShareNav } from './ShareNav' ;
2624
2725const PAGE_COMPONENTS : Record < string , React . ComponentType < { websiteId : string } > > = {
@@ -58,17 +56,20 @@ const ALL_SECTION_IDS = [
5856 'attribution' ,
5957] ;
6058
61- export function SharePage ( { shareId, path = '' } : { shareId : string ; path ? : string } ) {
62- const { shareToken , isLoading } = useShareTokenQuery ( shareId ) ;
59+ export function SharePage ( { shareId } : { shareId : string } ) {
60+ const share = useShare ( ) ;
6361 const { setTheme } = useTheme ( ) ;
6462 const router = useRouter ( ) ;
63+ const pathname = usePathname ( ) ;
64+ const path = pathname . split ( '/' ) [ 3 ] ;
65+ const { websiteId, parameters = { } } = share ;
6566
6667 // Calculate allowed sections
6768 const allowedSections = useMemo ( ( ) => {
68- if ( ! shareToken ?. parameters ) return [ ] ;
69- const params = shareToken . parameters ;
69+ if ( ! share ?. parameters ) return [ ] ;
70+ const params = share . parameters ;
7071 return ALL_SECTION_IDS . filter ( id => params [ id ] !== false ) ;
71- } , [ shareToken ?. parameters ] ) ;
72+ } , [ share ?. parameters ] ) ;
7273
7374 useEffect ( ( ) => {
7475 const url = new URL ( window ?. location ?. href ) ;
@@ -90,12 +91,6 @@ export function SharePage({ shareId, path = '' }: { shareId: string; path?: stri
9091 }
9192 } , [ allowedSections , shareId , path , router ] ) ;
9293
93- if ( isLoading || ! shareToken ) {
94- return null ;
95- }
96-
97- const { websiteId, parameters = { } , whiteLabel } = shareToken ;
98-
9994 // Redirect to only allowed section - return null while redirecting
10095 if (
10196 allowedSections . length === 1 &&
@@ -116,40 +111,25 @@ export function SharePage({ shareId, path = '' }: { shareId: string; path?: stri
116111 const PageComponent = PAGE_COMPONENTS [ pageKey ] || WebsitePage ;
117112
118113 return (
119- < Column backgroundColor = "2" >
120- < Grid columns = { { xs : '1fr' , lg : 'auto 1fr' } } width = "100%" height = "100%" >
121- < Row display = { { xs : 'flex' , lg : 'none' } } alignItems = "center" gap padding = "3" >
122- < Grid columns = "auto 1fr" flexGrow = { 1 } backgroundColor = "3" borderRadius >
123- < MobileMenuButton >
124- { ( { close } ) => {
125- return < ShareNav shareId = { shareId } parameters = { parameters } onItemClick = { close } /> ;
126- } }
127- </ MobileMenuButton >
128- </ Grid >
129- </ Row >
130- < Column
131- display = { { xs : 'none' , lg : 'flex' } }
132- width = "240px"
133- height = "100%"
134- border = "right"
135- backgroundColor
136- marginRight = "2"
137- >
138- < Column display = { { xs : 'none' , lg : 'flex' } } >
139- < ShareNav shareId = { shareId } parameters = { parameters } />
114+ < Grid columns = { { xs : '1fr' , lg : '240px 1fr' } } width = "100%" >
115+ < Row display = { { xs : 'flex' , lg : 'none' } } alignItems = "center" gap padding = "3" >
116+ < MobileMenuButton >
117+ { ( { close } ) => {
118+ return < ShareNav onItemClick = { close } /> ;
119+ } }
120+ </ MobileMenuButton >
121+ </ Row >
122+ < Column display = { { xs : 'none' , lg : 'flex' } } marginRight = "2" >
123+ < ShareNav />
124+ </ Column >
125+ < PageBody gap >
126+ < WebsiteProvider websiteId = { websiteId } >
127+ < Column >
128+ < WebsiteHeader showActions = { false } />
129+ < PageComponent websiteId = { websiteId } />
140130 </ Column >
141- </ Column >
142- < PageBody gap >
143- < WebsiteProvider websiteId = { websiteId } >
144- < ShareHeader whiteLabel = { whiteLabel } />
145- < Column >
146- < WebsiteHeader showActions = { false } />
147- < PageComponent websiteId = { websiteId } />
148- </ Column >
149- < ShareFooter whiteLabel = { whiteLabel } />
150- </ WebsiteProvider >
151- </ PageBody >
152- </ Grid >
153- </ Column >
131+ </ WebsiteProvider >
132+ </ PageBody >
133+ </ Grid >
154134 ) ;
155135}
0 commit comments