Skip to content

Commit

Permalink
fix(ui): filtres région / dpt sur organisation + format date (#3391)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbenfares authored Nov 24, 2023
1 parent e63a2b4 commit 5e4d3c3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions ui/common/internal/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export interface UserOrganisation {
type: string;
uai: string;
siret: string;
code_departement: string;
code_region: string;
organisme: UserOrganisme;
label: string;
}
Expand Down
11 changes: 8 additions & 3 deletions ui/modules/admin/users/models/users-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ export function filterUsersArrayFromUsersFilters(
);

if (usersFilters.departements?.length && usersFilters.departements?.length > 0)
filteredUsers = filteredUsers?.filter((item) => usersFilters.departements?.includes(item.organismeDepartement));
filteredUsers = filteredUsers?.filter(
(item) => usersFilters.departements?.includes(item.organismeDepartement || item.organisationDepartement)
);

if (usersFilters.regions?.length && usersFilters.regions?.length > 0)
filteredUsers = filteredUsers?.filter((item) => usersFilters.regions?.includes(item.organismeRegion));
if (usersFilters.regions?.length && usersFilters.regions?.length > 0) {
filteredUsers = filteredUsers?.filter(
(item) => usersFilters.regions?.includes(item.organismeRegion || item.organisationRegion)
);
}

return filteredUsers;
}
9 changes: 7 additions & 2 deletions ui/modules/admin/users/models/users.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { User, UserOrganisation } from "@/common/internal/User";
import { formatDateDayMonthYear } from "@/common/utils/dateUtils";

export type UserNormalized = {
_id: string;
Expand All @@ -19,6 +18,8 @@ export type UserNormalized = {
organismeReseaux: string[];
organismeDepartement: string;
organismeRegion: string;
organisationDepartement: string;
organisationRegion: string;
nom: string;
prenom: string;
account_status: string;
Expand All @@ -34,6 +35,8 @@ export const toUserNormalized = (user: User): UserNormalized => {
const organismeReseaux = user?.organisation?.organisme?.reseaux || [];
const organismeDepartement = user?.organisation?.organisme?.adresse?.departement || "";
const organismeRegion = user?.organisation?.organisme?.adresse?.region || "";
const organisationDepartement = user?.organisation?.code_departement || "";
const organisationRegion = user?.organisation?.code_region || "";

return {
...user,
Expand All @@ -42,7 +45,9 @@ export const toUserNormalized = (user: User): UserNormalized => {
organismeReseaux,
organismeDepartement,
organismeRegion,
created_at: formatDateDayMonthYear(user.created_at),
organisationDepartement,
organisationRegion,
created_at: user.created_at.toLocaleString(),
organisationType: user?.organisation?.label || "",
userType: user?.organisation?.type || "",
normalizedOrganismeNom: organismeNom.toLowerCase(),
Expand Down

0 comments on commit 5e4d3c3

Please sign in to comment.