Skip to content

Commit

Permalink
Ajoute l'affichage d'un badge quand un filtre par plage de date est a…
Browse files Browse the repository at this point in the history
…ctivé
  • Loading branch information
marc-rutkowski committed Dec 18, 2024
1 parent df558b6 commit 5deeeb8
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ export const useFiltersToBadges = ({ filters, customValues }: Args) => {
} else if (key === 'noServicePilote') {
mergedFilters[key] &&
badgeValues.push('Sans direction ou service pilote');
} else if (
key === 'typePeriode' &&
mergedFilters[key] &&
(mergedFilters.debutPeriode || mergedFilters.finPeriode)
) {
badgeValues.push(
typePeriodeToLabel[mergedFilters[key]] +
' ' +
dateRangeToLabel(
mergedFilters.debutPeriode,
mergedFilters.finPeriode
)
);
}
});

Expand All @@ -206,3 +219,23 @@ export const useFiltersToBadges = ({ filters, customValues }: Args) => {
return badgeValues;
});
};

const typePeriodeToLabel = {
modification: 'Modifiée',
creation: 'Créée',
debut: 'Commencée',
fin: 'Terminée',
};

const dateRangeToLabel = (
debut: string | undefined,
fin: string | undefined
) => {
if (debut && !fin) return `depuis le ${new Date(debut).toLocaleDateString()}`;
if (!debut && fin) return `avant le ${new Date(fin).toLocaleDateString()}`;
if (debut && fin)
return `entre le ${new Date(debut).toLocaleDateString()} et le ${new Date(
fin
).toLocaleDateString()}`;
return '';
};

0 comments on commit 5deeeb8

Please sign in to comment.