Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes required in dialogboxes in floweditor #1653

Merged
merged 2 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -161,6 +161,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 @@ -244,12 +245,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 @@ -353,12 +362,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 @@ -386,7 +405,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 @@ -445,9 +468,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