Skip to content

Commit

Permalink
refactor: member list sonarlint issues
Browse files Browse the repository at this point in the history
Signed-off-by: karan <[email protected]>
  • Loading branch information
16-karan committed Oct 19, 2023
1 parent 97d3d01 commit 3554a66
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/components/Ecosystem/MemberList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ const MemberList = () => {
const [error, setError] = useState<string | null>(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);
Expand All @@ -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: {
Expand Down Expand Up @@ -132,8 +138,6 @@ const MemberList = () => {
...currentPage,
total: totalPages,
});
} else {
setError(response as string);
}
setLoading(false);
};
Expand Down

0 comments on commit 3554a66

Please sign in to comment.