@@ -17,6 +17,7 @@ import { DateTime } from "ts-luxon";
17
17
import { useCoachingSessionStateStore } from "@/lib/providers/coaching-session-state-store-provider" ;
18
18
import { fetchOverarchingGoalsByCoachingSessionId } from "@/lib/api/overarching-goals" ;
19
19
import { OverarchingGoal } from "@/types/overarching-goal" ;
20
+ import { CoachingSession } from "@/types/coaching-session" ;
20
21
21
22
interface CoachingSessionsSelectorProps extends PopoverProps {
22
23
/// The CoachingRelationship Id for which to get a list of associated CoachingSessions
@@ -75,67 +76,63 @@ function CoachingSessionsSelectItems({
75
76
if ( isErrorSessions ) return < div > Error loading coaching sessions</ div > ;
76
77
if ( ! coachingSessions ?. length ) return < div > No coaching sessions found</ div > ;
77
78
79
+ const SessionItem = ( {
80
+ session,
81
+ goals,
82
+ sessionIndex,
83
+ } : {
84
+ session : CoachingSession ;
85
+ goals : ( OverarchingGoal [ ] | undefined ) [ ] ;
86
+ sessionIndex : number ;
87
+ } ) => (
88
+ < SelectItem value = { session . id } >
89
+ < div className = "flex min-w-0 w-[calc(100%-20px)]" >
90
+ < div className = "min-w-0 w-full" >
91
+ < p className = "truncate text-sm font-medium" >
92
+ { goals [ sessionIndex ] ?. [ 0 ] ?. title || "No goal set" }
93
+ </ p >
94
+ < p className = "truncate text-sm text-gray-400" >
95
+ { getDateTimeFromString ( session . date ) . toLocaleString (
96
+ DateTime . DATETIME_FULL
97
+ ) }
98
+ </ p >
99
+ </ div >
100
+ </ div >
101
+ </ SelectItem >
102
+ ) ;
103
+
78
104
return (
79
105
< >
80
- { coachingSessions . some (
81
- ( session ) => getDateTimeFromString ( session . date ) < DateTime . now ( )
82
- ) && (
83
- < SelectGroup >
84
- < SelectLabel > Previous Sessions</ SelectLabel >
85
- { coachingSessions
86
- . filter (
87
- ( session ) => getDateTimeFromString ( session . date ) < DateTime . now ( )
88
- )
89
- . map ( ( session ) => {
90
- const sessionIndex = coachingSessions . findIndex (
91
- ( s ) => s . id === session . id
92
- ) ;
93
- return (
94
- < SelectItem value = { session . id } key = { session . id } >
95
- < div className = "flex flex-col w-full" >
96
- < span className = "text-left truncate overflow-hidden" >
97
- { goals [ sessionIndex ] ?. [ 0 ] ?. title || "No goal set" }
98
- </ span >
99
- < span className = "text-sm text-gray-400" >
100
- { getDateTimeFromString ( session . date ) . toLocaleString (
101
- DateTime . DATETIME_FULL
102
- ) }
103
- </ span >
104
- </ div >
105
- </ SelectItem >
106
- ) ;
107
- } ) }
108
- </ SelectGroup >
109
- ) }
110
- { coachingSessions . some (
111
- ( session ) => getDateTimeFromString ( session . date ) >= DateTime . now ( )
112
- ) && (
113
- < SelectGroup >
114
- < SelectLabel > Upcoming Sessions</ SelectLabel >
115
- { coachingSessions
116
- . filter (
117
- ( session ) => getDateTimeFromString ( session . date ) >= DateTime . now ( )
118
- )
119
- . map ( ( session ) => {
120
- const sessionIndex = coachingSessions . findIndex (
121
- ( s ) => s . id === session . id
122
- ) ;
123
- return (
124
- < SelectItem value = { session . id } key = { session . id } >
125
- < div className = "flex flex-col w-full" >
126
- < span className = "text-left truncate overflow-hidden" >
127
- { goals [ sessionIndex ] ?. [ 0 ] ?. title || "No goal set" }
128
- </ span >
129
- < span className = "text-sm text-gray-400" >
130
- { getDateTimeFromString ( session . date ) . toLocaleString (
131
- DateTime . DATETIME_FULL
132
- ) }
133
- </ span >
134
- </ div >
135
- </ SelectItem >
136
- ) ;
137
- } ) }
138
- </ SelectGroup >
106
+ { [
107
+ {
108
+ label : "Previous Sessions" ,
109
+ condition : ( date : string ) =>
110
+ getDateTimeFromString ( date ) < DateTime . now ( ) ,
111
+ } ,
112
+ {
113
+ label : "Upcoming Sessions" ,
114
+ condition : ( date : string ) =>
115
+ getDateTimeFromString ( date ) >= DateTime . now ( ) ,
116
+ } ,
117
+ ] . map (
118
+ ( { label, condition } ) =>
119
+ coachingSessions . some ( ( session ) => condition ( session . date ) ) && (
120
+ < SelectGroup key = { label } >
121
+ < SelectLabel > { label } </ SelectLabel >
122
+ { coachingSessions
123
+ . filter ( ( session ) => condition ( session . date ) )
124
+ . map ( ( session ) => (
125
+ < SessionItem
126
+ key = { session . id }
127
+ session = { session }
128
+ goals = { goals }
129
+ sessionIndex = { coachingSessions . findIndex (
130
+ ( s ) => s . id === session . id
131
+ ) }
132
+ />
133
+ ) ) }
134
+ </ SelectGroup >
135
+ )
139
136
) }
140
137
</ >
141
138
) ;
@@ -188,11 +185,11 @@ export default function CoachingSessionSelector({
188
185
} ;
189
186
190
187
const displayValue = currentSession ? (
191
- < div className = "flex flex-col w-[28rem] " >
188
+ < div className = "flex flex-col w-full " >
192
189
< span className = "truncate overflow-hidden text-left" >
193
190
{ currentGoal ?. title || "No goal set" }
194
191
</ span >
195
- < span className = "text-sm text-gray-500 text-left" >
192
+ < span className = "text-sm text-gray-500 text-left truncate overflow-hidden " >
196
193
{ getDateTimeFromString ( currentSession . date ) . toLocaleString (
197
194
DateTime . DATETIME_FULL
198
195
) }
@@ -206,12 +203,18 @@ export default function CoachingSessionSelector({
206
203
value = { currentCoachingSessionId ?? undefined }
207
204
onValueChange = { handleSetCoachingSession }
208
205
>
209
- < SelectTrigger id = "coaching-session-selector" >
210
- < SelectValue placeholder = "Select coaching session" >
206
+ < SelectTrigger
207
+ className = "w-full min-w-0 py-6 pr-2"
208
+ id = "coaching-session-selector"
209
+ >
210
+ < SelectValue className = "truncate" placeholder = "Select coaching session" >
211
211
{ displayValue }
212
212
</ SelectValue >
213
213
</ SelectTrigger >
214
- < SelectContent >
214
+ < SelectContent
215
+ className = "w-[var(--radix-select-trigger-width)] min-w-0 max-w-full"
216
+ position = "popper"
217
+ >
215
218
< CoachingSessionsSelectItems relationshipId = { relationshipId } />
216
219
</ SelectContent >
217
220
</ Select >
0 commit comments