From 54c078e843db3be12aab4871dc233db76fe88828 Mon Sep 17 00:00:00 2001 From: Nuno Caseiro <90208434+nunocaseiro@users.noreply.github.com> Date: Mon, 30 Jan 2023 10:44:19 +0000 Subject: [PATCH] fix: settings in a split board (#955) --- backend/src/libs/utils/ordinal-date.ts | 17 +++++++ .../slack-communication.application.ts | 7 ++- .../src/components/Board/Settings/index.tsx | 47 ++++++++++++------- frontend/src/schema/schemaUpdateBoardForm.ts | 2 +- 4 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 backend/src/libs/utils/ordinal-date.ts diff --git a/backend/src/libs/utils/ordinal-date.ts b/backend/src/libs/utils/ordinal-date.ts new file mode 100644 index 000000000..e1ed4fc13 --- /dev/null +++ b/backend/src/libs/utils/ordinal-date.ts @@ -0,0 +1,17 @@ +/* eslint-disable padding-line-between-statements */ +export const get_nth_suffix = (date: number): string => { + switch (date) { + case 1: + case 21: + case 31: + return 'st'; + case 2: + case 22: + return 'nd'; + case 3: + case 23: + return 'rd'; + default: + return 'th'; + } +}; diff --git a/backend/src/modules/communication/applications/slack-communication.application.ts b/backend/src/modules/communication/applications/slack-communication.application.ts index a68899829..4da816c21 100644 --- a/backend/src/modules/communication/applications/slack-communication.application.ts +++ b/backend/src/modules/communication/applications/slack-communication.application.ts @@ -1,4 +1,5 @@ import { Logger } from '@nestjs/common'; +import { get_nth_suffix } from 'src/libs/utils/ordinal-date'; import { TeamDto } from 'src/modules/communication/dto/team.dto'; import { BoardRoles, BoardType, ConfigurationType } from 'src/modules/communication/dto/types'; import { UserDto } from 'src/modules/communication/dto/user.dto'; @@ -47,7 +48,9 @@ export class SlackCommunicationApplication implements CommunicationApplicationIn }, ''); const today = new Date(); - const until = new Date(today.setMonth(today.getMonth() + 1)).toLocaleDateString('en-US', { + const until = new Date(); + until.setDate(today.getDate() + 7); + const month = until.toLocaleDateString('en-US', { month: 'long' }); @@ -57,7 +60,7 @@ export class SlackCommunicationApplication implements CommunicationApplicationIn )}* \nIn order to proceed with the retro of this month, here are the random teams: \n\n ${textGeneralTeams} \n Each team has a *random* selected responsible, in order to organize the retro and everything else that is described in the doc(https://confluence.kigroup.de/display/OX/Retro) :eyes: :thumbsup:\n\n - This must be done until \`${until} 1st\`\n\n + This must be done until \`${month} ${until.getDate()}${get_nth_suffix(until.getDate())}\`\n\n All the needed boards and channels have been automatically created for your team and another one for responsibles of the teams.\n\n Talent wins games, but teamwork and intelligence wins championships. :fire: :muscle:`; diff --git a/frontend/src/components/Board/Settings/index.tsx b/frontend/src/components/Board/Settings/index.tsx index c49369724..82daf4b15 100644 --- a/frontend/src/components/Board/Settings/index.tsx +++ b/frontend/src/components/Board/Settings/index.tsx @@ -71,6 +71,7 @@ const BoardSettings = ({ addCards, }, } = useRecoilValue(boardInfoState); + const [editColumns, setEditColumns] = useRecoilState(editColumnsState); // State used to change values @@ -82,7 +83,7 @@ const BoardSettings = ({ maxVotes: boardMaxVotes, users, isPublic, - columns: editColumns, + columns: isRegularBoard ? editColumns : columns, addCards, }; @@ -132,7 +133,7 @@ const BoardSettings = ({ defaultValues: { title: data.title, maxVotes: data.maxVotes, - column1title: editColumns[0].title, + column1title: editColumns[0]?.title, column2title: editColumns[1]?.title, column3title: editColumns[2]?.title, column4title: editColumns[3]?.title, @@ -150,7 +151,7 @@ const BoardSettings = ({ ...prev, title: boardTitle, maxVotes: boardMaxVotes, - columns: editColumns, + columns: isRegularBoard ? editColumns : columns, hideCards, hideVotes, isPublic, @@ -158,10 +159,12 @@ const BoardSettings = ({ })); methods.setValue('title', boardTitle); methods.setValue('maxVotes', boardMaxVotes ?? null); - methods.setValue('column1title', editColumns[0].title); - methods.setValue('column2title', editColumns[1]?.title); - methods.setValue('column3title', editColumns[2]?.title); - methods.setValue('column4title', editColumns[3]?.title); + if (isRegularBoard) { + methods.setValue('column1title', editColumns[0]?.title); + methods.setValue('column2title', editColumns[1]?.title); + methods.setValue('column3title', editColumns[2]?.title); + methods.setValue('column4title', editColumns[3]?.title); + } setSwitchesState((prev) => ({ ...prev, @@ -181,6 +184,7 @@ const BoardSettings = ({ methods, editColumns, addCards, + isRegularBoard, ]); const handleHideCardsChange = () => { @@ -260,7 +264,7 @@ const BoardSettings = ({ ...data, title, maxVotes, - columns: updatedColumns, + columns: isRegularBoard ? updatedColumns : data.columns, socketId, }, { @@ -351,15 +355,24 @@ const BoardSettings = ({ { - const updatedColumnTitles = [column1title, column2title, column3title, column4title]; - const updatedColumns = [...editColumns]; - updatedColumns.forEach((column, index) => { - updatedColumns[index] = { - ...column, - title: updatedColumnTitles[index] as string, - }; - }); - updateBoard(title, maxVotes, updatedColumns); + if (isRegularBoard) { + const updatedColumnTitles = [ + column1title, + column2title, + column3title, + column4title, + ]; + const updatedColumns = [...editColumns]; + updatedColumns.forEach((column, index) => { + updatedColumns[index] = { + ...column, + title: updatedColumnTitles[index] as string, + }; + }); + updateBoard(title, maxVotes, updatedColumns); + } else { + updateBoard(title, maxVotes); + } }, )} > diff --git a/frontend/src/schema/schemaUpdateBoardForm.ts b/frontend/src/schema/schemaUpdateBoardForm.ts index 7e776c8a6..737fe000d 100644 --- a/frontend/src/schema/schemaUpdateBoardForm.ts +++ b/frontend/src/schema/schemaUpdateBoardForm.ts @@ -10,7 +10,7 @@ const SchemaUpdateBoard = Joi.object({ 'number.base': 'Max votes needs to be a number', 'number.min': 'Please insert a number greater than zero.', }), - column1title: Joi.string().required().trim().max(15).messages({ + column1title: Joi.string().trim().max(15).messages({ 'any.required': 'Please enter the Column 1 name', 'string.empty': 'Please enter the Column 1 name', 'string.max': 'Maximum of 15 characters',