Skip to content

Commit

Permalink
Fix User Role in People Section
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-bansal-7 committed Nov 20, 2024
1 parent 86849df commit 97b380a
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/screens/UserPortal/People/People.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function people(): JSX.Element {
const [rowsPerPage, setRowsPerPage] = useState<number>(5);
const [members, setMembers] = useState([]);
const [mode, setMode] = useState<number>(0);
const [updatedMembers, setUpdatedMembers] = useState([]);

// Extracting organization ID from URL parameters
const { orgId: organizationId } = useParams();
Expand Down Expand Up @@ -135,10 +136,21 @@ export default function people(): JSX.Element {
};

useEffect(() => {
if (data) {
setMembers(data.organizationsMemberConnection.edges);
if (data && data2) {
const adminIds = data2.organizations[0].admins.map((admin: any) => admin._id);

const updatedMembers = data.organizationsMemberConnection.edges.map((member: InterfaceMember) => {
const isAdmin = adminIds.includes(member._id);
return {
...member,
userType: isAdmin ? 'Admin' : 'User',
};
});
setUpdatedMembers(updatedMembers);
setMembers(updatedMembers);
}
}, [data]);
}, [data, data2]);


/**
* Updates the list of members based on the selected filter mode.
Expand All @@ -147,11 +159,12 @@ export default function people(): JSX.Element {
useEffect(() => {
if (mode == 0) {
if (data) {
setMembers(data.organizationsMemberConnection.edges);
setMembers(updatedMembers);
}
} else if (mode == 1) {
if (data2) {
setMembers(data2.organizations[0].admins);
const admins = data2.organizations[0].admins.map((admin: any) => { return { ...admin, userType: 'Admin' } });
setMembers(admins);
}
}
}, [mode]);
Expand Down

0 comments on commit 97b380a

Please sign in to comment.