Skip to content

Commit

Permalink
fix only template editing notice for users that can edit template
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiankaegy committed Apr 17, 2024
1 parent 93c52b9 commit 7a2c1db
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { __experimentalConfirmDialog as ConfirmDialog } from '@wordpress/components';
Expand Down Expand Up @@ -37,10 +38,19 @@ export default function EditTemplateBlocksNotification( { contentRef } ) {
};
}, [] );

const canEditTemplate = useSelect(
( select ) =>
select( coreStore ).canUser( 'create', 'templates' ) ?? false
);

const [ isDialogOpen, setIsDialogOpen ] = useState( false );

useEffect( () => {
const handleDblClick = ( event ) => {
if ( ! canEditTemplate ) {
return;
}

if ( ! event.target.classList.contains( 'is-root-container' ) ) {
return;
}
Expand All @@ -52,7 +62,11 @@ export default function EditTemplateBlocksNotification( { contentRef } ) {
return () => {
canvas?.removeEventListener( 'dblclick', handleDblClick );
};
}, [ contentRef ] );
}, [ contentRef, canEditTemplate ] );

if ( ! canEditTemplate ) {
return null;
}

return (
<ConfirmDialog
Expand Down

0 comments on commit 7a2c1db

Please sign in to comment.