Skip to content

Commit

Permalink
Merge pull request #1653 from glific/feature/flow-dialog-update
Browse files Browse the repository at this point in the history
Changes required in dialogboxes in floweditor
  • Loading branch information
kurund authored Sep 16, 2021
2 parents 0c36578 + a858d2e commit 975b0e7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 19 deletions.
35 changes: 24 additions & 11 deletions src/components/UI/DialogBox/DialogBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface DialogProps {
title: string;
handleOk?: Function;
handleCancel?: Function;
handleMiddle?: Function;
children?: ReactNode;
buttonOk?: string;
buttonCancel?: string;
Expand All @@ -26,14 +27,18 @@ export interface DialogProps {
contentText?: string;
disableOk?: boolean;
alwaysOntop?: boolean;
buttonMiddle?: string | null;
additionalTitleStyles?: string | null;
}

export const DialogBox: React.SFC<DialogProps> = ({
open = true,
title,
handleOk = () => {},
handleCancel = () => {},
handleMiddle = () => {},
children,
additionalTitleStyles,
buttonOk = 'Confirm',
buttonCancel = 'Cancel',
colorOk = 'primary',
Expand All @@ -46,21 +51,14 @@ export const DialogBox: React.SFC<DialogProps> = ({
contentText,
disableOk = false,
alwaysOntop = false,
buttonMiddle,
}) => {
const handleCancelButton = () => {
handleCancel();
};

const handleOKButton = () => {
handleOk();
};

let cancelButtonDisplay = null;
if (!skipCancel) {
cancelButtonDisplay = (
<Button
variant="contained"
onClick={handleCancelButton}
onClick={() => handleCancel()}
color={colorCancel}
data-testid="cancel-button"
>
Expand All @@ -74,16 +72,30 @@ export const DialogBox: React.SFC<DialogProps> = ({
titleStyle = styles.DialogTitleLeft;
}

if (additionalTitleStyles) {
titleStyle = [titleStyle, additionalTitleStyles].join(' ');
}

let contentStyle = styles.DialogContentLeft;
if (contentAlign === 'center') {
contentStyle = styles.DialogContentCenter;
}

let middleButtonDisplay;

if (buttonMiddle) {
middleButtonDisplay = (
<Button onClick={() => handleMiddle()} color="primary" variant="outlined">
{buttonMiddle}
</Button>
);
}

let okButtonDisplay = null;
if (!skipOk) {
okButtonDisplay = (
<Button
onClick={handleOKButton}
onClick={() => handleOk()}
disabled={disableOk}
color={colorOk}
variant="contained"
Expand All @@ -107,7 +119,7 @@ export const DialogBox: React.SFC<DialogProps> = ({
scrollPaper: styles.ScrollPaper,
root: alwaysOntop ? styles.DialogboxRoot : '',
}}
onClose={handleCancelButton}
onClose={() => handleCancel()}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
Expand All @@ -122,6 +134,7 @@ export const DialogBox: React.SFC<DialogProps> = ({
</DialogContent>
<DialogActions className={dialogActionStyle}>
{okButtonDisplay}
{middleButtonDisplay}
{cancelButtonDisplay}
</DialogActions>
</Dialog>
Expand Down
17 changes: 17 additions & 0 deletions src/components/floweditor/FlowEditor.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
.DialogDescription {
text-align: center;
margin: 0;
margin-bottom: 16px;
font-size: 14px;
font-weight: 400;
color: #073f24;
Expand Down Expand Up @@ -103,3 +104,19 @@
border-radius: 50%;
border: 2px solid #073f24;
}

.DialogContent {
max-width: 331px;
font-size: 16px;
font-weight: 400;
margin-bottom: 12px;
color: #073f24;
}

.DialogTitle > h2 {
font-size: 24px;
}

.PublishDialogTitle {
max-width: none !important;
}
37 changes: 29 additions & 8 deletions src/components/floweditor/FlowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export const FlowEditor = (props: FlowEditorProps) => {

const config = setConfig(uuid);
const [published, setPublished] = useState(false);
const [stayOnPublish, setStayOnPublish] = useState(false);
const [modalVisible, setModalVisible] = useState(false);
const [lastLocation, setLastLocation] = useState<Location | null>(null);
const [confirmedNavigation, setConfirmedNavigation] = useState(false);
Expand Down Expand Up @@ -243,12 +244,20 @@ export const FlowEditor = (props: FlowEditorProps) => {
if (modalVisible) {
modal = (
<DialogBox
title="Do you want to navigate away without saving your changes?"
title="Unsaved changes!"
handleOk={handleConfirmNavigationClick}
handleCancel={closeModal}
colorOk="secondary"
buttonOk="Ignore & leave"
buttonCancel="Stay & recheck"
alignButtons="center"
/>
contentAlign="center"
additionalTitleStyles={styles.DialogTitle}
>
<div className={styles.DialogContent}>
Your changes will not be saved if you navigate away. Please save as draft or publish.
</div>
</DialogBox>
);
}

Expand Down Expand Up @@ -352,12 +361,22 @@ export const FlowEditor = (props: FlowEditorProps) => {
if (publishDialog) {
dialog = (
<DialogBox
title="Are you ready to publish the flow?"
buttonOk="Publish"
handleOk={() => handlePublishFlow()}
title="Ready to publish?"
buttonOk="Publish & Stay"
titleAlign="center"
buttonMiddle="Publish & go back"
handleOk={() => {
setStayOnPublish(true);
handlePublishFlow();
}}
handleCancel={() => handleCancelFlow()}
handleMiddle={() => {
setStayOnPublish(false);
handlePublishFlow();
}}
alignButtons="center"
buttonCancel="Cancel"
additionalTitleStyles={styles.PublishDialogTitle}
>
<p className={styles.DialogDescription}>New changes will be activated for the users</p>
</DialogBox>
Expand Down Expand Up @@ -385,7 +404,11 @@ export const FlowEditor = (props: FlowEditorProps) => {

if (published && !IsError) {
setNotification(client, 'The flow has been published');
return <Redirect to="/flow" />;
if (!stayOnPublish) {
return <Redirect to="/flow" />;
}
setPublishDialog(false);
setPublished(false);
}

const resetMessage = () => {
Expand Down Expand Up @@ -444,9 +467,7 @@ export const FlowEditor = (props: FlowEditorProps) => {
data-testid="saveDraftButton"
className={simulatorId === 0 ? styles.Draft : styles.SimulatorDraft}
onClick={() => {
setConfirmedNavigation(true);
setNotification(client, 'The flow has been saved as draft');
history.push('/flow');
}}
>
Save as draft
Expand Down

0 comments on commit 975b0e7

Please sign in to comment.