Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: new split board team selection #898

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions frontend/src/components/CreateBoard/Select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { selectStyles, StyledBox, StyledSelect } from './styles';

const Control = ({ children, ...props }: ControlProps) => (
<components.Control {...props}>
{(props.selectProps.value as { label: string; value: string }).label && (
<Text color="primary300" size="xs">
Select Team
</Text>
)}
<Flex direction="column" css={{ width: '100%', px: '$17' }}>
{(props.selectProps.value as { label: string; value: string }).label && (
<Text color="primary300" size="xs">
Select Team
</Text>
)}
<Flex css={{ width: '100%' }}>{children}</Flex>
</Flex>
</components.Control>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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';
Expand All @@ -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],
);

Expand All @@ -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(() => {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -160,12 +165,7 @@ const SelectTeam = ({ previousTeam }: SelectTeamProps) => {
<HelperTextWrapper css={{ mt: '$8' }} gap="4">
<Icon css={{ width: '$24', height: '$24' }} name="info" />

<Text
hint
css={{
color: '$dangerBase',
}}
>
<Text hint css={{ color: '$dangerBase' }}>
In order to create a team board, you must be team-admin or stakeholder of at least one
team.
</Text>
Expand All @@ -182,9 +182,7 @@ const SelectTeam = ({ previousTeam }: SelectTeamProps) => {
{!isHelperEmpty && (
<Text
hint
css={{
color: currentSelectTeamState === 'error' ? '$dangerBase' : '$primary300',
}}
css={{ color: currentSelectTeamState === 'error' ? '$dangerBase' : '$primary300' }}
>
{message}
</Text>
Expand Down