@@ -10,7 +10,7 @@ import theme from '@/styles/theme';
1010import { Box , Container , Typography , useMediaQuery } from '@mui/material' ;
1111import { storyblokEditable } from '@storyblok/react/rsc' ;
1212import { useSearchParams } from 'next/navigation' ;
13- import { useCallback , useEffect } from 'react' ;
13+ import { useEffect , useRef } from 'react' ;
1414import { render , StoryblokRichtext } from 'storyblok-rich-text-react-renderer' ;
1515import NotesFromBloomPromo from '../banner/NotesFromBloomPromo' ;
1616import StoryblokPageSection , { StoryblokPageSectionProps } from './StoryblokPageSection' ;
@@ -76,37 +76,31 @@ const StoryblokMeetTheTeamPage = (props: StoryblokMeetTheTeamPageProps) => {
7676 const isSmallScreen = useMediaQuery ( theme . breakpoints . down ( 'md' ) ) ;
7777 const headerOffset = isSmallScreen ? 48 : 136 ;
7878
79+ const coreSectionRef = useRef < HTMLDivElement > ( null ) ;
80+ const somaticsSectionRef = useRef < HTMLDivElement > ( null ) ;
81+ const supportingSectionRef = useRef < HTMLDivElement > ( null ) ;
82+
7983 useEffect ( ( ) => {
8084 logEvent ( MEET_THE_TEAM_VIEWED ) ;
8185 } , [ ] ) ;
8286
83- const setCoreSectionRef = useCallback (
84- ( node : HTMLDivElement | null ) => {
85- if ( sectionQueryParam === 'core' && node ) {
86- const scrollToY = node . getBoundingClientRect ( ) . top + window . scrollY - headerOffset ;
87- window . scrollTo ( { top : scrollToY , behavior : 'smooth' } ) ;
88- }
89- } ,
90- [ sectionQueryParam , headerOffset ] ,
91- ) ;
92- const setSomaticsSectionRef = useCallback (
93- ( node : HTMLDivElement | null ) => {
94- if ( sectionQueryParam === 'somatics' && node ) {
95- const scrollToY = node . getBoundingClientRect ( ) . top + window . scrollY - headerOffset ;
96- window . scrollTo ( { top : scrollToY , behavior : 'smooth' } ) ;
97- }
98- } ,
99- [ sectionQueryParam , headerOffset ] ,
100- ) ;
101- const setSupportingSectionRef = useCallback (
102- ( node : HTMLDivElement | null ) => {
103- if ( sectionQueryParam === 'supporting' && node ) {
104- const scrollToY = node . getBoundingClientRect ( ) . top + window . scrollY - headerOffset ;
105- window . scrollTo ( { top : scrollToY , behavior : 'smooth' } ) ;
106- }
107- } ,
108- [ sectionQueryParam , headerOffset ] ,
109- ) ;
87+ useEffect ( ( ) => {
88+ const sectionMap = {
89+ core : coreSectionRef ,
90+ somatics : somaticsSectionRef ,
91+ supporting : supportingSectionRef ,
92+ } ;
93+
94+ const targetRef = sectionQueryParam
95+ ? sectionMap [ sectionQueryParam as keyof typeof sectionMap ]
96+ : null ;
97+
98+ if ( targetRef ?. current ) {
99+ const scrollToY =
100+ targetRef . current . getBoundingClientRect ( ) . top + window . scrollY - headerOffset ;
101+ window . scrollTo ( { top : scrollToY , behavior : 'smooth' } ) ;
102+ }
103+ } , [ ] ) ;
110104
111105 return (
112106 < Box
@@ -139,24 +133,24 @@ const StoryblokMeetTheTeamPage = (props: StoryblokMeetTheTeamPageProps) => {
139133 { page_section_1 ?. length > 0 && (
140134 < StoryblokPageSection { ...page_section_1 [ 0 ] } isLoggedIn = { ! ! userId } />
141135 ) }
142- < Container ref = { setCoreSectionRef } sx = { coreContainerStyle } >
136+
137+ { /* CHANGED: Apply the new refs */ }
138+ < Container ref = { coreSectionRef } sx = { coreContainerStyle } >
143139 < Typography variant = "h2" component = "h2" >
144140 { core_team_title }
145141 </ Typography >
146- { core_team_description &&
147- // this was clearly expecting a string in the code but it was causing an error because an object was coming through from storyblok.
148- // This is a patch to help with release but should be readdressed
149- typeof core_team_description === 'string' && (
150- < Typography maxWidth = { 650 } > { core_team_description } </ Typography >
151- ) }
142+ { core_team_description && typeof core_team_description === 'string' && (
143+ < Typography maxWidth = { 650 } > { core_team_description } </ Typography >
144+ ) }
152145 < StoryblokTeamMembersCards team_member_items = { core_team_members } cards_expandable = { false } />
153146 </ Container >
154147
155148 { page_section_2 ?. length > 0 && (
156149 < StoryblokPageSection { ...page_section_2 [ 0 ] } isLoggedIn = { ! ! userId } />
157150 ) }
158151
159- < Container ref = { setSomaticsSectionRef } sx = { somaticsContainerStyle } >
152+ { /* CHANGED: Apply the new refs */ }
153+ < Container ref = { somaticsSectionRef } sx = { somaticsContainerStyle } >
160154 < Typography variant = "h2" component = "h2" >
161155 { somatics_team_title }
162156 </ Typography >
@@ -169,7 +163,8 @@ const StoryblokMeetTheTeamPage = (props: StoryblokMeetTheTeamPageProps) => {
169163 />
170164 </ Container >
171165
172- < Container ref = { setSupportingSectionRef } sx = { supportingContainerStyle } >
166+ { /* CHANGED: Apply the new refs */ }
167+ < Container ref = { supportingSectionRef } sx = { supportingContainerStyle } >
173168 < Typography variant = "h2" component = "h2" >
174169 { supporting_team_title }
175170 </ Typography >
0 commit comments