Skip to content

Commit 15dbbff

Browse files
committed
Merge branch 'feat/block-styles' of https://github.com/gambitph/Stackable into feat/block-styles
2 parents e2f8dcc + b429e78 commit 15dbbff

File tree

1 file changed

+22
-23
lines changed
  • src/components/block-styles-control

1 file changed

+22
-23
lines changed

src/components/block-styles-control/index.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ export const BlockStylesControl = props => {
5151
const buttonRef = useRef( null )
5252
const panelBodyRef = useRef( null )
5353

54+
const [ userCanManageOptions, setUserCanManageOptions ] = useState( false )
55+
const id = useSelect( select => select( 'core' ).getCurrentUser()?.id, [] )
56+
57+
// Check if the user has "manage options" capabilities and can manage block styles.
58+
useEffect( () => {
59+
const checkCapabilities = async () => {
60+
const capabilities = await currentUserHasCapability( 'manage_options' )
61+
setUserCanManageOptions( capabilities )
62+
}
63+
64+
checkCapabilities()
65+
}, [ id ] )
66+
5467
// Reset openProNotice when the popover is closed
5568
useEffect( () => {
5669
if ( ! openPopover ) {
@@ -237,13 +250,15 @@ export const BlockStylesControl = props => {
237250
</li>
238251
} ) }
239252
</ul>
240-
<SaveUpdateButtons
241-
blockStyle={ blockStyle }
242-
inOptions={ inBlockStyleOptions }
243-
isModified={ isModified }
244-
setOpenSaveModal={ setOpenSaveModal }
245-
onAddBlockStyle={ onAddBlockStyle }
246-
/>
253+
{ userCanManageOptions && (
254+
<SaveUpdateButtons
255+
blockStyle={ blockStyle }
256+
inOptions={ inBlockStyleOptions }
257+
isModified={ isModified }
258+
setOpenSaveModal={ setOpenSaveModal }
259+
onAddBlockStyle={ onAddBlockStyle }
260+
/>
261+
) }
247262
<div className={ proControlClasses } >
248263
<ProControl type="global-block-styles" />
249264
</div>
@@ -266,25 +281,9 @@ const SaveUpdateButtons = props => {
266281
const {
267282
blockStyle, inOptions, isModified, setOpenSaveModal, onAddBlockStyle,
268283
} = props
269-
const [ userCanManageOptions, setUserCanManageOptions ] = useState( false )
270-
const id = useSelect( select => select( 'core' ).getCurrentUser()?.id, [] )
271-
272-
useEffect( () => {
273-
const checkCapabilities = async () => {
274-
const capabilities = await currentUserHasCapability( 'manage_options' )
275-
setUserCanManageOptions( capabilities )
276-
}
277-
278-
checkCapabilities()
279-
}, [ id ] )
280284

281285
const UpdateButton = applyFilters( 'stackable.global-settings.global-block-styles.update-button', Fragment )
282286

283-
// Do not show the add and update buttons if the user does not have "manage options" capabilities
284-
if ( ! userCanManageOptions ) {
285-
return Fragment
286-
}
287-
288287
return ( <>
289288
<Flex style={ { marginTop: '24px' } }>
290289
<FlexItem>

0 commit comments

Comments
 (0)