From 9e861a62a67efe29441d928be22ed28ce5540dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Wed, 5 Oct 2022 20:57:32 +0200 Subject: [PATCH] Adding confirmation modal when setting the board to public with Editor or Commenter role (#3913) * Adding confirmation modal when setting the board to public with Editor or Commenter role * Applying suggested text changes * Update webapp/i18n/en.json Co-authored-by: Justine Geffen * Update webapp/i18n/en.json Co-authored-by: Justine Geffen * Update webapp/src/components/shareBoard/teamPermissionsRow.tsx Co-authored-by: Justine Geffen * update text to match Co-authored-by: Scott Bishel Co-authored-by: Justine Geffen --- webapp/i18n/en.json | 3 ++ .../shareBoard/teamPermissionsRow.tsx | 44 ++++++++++++++++--- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/webapp/i18n/en.json b/webapp/i18n/en.json index c8af1eaa8..55d080c98 100644 --- a/webapp/i18n/en.json +++ b/webapp/i18n/en.json @@ -401,6 +401,9 @@ "share-board.publish": "Publish", "share-board.share": "Share", "shareBoard.channels-select-group": "Channels", + "shareBoard.confirm-change-team-role.body": "Everyone on this board with a lower permission than the \"{role}\" role will now be promoted to {role}. Are you sure you want to change the minimum role for the board?", + "shareBoard.confirm-change-team-role.confirmBtnText": "Change minimum board role", + "shareBoard.confirm-change-team-role.title": "Change minimum board role", "shareBoard.confirm-link-channel": "Link board to channel", "shareBoard.confirm-link-channel-button": "Link channel", "shareBoard.confirm-link-channel-button-with-other-channel": "Unlink and link here", diff --git a/webapp/src/components/shareBoard/teamPermissionsRow.tsx b/webapp/src/components/shareBoard/teamPermissionsRow.tsx index 34cd586e5..2650e7790 100644 --- a/webapp/src/components/shareBoard/teamPermissionsRow.tsx +++ b/webapp/src/components/shareBoard/teamPermissionsRow.tsx @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import React from 'react' +import React, {useState} from 'react' import {useIntl} from 'react-intl' import MenuWrapper from '../../widgets/menuWrapper' @@ -18,10 +18,11 @@ import {Permission} from '../../constants' import {Utils} from '../../utils' import BoardPermissionGate from '../permissions/boardPermissionGate' +import ConfirmationDialogBox from '../confirmationDialogBox' import mutator from '../../mutator' -function updateBoardType(board: Board, newType: string, newMinimumRole: MemberRole) { +async function updateBoardType(board: Board, newType: string, newMinimumRole: MemberRole) { if (board.type === newType && board.minimumRole === newMinimumRole) { return } @@ -30,13 +31,21 @@ function updateBoardType(board: Board, newType: string, newMinimumRole: MemberRo newBoard.type = newType newBoard.minimumRole = newMinimumRole - mutator.updateBoard(newBoard, board, 'update board type') + await mutator.updateBoard(newBoard, board, 'update board type') } const TeamPermissionsRow = (): JSX.Element => { const intl = useIntl() const team = useAppSelector(getCurrentTeam) const board = useAppSelector(getCurrentBoard) + const [changeRoleConfirmation, setChangeRoleConfirmation] = useState(null) + + const onChangeRole = async () => { + if (changeRoleConfirmation !== null) { + await updateBoardType(board, BoardTypeOpen, changeRoleConfirmation) + setChangeRoleConfirmation(null) + } + } let currentRoleName = intl.formatMessage({id: 'BoardMember.schemeNone', defaultMessage: 'None'}) if (board.type === BoardTypeOpen && board.minimumRole === MemberRole.Admin) { @@ -53,8 +62,33 @@ const TeamPermissionsRow = (): JSX.Element => { currentRoleName = intl.formatMessage({id: 'BoardMember.schemeViewer', defaultMessage: 'Viewer'}) } + const confirmationDialog = ( + now be promoted to {role}. Are you sure you want to change the minimum role for the board?', + }, { + b: (...chunks) => {chunks}, + role: changeRoleConfirmation === MemberRole.Editor ? intl.formatMessage({id: 'BoardMember.schemeEditor', defaultMessage: 'Editor'}) : intl.formatMessage({id: 'BoardMember.schemeCommenter', defaultMessage: 'Commenter'}), + }), + confirmButtonText: intl.formatMessage({ + id: 'shareBoard.confirm-change-team-role.confirmBtnText', + defaultMessage: 'Change minimum board role', + }), + onConfirm: onChangeRole, + onClose: () => setChangeRoleConfirmation(null), + }} + /> + ) + return (
+ {changeRoleConfirmation && confirmationDialog}
{Utils.isFocalboardPlugin() && { check={board.minimumRole === undefined || board.minimumRole === MemberRole.Editor} icon={board.type === BoardTypeOpen && board.minimumRole === MemberRole.Editor ? :
} name={intl.formatMessage({id: 'BoardMember.schemeEditor', defaultMessage: 'Editor'})} - onClick={() => updateBoardType(board, BoardTypeOpen, MemberRole.Editor)} + onClick={() => setChangeRoleConfirmation(MemberRole.Editor)} />} {!board.isTemplate && { check={board.minimumRole === MemberRole.Commenter} icon={board.type === BoardTypeOpen && board.minimumRole === MemberRole.Commenter ? :
} name={intl.formatMessage({id: 'BoardMember.schemeCommenter', defaultMessage: 'Commenter'})} - onClick={() => updateBoardType(board, BoardTypeOpen, MemberRole.Commenter)} + onClick={() => setChangeRoleConfirmation(MemberRole.Commenter)} />}