Skip to content

Commit

Permalink
sort items in follow cards
Browse files Browse the repository at this point in the history
  • Loading branch information
RenauxLeaInsee committed Apr 25, 2024
1 parent f0e2d2d commit 7bc3f92
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
29 changes: 28 additions & 1 deletion src/ui/FollowInterviewerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ type FilterInterviewerProps = {
search?: string;
};

/* filterInterviewers :
conditions enable to filter when user search by:
- firstName
- lastName
- firstName follow by lastName
- lastName follow by firstName
*/
const filterInterviewers = ({ interviewers, search }: FilterInterviewerProps) => {
if (search) {
interviewers = interviewers.filter(
Expand All @@ -117,5 +124,25 @@ const filterInterviewers = ({ interviewers, search }: FilterInterviewerProps) =>
);
}

return interviewers;
return interviewers.sort((i1, i2) => {
const nameI1 = getInterviewerName({
lastName: i1.interviewerLastName,
firstName: i1.interviewerFirstName,
});

const nameI2 = getInterviewerName({
lastName: i2.interviewerLastName,
firstName: i2.interviewerFirstName,
});

return nameI1.trim().localeCompare(nameI2.trim());
});
};

const getInterviewerName = ({ lastName, firstName }: { lastName?: string; firstName?: string }) => {
if (lastName) {
return firstName ? lastName.concat(firstName) : lastName;
} else {
return firstName ?? "";
}
};
2 changes: 1 addition & 1 deletion src/ui/FollowOrganizationUnitCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ const filterOrganizationUnits = ({ organizationUnits, search }: FilterOUProps) =
);
}

return organizationUnits;
return organizationUnits.sort((ou1, ou2) => ou1.label.localeCompare(ou2.label));
};
2 changes: 2 additions & 0 deletions src/ui/FollowSurveyCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const surveysMock = [
export const FollowSurveyCard = () => {
const intl = useIntl();

surveysMock.sort((su1, su2) => su1.label.localeCompare(su2.label));

return (
<Card variant="general" sx={{ height: "calc(100vh - 140px)", py: 4, px: 3, overflow: "auto" }}>
<Stack gap={3}>
Expand Down

0 comments on commit 7bc3f92

Please sign in to comment.