Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/components/ui/coaching-session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ import {
} from "@/components/ui/dropdown-menu";
import { MoreHorizontal } from "lucide-react";
import { CoachingSession as CoachingSessionType } from "@/types/coaching-session";
import { useAuthStore } from "@/lib/providers/auth-store-provider";

interface CoachingSessionProps {
coachingSession: CoachingSessionType;
onUpdate: () => void;
onDelete: () => void;
}

const CoachingSession: React.FC<CoachingSessionProps> = ({
coachingSession,
onUpdate,
onDelete,
}) => {
const { setCurrentCoachingSessionId } = useCoachingSessionStateStore(
(state) => state
);
const { isCoach } = useAuthStore((state) => state);

return (
<Card>
Expand Down Expand Up @@ -60,9 +64,11 @@ const CoachingSession: React.FC<CoachingSessionProps> = ({
<DropdownMenuItem onClick={onUpdate}>
Update Session
</DropdownMenuItem>
<DropdownMenuItem className="text-destructive">
Delete Session
</DropdownMenuItem>
{isCoach && (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isCoach is working out so well, I love it.

<DropdownMenuItem onClick={onDelete} className="text-destructive">
Delete Session
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mentioned in my other review in PR #96, change this text to "Delete".

</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
</div>
Expand Down
19 changes: 19 additions & 0 deletions src/components/ui/dashboard/coaching-session-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { ArrowUpDown } from "lucide-react";
import { useCoachingRelationshipStateStore } from "@/lib/providers/coaching-relationship-state-store-provider";
import { useCoachingSessionList } from "@/lib/api/coaching-sessions";
import { useCoachingSessionMutation } from "@/lib/api/coaching-sessions";
import { CoachingSession as CoachingSessionComponent } from "@/components/ui/coaching-session";
import { DateTime } from "ts-luxon";
import type { CoachingSession } from "@/types/coaching-session";
import { Id } from "@/types/general";

interface CoachingSessionListProps {
onUpdateSession: (session: CoachingSession) => void;
Expand All @@ -27,8 +29,24 @@ export default function CoachingSessionList({ onUpdateSession }: CoachingSession
coachingSessions,
isLoading: isLoadingCoachingSessions,
isError: isErrorCoachingSessions,
refresh: refreshCoachingSessions,
} = useCoachingSessionList(currentCoachingRelationshipId, fromDate, toDate);

const { delete: deleteCoachingSession } = useCoachingSessionMutation();

const handleDeleteCoachingSession = async (id: Id) => {
if (!confirm("Are you sure you want to delete this session?")) {
return;
}

try {
await deleteCoachingSession(id).then(() => refreshCoachingSessions());
} catch (error) {
console.error("Error deleting coaching session:", error);
// TODO: Show an error toast here once we start using toasts for showing operation results.
}
};

const [sortByDate, setSortByDate] = useState(true);

const sortedSessions = coachingSessions
Expand Down Expand Up @@ -84,6 +102,7 @@ export default function CoachingSessionList({ onUpdateSession }: CoachingSession
key={coachingSession.id}
coachingSession={coachingSession}
onUpdate={() => onUpdateSession(coachingSession)}
onDelete={() => handleDeleteCoachingSession(coachingSession.id)}
/>
))}
</div>
Expand Down