@@ -60,6 +60,7 @@ import { ActionsList } from "@/components/ui/coaching-sessions/actions-list";
6060import { Action } from "@/types/action" ;
6161import { createAction , deleteAction , updateAction } from "@/lib/api/actions" ;
6262import { DateTime } from "ts-luxon" ;
63+ import { CoachingSessionTitle } from "@/components/ui/coaching-sessions/coaching-session-title" ;
6364
6465// export const metadata: Metadata = {
6566// title: "Coaching Session",
@@ -72,26 +73,28 @@ export default function CoachingSessionsPage() {
7273 const [ note , setNote ] = useState < string > ( "" ) ;
7374 const [ syncStatus , setSyncStatus ] = useState < string > ( "" ) ;
7475 const { userId } = useAuthStore ( ( state ) => state ) ;
75- const { coachingSessionId } = useAppStateStore ( ( state ) => state ) ;
76+ const { coachingSession, coachingRelationship } = useAppStateStore (
77+ ( state ) => state
78+ ) ;
7679
7780 useEffect ( ( ) => {
7881 async function fetchNote ( ) {
79- if ( ! coachingSessionId ) {
82+ if ( ! coachingSession . id ) {
8083 console . error (
81- "Failed to fetch Note since coachingSessionId is not set."
84+ "Failed to fetch Note since coachingSession.id is not set."
8285 ) ;
8386 return ;
8487 }
8588
86- await fetchNotesByCoachingSessionId ( coachingSessionId )
89+ await fetchNotesByCoachingSessionId ( coachingSession . id )
8790 . then ( ( notes ) => {
8891 const note = notes [ 0 ] ;
8992 if ( notes . length > 0 ) {
9093 console . trace ( "note: " + noteToString ( note ) ) ;
9194 setNoteId ( note . id ) ;
9295 setNote ( note . body ) ;
9396 } else {
94- console . trace ( "No Notes associated with this coachingSessionId " ) ;
97+ console . trace ( "No Notes associated with this coachingSession.id " ) ;
9598 }
9699 } )
97100 . catch ( ( err ) => {
@@ -101,11 +104,11 @@ export default function CoachingSessionsPage() {
101104 } ) ;
102105 }
103106 fetchNote ( ) ;
104- } , [ coachingSessionId , noteId ] ) ;
107+ } , [ coachingSession . id , noteId ] ) ;
105108
106109 const handleAgreementAdded = ( body : string ) : Promise < Agreement > => {
107110 // Calls the backend endpoint that creates and stores a full Agreement entity
108- return createAgreement ( coachingSessionId , userId , body )
111+ return createAgreement ( coachingSession . id , userId , body )
109112 . then ( ( agreement ) => {
110113 return agreement ;
111114 } )
@@ -116,7 +119,7 @@ export default function CoachingSessionsPage() {
116119 } ;
117120
118121 const handleAgreementEdited = ( id : Id , body : string ) : Promise < Agreement > => {
119- return updateAgreement ( id , coachingSessionId , userId , body )
122+ return updateAgreement ( id , coachingSession . id , userId , body )
120123 . then ( ( agreement ) => {
121124 return agreement ;
122125 } )
@@ -143,7 +146,7 @@ export default function CoachingSessionsPage() {
143146 dueBy : DateTime
144147 ) : Promise < Action > => {
145148 // Calls the backend endpoint that creates and stores a full Action entity
146- return createAction ( coachingSessionId , body , status , dueBy )
149+ return createAction ( coachingSession . id , body , status , dueBy )
147150 . then ( ( action ) => {
148151 return action ;
149152 } )
@@ -159,7 +162,7 @@ export default function CoachingSessionsPage() {
159162 status : ActionStatus ,
160163 dueBy : DateTime
161164 ) : Promise < Action > => {
162- return updateAction ( id , coachingSessionId , body , status , dueBy )
165+ return updateAction ( id , coachingSession . id , body , status , dueBy )
163166 . then ( ( action ) => {
164167 return action ;
165168 } )
@@ -183,8 +186,8 @@ export default function CoachingSessionsPage() {
183186 const handleInputChange = ( value : string ) => {
184187 setNote ( value ) ;
185188
186- if ( noteId && coachingSessionId && userId ) {
187- updateNote ( noteId , coachingSessionId , userId , value )
189+ if ( noteId && coachingSession . id && userId ) {
190+ updateNote ( noteId , coachingSession . id , userId , value )
188191 . then ( ( note ) => {
189192 console . trace ( "Updated Note: " + noteToString ( note ) ) ;
190193 setSyncStatus ( "All changes saved" ) ;
@@ -193,8 +196,8 @@ export default function CoachingSessionsPage() {
193196 setSyncStatus ( "Failed to save changes" ) ;
194197 console . error ( "Failed to update Note: " + err ) ;
195198 } ) ;
196- } else if ( ! noteId && coachingSessionId && userId ) {
197- createNote ( coachingSessionId , userId , value )
199+ } else if ( ! noteId && coachingSession . id && userId ) {
200+ createNote ( coachingSession . id , userId , value )
198201 . then ( ( note ) => {
199202 console . trace ( "Newly created Note: " + noteToString ( note ) ) ;
200203 setNoteId ( note . id ) ;
@@ -206,7 +209,7 @@ export default function CoachingSessionsPage() {
206209 } ) ;
207210 } else {
208211 console . error (
209- "Could not update or create a Note since coachingSessionId or userId are not set."
212+ "Could not update or create a Note since coachingSession.id or userId are not set."
210213 ) ;
211214 }
212215 } ;
@@ -215,11 +218,19 @@ export default function CoachingSessionsPage() {
215218 setSyncStatus ( "" ) ;
216219 } ;
217220
221+ const handleTitleRender = ( sessionTitle : string ) => {
222+ document . title = sessionTitle ;
223+ } ;
224+
218225 return (
219226 < >
220- < div className = "hidden h-full flex-col md:flex" >
227+ < div className = "h-full flex-col md:flex" >
221228 < div className = "flex flex-col items-start justify-between space-y-2 py-4 px-4 sm:flex-row sm:items-center sm:space-y-0 md:h-16" >
222- < h4 className = "w-16 md:w-32 lg:w-48 font-semibold" > Session Title</ h4 >
229+ < CoachingSessionTitle
230+ locale = { siteConfig . locale }
231+ style = { siteConfig . titleStyle }
232+ onRender = { handleTitleRender }
233+ > </ CoachingSessionTitle >
223234 < div className = "ml-auto flex w-full space-x-2 sm:justify-end" >
224235 < PresetSelector current = { current } future = { future } past = { past } />
225236 < PresetActions />
@@ -289,7 +300,7 @@ export default function CoachingSessionsPage() {
289300 < TabsContent value = "agreements" >
290301 < div className = "w-full" >
291302 < AgreementsList
292- coachingSessionId = { coachingSessionId }
303+ coachingSessionId = { coachingSession . id }
293304 userId = { userId }
294305 locale = { siteConfig . locale }
295306 onAgreementAdded = { handleAgreementAdded }
@@ -301,7 +312,7 @@ export default function CoachingSessionsPage() {
301312 < TabsContent value = "actions" >
302313 < div className = "w-full" >
303314 < ActionsList
304- coachingSessionId = { coachingSessionId }
315+ coachingSessionId = { coachingSession . id }
305316 userId = { userId }
306317 locale = { siteConfig . locale }
307318 onActionAdded = { handleActionAdded }
0 commit comments