Giter VIP home page Giter VIP logo

privileges-managment-example's Introduction

Privileges

Allows you to control the components on the page by privileges in a simple way.

Custom privileges component

By creating a custom privileges component, you can ensure faster and cleaner development

//custom-privileges.tsx
import { PrivilegesContainer } from "./container";
import { Button } from "../ui/button";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip";
import WarningSVG from "@/components/icons/warning";

export type Privilege = {
    [key: string]: string;
}

export const moderator: Readonly<Privilege> = Object.freeze({
    ADMIN: 'admin',
});

export const CustomPrivilegesComponent = ({ children, userPrivileges, componentPrivileges, active, not_privileges = "component" }: {
    children: React.ReactNode;
    userPrivileges: string[];
    // moderator: string[];
    componentPrivileges: string | string[];
    active: "button" | "tooltip" | "not_privileges";
    not_privileges?: "pages" | "component";
}) => {
    return (
        <PrivilegesContainer
            moderator={Object.values(moderator)}
            userPrivileges={userPrivileges}
            componentPrivileges={componentPrivileges}
            active={active}
            button_container={
                <Button disabled className="select-none">
                    You are not privileges for this
                </Button>
            }
            not_privileges_container={
                not_privileges === "component"
                    ? (
                        <div className="p-2 rounded-md border text-orange-600 border-orange-500 select-none bg-orange-50">
                            <WarningSVG className="w-5 h-5 mr-2 inline" />
                            You are not privileges for component
                        </div>
                    )
                    : (
                        <div className="p-2 select-none space-y-3">
                            <WarningSVG className="w-16 h-16 mr-2 inline" />
                            <p>You are not privileges for pages</p>
                            <Button>
                                Go to home
                            </Button>
                        </div>
                    )
            }
            tooltip_container={
                <TooltipProvider
                    delayDuration={0}
                >
                    <Tooltip>
                        <TooltipTrigger className="p-0 h-fit w-fit select-none">
                            {children}
                        </TooltipTrigger>
                        <TooltipContent>
                            You are not privileges for this
                        </TooltipContent>
                    </Tooltip>
                </TooltipProvider>
            }
        />
    )
}


//index.tsx
<CustomPrivilegesComponent
  userPrivileges={[PRIVILEGES.PAID]}
  componentPrivileges={[PRIVILEGES.PAID]}
  active="button"
>
  TEST PRIVILEGES
</CustomPrivilegesComponent>

privileges-managment-example's People

Contributors

yusufgns avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.