prevent navigation with unsaved code

This commit is contained in:
Shams mosowi
2020-10-20 13:48:47 +11:00
parent d72263db5c
commit 736360ddfc

View File

@@ -1,7 +1,7 @@
import React, { useState, useEffect, useRef } from "react";
import { Controller } from "react-hook-form";
import { IFieldProps } from "../utils";
import { Prompt } from "react-router-dom";
import AceEditor from "react-ace";
import "ace-builds/src-noconflict/mode-javascript";
import "ace-builds/src-noconflict/theme-github";
@@ -92,13 +92,21 @@ function ControlledCode({ onChange, onBlur, value }: IControlledCodeProps) {
</div>
{!autoSave && value !== localValue && (
<Button
onClick={() => onChange(localValue)}
className={classes.saveButton}
variant="contained"
>
Save Changes
</Button>
<>
<Prompt
when={true}
message={(location) =>
`You have some unsaved code changes, Are you sure you want to discard and continue?`
}
/>
<Button
onClick={() => onChange(localValue)}
className={classes.saveButton}
variant="contained"
>
Save Changes
</Button>
</>
)}
</>
);