From b155d7d1ba3e8bb797ab64c90fb46f79b312da28 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Tue, 1 Feb 2022 09:41:50 +0530 Subject: [PATCH] Show confirm dialog when change your own power level Signed-off-by: Ajay Bura --- src/app/organisms/profile-viewer/ProfileViewer.jsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/organisms/profile-viewer/ProfileViewer.jsx b/src/app/organisms/profile-viewer/ProfileViewer.jsx index 3af19c29..34530122 100644 --- a/src/app/organisms/profile-viewer/ProfileViewer.jsx +++ b/src/app/organisms/profile-viewer/ProfileViewer.jsx @@ -371,10 +371,16 @@ function ProfileViewer() { const handleChangePowerLevel = (newPowerLevel) => { if (newPowerLevel === powerLevel) return; - if (newPowerLevel === myPowerLevel - ? confirm('You will not be able to undo this change as you are promoting the user to have the same power level as yourself. Are you sure?') - : true - ) { + const SHARED_POWER_MSG = 'You will not be able to undo this change as you are promoting the user to have the same power level as yourself. Are you sure?'; + const DEMOTING_MYSELF_MSG = 'You will not be able to undo this change as you are demoting yourself. Are you sure?'; + + const isSharedPower = newPowerLevel === myPowerLevel; + const isDemotingMyself = userId === mx.getUserId(); + if (isSharedPower || isDemotingMyself) { + if (confirm(isSharedPower ? SHARED_POWER_MSG : DEMOTING_MYSELF_MSG)) { + roomActions.setPowerLevel(roomId, userId, newPowerLevel); + } + } else { roomActions.setPowerLevel(roomId, userId, newPowerLevel); } };