From c96b594e218e6eb84652ac4e0c047c3d00a653b8 Mon Sep 17 00:00:00 2001 From: royallsilwallz Date: Tue, 17 Dec 2024 11:08:12 +0545 Subject: [PATCH] Add `HOT Global Validators Team` by default for specific validation permissions - Validation Permissions includes `Only team members` & `Only intermediate and advanced team members` - Related to #6628 --- .../src/components/projectEdit/teamSelect.js | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/projectEdit/teamSelect.js b/frontend/src/components/projectEdit/teamSelect.js index 3a97b3fafc..1542b4276c 100644 --- a/frontend/src/components/projectEdit/teamSelect.js +++ b/frontend/src/components/projectEdit/teamSelect.js @@ -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'; @@ -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 = { @@ -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', @@ -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;