mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-14 17:41:33 +03:00
groups: prevent accidental group deletion
Fixes https://github.com/urbit/landscape/issues/68
This commit is contained in:
parent
61442c4c2e
commit
7017b3d9cb
@ -327,11 +327,18 @@ export function numToUd(num) {
|
||||
)(num.toString())
|
||||
}
|
||||
|
||||
export function usePreventWindowUnload(shouldPreventDefault) {
|
||||
export function usePreventWindowUnload(shouldPreventDefault, message = "You have unsaved changes. Are you sure you want to exit?") {
|
||||
React.useEffect(() => {
|
||||
if (!shouldPreventDefault) return;
|
||||
const handleBeforeUnload = event => event.preventDefault();
|
||||
const handleBeforeUnload = event => {
|
||||
event.preventDefault();
|
||||
return message;
|
||||
}
|
||||
window.addEventListener("beforeunload", handleBeforeUnload);
|
||||
return () => window.removeEventListener("beforeunload", handleBeforeUnload);
|
||||
window.onbeforeunload = handleBeforeUnload;
|
||||
return () => {
|
||||
window.removeEventListener("beforeunload", handleBeforeUnload);
|
||||
window.onbeforeunload = undefined;
|
||||
}
|
||||
}, [shouldPreventDefault]);
|
||||
}
|
@ -30,7 +30,7 @@ const PromptIfDirty = () => {
|
||||
return (
|
||||
<Prompt
|
||||
when={formik.dirty}
|
||||
message="Are you sure you want to leave? You have with unsaved changes."
|
||||
message="Are you sure you want to leave? You have unsaved changes."
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
@ -83,8 +83,11 @@ export function GroupSettings(props: GroupSettingsProps) {
|
||||
};
|
||||
|
||||
const onDelete = async () => {
|
||||
await props.api.contacts.delete(association["group-path"]);
|
||||
history.push("/");
|
||||
const name = association['group-path'].split('/').pop();
|
||||
if (prompt(`To confirm deleting this group, type ${name}`) === name) {
|
||||
await props.api.contacts.delete(association["group-path"]);
|
||||
history.push("/");
|
||||
}
|
||||
};
|
||||
|
||||
const disabled =
|
||||
|
Loading…
Reference in New Issue
Block a user