|
1 | 1 | import Hero from "components/layouts/Hero/Hero"; |
2 | 2 | import Map from "components/ui/Map/Map"; |
3 | | -import { FC, useState, useEffect } from "react"; |
| 3 | +import { FC, useState, useEffect, useMemo } from "react"; |
4 | 4 | import { MapboxEvent, Map as MapInstance } from "mapbox-gl"; |
5 | 5 | import { FormattedMessage } from "react-intl"; |
6 | 6 | import { TPropsFromRedux } from "./AreaViewContainer"; |
@@ -38,6 +38,18 @@ const AreasView: FC<IProps & RouteComponentProps<TParams>> = ({ |
38 | 38 | let { path, url } = useRouteMatch(); |
39 | 39 | const userId = useGetUserId(); |
40 | 40 |
|
| 41 | + const templatesToAdd = useMemo(() => { |
| 42 | + return ( |
| 43 | + templates?.filter( |
| 44 | + template => !area?.attributes.reportTemplate.find(areaTemplate => areaTemplate.id === template.id) |
| 45 | + ) || [] |
| 46 | + ); |
| 47 | + }, [area?.attributes.reportTemplate, templates]); |
| 48 | + |
| 49 | + const teamsToAdd = useMemo(() => { |
| 50 | + return teams?.filter(team => !areaTeams.find(areaTeam => areaTeam.data.id === team.id)) || []; |
| 51 | + }, [areaTeams, teams]); |
| 52 | + |
41 | 53 | const handleMapLoad = (e: MapboxEvent) => { |
42 | 54 | setMapRef(e.target); |
43 | 55 | }; |
@@ -181,13 +193,13 @@ const AreasView: FC<IProps & RouteComponentProps<TParams>> = ({ |
181 | 193 | </div> |
182 | 194 | <Switch> |
183 | 195 | <Route path={`${path}/template/add`}> |
184 | | - <AddTemplateModal templates={templates} /> |
| 196 | + <AddTemplateModal templates={templatesToAdd} /> |
185 | 197 | </Route> |
186 | 198 | <Route path={`${path}/template/remove/:templateId`}> |
187 | 199 | <RemoveTemplateModal /> |
188 | 200 | </Route> |
189 | 201 | <Route path={`${path}/team/add`}> |
190 | | - <AddTeamModal teams={teams} /> |
| 202 | + <AddTeamModal teams={teamsToAdd} /> |
191 | 203 | </Route> |
192 | 204 | <Route path={`${path}/team/remove/:teamId`}> |
193 | 205 | <RemoveTemplateModal /> |
|
0 commit comments