From 3554a662ece92c98842fb00ff6237c648985e9cb Mon Sep 17 00:00:00 2001 From: karan Date: Thu, 19 Oct 2023 17:32:16 +0530 Subject: [PATCH] refactor: member list sonarlint issues Signed-off-by: karan --- src/components/Ecosystem/MemberList.tsx | 40 ++++++++++++++----------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/components/Ecosystem/MemberList.tsx b/src/components/Ecosystem/MemberList.tsx index 43125b5be..a6b5001cd 100644 --- a/src/components/Ecosystem/MemberList.tsx +++ b/src/components/Ecosystem/MemberList.tsx @@ -22,6 +22,23 @@ const MemberList = () => { const [error, setError] = useState(null); const [currentPage, setCurrentPage] = useState(initialPageState); + const compareMembers = ( + firstMember: { ecosystemRole: { name: string } }, + secondMember: { ecosystemRole: { name: string } }, + ) => { + const firstName = firstMember?.ecosystemRole?.name; + const secondName = secondMember?.ecosystemRole?.name; + + switch (true) { + case firstName > secondName: + return 1; + case secondName > firstName: + return -1; + default: + return 0; + } + }; + const getEcosystemMembers = async () => { const userOrgId = await getFromLocalStorage(storageKeys.ORG_ID); setLoading(true); @@ -32,25 +49,14 @@ const MemberList = () => { ); const { data } = response as AxiosResponse; + if (data?.statusCode !== apiStatusCodes.API_STATUS_SUCCESS) { + setError(response as string); + return; + } + if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) { const totalPages = data?.data?.totalPages; - const compareMembers = ( - firstMember: { ecosystemRole: { name: string } }, - secondMember: { ecosystemRole: { name: string } }, - ) => { - const firstName = firstMember?.ecosystemRole?.name; - const secondName = secondMember?.ecosystemRole?.name; - - switch (true) { - case firstName > secondName: - return 1; - case secondName > firstName: - return -1; - default: - return 0; - } - }; const sortedMemberList = data?.data?.members?.sort(compareMembers); const membersData = sortedMemberList?.map( (member: { @@ -132,8 +138,6 @@ const MemberList = () => { ...currentPage, total: totalPages, }); - } else { - setError(response as string); } setLoading(false); };