Skip to content

Commit a17885a

Browse files
authored
Merge pull request #100 from refactor-group/delete_coaching_sessions
Delete coaching sessions.
2 parents e9cb3e7 + dbc6966 commit a17885a

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/components/ui/coaching-session.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@ import {
1616
} from "@/components/ui/dropdown-menu";
1717
import { MoreHorizontal } from "lucide-react";
1818
import { CoachingSession as CoachingSessionType } from "@/types/coaching-session";
19+
import { useAuthStore } from "@/lib/providers/auth-store-provider";
1920

2021
interface CoachingSessionProps {
2122
coachingSession: CoachingSessionType;
2223
onUpdate: () => void;
24+
onDelete: () => void;
2325
}
2426

2527
const CoachingSession: React.FC<CoachingSessionProps> = ({
2628
coachingSession,
2729
onUpdate,
30+
onDelete,
2831
}) => {
2932
const { setCurrentCoachingSessionId } = useCoachingSessionStateStore(
3033
(state) => state
3134
);
35+
const { isCoach } = useAuthStore((state) => state);
3236

3337
return (
3438
<Card>
@@ -60,9 +64,11 @@ const CoachingSession: React.FC<CoachingSessionProps> = ({
6064
<DropdownMenuItem onClick={onUpdate}>
6165
Update Session
6266
</DropdownMenuItem>
63-
<DropdownMenuItem className="text-destructive">
64-
Delete Session
65-
</DropdownMenuItem>
67+
{isCoach && (
68+
<DropdownMenuItem onClick={onDelete} className="text-destructive">
69+
Delete Session
70+
</DropdownMenuItem>
71+
)}
6672
</DropdownMenuContent>
6773
</DropdownMenu>
6874
</div>

src/components/ui/dashboard/coaching-session-list.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
66
import { ArrowUpDown } from "lucide-react";
77
import { useCoachingRelationshipStateStore } from "@/lib/providers/coaching-relationship-state-store-provider";
88
import { useCoachingSessionList } from "@/lib/api/coaching-sessions";
9+
import { useCoachingSessionMutation } from "@/lib/api/coaching-sessions";
910
import { CoachingSession as CoachingSessionComponent } from "@/components/ui/coaching-session";
1011
import { DateTime } from "ts-luxon";
1112
import type { CoachingSession } from "@/types/coaching-session";
13+
import { Id } from "@/types/general";
1214

1315
interface 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

Comments
 (0)