mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 01:52:42 +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())
|
)(num.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usePreventWindowUnload(shouldPreventDefault) {
|
export function usePreventWindowUnload(shouldPreventDefault, message = "You have unsaved changes. Are you sure you want to exit?") {
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!shouldPreventDefault) return;
|
if (!shouldPreventDefault) return;
|
||||||
const handleBeforeUnload = event => event.preventDefault();
|
const handleBeforeUnload = event => {
|
||||||
|
event.preventDefault();
|
||||||
|
return message;
|
||||||
|
}
|
||||||
window.addEventListener("beforeunload", handleBeforeUnload);
|
window.addEventListener("beforeunload", handleBeforeUnload);
|
||||||
return () => window.removeEventListener("beforeunload", handleBeforeUnload);
|
window.onbeforeunload = handleBeforeUnload;
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("beforeunload", handleBeforeUnload);
|
||||||
|
window.onbeforeunload = undefined;
|
||||||
|
}
|
||||||
}, [shouldPreventDefault]);
|
}, [shouldPreventDefault]);
|
||||||
}
|
}
|
@ -30,7 +30,7 @@ const PromptIfDirty = () => {
|
|||||||
return (
|
return (
|
||||||
<Prompt
|
<Prompt
|
||||||
when={formik.dirty}
|
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 () => {
|
const onDelete = async () => {
|
||||||
|
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"]);
|
await props.api.contacts.delete(association["group-path"]);
|
||||||
history.push("/");
|
history.push("/");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const disabled =
|
const disabled =
|
||||||
|
Loading…
Reference in New Issue
Block a user