11import { useState } from "react" ;
22import { useCurrentOrganization } from "@/lib/hooks/use-current-organization" ;
33import { useAuthStore } from "@/lib/providers/auth-store-provider" ;
4- import { useCurrentUserRole } from "@/lib/hooks/use-current-user-role" ;
54import { useUserMutation } from "@/lib/api/organizations/users" ;
65import { getUserDisplayRoles , getUserCoaches } from "@/lib/utils/user-roles" ;
76import { Button } from "@/components/ui/button" ;
@@ -31,7 +30,7 @@ import {
3130import { CoachingRelationshipWithUserNames } from "@/types/coaching_relationship" ;
3231import { AuthStore } from "@/lib/stores/auth-store" ;
3332import { Id } from "@/types/general" ;
34- import { User , Role , isAdminOrSuperAdmin } from "@/types/user" ;
33+ import { User , isAdminOrSuperAdmin , UserRoleState } from "@/types/user" ;
3534import { RelationshipRole } from "@/types/relationship-role" ;
3635import { useCoachingRelationshipMutation } from "@/lib/api/coaching-relationships" ;
3736import { toast } from "sonner" ;
@@ -42,6 +41,7 @@ interface MemberCardProps {
4241 userRelationships : CoachingRelationshipWithUserNames [ ] ;
4342 onRefresh : ( ) => void ;
4443 users : User [ ] ;
44+ currentUserRoleState : UserRoleState ;
4545}
4646
4747interface Member {
@@ -56,10 +56,10 @@ export function MemberCard({
5656 userRelationships,
5757 onRefresh,
5858 users,
59+ currentUserRoleState,
5960} : MemberCardProps ) {
6061 const { currentOrganizationId } = useCurrentOrganization ( ) ;
6162 const { isACoach, userSession } = useAuthStore ( ( state : AuthStore ) => state ) ;
62- const currentUserRoleState = useCurrentUserRole ( ) ;
6363
6464 // Extract user properties
6565 const { id : userId , first_name : firstName , last_name : lastName , email } = user ;
@@ -77,17 +77,11 @@ export function MemberCard({
7777
7878 console . log ( "is a coach" , isACoach ) ;
7979
80- // Check if current user is a coach in any of this user's relationships
81- // and make sure we can't delete ourselves. Admins and SuperAdmins can delete any user.
80+ // Only admins and super admins can delete users (but not themselves)
8281 const canDeleteUser =
8382 currentUserRoleState . hasAccess &&
8483 userSession . id !== userId &&
85- (
86- userRelationships ?. some (
87- ( rel ) => rel . coach_id === userSession . id
88- ) ||
89- isAdminOrSuperAdmin ( currentUserRoleState )
90- ) ;
84+ isAdminOrSuperAdmin ( currentUserRoleState ) ;
9185
9286 const handleDelete = async ( ) => {
9387 if ( ! confirm ( "Are you sure you want to delete this member?" ) ) {
@@ -171,7 +165,7 @@ export function MemberCard({
171165 < span className = "font-medium" > Coaches:</ span > { coaches . length > 0 ? coaches . join ( ', ' ) : 'None' }
172166 </ p >
173167 </ div >
174- { ( isAdminOrSuperAdmin ( currentUserRoleState ) || canDeleteUser ) && (
168+ { isAdminOrSuperAdmin ( currentUserRoleState ) && (
175169 < DropdownMenu >
176170 < DropdownMenuTrigger asChild >
177171 < Button
@@ -215,7 +209,7 @@ export function MemberCard({
215209 ) }
216210 { canDeleteUser && (
217211 < >
218- < DropdownMenuSeparator />
212+ { userId !== currentUserId && < DropdownMenuSeparator /> }
219213 < DropdownMenuItem
220214 onClick = { handleDelete }
221215 className = "text-destructive focus:text-destructive"
0 commit comments