Skip to content

Commit 7ac7872

Browse files
committed
fix member page bugs
1 parent 519db46 commit 7ac7872

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

src/components/ui/members/member-card.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useState } from "react";
22
import { useCurrentOrganization } from "@/lib/hooks/use-current-organization";
33
import { useAuthStore } from "@/lib/providers/auth-store-provider";
4-
import { useCurrentUserRole } from "@/lib/hooks/use-current-user-role";
54
import { useUserMutation } from "@/lib/api/organizations/users";
65
import { getUserDisplayRoles, getUserCoaches } from "@/lib/utils/user-roles";
76
import { Button } from "@/components/ui/button";
@@ -31,7 +30,7 @@ import {
3130
import { CoachingRelationshipWithUserNames } from "@/types/coaching_relationship";
3231
import { AuthStore } from "@/lib/stores/auth-store";
3332
import { Id } from "@/types/general";
34-
import { User, Role, isAdminOrSuperAdmin } from "@/types/user";
33+
import { User, isAdminOrSuperAdmin, UserRoleState } from "@/types/user";
3534
import { RelationshipRole } from "@/types/relationship-role";
3635
import { useCoachingRelationshipMutation } from "@/lib/api/coaching-relationships";
3736
import { toast } from "sonner";
@@ -42,6 +41,7 @@ interface MemberCardProps {
4241
userRelationships: CoachingRelationshipWithUserNames[];
4342
onRefresh: () => void;
4443
users: User[];
44+
currentUserRoleState: UserRoleState;
4545
}
4646

4747
interface 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"

src/components/ui/members/member-container.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export function MemberContainer({
6767
relationships={relationships}
6868
onRefresh={onRefresh}
6969
currentUserId={userSession.id}
70+
currentUserRoleState={currentUserRoleState}
7071
/>
7172
</div>
7273
);

src/components/ui/members/member-list.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Card, CardContent } from "@/components/ui/card";
2-
import { User } from "@/types/user";
2+
import { User, UserRoleState } from "@/types/user";
33
import { MemberCard } from "./member-card";
44
import { CoachingRelationshipWithUserNames } from "@/types/coaching_relationship";
55
import { Id } from "@/types/general";
@@ -9,13 +9,15 @@ interface MemberListProps {
99
relationships: CoachingRelationshipWithUserNames[];
1010
onRefresh: () => void;
1111
currentUserId: Id;
12+
currentUserRoleState: UserRoleState;
1213
}
1314

1415
export function MemberList({
1516
users,
1617
relationships,
1718
onRefresh,
1819
currentUserId,
20+
currentUserRoleState,
1921
}: MemberListProps) {
2022
// Create a mapping of user IDs to their associated relationships
2123
const userRelationshipsMap = users.reduce<Record<Id, CoachingRelationshipWithUserNames[]>>(
@@ -42,6 +44,7 @@ export function MemberList({
4244
userRelationships={userRelationshipsMap[user.id] ?? []}
4345
onRefresh={onRefresh}
4446
users={users}
47+
currentUserRoleState={currentUserRoleState}
4548
/>
4649
))}
4750
</div>

0 commit comments

Comments
 (0)