seas-computing / mark-one

A UI component library for building React Apps (in development)
https://seas-computing.github.io/mark-one/
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Add useConfirm Hook #124

Closed jonseitz closed 2 years ago

jonseitz commented 2 years ago

Describe your changes

This extracts the unsaved changes warning code from course-planner (seas-computing/course-planner#370) into a custom hook that can be reused in other projects. The hook returns two functions: markAsChanged can be called with a boolean to indicate when the data has changed (true) or not (false), and confirmDiscard will show a confirm dialog and return the user's response as a boolean if they want to discard their changes (true) or return to working (false).

I've added test for the confirmDiscard functionality, but I wasn't able to find a reasonable to test the onbeforeunload handler that blocks navigation events; we're using jsdom to render our components, and it doesn't support simulating navigation.

Types of changes

Checklist:

Priority:

Related Issues:

Fixes seas-computing/course-planner#419