| 1 |
import { useCallback } from 'react'; |
| 2 |
import { useNavigate } from '@reach/router'; |
| 3 |
import { Dialog } from '@elementor/app-ui'; |
| 4 |
|
| 5 |
export default function ApplyKitDialog( props ) { |
| 6 |
const navigate = useNavigate(); |
| 7 |
|
| 8 |
const startImportProcess = useCallback( ( applyAll = false ) => { |
| 9 |
let url = '/import/process' + |
| 10 |
`?file_url=${ encodeURIComponent( props.downloadLink ) }` + |
| 11 |
`&nonce=${ props.nonce }&referrer=kit-library`; |
| 12 |
|
| 13 |
if ( applyAll ) { |
| 14 |
url += '&action_type=apply-all'; |
| 15 |
} |
| 16 |
|
| 17 |
navigate( url ); |
| 18 |
}, [ props.downloadLink, props.nonce ] ); |
| 19 |
|
| 20 |
return ( |
| 21 |
<Dialog |
| 22 |
// Translators: %s is the kit name. |
| 23 |
title={ __( 'Apply %s?', 'elementor' ).replace( '%s', props.title ) } |
| 24 |
text={ <> |
| 25 |
{ __( 'You can use everything in this kit, or Customize to only include some items.', 'elementor' ) } |
| 26 |
<br /><br /> |
| 27 |
{ __( 'By applying the entire kit, you\'ll override any styles, settings or content already on your site.', 'elementor' ) } |
| 28 |
</> } |
| 29 |
approveButtonText={ __( 'Apply All', 'elementor' ) } |
| 30 |
approveButtonColor="primary" |
| 31 |
approveButtonOnClick={ () => startImportProcess( true ) } |
| 32 |
dismissButtonText={ __( 'Customize', 'elementor' ) } |
| 33 |
dismissButtonOnClick={ () => startImportProcess( false ) } |
| 34 |
onClose={ props.onClose } |
| 35 |
/> |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
ApplyKitDialog.propTypes = { |
| 40 |
downloadLink: PropTypes.string.isRequired, |
| 41 |
nonce: PropTypes.string.isRequired, |
| 42 |
onClose: PropTypes.func.isRequired, |
| 43 |
title: PropTypes.string, |
| 44 |
}; |
| 45 |
|
| 46 |
ApplyKitDialog.defaultProps = { |
| 47 |
title: 'Kit', |
| 48 |
}; |
| 49 |
|