diff --git a/.talismanrc b/.talismanrc index fb1bd5736..b673ae6ae 100644 --- a/.talismanrc +++ b/.talismanrc @@ -31,4 +31,5 @@ allowed_patterns: - keyof - \[key\] - key= +- "key:" version: "1.0" diff --git a/frontend/src/hooks/useFilters.tsx b/frontend/src/hooks/useFilters.tsx index 0ca338598..a75b19d62 100644 --- a/frontend/src/hooks/useFilters.tsx +++ b/frontend/src/hooks/useFilters.tsx @@ -1,10 +1,8 @@ import { useMemo, useState } from 'react'; import housingSlice, { - initialHousingFilters, + initialHousingFilters } from '../store/reducers/housingReducer'; import { HousingFilters } from '../models/HousingFilters'; -import { TrackEventActions, TrackEventCategories } from '../models/TrackEvent'; -import { useMatomo } from '@jonkoops/matomo-tracker-react'; import { useAppDispatch, useAppSelector } from './useStore'; interface FiltersOptions { @@ -17,7 +15,6 @@ interface FiltersOptions { export function useFilters(opts?: FiltersOptions) { const dispatch = useAppDispatch(); - const { trackEvent } = useMatomo(); const initialState = opts?.initialState ?? initialHousingFilters; const storage = opts?.storage ?? 'store'; @@ -31,10 +28,6 @@ export function useFilters(opts?: FiltersOptions) { const [filters, setFilters] = storage === 'store' ? [store.filters, changeFilters] : state; - const establishment = useAppSelector( - (state) => state.authentication.authUser?.establishment, - ); - const { filtersExpanded: expand } = useAppSelector((state) => state.housing); const { expandFilters } = housingSlice.actions; @@ -45,42 +38,17 @@ export function useFilters(opts?: FiltersOptions) { function removeFilter(removed: HousingFilters) { setFilters({ ...filters, - ...removed, + ...removed }); } const length = useMemo(() => Object.keys(filters).length, [filters]); - function onChange(changed: HousingFilters, filterLabel?: string): void { + function onChange(changed: HousingFilters): void { setFilters({ ...filters, - ...changed, + ...changed }); - if (filterLabel) { - trackNewFilter(changed, filterLabel); - } - } - - function trackNewFilter(changedFilters: HousingFilters, filterLabel: string) { - const filterEntry = Object.entries(changedFilters)[0]; - const prevFilterEntry = Object.entries(filters).find( - (_) => _[0] === filterEntry[0], - ); - const filterValues = filterEntry[1] as Array; - const prevFilterValues = prevFilterEntry - ? (prevFilterEntry[1] as Array) - : []; - const newValues = filterValues.filter - ? filterValues.filter((_) => prevFilterValues?.indexOf(_) === -1) - : []; - if (newValues.length) { - trackEvent({ - category: TrackEventCategories.Filter, - action: TrackEventActions.Filter(filterLabel), - name: newValues.toString(), - value: establishment?.siren, - }); - } } function onReset(): void { @@ -95,6 +63,6 @@ export function useFilters(opts?: FiltersOptions) { removeFilter, onChangeFilters: onChange, onResetFilters: onReset, - setExpand, + setExpand }; } diff --git a/frontend/src/views/Group/GroupView.tsx b/frontend/src/views/Group/GroupView.tsx index c5471de3a..abafd311c 100644 --- a/frontend/src/views/Group/GroupView.tsx +++ b/frontend/src/views/Group/GroupView.tsx @@ -1,6 +1,6 @@ import Alert from '@codegouvfr/react-dsfr/Alert'; -import { useMatomo } from '@jonkoops/matomo-tracker-react'; import Grid from '@mui/material/Unstable_Grid2'; +import { useEffect } from 'react'; import { useHistory, useParams } from 'react-router-dom'; import { @@ -10,12 +10,7 @@ import { } from '../../services/group.service'; import Group from '../../components/Group/Group'; import { useDocumentTitle } from '../../hooks/useDocumentTitle'; -import { useFilters } from '../../hooks/useFilters'; import HousingListFiltersSidemenu from '../../components/HousingListFilters/HousingListFiltersSidemenu'; -import { - TrackEventActions, - TrackEventCategories -} from '../../models/TrackEvent'; import HousingFiltersBadges from '../../components/HousingFiltersBadges/HousingFiltersBadges'; import HousingListMap from '../HousingList/HousingListMap'; import HousingListTabs from '../HousingList/HousingListTabs'; @@ -26,9 +21,12 @@ import authService from '../../services/auth.service'; import { GroupPayload } from '../../models/GroupPayload'; import AppSearchBar from '../../components/_app/AppSearchBar/AppSearchBar'; import { HousingDisplaySwitch } from '../../components/HousingDisplaySwitch/HousingDisplaySwitch'; -import { useCampaignList } from '../../hooks/useCampaignList'; -import { useCreateCampaignFromGroupMutation } from '../../services/campaign.service'; +import { + useCreateCampaignFromGroupMutation, + useFindCampaignsQuery +} from '../../services/campaign.service'; import NotFoundView from '../NotFoundView'; +import { useFilters } from '../../hooks/useFilters'; interface RouterState { alert?: string; @@ -36,19 +34,19 @@ interface RouterState { function GroupView() { const { id } = useParams<{ id: string }>(); + const { data: group, isLoading: isLoadingGroup } = useGetGroupQuery(id); useDocumentTitle(group ? `Groupe - ${group?.title}` : 'Page non trouvée'); - const { trackEvent } = useMatomo(); const { filters, + removeFilter: removeFilters, setFilters, - expand, - removeFilter, - setExpand, onChangeFilters, - onResetFilters + onResetFilters, + expand, + setExpand } = useFilters({ storage: 'state', initialState: { @@ -56,19 +54,13 @@ function GroupView() { } }); - const { view } = useAppSelector((state) => state.housing); - - function searchWithQuery(query: string): void { - trackEvent({ - category: TrackEventCategories.Group, - action: TrackEventActions.HousingList.Search, - name: query - }); + useEffect(() => { setFilters({ - ...filters, - query + groupIds: [id] }); - } + }, [setFilters, id]); + + const { view } = useAppSelector((state) => state.housing); const router = useHistory(); const alert = router.location.state?.alert ?? ''; @@ -115,14 +107,14 @@ function GroupView() { } } - const campaigns = useCampaignList({ + const { data: campaigns } = useFindCampaignsQuery({ filters: { groupIds: [id] } }); if (isLoadingGroup) { - return <>; + return null; } if (!group || !!group.archivedAt) { @@ -163,7 +155,7 @@ function GroupView() { onChangeFilters({ query })} initialQuery={filters.query} placeholder="Rechercher (propriétaire, identifiant fiscal, ref. cadastrale...)" /> @@ -174,7 +166,7 @@ function GroupView() { - + {view === 'map' ? ( diff --git a/frontend/src/views/HousingList/HousingListView.tsx b/frontend/src/views/HousingList/HousingListView.tsx index 8bb545973..08804184d 100644 --- a/frontend/src/views/HousingList/HousingListView.tsx +++ b/frontend/src/views/HousingList/HousingListView.tsx @@ -11,7 +11,6 @@ import { TrackEventCategories } from '../../models/TrackEvent'; import AppSearchBar from '../../components/_app/AppSearchBar/AppSearchBar'; -import { useFilters } from '../../hooks/useFilters'; import { useDocumentTitle } from '../../hooks/useDocumentTitle'; import { useAppSelector } from '../../hooks/useStore'; import HousingListFiltersSidemenu from '../../components/HousingListFilters/HousingListFiltersSidemenu'; @@ -20,20 +19,25 @@ import HousingListMap from './HousingListMap'; import { HousingDisplaySwitch } from '../../components/HousingDisplaySwitch/HousingDisplaySwitch'; import HousingCreationModal from '../../components/modals/HousingCreationModal/HousingCreationModal'; import { useUser } from '../../hooks/useUser'; +import { useFilters } from '../../hooks/useFilters'; +import { initialHousingFilters } from '../../store/reducers/housingReducer'; const HousingListView = () => { useDocumentTitle('Parc de logements'); const { trackEvent } = useMatomo(); const { + expand, filters, + setExpand, setFilters, - expand, onChangeFilters, onResetFilters, - setExpand, removeFilter - } = useFilters(); + } = useFilters({ + storage: 'store', + initialState: initialHousingFilters + }); const { view } = useAppSelector((state) => state.housing);