@@ -45,17 +45,21 @@ import {
4545 fetchNotesByCoachingSessionId ,
4646 updateNote ,
4747} from "@/lib/api/notes" ;
48- import { Note , noteToString } from "@/types/note" ;
48+ import { noteToString } from "@/types/note" ;
4949import { useAuthStore } from "@/lib/providers/auth-store-provider" ;
50- import { Id } from "@/types/general" ;
50+ import { ActionStatus , Id } from "@/types/general" ;
5151import { AgreementsList } from "@/components/ui/coaching-sessions/agreements-list" ;
52- import { Agreement , agreementToString } from "@/types/agreement" ;
52+ import { Agreement } from "@/types/agreement" ;
5353import {
5454 createAgreement ,
5555 deleteAgreement ,
5656 updateAgreement ,
5757} from "@/lib/api/agreements" ;
5858import { siteConfig } from "@/site.config" ;
59+ import { ActionsList } from "@/components/ui/coaching-sessions/actions-list" ;
60+ import { Action } from "@/types/action" ;
61+ import { createAction , deleteAction , updateAction } from "@/lib/api/actions" ;
62+ import { DateTime } from "ts-luxon" ;
5963
6064// export const metadata: Metadata = {
6165// title: "Coaching Session",
@@ -133,6 +137,49 @@ export default function CoachingSessionsPage() {
133137 } ) ;
134138 } ;
135139
140+ const handleActionAdded = (
141+ body : string ,
142+ status : ActionStatus ,
143+ dueBy : DateTime
144+ ) : Promise < Action > => {
145+ // Calls the backend endpoint that creates and stores a full Action entity
146+ return createAction ( coachingSessionId , body , status , dueBy )
147+ . then ( ( action ) => {
148+ return action ;
149+ } )
150+ . catch ( ( err ) => {
151+ console . error ( "Failed to create new Action: " + err ) ;
152+ throw err ;
153+ } ) ;
154+ } ;
155+
156+ const handleActionEdited = (
157+ id : Id ,
158+ body : string ,
159+ status : ActionStatus ,
160+ dueBy : DateTime
161+ ) : Promise < Action > => {
162+ return updateAction ( id , coachingSessionId , body , status , dueBy )
163+ . then ( ( action ) => {
164+ return action ;
165+ } )
166+ . catch ( ( err ) => {
167+ console . error ( "Failed to update Action (id: " + id + "): " + err ) ;
168+ throw err ;
169+ } ) ;
170+ } ;
171+
172+ const handleActionDeleted = ( id : Id ) : Promise < Action > => {
173+ return deleteAction ( id )
174+ . then ( ( action ) => {
175+ return action ;
176+ } )
177+ . catch ( ( err ) => {
178+ console . error ( "Failed to update Action (id: " + id + "): " + err ) ;
179+ throw err ;
180+ } ) ;
181+ } ;
182+
136183 const handleInputChange = ( value : string ) => {
137184 setNote ( value ) ;
138185
@@ -252,7 +299,16 @@ export default function CoachingSessionsPage() {
252299 </ div >
253300 </ TabsContent >
254301 < TabsContent value = "actions" >
255- { /* <div className="bg-red-500 text-white">Actions</div> */ }
302+ < div className = "w-full" >
303+ < ActionsList
304+ coachingSessionId = { coachingSessionId }
305+ userId = { userId }
306+ locale = { siteConfig . locale }
307+ onActionAdded = { handleActionAdded }
308+ onActionEdited = { handleActionEdited }
309+ onActionDeleted = { handleActionDeleted }
310+ > </ ActionsList >
311+ </ div >
256312 </ TabsContent >
257313 < TabsContent value = "program" >
258314 { /* <div className="bg-blue-500 text-white">Program</div> */ }
0 commit comments