@@ -6,9 +6,11 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
66import { ArrowUpDown } from "lucide-react" ;
77import { useCoachingRelationshipStateStore } from "@/lib/providers/coaching-relationship-state-store-provider" ;
88import { useCoachingSessionList } from "@/lib/api/coaching-sessions" ;
9+ import { useCoachingSessionMutation } from "@/lib/api/coaching-sessions" ;
910import { CoachingSession as CoachingSessionComponent } from "@/components/ui/coaching-session" ;
1011import { DateTime } from "ts-luxon" ;
1112import type { CoachingSession } from "@/types/coaching-session" ;
13+ import { Id } from "@/types/general" ;
1214
1315interface CoachingSessionListProps {
1416 onUpdateSession : ( session : CoachingSession ) => void ;
@@ -27,8 +29,24 @@ export default function CoachingSessionList({ onUpdateSession }: CoachingSession
2729 coachingSessions,
2830 isLoading : isLoadingCoachingSessions ,
2931 isError : isErrorCoachingSessions ,
32+ refresh : refreshCoachingSessions ,
3033 } = useCoachingSessionList ( currentCoachingRelationshipId , fromDate , toDate ) ;
3134
35+ const { delete : deleteCoachingSession } = useCoachingSessionMutation ( ) ;
36+
37+ const handleDeleteCoachingSession = async ( id : Id ) => {
38+ if ( ! confirm ( "Are you sure you want to delete this session?" ) ) {
39+ return ;
40+ }
41+
42+ try {
43+ await deleteCoachingSession ( id ) . then ( ( ) => refreshCoachingSessions ( ) ) ;
44+ } catch ( error ) {
45+ console . error ( "Error deleting coaching session:" , error ) ;
46+ // TODO: Show an error toast here once we start using toasts for showing operation results.
47+ }
48+ } ;
49+
3250 const [ sortByDate , setSortByDate ] = useState ( true ) ;
3351
3452 const sortedSessions = coachingSessions
@@ -84,6 +102,7 @@ export default function CoachingSessionList({ onUpdateSession }: CoachingSession
84102 key = { coachingSession . id }
85103 coachingSession = { coachingSession }
86104 onUpdate = { ( ) => onUpdateSession ( coachingSession ) }
105+ onDelete = { ( ) => handleDeleteCoachingSession ( coachingSession . id ) }
87106 />
88107 ) ) }
89108 </ div >
0 commit comments