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