Skip to content

Commit

Permalink
Add HOT Global Validators Team by default for specific validation p…
Browse files Browse the repository at this point in the history
…ermissions

- Validation Permissions includes `Only team members` & `Only intermediate and advanced team members`
- Related to hotosm#6628
  • Loading branch information
royallsilwallz committed Dec 17, 2024
1 parent 505acfa commit c96b594
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion frontend/src/components/projectEdit/teamSelect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useContext } from 'react';
import { useState, useContext, useEffect, useRef } from 'react';
import Select from 'react-select';
import { FormattedMessage, useIntl } from 'react-intl';

Expand All @@ -9,6 +9,8 @@ import { StateContext } from '../../views/projectEdit';
import { PencilIcon, WasteIcon, ExternalLinkIcon } from '../svgIcons';
import { useFetchWithAbort } from '../../hooks/UseFetch';

const globalValidatorPermissions = ['TEAMS', 'TEAMS_LEVEL'];

export const TeamSelect = () => {
const intl = useIntl();
const nullState = {
Expand All @@ -20,6 +22,8 @@ export const TeamSelect = () => {
const { projectInfo, setProjectInfo } = useContext(StateContext);
const [teamSelect, setTeamSelect] = useState(nullState);
const [org, setOrg] = useState(null);
// for tracking if hotGlobalValidatorTeam is added to the team by default
const isGlobalValidatorAdded = useRef(false);

const [, isOrganisationsLoading, organisationsData] = useFetchWithAbort(
'organisations/?omitManagerList=true',
Expand Down Expand Up @@ -65,6 +69,33 @@ export const TeamSelect = () => {
setTeamSelect(nullState);
};

// Add hotGlobalValidatorTeam as default for validationPermission set to
// 'Only team members' or 'Only intermediate and advanced team members'
useEffect(() => {
// prevent adding hotGlobalValidatorTeam multiple times
if (isGlobalValidatorAdded.current) return;
// check if hotGlobalValidatorTeam should be added or not
if (!globalValidatorPermissions.includes(projectInfo.validationPermission)) return;
// do not add hotGlobalValidatorTeam if already present
if (projectInfo.teams.some((team) => team.name === 'HOT Global Validators')) return;
const globalValidatorTeam = teamsData.teams.find(
(team) => team.name === 'HOT Global Validators',
);
// return if no globalValidatorTeam found
if (!globalValidatorTeam) return;
const hotGlobalValidatorTeam = {
teamId: globalValidatorTeam.teamId,
name: globalValidatorTeam.name,
role: 'VALIDATOR',
};
setProjectInfo({
...projectInfo,
teams: [hotGlobalValidatorTeam, ...projectInfo.teams],
});
// set isGlobalValidatorAdded to true
isGlobalValidatorAdded.current = true;
}, [projectInfo, setProjectInfo, teamsData]);

const updateTeam = () => {
const teams = projectInfo.teams.map((t) => {
let item = t;
Expand Down

0 comments on commit c96b594

Please sign in to comment.