Skip to content

Commit

Permalink
fix: regular board votes and quick create (#996)
Browse files Browse the repository at this point in the history
Co-authored-by: Nuno Caseiro <90208434+nunocaseiro@users.noreply.github.com>
Co-authored-by: rpvsilva <rpvsilva@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 3, 2023
1 parent e57f45f commit cfe9e2d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions frontend/src/helper/board/transformBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const handleDeleteCard = (board: BoardType, data: DeleteCardDto): BoardTy
}

const boardUserIdx = boardData.users.findIndex((bUser) => bUser.user._id === userId);

if (boardUserIdx > -1) {
boardData.users[boardUserIdx].votesCount -= votesOfUser;
}
Expand Down
15 changes: 12 additions & 3 deletions frontend/src/pages/boards/[boardId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { dehydrate, QueryClient } from '@tanstack/react-query';
import { GetServerSideProps, NextPage } from 'next';
import { useRouter } from 'next/router';
import { getSession, useSession } from 'next-auth/react';
import { useRecoilState } from 'recoil';
import { useRecoilState, useSetRecoilState } from 'recoil';

import { Container } from '@/styles/pages/boards/board.styles';

Expand All @@ -15,7 +15,12 @@ import AlertBox from '@/components/Primitives/AlertBox';
import Flex from '@/components/Primitives/Flex';
import useBoard from '@/hooks/useBoard';
import { useSocketIO } from '@/hooks/useSocketIO';
import { boardInfoState, newBoardState } from '@/store/board/atoms/board.atom';
import {
boardInfoState,
deletedColumnsState,
editColumnsState,
newBoardState,
} from '@/store/board/atoms/board.atom';
import { BoardUserRoles } from '@/utils/enums/board.user.roles';
import { TeamUserRoles } from '@/utils/enums/team.user.roles';
import isEmpty from '@/utils/isEmpty';
Expand Down Expand Up @@ -94,6 +99,8 @@ const Board: NextPage<Props> = ({ boardId, mainBoardId }) => {
// Recoil States
const [newBoard, setNewBoard] = useRecoilState(newBoardState);
const [recoilBoard, setRecoilBoard] = useRecoilState(boardInfoState);
const setEditColumns = useSetRecoilState(editColumnsState);
const setDeletedColumns = useSetRecoilState(deletedColumnsState);

// Session Details
const { data: session } = useSession();
Expand Down Expand Up @@ -124,8 +131,10 @@ const Board: NextPage<Props> = ({ boardId, mainBoardId }) => {
useEffect(() => {
if (data) {
setRecoilBoard(data);
setEditColumns(data.board.columns);
setDeletedColumns([]);
}
}, [data, setRecoilBoard]);
}, [data, setDeletedColumns, setEditColumns, setRecoilBoard]);

// Board Settings permissions
const isStakeholderOrAdmin = useMemo(
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/boards/newRegularBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const NewRegularBoard: NextPage = () => {
reValidateMode: 'onBlur',
defaultValues: {
text: '',
maxVotes: 2,
maxVotes: boardState.board.maxVotes,
slackEnable: false,
},
resolver: joiResolver(SchemaCreateRegularBoard),
Expand Down Expand Up @@ -181,7 +181,7 @@ const NewRegularBoard: NextPage = () => {
mutate({
...boardState.board,
users: isEmpty(boardState.users) ? users : boardState.users,
title: title || boardState.board.title,
title: title || defaultBoard.board.title,
dividedBoards: [],
maxVotes,
slackEnable,
Expand All @@ -200,7 +200,7 @@ const NewRegularBoard: NextPage = () => {
mutate({
...boardState.board,
users: isEmpty(boardState.users) ? users : boardState.users,
title: boardState.board.title,
title: defaultBoard.board.title,
dividedBoards: [],
maxUsers: boardState.count.maxUsersCount,
recurrent: false,
Expand Down

0 comments on commit cfe9e2d

Please sign in to comment.