-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip wip
- Loading branch information
Showing
4 changed files
with
139 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Checkbox, CheckboxGroup, Stack } from "@chakra-ui/react"; | ||
import { useState } from "react"; | ||
|
||
import { organisationTypes } from "@/common/internal/Organisation"; | ||
import SimpleOverlayMenu from "@/modules/dashboard/SimpleOverlayMenu"; | ||
import { OrganismesFilterButton } from "@/modules/organismes/filters/OrganismesFilterButton"; | ||
|
||
interface FiltreUsersTypesProps { | ||
value: string[]; | ||
onChange: (typesUtilisateurs: string[]) => void; | ||
} | ||
|
||
function FiltreUserTypes(props: FiltreUsersTypesProps) { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const typesUtilisateurs = props.value; | ||
|
||
return ( | ||
<div> | ||
<OrganismesFilterButton | ||
isOpen={isOpen} | ||
setIsOpen={setIsOpen} | ||
buttonLabel="Type d'utilisateur" | ||
badge={typesUtilisateurs?.length} | ||
/> | ||
{isOpen && ( | ||
<SimpleOverlayMenu onClose={() => setIsOpen(false)} width="auto" p="3w"> | ||
<CheckboxGroup | ||
defaultValue={typesUtilisateurs} | ||
size="sm" | ||
onChange={(selectedTypesUtilisateurs: string[]) => props.onChange(selectedTypesUtilisateurs)} | ||
> | ||
<Stack> | ||
{organisationTypes.map((type, i) => ( | ||
<Checkbox iconSize="0.5rem" value={type} key={i}> | ||
{type} | ||
</Checkbox> | ||
))} | ||
</Stack> | ||
</CheckboxGroup> | ||
</SimpleOverlayMenu> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
export default FiltreUserTypes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { stripEmptyFields } from "@/common/utils/misc"; | ||
|
||
export interface UsersFilters { | ||
type_utilisateur: string[]; | ||
} | ||
|
||
export interface UsersFiltersQuery { | ||
type_utilisateur?: string; | ||
} | ||
|
||
export function parseUsersFiltersFromQuery(query: UsersFiltersQuery): UsersFilters { | ||
return { | ||
type_utilisateur: query.type_utilisateur?.split(",") ?? [], | ||
}; | ||
} | ||
|
||
export function convertUsersFiltersToQuery(organismesFilters: Partial<UsersFilters>): Partial<UsersFiltersQuery> { | ||
return stripEmptyFields({ | ||
type_utilisateur: organismesFilters.type_utilisateur?.join(","), | ||
}); | ||
} | ||
|
||
export function filterUsersArrayFromUsersFilters(users, usersFilters: Partial<UsersFilters>) { | ||
let filteredUsers = users; | ||
console.log("usersFilters :>> ", usersFilters); | ||
|
||
if (usersFilters.type_utilisateur?.length && usersFilters.type_utilisateur?.length > 0) | ||
filteredUsers = filteredUsers?.filter((item) => usersFilters.type_utilisateur?.includes(item.userType)); | ||
|
||
console.log("filteredUsers :>> ", filteredUsers); | ||
return filteredUsers; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters