-
-
Notifications
You must be signed in to change notification settings - Fork 892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix User Role in People Section #2459
Changes from 1 commit
97b380a
f19cf8b
90e6e02
2973b7a
2236632
1d8069a
a2eb1c2
9b6cf5a
c1b6e3a
f26b9e5
d9ae4d0
f7ccfb5
943eebe
a5191df
4982b1f
25beeb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add type safety and error handling to the data processing logic The current implementation has several potential issues:
Consider applying these improvements: useEffect(() => {
if (data && data2) {
+ // Ensure organization exists
+ const organization = data2.organizations?.[0];
+ if (!organization) {
+ console.error('Organization not found');
+ return;
+ }
+
- const adminIds = data2.organizations[0].admins.map((admin: any) => admin._id);
+ interface Admin {
+ _id: string;
+ }
+ const adminIds = organization.admins.map((admin: Admin) => 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, data2]); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Updates the list of members based on the selected filter mode. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -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); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve mode-based filtering implementation The current implementation has several areas for improvement:
Consider these improvements: + // Add at the top of the file with other constants
+ const FILTER_MODES = {
+ ALL_MEMBERS: 0,
+ ADMINS: 1
+ } as const;
useEffect(() => {
- if (mode == 0) {
+ if (mode === FILTER_MODES.ALL_MEMBERS) {
if (data) {
setMembers(updatedMembers);
}
- } else if (mode == 1) {
+ } else if (mode === FILTER_MODES.ADMINS) {
if (data2) {
- const admins = data2.organizations[0].admins.map((admin: any) => { return { ...admin, userType: 'Admin' } });
+ const admins = data2.organizations[0].admins.map((admin: InterfaceMember) => ({
+ ...admin,
+ userType: 'Admin' as const
+ }));
setMembers(admins);
}
}
+ return () => {
+ // Cleanup to prevent state updates after unmount
+ setMembers([]);
+ };
}, [mode]);
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, [mode]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add type safety to the state variable
The new state variable should be properly typed to match the member interface.
📝 Committable suggestion