ConfirmDialog.js
2 months ago
LabelWithTooltip.js
2 months ago
ProGate.js
2 months ago
SectionCard.js
2 months ago
SettingsDataProvider.js
2 months ago
SettingsPageShell.js
2 months ago
UnsavedChangesDialog.js
2 months ago
navigationGuard.js
2 months ago
UnsavedChangesDialog.js
76 lines
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | import { useState } from 'react'; |
| 3 | import { Dialog, Button, Loader } from '@bsf/force-ui'; |
| 4 | |
| 5 | const UnsavedChangesDialog = ( { open, onSave, onDiscard, onCancel } ) => { |
| 6 | const [ isSaving, setIsSaving ] = useState( false ); |
| 7 | |
| 8 | const handleSave = async () => { |
| 9 | setIsSaving( true ); |
| 10 | try { |
| 11 | await onSave?.(); |
| 12 | } finally { |
| 13 | setIsSaving( false ); |
| 14 | } |
| 15 | }; |
| 16 | |
| 17 | return ( |
| 18 | <Dialog |
| 19 | design="simple" |
| 20 | exitOnEsc |
| 21 | scrollLock |
| 22 | open={ open } |
| 23 | setOpen={ ( next ) => { |
| 24 | if ( ! next ) { |
| 25 | onCancel?.(); |
| 26 | } |
| 27 | } } |
| 28 | > |
| 29 | <Dialog.Backdrop /> |
| 30 | <Dialog.Panel> |
| 31 | <Dialog.Header> |
| 32 | <Dialog.Title> |
| 33 | { __( 'Unsaved changes', 'presto-player' ) } |
| 34 | </Dialog.Title> |
| 35 | <Dialog.Description> |
| 36 | { __( |
| 37 | 'You have unsaved changes on this page. What would you like to do?', |
| 38 | 'presto-player' |
| 39 | ) } |
| 40 | </Dialog.Description> |
| 41 | </Dialog.Header> |
| 42 | |
| 43 | <Dialog.Footer> |
| 44 | <Button |
| 45 | variant="outline" |
| 46 | onClick={ onDiscard } |
| 47 | disabled={ isSaving } |
| 48 | > |
| 49 | { __( 'Discard Changes', 'presto-player' ) } |
| 50 | </Button> |
| 51 | <Button |
| 52 | variant="primary" |
| 53 | onClick={ handleSave } |
| 54 | disabled={ isSaving } |
| 55 | icon={ |
| 56 | isSaving && ( |
| 57 | <Loader |
| 58 | icon={ null } |
| 59 | size="sm" |
| 60 | variant="primary" |
| 61 | className="bg-transparent" |
| 62 | /> |
| 63 | ) |
| 64 | } |
| 65 | iconPosition="right" |
| 66 | > |
| 67 | { __( 'Save & Continue', 'presto-player' ) } |
| 68 | </Button> |
| 69 | </Dialog.Footer> |
| 70 | </Dialog.Panel> |
| 71 | </Dialog> |
| 72 | ); |
| 73 | }; |
| 74 | |
| 75 | export default UnsavedChangesDialog; |
| 76 |