| 1 |
import { Modal, Button, ButtonGroup } from '@wordpress/components' |
| 2 |
import { dispatch, select } from '@wordpress/data' |
| 3 |
import { useState } from '@wordpress/element' |
| 4 |
import { __ } from '@wordpress/i18n' |
| 5 |
|
| 6 |
export default function ReloadRequiredModal() { |
| 7 |
const [isSaving, setSaving] = useState(false) |
| 8 |
const { isEditedPostDirty } = select('core/editor') |
| 9 |
const hasUnsavedChanges = isEditedPostDirty() |
| 10 |
const saveChanges = () => { |
| 11 |
setSaving(true) |
| 12 |
dispatch('core/editor').savePost() |
| 13 |
setSaving(false) |
| 14 |
} |
| 15 |
const reload = () => { |
| 16 |
// location.reload() |
| 17 |
} |
| 18 |
if (!hasUnsavedChanges) { |
| 19 |
reload() |
| 20 |
return null |
| 21 |
} |
| 22 |
return ( |
| 23 |
<Modal title={__('Reload required', 'extendify')} isDismissible={false}> |
| 24 |
<p |
| 25 |
style={{ |
| 26 |
maxWidth: '400px', |
| 27 |
}}> |
| 28 |
{__( |
| 29 |
'Just one more thing! We need to reload the page to continue.', |
| 30 |
'extendify', |
| 31 |
)} |
| 32 |
</p> |
| 33 |
<ButtonGroup> |
| 34 |
<Button isPrimary onClick={reload} disabled={isSaving}> |
| 35 |
{__('Reload page', 'extendify')} |
| 36 |
</Button> |
| 37 |
<Button |
| 38 |
isSecondary |
| 39 |
onClick={saveChanges} |
| 40 |
isBusy={isSaving} |
| 41 |
style={{ |
| 42 |
margin: '0 4px', |
| 43 |
}}> |
| 44 |
{__('Save changes', 'extendify')} |
| 45 |
</Button> |
| 46 |
</ButtonGroup> |
| 47 |
</Modal> |
| 48 |
) |
| 49 |
} |
| 50 |
|