From d760be58c3b64629e6fc6483dc6c5a2b343ab55b Mon Sep 17 00:00:00 2001
From: Ajay Bura <32841439+ajbura@users.noreply.github.com>
Date: Mon, 25 Apr 2022 20:21:21 +0530
Subject: [PATCH] Replace confirm and prompt with custom dialogs (#500)
---
.../confirm-dialog/ConfirmDialog.jsx | 58 ++++++++++++++++++
.../confirm-dialog/ConfirmDialog.scss | 11 ++++
src/app/molecules/message/Message.jsx | 15 +++--
.../room-encryption/RoomEncryption.jsx | 21 ++++---
.../molecules/room-options/RoomOptions.jsx | 20 ++++---
.../molecules/room-profile/RoomProfile.jsx | 9 ++-
.../molecules/space-options/SpaceOptions.jsx | 17 ++++--
.../profile-editor/ProfileEditor.jsx | 11 +++-
.../profile-viewer/ProfileViewer.jsx | 14 +++--
src/app/organisms/room/RoomSettings.jsx | 14 +++--
src/app/organisms/settings/DeviceManage.jsx | 60 ++++++++++++++++---
src/app/organisms/settings/DeviceManage.scss | 11 ++++
src/app/organisms/settings/Settings.jsx | 7 ++-
.../space-settings/SpaceSettings.jsx | 14 +++--
14 files changed, 232 insertions(+), 50 deletions(-)
create mode 100644 src/app/molecules/confirm-dialog/ConfirmDialog.jsx
create mode 100644 src/app/molecules/confirm-dialog/ConfirmDialog.scss
diff --git a/src/app/molecules/confirm-dialog/ConfirmDialog.jsx b/src/app/molecules/confirm-dialog/ConfirmDialog.jsx
new file mode 100644
index 0000000..5771f2c
--- /dev/null
+++ b/src/app/molecules/confirm-dialog/ConfirmDialog.jsx
@@ -0,0 +1,58 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import './ConfirmDialog.scss';
+
+import { openReusableDialog } from '../../../client/action/navigation';
+
+import Text from '../../atoms/text/Text';
+import Button from '../../atoms/button/Button';
+
+function ConfirmDialog({
+ desc, actionTitle, actionType, onComplete,
+}) {
+ return (
+
+
{desc}
+
+
+
+
+
+ );
+}
+ConfirmDialog.propTypes = {
+ desc: PropTypes.string.isRequired,
+ actionTitle: PropTypes.string.isRequired,
+ actionType: PropTypes.oneOf(['primary', 'positive', 'danger', 'caution']).isRequired,
+ onComplete: PropTypes.func.isRequired,
+};
+
+/**
+ * @param {string} title title of confirm dialog
+ * @param {string} desc description of confirm dialog
+ * @param {string} actionTitle title of main action to take
+ * @param {'primary' | 'positive' | 'danger' | 'caution'} actionType type of action. default=primary
+ * @return {Promise} does it get's confirmed or not
+ */
+// eslint-disable-next-line import/prefer-default-export
+export const confirmDialog = (title, desc, actionTitle, actionType = 'primary') => new Promise((resolve) => {
+ let isCompleted = false;
+ openReusableDialog(
+ {title},
+ (requestClose) => (
+ {
+ isCompleted = true;
+ resolve(isConfirmed);
+ requestClose();
+ }}
+ />
+ ),
+ () => {
+ if (!isCompleted) resolve(false);
+ },
+ );
+});
diff --git a/src/app/molecules/confirm-dialog/ConfirmDialog.scss b/src/app/molecules/confirm-dialog/ConfirmDialog.scss
new file mode 100644
index 0000000..05f88be
--- /dev/null
+++ b/src/app/molecules/confirm-dialog/ConfirmDialog.scss
@@ -0,0 +1,11 @@
+.confirm-dialog {
+ padding: var(--sp-normal);
+
+ & > .text {
+ padding-bottom: var(--sp-normal);
+ }
+ &__btn {
+ display: flex;
+ gap: var(--sp-normal);
+ }
+}
\ No newline at end of file
diff --git a/src/app/molecules/message/Message.jsx b/src/app/molecules/message/Message.jsx
index 70ca87e..be4dea5 100644
--- a/src/app/molecules/message/Message.jsx
+++ b/src/app/molecules/message/Message.jsx
@@ -36,6 +36,8 @@ import TickMarkIC from '../../../../public/res/ic/outlined/tick-mark.svg';
import CmdIC from '../../../../public/res/ic/outlined/cmd.svg';
import BinIC from '../../../../public/res/ic/outlined/bin.svg';
+import { confirmDialog } from '../confirm-dialog/ConfirmDialog';
+
function PlaceholderMessage() {
return (
@@ -546,10 +548,15 @@ const MessageOptions = React.memo(({