From 59cf09e9319b3f84c1dc09a4add09e42b2705af6 Mon Sep 17 00:00:00 2001 From: Guido Date: Wed, 18 Jan 2023 15:19:44 +0000 Subject: [PATCH 1/2] fix: select label bug --- frontend/src/components/CreateBoard/Select/index.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/src/components/CreateBoard/Select/index.tsx b/frontend/src/components/CreateBoard/Select/index.tsx index 32a7da363..0d6fad43b 100644 --- a/frontend/src/components/CreateBoard/Select/index.tsx +++ b/frontend/src/components/CreateBoard/Select/index.tsx @@ -7,12 +7,12 @@ import { selectStyles, StyledBox, StyledSelect } from './styles'; const Control = ({ children, ...props }: ControlProps) => ( - {(props.selectProps.value as { label: string; value: string }).label && ( - - Select Team - - )} + {(props.selectProps.value as { label: string; value: string }).label && ( + + Select Team + + )} {children} From fb9612162daec0d099265d388a5610aac659622e Mon Sep 17 00:00:00 2001 From: Guido Date: Wed, 18 Jan 2023 16:08:15 +0000 Subject: [PATCH 2/2] fix: select only team-admin or stakeholder --- .../SubTeamsTab/SelectTeam/index.tsx | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/frontend/src/components/CreateBoard/SplitBoard/SubTeamsTab/SelectTeam/index.tsx b/frontend/src/components/CreateBoard/SplitBoard/SubTeamsTab/SelectTeam/index.tsx index fb738ec94..d43d7eceb 100644 --- a/frontend/src/components/CreateBoard/SplitBoard/SubTeamsTab/SelectTeam/index.tsx +++ b/frontend/src/components/CreateBoard/SplitBoard/SubTeamsTab/SelectTeam/index.tsx @@ -14,6 +14,7 @@ import { BoardUserRoles } from '@/utils/enums/board.user.roles'; import useCreateBoard from '@/hooks/useCreateBoard'; import { useRouter } from 'next/router'; import SelectComponent from '@/components/CreateBoard/Select'; +import { Team } from '@/types/team/team'; import { HelperTextWrapper } from './styles'; type SelectTeamProps = { @@ -45,8 +46,15 @@ const SelectTeam = ({ previousTeam }: SelectTeamProps) => { const teamValueOnForm = getValues().team; const isValueEmpty = isEmpty(teamValueOnForm); + const isAdminOrStakeholder = (team: Team) => + !!team.users?.find( + (teamUser) => + teamUser.user._id === session?.user.id && + [TeamUserRoles.ADMIN, TeamUserRoles.STAKEHOLDER].includes(teamUser.role), + ) || session?.user.isSAdmin; + const teamMembersCount = teamMembers?.length ?? 0; - const numberOfTeams = teams?.length ?? 0; + const numberOfTeams = teams?.filter((team) => isAdminOrStakeholder(team)).length ?? 0; const currentSelectTeamState = useMemo(() => { if (message) return 'error'; @@ -68,10 +76,12 @@ const SelectTeam = ({ previousTeam }: SelectTeamProps) => { const teamsNames = useMemo( () => - teams.map((team) => ({ - label: `${team.name} (${team.users.length} members)`, - value: team._id, - })), + teams + .filter((team) => isAdminOrStakeholder(team)) + .map((team) => ({ + label: `${team.name} (${team.users.length} members)`, + value: team._id, + })), [teams], ); @@ -85,14 +95,7 @@ const SelectTeam = ({ previousTeam }: SelectTeamProps) => { MIN_MEMBERS ); - const isAdminOrStakeholder = - !!selectedTeam.users?.find( - (teamUser) => - teamUser.user._id === session?.user.id && - [TeamUserRoles.ADMIN, TeamUserRoles.STAKEHOLDER].includes(teamUser.role), - ) || session?.user.isSAdmin; - - return !haveMinMembers || !isAdminOrStakeholder; + return !haveMinMembers || !isAdminOrStakeholder(selectedTeam); }, [selectedTeam, session?.user.id, session?.user.isSAdmin]); const createBoard = useCallback(() => { @@ -131,8 +134,10 @@ const SelectTeam = ({ previousTeam }: SelectTeamProps) => { if (routerTeam) { setValue('team', routerTeam); } + + setHaveError(numberOfTeams <= 0); // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [numberOfTeams]); useEffect(() => { if (selectedTeam) { @@ -160,12 +165,7 @@ const SelectTeam = ({ previousTeam }: SelectTeamProps) => { - + In order to create a team board, you must be team-admin or stakeholder of at least one team. @@ -182,9 +182,7 @@ const SelectTeam = ({ previousTeam }: SelectTeamProps) => { {!isHelperEmpty && ( {message}