Skip to content

Commit

Permalink
fix: fix newJoiner status, responsible of subBoard (#807)
Browse files Browse the repository at this point in the history
  • Loading branch information
CatiaAntunes96 authored Jan 5, 2023
1 parent aa637e6 commit 27d2863
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 20 deletions.
8 changes: 4 additions & 4 deletions backend/src/modules/boards/services/create.board.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ export default class CreateBoardServiceImpl implements CreateBoardService {
sortUsersListByOldestCreatedDate = (users: TeamUser[]) =>
users
.map((user) => {
user.userCreated =
(user.user as User).providerAccountCreatedAt || (user.user as User).joinedAt;

return user;
return {
...user,
userCreated: (user.user as User).providerAccountCreatedAt || (user.user as User).joinedAt
};
})
.sort((a, b) => Number(b.userCreated) - Number(a.userCreated));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export class TeamUserRepository
}

getUsersOfTeam(teamId: string) {
return this.findAllWithQuery({ team: teamId }, undefined, {
return this.findAllWithQuery({ team: teamId }, 'user role isNewJoiner _id', {
path: 'user',
select: '_id firstName lastName email isSAdmin'
select: '_id firstName lastName email isSAdmin providerAccountCreatedAt'
});
}

Expand Down
8 changes: 4 additions & 4 deletions backend/src/modules/teams/repositories/team.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class TeamRepository
select: 'user role isNewJoiner',
populate: {
path: 'user',
select: '_id firstName lastName email joinedAt'
select: '_id firstName lastName email joinedAt providerAccountCreatedAt'
}
}
);
Expand All @@ -33,10 +33,10 @@ export class TeamRepository
return this.findAllWithQuery({ _id: { $in: teamIds } }, { _id: 1, name: 1 }, [
{
path: 'users',
select: 'user role',
select: 'user role isNewJoiner',
populate: {
path: 'user',
select: '_id firstName lastName email joinedAt'
select: '_id firstName lastName email joinedAt providerAccountCreatedAt'
}
},
{
Expand All @@ -52,7 +52,7 @@ export class TeamRepository
select: 'user role email',
populate: {
path: 'user',
select: '_id firstName lastName email joinedAt'
select: '_id firstName lastName email joinedAt providerAccountCreatedAt'
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/Boards/MyBoards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const MyBoards = React.memo<MyBoardsProps>(({ userId, isSuperAdmin }) => {

const { data, isLoading } = fetchBoards;

console.log('data', data);

const teamSocketId = data?.pages[0].boards[0].team
? data?.pages[0].boards[0].team._id
: undefined;
Expand Down
31 changes: 28 additions & 3 deletions frontend/src/hooks/useBoard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMutation, useQuery } from 'react-query';
import { InfiniteData, useMutation, useQuery } from 'react-query';
import { useSetRecoilState } from 'recoil';
import { AxiosError } from 'axios';

Expand All @@ -11,6 +11,7 @@ import {
import { newBoardState } from '@/store/board/atoms/board.atom';
import UseBoardType from '@/types/board/useBoard';
import { ToastStateEnum } from '@/utils/enums/toast-types';
import BoardType from '@/types/board/board';
import useBoardUtils from './useBoardUtils';

interface AutoFetchProps {
Expand Down Expand Up @@ -48,8 +49,32 @@ const useBoard = ({ autoFetchBoard = false }: AutoFetchProps): UseBoardType => {
});

const deleteBoard = useMutation(deleteBoardRequest, {
onSuccess: () => {
queryClient.invalidateQueries('boards');
onSuccess: (data, variables) => {
queryClient.setQueryData(
['boards'],
(
oldData:
| InfiniteData<{
boards: BoardType[];
hasNextPage: boolean;
page: number;
}>
| undefined,
) => {
if (!oldData) return { pages: [], pageParams: [] };

return {
...oldData,
pages: oldData.pages.map((page) => ({
...page,
boards: page.boards.filter((board) => board._id !== variables.id),
})),
};
},
);

queryClient.invalidateQueries(['boards']);

setToastState({
open: true,
content: 'The board was successfully deleted.',
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/hooks/useCreateBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ const useCreateBoard = (team?: Team) => {

const sortUsersListByOldestCreatedDate = (users: TeamUser[]) =>
users
.map((user) => {
user.userCreated = user.user.providerAccountCreatedAt || user.user.joinedAt;
return user;
})
.map((user) => ({
...user,
userCreated: user.user.providerAccountCreatedAt || user.user.joinedAt,
}))
.sort((a, b) => Number(b.userCreated) - Number(a.userCreated));

const getAvailableUsersToBeResponsible = useCallback((availableUsers: TeamUser[]) => {
Expand All @@ -103,6 +103,7 @@ const useCreateBoard = (team?: Team) => {

// this object ensures that each group has one element that can be responsible
const candidateToBeTeamResponsible = getRandomUser(availableUsersToBeResponsible);

randomGroupOfUsers.push({
user: candidateToBeTeamResponsible.user,
role: BoardUserRoles.MEMBER,
Expand Down
1 change: 0 additions & 1 deletion frontend/src/hooks/useSocketIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const useSocketIO = (boardId: string): string | undefined => {
});

newSocket.on('updateAllBoard', () => {
console.log('UPDATE ALL BOARD');
queryClient.invalidateQueries(['board', { id: boardId }]);
});

Expand Down
3 changes: 1 addition & 2 deletions frontend/src/pages/teams/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { ToastStateEnum } from '@/utils/enums/toast-types';
import QueryError from '@/components/Errors/QueryError';
import LoadingPage from '@/components/loadings/LoadingPage';
import { Suspense, useEffect } from 'react';
import { verifyIfIsNewJoiner } from '@/utils/verifyIfIsNewJoiner';

const NewTeam: NextPage = () => {
const { data: session } = useSession({ required: true });
Expand Down Expand Up @@ -45,7 +44,7 @@ const NewTeam: NextPage = () => {
listMembers.push({
user,
role: TeamUserRoles.ADMIN,
isNewJoiner: verifyIfIsNewJoiner(user.joinedAt, user.providerAccountCreatedAt),
isNewJoiner: false,
});
}
});
Expand Down

0 comments on commit 27d2863

Please sign in to comment.