Skip to content

Commit

Permalink
fix: recent issues (#970)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunocaseiro authored Jan 31, 2023
1 parent 2fb1390 commit f6fdf60
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { InjectModel } from '@nestjs/mongoose';
import { SchedulerRegistry } from '@nestjs/schedule';
import { CronJob } from 'cron';
import { LeanDocument, Model } from 'mongoose';
import { DELETE_FAILED } from 'src/libs/exceptions/messages';
import { getDay, getNextMonth } from 'src/libs/utils/dates';
import {
Configs,
Expand Down Expand Up @@ -83,6 +82,11 @@ export class CreateSchedulesService implements CreateSchedulesServiceInterface {
new Date().getUTCMonth() === 11 && newMonth === 0
? new Date().getFullYear() + 1
: new Date().getFullYear();

const job = new CronJob(`${minutes} ${hours} ${day} ${newMonth} *`, () =>
this.handleComplete(String(ownerId), teamId, String(boardId))
);

const cronJobDoc = await this.schedulesModel.create({
board: String(boardId),
team: String(teamId),
Expand All @@ -93,14 +97,10 @@ export class CreateSchedulesService implements CreateSchedulesServiceInterface {

if (!cronJobDoc) throw Error('CronJob not created');

const job = new CronJob(`${minutes} ${hours} ${day} ${newMonth} *`, () =>
this.handleComplete(String(ownerId), teamId, cronJobDoc.board.toString())
);
this.schedulerRegistry.addCronJob(String(boardId), job);
job.start();
} catch (e) {
this.logger.log(e);
await this.schedulesModel.deleteOne({ board: boardId });
this.logger.error(e);
}
}

Expand Down Expand Up @@ -136,7 +136,7 @@ export class CreateSchedulesService implements CreateSchedulesServiceInterface {

this.createSchedule(oldBoard, deletedSchedule, ownerId, teamId, oldBoardId);
} catch (e) {
throw Error(DELETE_FAILED);
this.logger.error(e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Board/AddCardOrComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const AddCard = React.memo<AddCardProps>(
mode: 'onSubmit',
reValidateMode: 'onChange',
defaultValues: {
text: '',
text: cardText === 'Write your comment here...' ? '' : cardText,
},
resolver: joiResolver(SchemaAddCommentForm),
});
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/components/Board/Card/CardBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface CardBoardProps {
hideCards: boolean;
isDefaultText: boolean;
cardText?: string;
hasAdminRole: boolean;
}

const CardBoard = React.memo<CardBoardProps>(
Expand All @@ -57,6 +58,7 @@ const CardBoard = React.memo<CardBoardProps>(
isSubmited,
hideCards,
isDefaultText,
hasAdminRole,
}) => {
const isCardGroup = card.items.length > 1;
const comments = useMemo(
Expand Down Expand Up @@ -163,11 +165,7 @@ const CardBoard = React.memo<CardBoardProps>(
>
{card.text}
</Text>
{isSubmited && (
<Icon css={{ width: '$20', height: '$20' }} name="menu-dots" />
)}

{!isSubmited && userId === card?.createdBy?._id && (
{!isSubmited && (userId === card?.createdBy?._id || hasAdminRole) && (
<PopoverCardSettings
boardId={boardId}
cardGroupId={card._id}
Expand All @@ -182,6 +180,7 @@ const CardBoard = React.memo<CardBoardProps>(
newPosition={0}
socketId={socketId}
userId={userId}
hasAdminRole={hasAdminRole}
/>
)}
</Flex>
Expand All @@ -200,6 +199,7 @@ const CardBoard = React.memo<CardBoardProps>(
socketId={socketId}
userId={userId}
isDefaultText={isDefaultText}
hasAdminRole={hasAdminRole}
/>
)}
<CardFooter
Expand Down Expand Up @@ -243,6 +243,7 @@ const CardBoard = React.memo<CardBoardProps>(
userId={userId}
columnId={colId}
isDefaultText={isDefaultText}
hasAdminRole={hasAdminRole}
/>
)}
</Flex>
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/components/Board/Card/CardFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const CardFooter = ({
gap="4"
css={{
filter: cardFooterBlur(hideCards, createdBy, userId),
maxWidth: '$226',
}}
>
<Avatar
Expand All @@ -160,8 +161,16 @@ const CardFooter = ({
id={createdBy?._id}
isDefaultColor={createdBy?._id === userId}
size={20}
css={{ flexShrink: 0 }}
/>
<Text size="xs">
<Text
size="xs"
css={{
textOverflow: 'ellipsis',
overflow: 'hidden',
whiteSpace: 'nowrap',
}}
>
{createdBy?.firstName} {createdBy?.lastName}
</Text>
</Flex>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/Board/Card/CardItem/CardItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface CardItemProps {
isSubmited: boolean;
hideCards: boolean;
isDefaultText: boolean;
hasAdminRole: boolean;
}

const Container = styled(Flex, {
Expand All @@ -53,6 +54,7 @@ const CardItem: React.FC<CardItemProps> = React.memo(
isSubmited,
hideCards,
isDefaultText,
hasAdminRole,
}) => {
const [editing, setEditing] = useState(false);
const [deleting, setDeleting] = useState(false);
Expand Down Expand Up @@ -111,6 +113,7 @@ const CardItem: React.FC<CardItemProps> = React.memo(
newPosition={cardGroupPosition}
socketId={socketId}
userId={userId}
hasAdminRole={hasAdminRole}
/>
)}
</Flex>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/Board/Card/CardItem/CardItemList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface CardItemListProps {
isSubmited: boolean;
hideCards: boolean;
isDefaultText: boolean;
hasAdminRole: boolean;
}

const CardItemList: React.FC<CardItemListProps> = ({
Expand All @@ -32,6 +33,7 @@ const CardItemList: React.FC<CardItemListProps> = ({
isSubmited,
hideCards,
isDefaultText,
hasAdminRole,
}) => (
<Flex direction="column">
{items.map((item, idx) => (
Expand Down Expand Up @@ -63,6 +65,7 @@ const CardItemList: React.FC<CardItemListProps> = ({
socketId={socketId}
userId={userId}
isDefaultText={isDefaultText}
hasAdminRole={hasAdminRole}
/>
</Flex>
))}
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/Board/Card/PopoverSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ interface PopoverSettingsProps {
hideCards: boolean;
userId: string;
item: CardItemType;
hasAdminRole: boolean;
handleEditing: () => void;
handleDeleteCard?: () => void;
}
Expand Down Expand Up @@ -126,6 +127,7 @@ const PopoverCardSettings: React.FC<PopoverSettingsProps> = React.memo(
item,
userId,
hideCards,
hasAdminRole,
}) => {
const [openPopover, setOpenPopover] = useState(false);

Expand Down Expand Up @@ -171,7 +173,7 @@ const PopoverCardSettings: React.FC<PopoverSettingsProps> = React.memo(

<PopoverSettingsContent
isItem={isItem}
isOwner={item.createdBy?._id === userId}
isOwner={item.createdBy?._id === userId || hasAdminRole}
setDeleteCard={handleDelete}
setEditCard={handleEditing}
unmergeCard={unmergeCard}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/Board/Column/CardsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const CardsList = React.memo<ColumnInnerList>(
isSubmited,
hideCards,
isDefaultText,
hasAdminRole,
}) => (
<>
{cards.map((card: CardType, idx) => (
Expand All @@ -36,6 +37,7 @@ const CardsList = React.memo<ColumnInnerList>(
socketId={socketId}
userId={userId}
isDefaultText={isDefaultText || true}
hasAdminRole={hasAdminRole}
/>
))}
</>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Board/Column/Column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ const Column = React.memo<ColumMemoProps>(
maxVotes={maxVotes}
socketId={socketId}
userId={userId}
hasAdminRole={hasAdminRole}
/>
{provided.placeholder}
</CardsContainer>
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/Board/Column/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ const Container = styled(Flex, Box, {

const OuterContainer = styled(Flex, {
height: 'fit-content',

flex: '1',
flex: '1 1 0',
flexGrow: 1,
flexShrink: 0,
width: '100%',
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/components/Board/Comment/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface CommentProps {
userId: string;
columnId: string;
isDefaultText: boolean;
hasAdminRole: boolean;
}

const Comment: React.FC<CommentProps> = React.memo(
Expand All @@ -35,6 +36,7 @@ const Comment: React.FC<CommentProps> = React.memo(
userId,
columnId,
isDefaultText,
hasAdminRole,
}) => {
const { deleteComment } = useComments();
const [editing, setEditing] = useState(false);
Expand Down Expand Up @@ -88,20 +90,23 @@ const Comment: React.FC<CommentProps> = React.memo(
}}
/>
)}
{!isSubmited && userId === comment.createdBy._id && (
{!isSubmited && (userId === comment.createdBy._id || hasAdminRole) && (
<PopoverCommentSettings
handleDeleteComment={handleDeleteComment}
handleEditing={handleEditing}
/>
)}
</Flex>
<Flex align="center" css={{ minHeight: '$24' }}>
<Flex align="center" css={{ minHeight: '$24', maxWidth: '$226' }}>
{!comment.anonymous && (
<Text
size="xs"
fontWeight="medium"
css={{
filter: commentBlur(hideCards, comment, userId),
textOverflow: 'ellipsis',
overflow: 'hidden',
whiteSpace: 'nowrap',
}}
>
{comment.createdBy.firstName} {comment.createdBy.lastName}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/Board/Comment/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface CommentsListProps {
userId: string;
columnId: string;
isDefaultText: boolean;
hasAdminRole: boolean;
}

const Comments = React.memo(
Expand All @@ -34,6 +35,7 @@ const Comments = React.memo(
userId,
columnId,
isDefaultText,
hasAdminRole,
}: CommentsListProps) => {
const [isCreateCommentOpened, setCreateComment] = useState(false);

Expand Down Expand Up @@ -67,6 +69,7 @@ const Comments = React.memo(
userId={userId}
columnId={columnId}
isDefaultText={isDefaultText}
hasAdminRole={hasAdminRole}
cardItemId={
cardItems.find((item) => {
if (item && item.comments)
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/components/Boards/TeamHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ const TeamHeader: React.FC<TeamHeaderProps> = ({ team, userId, users }) => {
<Text color="primary300" size="sm">
Team admin
</Text>
<CardAvatars teamAdmins listUsers={team.users} responsible={false} userId={userId} />
<CardAvatars
teamAdmins
stakeholders
listUsers={team.users}
responsible={false}
userId={userId}
/>
</Flex>
)}
{!hasTeam && users && (
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/components/CardBoard/CardAvatars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ const CardAvatars = React.memo<CardAvatarProps>(
.filter((user) => user.role === BoardUserRoles.RESPONSIBLE)
.map((user) => user.user);

if (teamAdmins && stakeholders) {
return listUsers
.filter((user) => ![TeamUserRoles.MEMBER, BoardUserRoles.MEMBER].includes(user.role))
.map((user) => user.user);
}

if (teamAdmins)
return listUsers
.filter((user) => user.role === TeamUserRoles.ADMIN)
Expand Down Expand Up @@ -193,12 +199,16 @@ const CardAvatars = React.memo<CardAvatarProps>(
<Flex align="center" css={{ height: 'fit-content', overflow: 'hidden' }}>
{haveError
? ['-', '-', '-'].map((value, index) =>
renderAvatar(value, stakeholders ? stakeholdersColors : undefined, index),
renderAvatar(
value,
stakeholders && !teamAdmins ? stakeholdersColors : undefined,
index,
),
)
: (data.slice(0, numberOfAvatars) as User[]).map((user: User, index: number) =>
renderAvatar(
getInitials(user, index),
stakeholders ? stakeholdersColors : undefined,
stakeholders && !teamAdmins ? stakeholdersColors : undefined,
index,
),
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ const CardBody = React.memo<CardBodyProps>(({ userId, teamId, team, isTeamPage }
Team admin
</Text>

<CardAvatars teamAdmins listUsers={team.users} responsible={false} userId={userId} />
<CardAvatars
stakeholders
teamAdmins
listUsers={team.users}
responsible={false}
userId={userId}
/>
</Flex>
<Separator
orientation="vertical"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface ColumnInnerList {
hideCards: boolean;
cardText?: string;
isDefaultText?: boolean;
hasAdminRole: boolean;
}

export type ColumnDragItem = {
Expand Down

0 comments on commit f6fdf60

Please sign in to comment.