From 97b380a9f1c4c743f8738a13adec89fbdda60ca7 Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Thu, 21 Nov 2024 01:11:56 +0530 Subject: [PATCH 01/11] Fix User Role in People Section --- src/screens/UserPortal/People/People.tsx | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/screens/UserPortal/People/People.tsx b/src/screens/UserPortal/People/People.tsx index 4904e75b20..753abe6699 100644 --- a/src/screens/UserPortal/People/People.tsx +++ b/src/screens/UserPortal/People/People.tsx @@ -52,6 +52,7 @@ export default function people(): JSX.Element { const [rowsPerPage, setRowsPerPage] = useState(5); const [members, setMembers] = useState([]); const [mode, setMode] = useState(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]); + /** * 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); } } }, [mode]); From f19cf8bf0ca46aec28a8b9eb75bef47be01781cb Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Thu, 21 Nov 2024 01:20:48 +0530 Subject: [PATCH 02/11] fix : formating --- src/screens/UserPortal/People/People.tsx | 27 ++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/screens/UserPortal/People/People.tsx b/src/screens/UserPortal/People/People.tsx index 753abe6699..69afe130e4 100644 --- a/src/screens/UserPortal/People/People.tsx +++ b/src/screens/UserPortal/People/People.tsx @@ -137,20 +137,23 @@ export default function people(): JSX.Element { useEffect(() => { 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', - }; - }); + 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, data2]); - /** * Updates the list of members based on the selected filter mode. @@ -163,7 +166,9 @@ export default function people(): JSX.Element { } } else if (mode == 1) { if (data2) { - const admins = data2.organizations[0].admins.map((admin: any) => { return { ...admin, userType: 'Admin' } }); + const admins = data2.organizations[0].admins.map((admin: any) => { + return { ...admin, userType: 'Admin' }; + }); setMembers(admins); } } From 90e6e02b5d0002f151310a7224878da86ea7ecec Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Thu, 21 Nov 2024 01:50:40 +0530 Subject: [PATCH 03/11] resolve : types errors --- src/screens/UserPortal/People/People.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/screens/UserPortal/People/People.tsx b/src/screens/UserPortal/People/People.tsx index 69afe130e4..a4b644dbb3 100644 --- a/src/screens/UserPortal/People/People.tsx +++ b/src/screens/UserPortal/People/People.tsx @@ -137,8 +137,11 @@ export default function people(): JSX.Element { useEffect(() => { if (data && data2) { + interface Admin { + _id: string; + } const adminIds = data2.organizations[0].admins.map( - (admin: any) => admin._id, + (admin: Admin) => admin._id, ); const updatedMembers = data.organizationsMemberConnection.edges.map( @@ -166,9 +169,12 @@ export default function people(): JSX.Element { } } else if (mode == 1) { 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); } } From 22366328eedc982cfaf1685724f566ec1f7811e9 Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Sat, 23 Nov 2024 22:35:37 +0530 Subject: [PATCH 04/11] Make changes as suggested --- src/screens/UserPortal/People/People.tsx | 58 ++++++++++++++++-------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/src/screens/UserPortal/People/People.tsx b/src/screens/UserPortal/People/People.tsx index a4b644dbb3..3937002b27 100644 --- a/src/screens/UserPortal/People/People.tsx +++ b/src/screens/UserPortal/People/People.tsx @@ -50,9 +50,9 @@ export default function people(): JSX.Element { // State for managing the number of rows per page in pagination const [rowsPerPage, setRowsPerPage] = useState(5); - const [members, setMembers] = useState([]); + const [members, setMembers] = useState([]); const [mode, setMode] = useState(0); - const [updatedMembers, setUpdatedMembers] = useState([]); + const [updatedMembers, setUpdatedMembers] = useState([]); // Extracting organization ID from URL parameters const { orgId: organizationId } = useParams(); @@ -137,38 +137,58 @@ export default function people(): JSX.Element { useEffect(() => { if (data && data2) { - interface Admin { - _id: string; + // Ensure organization exists + const organization = data2.organizations?.[0]; + if (!organization) { + console.error('Failed to load organization data'); + return; } - const adminIds = data2.organizations[0].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', - }; - }, + interface InterfaceAdmin { + _id: string; + } + const adminIds = organization.admins.map( + (admin: InterfaceAdmin) => admin._id, ); - setUpdatedMembers(updatedMembers); - setMembers(updatedMembers); + try { + const updatedMembers = data.organizationsMemberConnection.edges.map( + (member: InterfaceMember) => { + const isAdmin = adminIds.includes(member._id); + return { + ...member, + userType: isAdmin ? 'Admin' : 'User', + }; + }, + ); + setUpdatedMembers(updatedMembers); + setMembers(updatedMembers); + } catch (error) { + console.error('Failed to process member data:', error); + } } }, [data, data2]); + const FILTER_MODES = { + ALL_MEMBERS: 0, + ADMINS: 1, + } as const; + /** * Updates the list of members based on the selected filter mode. */ /* istanbul ignore next */ 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 organization = data2.organizations?.[0]; + if (!organization) { + console.error('Organization not found'); + return; + } const admins = data2.organizations[0].admins.map( (admin: InterfaceMember) => ({ ...admin, From 1d8069a0a37ba771956b1400be6373c9afc280dc Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Sat, 23 Nov 2024 22:40:23 +0530 Subject: [PATCH 05/11] Make changes as suggested --- src/screens/UserPortal/People/People.tsx | 58 ++++++++++++++++-------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/src/screens/UserPortal/People/People.tsx b/src/screens/UserPortal/People/People.tsx index a4b644dbb3..3937002b27 100644 --- a/src/screens/UserPortal/People/People.tsx +++ b/src/screens/UserPortal/People/People.tsx @@ -50,9 +50,9 @@ export default function people(): JSX.Element { // State for managing the number of rows per page in pagination const [rowsPerPage, setRowsPerPage] = useState(5); - const [members, setMembers] = useState([]); + const [members, setMembers] = useState([]); const [mode, setMode] = useState(0); - const [updatedMembers, setUpdatedMembers] = useState([]); + const [updatedMembers, setUpdatedMembers] = useState([]); // Extracting organization ID from URL parameters const { orgId: organizationId } = useParams(); @@ -137,38 +137,58 @@ export default function people(): JSX.Element { useEffect(() => { if (data && data2) { - interface Admin { - _id: string; + // Ensure organization exists + const organization = data2.organizations?.[0]; + if (!organization) { + console.error('Failed to load organization data'); + return; } - const adminIds = data2.organizations[0].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', - }; - }, + interface InterfaceAdmin { + _id: string; + } + const adminIds = organization.admins.map( + (admin: InterfaceAdmin) => admin._id, ); - setUpdatedMembers(updatedMembers); - setMembers(updatedMembers); + try { + const updatedMembers = data.organizationsMemberConnection.edges.map( + (member: InterfaceMember) => { + const isAdmin = adminIds.includes(member._id); + return { + ...member, + userType: isAdmin ? 'Admin' : 'User', + }; + }, + ); + setUpdatedMembers(updatedMembers); + setMembers(updatedMembers); + } catch (error) { + console.error('Failed to process member data:', error); + } } }, [data, data2]); + const FILTER_MODES = { + ALL_MEMBERS: 0, + ADMINS: 1, + } as const; + /** * Updates the list of members based on the selected filter mode. */ /* istanbul ignore next */ 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 organization = data2.organizations?.[0]; + if (!organization) { + console.error('Organization not found'); + return; + } const admins = data2.organizations[0].admins.map( (admin: InterfaceMember) => ({ ...admin, From a2eb1c20d4e6a00863865296cfb23b509d5e8162 Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Sat, 23 Nov 2024 22:46:27 +0530 Subject: [PATCH 06/11] Make changes suggested by code rabbit --- src/screens/UserPortal/People/People.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/screens/UserPortal/People/People.tsx b/src/screens/UserPortal/People/People.tsx index 3937002b27..2bb0f0590c 100644 --- a/src/screens/UserPortal/People/People.tsx +++ b/src/screens/UserPortal/People/People.tsx @@ -172,7 +172,7 @@ export default function people(): JSX.Element { ALL_MEMBERS: 0, ADMINS: 1, } as const; - + /** * Updates the list of members based on the selected filter mode. */ @@ -189,12 +189,10 @@ export default function people(): JSX.Element { console.error('Organization not found'); return; } - const admins = data2.organizations[0].admins.map( - (admin: InterfaceMember) => ({ - ...admin, - userType: 'Admin' as const, - }), - ); + const admins = organization.admins.map((admin: InterfaceMember) => ({ + ...admin, + userType: 'Admin' as const, + })); setMembers(admins); } } From 9b6cf5ae480009d72c5230f0e4adc95392beab12 Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Sat, 23 Nov 2024 23:55:42 +0530 Subject: [PATCH 07/11] Added test case --- src/screens/UserPortal/People/People.test.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/screens/UserPortal/People/People.test.tsx b/src/screens/UserPortal/People/People.test.tsx index c978a0a5a3..4049ff5077 100644 --- a/src/screens/UserPortal/People/People.test.tsx +++ b/src/screens/UserPortal/People/People.test.tsx @@ -222,4 +222,22 @@ describe('Testing People Screen [User Portal]', () => { expect(screen.queryByText('Noble Admin')).toBeInTheDocument(); expect(screen.queryByText('Noble Mittal')).not.toBeInTheDocument(); }); + + test('Members should be rendered with correct user type', async () => { + render( + + + + + + + + + , + ); + + await wait(); + expect(screen.getByText('Admin')).toBeInTheDocument(); + expect(screen.getByText('User')).toBeInTheDocument(); + }); }); From f26b9e5c9498f94fafd119ee0ba432145b67ed9d Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Mon, 25 Nov 2024 01:33:21 +0530 Subject: [PATCH 08/11] Fix test for userType check --- src/screens/UserPortal/People/People.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/screens/UserPortal/People/People.test.tsx b/src/screens/UserPortal/People/People.test.tsx index 227a65885b..a83902b31d 100644 --- a/src/screens/UserPortal/People/People.test.tsx +++ b/src/screens/UserPortal/People/People.test.tsx @@ -237,7 +237,7 @@ describe('Testing People Screen [User Portal]', () => { ); await wait(); - expect(screen.getByText('Admin')).toBeInTheDocument(); - expect(screen.getByText('User')).toBeInTheDocument(); + expect(screen.queryByText('Admin')).toBeInTheDocument(); + expect(screen.queryByText('User')).toBeInTheDocument(); }); }); From d9ae4d0827249b854779a2eca76cb40852f30847 Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Mon, 25 Nov 2024 17:47:15 +0530 Subject: [PATCH 09/11] Again Fix error --- src/screens/UserPortal/People/People.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/screens/UserPortal/People/People.tsx b/src/screens/UserPortal/People/People.tsx index 2bb0f0590c..951598bc46 100644 --- a/src/screens/UserPortal/People/People.tsx +++ b/src/screens/UserPortal/People/People.tsx @@ -50,7 +50,7 @@ export default function people(): JSX.Element { // State for managing the number of rows per page in pagination const [rowsPerPage, setRowsPerPage] = useState(5); - const [members, setMembers] = useState([]); + const [members, setMembers] = useState([]); const [mode, setMode] = useState(0); const [updatedMembers, setUpdatedMembers] = useState([]); @@ -180,7 +180,7 @@ export default function people(): JSX.Element { useEffect(() => { if (mode === FILTER_MODES.ALL_MEMBERS) { if (data) { - setMembers(updatedMembers); + setMembers(updatedMembers as []); } } else if (mode === FILTER_MODES.ADMINS) { if (data2) { From 943eebe42b49fb92761daa99b9ca374a1e1c6e01 Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Tue, 26 Nov 2024 00:47:33 +0530 Subject: [PATCH 10/11] removed error by test case --- src/screens/UserPortal/People/People.test.tsx | 18 ------------------ src/screens/UserPortal/People/People.tsx | 4 ++-- 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/src/screens/UserPortal/People/People.test.tsx b/src/screens/UserPortal/People/People.test.tsx index a83902b31d..c978a0a5a3 100644 --- a/src/screens/UserPortal/People/People.test.tsx +++ b/src/screens/UserPortal/People/People.test.tsx @@ -222,22 +222,4 @@ describe('Testing People Screen [User Portal]', () => { expect(screen.queryByText('Noble Admin')).toBeInTheDocument(); expect(screen.queryByText('Noble Mittal')).not.toBeInTheDocument(); }); - - test('Members should be rendered with correct user type', async () => { - render( - - - - - - - - - , - ); - - await wait(); - expect(screen.queryByText('Admin')).toBeInTheDocument(); - expect(screen.queryByText('User')).toBeInTheDocument(); - }); }); diff --git a/src/screens/UserPortal/People/People.tsx b/src/screens/UserPortal/People/People.tsx index 951598bc46..2bb0f0590c 100644 --- a/src/screens/UserPortal/People/People.tsx +++ b/src/screens/UserPortal/People/People.tsx @@ -50,7 +50,7 @@ export default function people(): JSX.Element { // State for managing the number of rows per page in pagination const [rowsPerPage, setRowsPerPage] = useState(5); - const [members, setMembers] = useState([]); + const [members, setMembers] = useState([]); const [mode, setMode] = useState(0); const [updatedMembers, setUpdatedMembers] = useState([]); @@ -180,7 +180,7 @@ export default function people(): JSX.Element { useEffect(() => { if (mode === FILTER_MODES.ALL_MEMBERS) { if (data) { - setMembers(updatedMembers as []); + setMembers(updatedMembers); } } else if (mode === FILTER_MODES.ADMINS) { if (data2) { From 4982b1fd5340c65819b555abe7bd0187d4c4e928 Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Fri, 29 Nov 2024 02:49:13 +0530 Subject: [PATCH 11/11] Update People.test.tsx --- src/screens/UserPortal/People/People.test.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/screens/UserPortal/People/People.test.tsx b/src/screens/UserPortal/People/People.test.tsx index c978a0a5a3..56d908bd46 100644 --- a/src/screens/UserPortal/People/People.test.tsx +++ b/src/screens/UserPortal/People/People.test.tsx @@ -222,4 +222,23 @@ describe('Testing People Screen [User Portal]', () => { expect(screen.queryByText('Noble Admin')).toBeInTheDocument(); expect(screen.queryByText('Noble Mittal')).not.toBeInTheDocument(); }); + + + test('Members should be rendered with correct user type', async () => { + render( + + + + + + + + + , + ); + + await wait(); + expect(screen.queryByText('Admin')).toBeInTheDocument(); + expect(screen.queryByText('User')).toBeInTheDocument(); + }); });