Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add IsAdmin component #3

Merged
merged 6 commits into from
Jan 28, 2021
Merged

add IsAdmin component #3

merged 6 commits into from
Jan 28, 2021

Conversation

fabiankaegy
Copy link
Member

This is a component I had to use several times in projects. It allows the developer to check wether the current logged in user is an admin and render items only if it is the case.

An example for the use case:

import { IsAdmin } from '@10up/block-components';
function MyComponent( props ) {
    return (
        <IsAdmin
            fallback={ <p>Sorry, you are not allowed to do that</p> }
        >
            <p>Only Administrators can see what you put in here</p>
        </IsAdmin>
    )
}

This very much mirrors the MediaUploadCheck component from Gutenberg directly.

@ryanwelcher
Copy link
Contributor

@fabiankaegy code looks good to me.

I wonder if we can add a more concrete example? I can see users not being totally clear on why/when this component should be used.

At a high-level, I think we should be overly verbose on use-cases and details for these components - especially ones that may not be used extensively or have nice use-cases.

# Conflicts:
#	README.md
#	index.js
@fabiankaegy
Copy link
Member Author

@ryanwelcher Yeah that is true. It is a very special use case that should be described more concise :) Will take a look at a better example

@fabiankaegy
Copy link
Member Author

@ryanwelcher I have added some more context to the readme and linked to a real world example. A version of this component was actually build in the Maps Block Apple :)

Base automatically changed from main to trunk January 20, 2021 17:51
@tlovett1 tlovett1 merged commit b71acdf into trunk Jan 28, 2021
@tlovett1 tlovett1 deleted the feature/is-admin-component branch January 28, 2021 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants