From 1b839ebc3f7fd0fd8f2c7ed63cbccf0c109cf871 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Patr=C3=ADcia=20Dias?=
Date: Thu, 5 Jan 2023 17:21:46 +0000
Subject: [PATCH 1/9] feat: personal boards endpoint
---
backend/src/libs/dto/param/pagination.params.ts | 4 ++++
.../src/modules/boards/controller/boards.controller.ts | 4 ++--
.../applications/get.board.application.interface.ts | 1 +
backend/src/modules/boards/interfaces/findQuery.ts | 1 +
.../interfaces/services/get.board.service.interface.ts | 6 ++++++
.../src/modules/boards/services/get.board.service.ts | 10 ++++++++++
6 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/backend/src/libs/dto/param/pagination.params.ts b/backend/src/libs/dto/param/pagination.params.ts
index 24902ccf4..b9a6626eb 100644
--- a/backend/src/libs/dto/param/pagination.params.ts
+++ b/backend/src/libs/dto/param/pagination.params.ts
@@ -21,4 +21,8 @@ export class PaginationParams {
@IsOptional()
@Type(() => String)
team?: string;
+
+ @IsOptional()
+ @Type(() => String)
+ personalBoards?: boolean;
}
diff --git a/backend/src/modules/boards/controller/boards.controller.ts b/backend/src/modules/boards/controller/boards.controller.ts
index 2be368f95..f3e83e684 100644
--- a/backend/src/modules/boards/controller/boards.controller.ts
+++ b/backend/src/modules/boards/controller/boards.controller.ts
@@ -136,11 +136,11 @@ export default class BoardsController {
@Get()
async getAllBoards(
@Req() request: RequestWithUser,
- @Query() { page, size, team }: PaginationParams
+ @Query() { page, size, team, personalBoards }: PaginationParams
) {
const { _id: userId, isSAdmin } = request.user;
- return this.getBoardApp.getAllBoards(team, userId, isSAdmin, page, size);
+ return this.getBoardApp.getAllBoards(team, userId, isSAdmin, personalBoards, page, size);
}
@ApiOperation({ summary: 'Retrieve one board by id' })
diff --git a/backend/src/modules/boards/interfaces/applications/get.board.application.interface.ts b/backend/src/modules/boards/interfaces/applications/get.board.application.interface.ts
index 74b03a884..163be8547 100644
--- a/backend/src/modules/boards/interfaces/applications/get.board.application.interface.ts
+++ b/backend/src/modules/boards/interfaces/applications/get.board.application.interface.ts
@@ -13,6 +13,7 @@ export interface GetBoardApplicationInterface {
teamId?: string,
userId?: string,
isSuperAdmin?: boolean,
+ personalBoards?: boolean,
page?: number,
size?: number
): Promise;
diff --git a/backend/src/modules/boards/interfaces/findQuery.ts b/backend/src/modules/boards/interfaces/findQuery.ts
index 48fda1a1a..1446c312c 100644
--- a/backend/src/modules/boards/interfaces/findQuery.ts
+++ b/backend/src/modules/boards/interfaces/findQuery.ts
@@ -21,6 +21,7 @@ export type QueryType = {
| {
team: {
$in?: Team[] | string[];
+ $type?: number;
$ne?: undefined | null;
};
_id?: undefined;
diff --git a/backend/src/modules/boards/interfaces/services/get.board.service.interface.ts b/backend/src/modules/boards/interfaces/services/get.board.service.interface.ts
index bc33a60ea..8db0cf44f 100644
--- a/backend/src/modules/boards/interfaces/services/get.board.service.interface.ts
+++ b/backend/src/modules/boards/interfaces/services/get.board.service.interface.ts
@@ -15,6 +15,12 @@ export interface GetBoardServiceInterface {
getTeamBoards(teamId: string, page?: number, size?: number): Promise;
+ getPersonalUserBoards(
+ userId: string,
+ page?: number,
+ size?: number
+ ): Promise;
+
getBoardFromRepo(boardId: string): Promise | null>;
getBoard(
diff --git a/backend/src/modules/boards/services/get.board.service.ts b/backend/src/modules/boards/services/get.board.service.ts
index ce8b1213a..b51b65cff 100644
--- a/backend/src/modules/boards/services/get.board.service.ts
+++ b/backend/src/modules/boards/services/get.board.service.ts
@@ -87,6 +87,16 @@ export default class GetBoardServiceImpl implements GetBoardServiceInterface {
return this.getBoards(false, query, page, size);
}
+ async getPersonalUserBoards(userId: string, page: number, size?: number) {
+ const { boardIds } = await this.getAllBoardIdsAndTeamIdsOfUser(userId);
+
+ const query = {
+ $and: [{ isSubBoard: false }, { $or: [{ _id: { $in: boardIds } }, { team: { $type: 10 } }] }] //`$type: 10` means team is null
+ };
+
+ return this.getBoards(false, query, page, size);
+ }
+
async getBoards(allBoards: boolean, query: QueryType, page = 0, size = 10) {
const count = await this.boardModel.find(query).countDocuments().exec();
const hasNextPage = page + 1 < Math.ceil(count / (allBoards ? count : size));
From cc8949c20fb1b92aa64267f9e82c6b73023c88d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Patr=C3=ADcia=20Dias?=
Date: Thu, 5 Jan 2023 17:22:36 +0000
Subject: [PATCH 2/9] feat: personal boards endpoint
---
.../src/modules/boards/applications/get.board.application.ts | 3 +++
1 file changed, 3 insertions(+)
diff --git a/backend/src/modules/boards/applications/get.board.application.ts b/backend/src/modules/boards/applications/get.board.application.ts
index 85b641258..c4548ab14 100644
--- a/backend/src/modules/boards/applications/get.board.application.ts
+++ b/backend/src/modules/boards/applications/get.board.application.ts
@@ -23,6 +23,7 @@ export class GetBoardApplication implements GetBoardApplicationInterface {
teamId?: string,
userId?: string,
isSuperAdmin?: boolean,
+ personalBoards?: boolean,
page?: number,
size?: number
) {
@@ -30,6 +31,8 @@ export class GetBoardApplication implements GetBoardApplicationInterface {
if (isSuperAdmin) return this.getBoardService.getSuperAdminBoards(userId, page, size);
+ if (personalBoards) return this.getBoardService.getPersonalUserBoards(userId, page, size);
+
return this.getBoardService.getUsersBoards(userId, page, size);
}
From 4e109db6fc8bf651f96fc831da91b45e76bd4d24 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Patr=C3=ADcia=20Dias?=
Date: Thu, 5 Jan 2023 17:48:10 +0000
Subject: [PATCH 3/9] refactor: updating endpoint
---
.../src/libs/dto/param/pagination.params.ts | 4 ---
.../applications/get.board.application.ts | 7 +++--
.../boards/controller/boards.controller.ts | 28 +++++++++++++++++--
.../get.board.application.interface.ts | 3 +-
4 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/backend/src/libs/dto/param/pagination.params.ts b/backend/src/libs/dto/param/pagination.params.ts
index b9a6626eb..24902ccf4 100644
--- a/backend/src/libs/dto/param/pagination.params.ts
+++ b/backend/src/libs/dto/param/pagination.params.ts
@@ -21,8 +21,4 @@ export class PaginationParams {
@IsOptional()
@Type(() => String)
team?: string;
-
- @IsOptional()
- @Type(() => String)
- personalBoards?: boolean;
}
diff --git a/backend/src/modules/boards/applications/get.board.application.ts b/backend/src/modules/boards/applications/get.board.application.ts
index c4548ab14..437179448 100644
--- a/backend/src/modules/boards/applications/get.board.application.ts
+++ b/backend/src/modules/boards/applications/get.board.application.ts
@@ -23,7 +23,6 @@ export class GetBoardApplication implements GetBoardApplicationInterface {
teamId?: string,
userId?: string,
isSuperAdmin?: boolean,
- personalBoards?: boolean,
page?: number,
size?: number
) {
@@ -31,11 +30,13 @@ export class GetBoardApplication implements GetBoardApplicationInterface {
if (isSuperAdmin) return this.getBoardService.getSuperAdminBoards(userId, page, size);
- if (personalBoards) return this.getBoardService.getPersonalUserBoards(userId, page, size);
-
return this.getBoardService.getUsersBoards(userId, page, size);
}
+ getPersonalBoards(userId?: string, page?: number, size?: number) {
+ return this.getBoardService.getPersonalUserBoards(userId, page, size);
+ }
+
getBoard(boardId: string, userId: string) {
return this.getBoardService.getBoard(boardId, userId);
}
diff --git a/backend/src/modules/boards/controller/boards.controller.ts b/backend/src/modules/boards/controller/boards.controller.ts
index f3e83e684..6615fd734 100644
--- a/backend/src/modules/boards/controller/boards.controller.ts
+++ b/backend/src/modules/boards/controller/boards.controller.ts
@@ -136,11 +136,35 @@ export default class BoardsController {
@Get()
async getAllBoards(
@Req() request: RequestWithUser,
- @Query() { page, size, team, personalBoards }: PaginationParams
+ @Query() { page, size, team }: PaginationParams
) {
const { _id: userId, isSAdmin } = request.user;
- return this.getBoardApp.getAllBoards(team, userId, isSAdmin, personalBoards, page, size);
+ return this.getBoardApp.getAllBoards(team, userId, isSAdmin, page, size);
+ }
+
+ @ApiOperation({ summary: 'Retrieve all boards from database' })
+ @ApiOkResponse({ type: BoardResponse, description: 'Boards' })
+ @ApiBadRequestResponse({
+ description: 'Bad Request',
+ type: BadRequestResponse
+ })
+ @ApiUnauthorizedResponse({
+ description: 'Unauthorized',
+ type: UnauthorizedResponse
+ })
+ @ApiInternalServerErrorResponse({
+ description: 'Internal Server Error',
+ type: InternalServerErrorResponse
+ })
+ @Get()
+ async getPersonalBoards(
+ @Req() request: RequestWithUser,
+ @Query() { page, size }: PaginationParams
+ ) {
+ const { _id: userId } = request.user;
+
+ return this.getBoardApp.getPersonalBoards(userId, page, size);
}
@ApiOperation({ summary: 'Retrieve one board by id' })
diff --git a/backend/src/modules/boards/interfaces/applications/get.board.application.interface.ts b/backend/src/modules/boards/interfaces/applications/get.board.application.interface.ts
index 163be8547..c7ec0c011 100644
--- a/backend/src/modules/boards/interfaces/applications/get.board.application.interface.ts
+++ b/backend/src/modules/boards/interfaces/applications/get.board.application.interface.ts
@@ -13,11 +13,12 @@ export interface GetBoardApplicationInterface {
teamId?: string,
userId?: string,
isSuperAdmin?: boolean,
- personalBoards?: boolean,
page?: number,
size?: number
): Promise;
+ getPersonalBoards(userId?: string, page?: number, size?: number): Promise;
+
getBoard(
boardId: string,
userId: string
From c1eb9323cc092f4957757dc765cf9472b3ec0aaf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Patr=C3=ADcia=20Dias?=
Date: Thu, 5 Jan 2023 17:52:10 +0000
Subject: [PATCH 4/9] fix: added correct personal boards endpoint path
---
backend/src/modules/boards/controller/boards.controller.ts | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/backend/src/modules/boards/controller/boards.controller.ts b/backend/src/modules/boards/controller/boards.controller.ts
index 6615fd734..78b45b684 100644
--- a/backend/src/modules/boards/controller/boards.controller.ts
+++ b/backend/src/modules/boards/controller/boards.controller.ts
@@ -143,8 +143,8 @@ export default class BoardsController {
return this.getBoardApp.getAllBoards(team, userId, isSAdmin, page, size);
}
- @ApiOperation({ summary: 'Retrieve all boards from database' })
- @ApiOkResponse({ type: BoardResponse, description: 'Boards' })
+ @ApiOperation({ summary: 'Retrieve personal boards from user' })
+ @ApiOkResponse({ type: BoardResponse, description: 'Personal boards' })
@ApiBadRequestResponse({
description: 'Bad Request',
type: BadRequestResponse
@@ -157,7 +157,7 @@ export default class BoardsController {
description: 'Internal Server Error',
type: InternalServerErrorResponse
})
- @Get()
+ @Get('/personal')
async getPersonalBoards(
@Req() request: RequestWithUser,
@Query() { page, size }: PaginationParams
From 6dc90bdbce7f0709397a450512de5b75b58e6f9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Patr=C3=ADcia=20Dias?=
Date: Fri, 6 Jan 2023 12:28:06 +0000
Subject: [PATCH 5/9] fix: boardIds in query correct and personal boards
endpoint fixed
---
backend/src/modules/boards/interfaces/findQuery.ts | 10 +++++++++-
.../src/modules/boards/services/get.board.service.ts | 9 ++++++---
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/backend/src/modules/boards/interfaces/findQuery.ts b/backend/src/modules/boards/interfaces/findQuery.ts
index 1446c312c..34105e64e 100644
--- a/backend/src/modules/boards/interfaces/findQuery.ts
+++ b/backend/src/modules/boards/interfaces/findQuery.ts
@@ -9,6 +9,7 @@ export type QueryType = {
$gte: number;
};
$or?: undefined;
+ $and?: undefined;
}
| {
$or: (
@@ -21,7 +22,6 @@ export type QueryType = {
| {
team: {
$in?: Team[] | string[];
- $type?: number;
$ne?: undefined | null;
};
_id?: undefined;
@@ -34,5 +34,13 @@ export type QueryType = {
isSubBoard?: undefined;
updatedAt?: undefined;
}
+ | {
+ _id: {
+ $in: LeanDocument[];
+ };
+ }
+ | {
+ team: string;
+ }
)[];
};
diff --git a/backend/src/modules/boards/services/get.board.service.ts b/backend/src/modules/boards/services/get.board.service.ts
index b51b65cff..788830308 100644
--- a/backend/src/modules/boards/services/get.board.service.ts
+++ b/backend/src/modules/boards/services/get.board.service.ts
@@ -29,7 +29,7 @@ export default class GetBoardServiceImpl implements GetBoardServiceInterface {
private readonly logger = new Logger(GetBoardServiceImpl.name);
getAllBoardsIdsOfUser(userId: string) {
- return this.boardModel.find({ user: userId }).select('board').lean().exec();
+ return this.boardUserModel.find({ user: userId }).select('board').lean().exec();
}
async getAllBoardIdsAndTeamIdsOfUser(userId: string) {
@@ -38,7 +38,10 @@ export default class GetBoardServiceImpl implements GetBoardServiceInterface {
this.getTeamService.getTeamsOfUser(userId)
]);
- return { boardIds, teamIds: teamIds.map((team) => team._id) };
+ return {
+ boardIds: boardIds.map((boardUser) => boardUser.board),
+ teamIds: teamIds.map((team) => team._id)
+ };
}
async getUserBoardsOfLast3Months(userId: string, page: number, size?: number) {
@@ -91,7 +94,7 @@ export default class GetBoardServiceImpl implements GetBoardServiceInterface {
const { boardIds } = await this.getAllBoardIdsAndTeamIdsOfUser(userId);
const query = {
- $and: [{ isSubBoard: false }, { $or: [{ _id: { $in: boardIds } }, { team: { $type: 10 } }] }] //`$type: 10` means team is null
+ $and: [{ isSubBoard: false }, { team: null }, { _id: { $in: boardIds } }]
};
return this.getBoards(false, query, page, size);
From 04114a8960ec9674717f409815628b294e22e2f2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Patr=C3=ADcia=20Dias?=
Date: Fri, 6 Jan 2023 12:37:59 +0000
Subject: [PATCH 6/9] refactor: remove unnecessary
---
backend/src/modules/boards/interfaces/findQuery.ts | 1 -
1 file changed, 1 deletion(-)
diff --git a/backend/src/modules/boards/interfaces/findQuery.ts b/backend/src/modules/boards/interfaces/findQuery.ts
index 34105e64e..ffa20eed3 100644
--- a/backend/src/modules/boards/interfaces/findQuery.ts
+++ b/backend/src/modules/boards/interfaces/findQuery.ts
@@ -9,7 +9,6 @@ export type QueryType = {
$gte: number;
};
$or?: undefined;
- $and?: undefined;
}
| {
$or: (
From 4bca3fac62430325dc1ed3894382044c715dd24a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Patr=C3=ADcia=20Dias?=
Date: Fri, 6 Jan 2023 15:43:48 +0000
Subject: [PATCH 7/9] feat: personal boards connected to api
---
frontend/src/api/boardService.tsx | 6 +
.../Boards/MyBoards/ListBoards/index.tsx | 6 +-
.../EmptyTeamBoards/index.tsx | 0
.../MyBoards/ListBoardsByTeam/index.tsx | 8 +-
.../EmptyPersonalBoards.tsx/index.tsx | 28 ++++
.../MyBoards/ListPersonalBoards/index.tsx | 134 ++++++++++++++++++
.../src/components/Boards/MyBoards/index.tsx | 12 +-
frontend/src/pages/boards/index.tsx | 19 ++-
8 files changed, 197 insertions(+), 16 deletions(-)
rename frontend/src/components/Boards/MyBoards/{ => ListBoardsByTeam}/EmptyTeamBoards/index.tsx (100%)
create mode 100644 frontend/src/components/Boards/MyBoards/ListPersonalBoards/EmptyPersonalBoards.tsx/index.tsx
create mode 100644 frontend/src/components/Boards/MyBoards/ListPersonalBoards/index.tsx
diff --git a/frontend/src/api/boardService.tsx b/frontend/src/api/boardService.tsx
index 7ace634ab..fd921f66f 100644
--- a/frontend/src/api/boardService.tsx
+++ b/frontend/src/api/boardService.tsx
@@ -47,6 +47,12 @@ export const getBoardsRequest = (
{ context, serverSide: !!context },
);
+export const getPersonalBoardsRequest = (
+ pageParam = 0,
+ context?: GetServerSidePropsContext,
+): Promise<{ boards: BoardType[]; hasNextPage: boolean; page: number }> =>
+ fetchData(`/boards/personal?page=${pageParam}&size=10`, { context, serverSide: !!context });
+
export const deleteBoardRequest = async ({
id,
socketId,
diff --git a/frontend/src/components/Boards/MyBoards/ListBoards/index.tsx b/frontend/src/components/Boards/MyBoards/ListBoards/index.tsx
index 4e962c1b6..74fc4b76f 100644
--- a/frontend/src/components/Boards/MyBoards/ListBoards/index.tsx
+++ b/frontend/src/components/Boards/MyBoards/ListBoards/index.tsx
@@ -30,13 +30,13 @@ interface ListBoardsProps {
const ListBoards = React.memo(
({ userId, isSuperAdmin, dataByTeamAndDate, scrollRef, onScroll, filter, isLoading, socket }) => {
const currentDate = new Date().toDateString();
- const teamsList = useRecoilValue(teamsListState);
+ const allTeamsList = useRecoilValue(teamsListState);
return (
{Array.from(dataByTeamAndDate.boardsTeamAndDate).map(([teamId, boardsOfTeam]) => {
const { users } = Array.from(boardsOfTeam)[0][1][0];
- const teamFound = teamsList.find((team) => team._id === teamId);
- if ((filter !== 'all' && teamId !== filter) || !teamFound) return null;
+ const teamFound = allTeamsList.find((team) => team._id === teamId);
+ if (filter !== 'all' && teamId !== filter) return null;
return (
{
page.boards?.forEach((board) => {
- const boardsOfTeam = boardsTeamAndDate.get(`${board.team?._id ?? `personal`}`);
+ const boardsOfTeam = boardsTeamAndDate.get(`${board.team._id}`);
const date = new Date(board.updatedAt).toDateString();
if (!boardsOfTeam) {
- boardsTeamAndDate.set(`${board.team?._id ?? `personal`}`, new Map([[date, [board]]]));
- if (board.team) teams.set(`${board.team?._id}`, board.team);
+ boardsTeamAndDate.set(`${board.team?._id}`, new Map([[date, [board]]]));
+ teams.set(`${board.team?._id}`, board.team);
return;
}
const boardsOfDay = boardsOfTeam.get(date);
diff --git a/frontend/src/components/Boards/MyBoards/ListPersonalBoards/EmptyPersonalBoards.tsx/index.tsx b/frontend/src/components/Boards/MyBoards/ListPersonalBoards/EmptyPersonalBoards.tsx/index.tsx
new file mode 100644
index 000000000..4af52e582
--- /dev/null
+++ b/frontend/src/components/Boards/MyBoards/ListPersonalBoards/EmptyPersonalBoards.tsx/index.tsx
@@ -0,0 +1,28 @@
+import {
+ EmptyBoardsText,
+ StyledBox,
+ StyledImage,
+ StyledNewBoardLink,
+} from '@/components/Dashboard/RecentRetros/partials/EmptyBoards/styles';
+import Link from 'next/link';
+
+const EmptyPersonalBoards = () => (
+
+
+
+ You have no personal boards yet.
+
+
+
+ Add a new personal board
+
+ {' '}
+ now.
+
+
+);
+export default EmptyPersonalBoards;
diff --git a/frontend/src/components/Boards/MyBoards/ListPersonalBoards/index.tsx b/frontend/src/components/Boards/MyBoards/ListPersonalBoards/index.tsx
new file mode 100644
index 000000000..4c8b96231
--- /dev/null
+++ b/frontend/src/components/Boards/MyBoards/ListPersonalBoards/index.tsx
@@ -0,0 +1,134 @@
+import React, { useMemo, useRef } from 'react';
+
+import { getPersonalBoardsRequest } from '@/api/boardService';
+import { ToastStateEnum } from '@/utils/enums/toast-types';
+import { useInfiniteQuery } from 'react-query';
+import { useSetRecoilState } from 'recoil';
+import { toastState } from '@/store/toast/atom/toast.atom';
+import BoardType from '@/types/board/board';
+import { Team } from '@/types/team/team';
+import { Socket } from 'socket.io-client';
+import ListBoards from '../ListBoards';
+
+interface ListBoardsByTeamProps {
+ userId: string;
+ isSuperAdmin: boolean;
+ socket: Socket | null;
+}
+
+const ListPersonalBoards = ({ userId, isSuperAdmin, socket }: ListBoardsByTeamProps) => {
+ const setToastState = useSetRecoilState(toastState);
+ const scrollRef = useRef(null);
+
+ const fetchBoardsByTeam = useInfiniteQuery(
+ ['boards/personal'],
+ ({ pageParam = 0 }) => getPersonalBoardsRequest(pageParam),
+ {
+ enabled: true,
+ refetchOnWindowFocus: false,
+ getNextPageParam: (lastPage) => {
+ const { hasNextPage, page } = lastPage;
+ if (hasNextPage) return page + 1;
+ return undefined;
+ },
+ onError: () => {
+ setToastState({
+ open: true,
+ content: 'Error getting the boards',
+ type: ToastStateEnum.ERROR,
+ });
+ },
+ },
+ );
+ const { data, isLoading } = fetchBoardsByTeam;
+
+ // const personalBoards = useMemo(() => {
+ // const teams = new Map();
+ // const boardsAndDate = new Map;
+
+ // data?.pages.forEach((page) => {
+ // page.boards?.forEach((board) => {
+ // boards.push(board);
+ // const date = new Date(board.updatedAt).toDateString();
+ // if (!boardsOfTeam) {
+ // boardsTeamAndDate.set(`personal`, new Map([[date, [board]]]));
+ // return;
+ // }
+ // const boardsOfDay = boardsOfTeam.get(date);
+ // if (boardsOfDay) {
+ // boardsOfDay.push(board);
+ // return;
+ // }
+ // boardsOfTeam.set(date, [board]);
+ // });
+ // });
+ // return { boards, teams };
+ // }, [data?.pages]);
+
+ const dataByTeamAndDate = useMemo(() => {
+ const teams = new Map();
+ const boardsTeamAndDate = new Map>();
+
+ data?.pages.forEach((page) => {
+ page.boards?.forEach((board) => {
+ const date = new Date(board.updatedAt).toDateString();
+ const boardsOfPersonal = boardsTeamAndDate.get('personal');
+ if (!boardsOfPersonal) {
+ boardsTeamAndDate.set('personal', new Map([[date, [board]]]));
+ return;
+ }
+ boardsOfPersonal.set(date, [board]);
+ });
+ });
+ return { boardsTeamAndDate, teams };
+ }, [data?.pages]);
+
+ const onScroll = () => {
+ if (scrollRef.current) {
+ const { scrollTop, scrollHeight, clientHeight } = scrollRef.current;
+ if (scrollTop + clientHeight + 2 >= scrollHeight && fetchBoardsByTeam.hasNextPage) {
+ fetchBoardsByTeam.fetchNextPage();
+ }
+ }
+ };
+
+ // if (personalBoards.length === 0 && !isLoading) {
+ // return (
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ // );
+ // }
+
+ return (
+
+ );
+};
+
+export default ListPersonalBoards;
diff --git a/frontend/src/components/Boards/MyBoards/index.tsx b/frontend/src/components/Boards/MyBoards/index.tsx
index dd9f8e2b2..eb3139b08 100644
--- a/frontend/src/components/Boards/MyBoards/index.tsx
+++ b/frontend/src/components/Boards/MyBoards/index.tsx
@@ -11,11 +11,12 @@ import { Team } from '@/types/team/team';
import { ToastStateEnum } from '@/utils/enums/toast-types';
import isEmpty from '@/utils/isEmpty';
import { useRouter } from 'next/router';
-import { teamsListState } from '@/store/team/atom/team.atom';
+import { userTeamsListState } from '@/store/team/atom/team.atom';
import { filterTeamBoardsState } from '@/store/board/atoms/board.atom';
import FilterBoards from '../Filters/FilterBoards';
import ListBoardsByTeam from './ListBoardsByTeam';
import ListBoards from './ListBoards';
+import ListPersonalBoards from './ListPersonalBoards';
interface MyBoardsProps {
userId: string;
@@ -33,7 +34,7 @@ const MyBoards = React.memo(({ userId, isSuperAdmin }) => {
const scrollRef = useRef(null);
const router = useRouter();
const routerTeam = router.query.team as string;
- const teamsList = useRecoilValue(teamsListState);
+ const userTeamsList = useRecoilValue(userTeamsListState);
const fetchBoards = useInfiniteQuery(
'boards',
@@ -110,7 +111,7 @@ const MyBoards = React.memo(({ userId, isSuperAdmin }) => {
}
};
- const teamNames: OptionType[] = teamsList.map((team) => ({
+ const teamNames: OptionType[] = userTeamsList.map((team) => ({
value: team._id,
label: team.name,
}));
@@ -118,7 +119,7 @@ const MyBoards = React.memo(({ userId, isSuperAdmin }) => {
if (filterState === 'all' && isEmpty(dataByTeamAndDate.boardsTeamAndDate.size) && !isLoading)
return ;
- const filteredTeam: Team | undefined = teamsList.find((team) => team._id === filterState);
+ const filteredTeam: Team | undefined = userTeamsList.find((team) => team._id === filterState);
return (
<>
@@ -132,6 +133,9 @@ const MyBoards = React.memo(({ userId, isSuperAdmin }) => {
socket={socket}
/>
)}
+ {filterState === 'personal' && (
+
+ )}
{
const { data: session } = useSession({ required: true });
- const setTeamsList = useSetRecoilState(teamsListState);
+ const setUserTeamsList = useSetRecoilState(userTeamsListState);
+ const setAllTeamsList = useSetRecoilState(teamsListState);
const {
fetchTeamsOfUser: { data },
+ fetchAllTeams: { data: dataAllTeams },
} = useTeam();
useEffect(() => {
if (data) {
- setTeamsList(data);
+ setUserTeamsList(data);
}
- }, [data, setTeamsList]);
+ }, [data, setUserTeamsList]);
+
+ useEffect(() => {
+ if (dataAllTeams) {
+ setAllTeamsList(dataAllTeams);
+ }
+ }, [dataAllTeams, setAllTeamsList]);
if (!session) return null;
return (
@@ -47,6 +55,7 @@ export const getServerSideProps: GetServerSideProps = requireAuthentication(
async (context: GetServerSidePropsContext) => {
const queryClient = new QueryClient();
await queryClient.prefetchQuery('teams', () => getTeamsOfUser(undefined, context));
+ await queryClient.prefetchQuery('allTeams', () => getAllTeams(context));
return {
props: {
dehydratedState: JSON.parse(JSON.stringify(dehydrate(queryClient))),
From 88495e599646a05ed197325621dc07c1abba52bd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Patr=C3=ADcia=20Dias?=
Date: Fri, 6 Jan 2023 16:42:03 +0000
Subject: [PATCH 8/9] feat: added empty personal component
---
.../Boards/MyBoards/ListBoards/index.tsx | 2 +-
.../MyBoards/ListPersonalBoards/index.tsx | 67 +++++--------------
.../src/components/Boards/MyBoards/index.tsx | 23 ++++---
3 files changed, 30 insertions(+), 62 deletions(-)
diff --git a/frontend/src/components/Boards/MyBoards/ListBoards/index.tsx b/frontend/src/components/Boards/MyBoards/ListBoards/index.tsx
index 74fc4b76f..f887dbac1 100644
--- a/frontend/src/components/Boards/MyBoards/ListBoards/index.tsx
+++ b/frontend/src/components/Boards/MyBoards/ListBoards/index.tsx
@@ -54,7 +54,7 @@ const ListBoards = React.memo(
diff --git a/frontend/src/components/Boards/MyBoards/ListPersonalBoards/index.tsx b/frontend/src/components/Boards/MyBoards/ListPersonalBoards/index.tsx
index 4c8b96231..c2c7bbcb7 100644
--- a/frontend/src/components/Boards/MyBoards/ListPersonalBoards/index.tsx
+++ b/frontend/src/components/Boards/MyBoards/ListPersonalBoards/index.tsx
@@ -8,7 +8,9 @@ import { toastState } from '@/store/toast/atom/toast.atom';
import BoardType from '@/types/board/board';
import { Team } from '@/types/team/team';
import { Socket } from 'socket.io-client';
+import Flex from '@/components/Primitives/Flex';
import ListBoards from '../ListBoards';
+import EmptyPersonalBoards from './EmptyPersonalBoards.tsx';
interface ListBoardsByTeamProps {
userId: string;
@@ -42,42 +44,24 @@ const ListPersonalBoards = ({ userId, isSuperAdmin, socket }: ListBoardsByTeamPr
);
const { data, isLoading } = fetchBoardsByTeam;
- // const personalBoards = useMemo(() => {
- // const teams = new Map();
- // const boardsAndDate = new Map;
-
- // data?.pages.forEach((page) => {
- // page.boards?.forEach((board) => {
- // boards.push(board);
- // const date = new Date(board.updatedAt).toDateString();
- // if (!boardsOfTeam) {
- // boardsTeamAndDate.set(`personal`, new Map([[date, [board]]]));
- // return;
- // }
- // const boardsOfDay = boardsOfTeam.get(date);
- // if (boardsOfDay) {
- // boardsOfDay.push(board);
- // return;
- // }
- // boardsOfTeam.set(date, [board]);
- // });
- // });
- // return { boards, teams };
- // }, [data?.pages]);
-
const dataByTeamAndDate = useMemo(() => {
const teams = new Map();
const boardsTeamAndDate = new Map>();
data?.pages.forEach((page) => {
page.boards?.forEach((board) => {
+ const boardsOfTeam = boardsTeamAndDate.get('personal');
const date = new Date(board.updatedAt).toDateString();
- const boardsOfPersonal = boardsTeamAndDate.get('personal');
- if (!boardsOfPersonal) {
+ if (!boardsOfTeam) {
boardsTeamAndDate.set('personal', new Map([[date, [board]]]));
return;
}
- boardsOfPersonal.set(date, [board]);
+ const boardsOfDay = boardsOfTeam.get(date);
+ if (boardsOfDay) {
+ boardsOfDay.push(board);
+ return;
+ }
+ boardsOfTeam.set(date, [board]);
});
});
return { boardsTeamAndDate, teams };
@@ -92,30 +76,13 @@ const ListPersonalBoards = ({ userId, isSuperAdmin, socket }: ListBoardsByTeamPr
}
};
- // if (personalBoards.length === 0 && !isLoading) {
- // return (
- //
- //
- //
- //
- //
- //
- //
- //
- // );
- // }
+ if (dataByTeamAndDate.boardsTeamAndDate.size === 0 && !isLoading) {
+ return (
+
+
+
+ );
+ }
return (
(({ userId, isSuperAdmin }) => {
{filterState === 'personal' && (
)}
-
-
+ {filterState === 'all' && (
+
+ )}
>
);
});
From daf99374f03708dfdc14a62f22327784dd06a61b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Patr=C3=ADcia=20Dias?=
Date: Fri, 6 Jan 2023 17:52:35 +0000
Subject: [PATCH 9/9] fix: undefined error on getting board.team
---
frontend/src/components/Boards/MyBoards/index.tsx | 2 +-
frontend/src/components/Dashboard/RecentRetros/index.tsx | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/frontend/src/components/Boards/MyBoards/index.tsx b/frontend/src/components/Boards/MyBoards/index.tsx
index b5f08e3c5..1141c670d 100644
--- a/frontend/src/components/Boards/MyBoards/index.tsx
+++ b/frontend/src/components/Boards/MyBoards/index.tsx
@@ -59,7 +59,7 @@ const MyBoards = React.memo(({ userId, isSuperAdmin }) => {
const { data, isLoading } = fetchBoards;
- const teamSocketId = data?.pages[0].boards[0].team
+ const teamSocketId = data?.pages[0].boards[0]?.team
? data?.pages[0].boards[0].team._id
: undefined;
diff --git a/frontend/src/components/Dashboard/RecentRetros/index.tsx b/frontend/src/components/Dashboard/RecentRetros/index.tsx
index f3a877d16..d94bb1eb0 100644
--- a/frontend/src/components/Dashboard/RecentRetros/index.tsx
+++ b/frontend/src/components/Dashboard/RecentRetros/index.tsx
@@ -40,7 +40,7 @@ const RecentRetros = React.memo(({ userId }) => {
const { data, isFetching } = fetchDashboardBoards;
- const teamSocketId = data?.pages[0].boards[0].team
+ const teamSocketId = data?.pages[0].boards[0]?.team
? data?.pages[0].boards[0].team._id
: undefined;