diff --git a/apps/hackathon/src/app/teams/[teamId]/page.tsx b/apps/hackathon/src/app/teams/[teamId]/page.tsx index a8d6ba8..4ba40ee 100644 --- a/apps/hackathon/src/app/teams/[teamId]/page.tsx +++ b/apps/hackathon/src/app/teams/[teamId]/page.tsx @@ -7,6 +7,7 @@ import { useInviteMember, useTeamJoinRequests, useRespondToJoinRequest, + useLeaveTeam, ETeamMemberRole, useAuthStore, } from '@imphnen-frontend-service/service'; @@ -52,6 +53,7 @@ const TeamDashboardPage: FC = (): ReactElement => { const { session } = useAuthStore(); const [showInviteModal, setShowInviteModal] = useState(false); const [showJoinRequestsModal, setShowJoinRequestsModal] = useState(false); + const [showLeaveModal, setShowLeaveModal] = useState(false); const [inviteEmail, setInviteEmail] = useState(''); const [imagesLoaded, setImagesLoaded] = useState(false); const [imageLoadCount, setImageLoadCount] = useState(0); @@ -94,6 +96,7 @@ const TeamDashboardPage: FC = (): ReactElement => { ); const { mutateAsync: respondToJoinRequest, isPending: isResponding } = useRespondToJoinRequest(teamId || ''); + const { mutateAsync: leaveTeam, isPending: isLeaving } = useLeaveTeam(); const team = teamData?.data; const members = membersData?.data || []; @@ -139,6 +142,19 @@ const TeamDashboardPage: FC = (): ReactElement => { } }; + const handleLeaveTeam = async () => { + if (!teamId) return; + + try { + await leaveTeam(teamId); + toast.success('You have left the team'); + navigate('/dashboard'); + } catch (error) { + console.error('Failed to leave team:', error); + toast.error('Failed to leave team'); + } + }; + if (isLoadingTeam || isLoadingMembers) { return (
+ Are you sure you want to leave {team?.name}? +
++ Warning: If you leave, you will need to request to join again or be re-invited by the team leader. +
+