import { Button, ButtonProps } from '@mui/material'; import { Lock } from '@mui/icons-material'; import React from 'react'; import { TooltipResolver, ITooltipResolverProps, } from 'component/common/TooltipResolver/TooltipResolver'; import { formatAccessText } from 'utils/formatAccessText'; import { useId } from 'hooks/useId'; import { useHasRootAccess, useHasProjectEnvironmentAccess, } from 'hooks/useHasAccess'; export interface IPermissionButtonProps extends Omit { permission: string | string[]; onClick?: (e: any) => void; disabled?: boolean; projectId?: string; environmentId?: string; tooltipProps?: Omit; hideLockIcon?: boolean; } interface IPermissionBaseButtonProps extends IPermissionButtonProps { access: boolean; } export interface IProjectPermissionButtonProps extends IPermissionButtonProps { projectId: string; environmentId: string; } const getEndIcon = ( access: boolean, fallBackIcon?: React.ReactNode, hideLockIcon?: boolean, ): React.ReactNode => { if (!access && !hideLockIcon) { return ; } if (fallBackIcon) { return fallBackIcon; } return null; }; const ProjectEnvironmentPermissionButton: React.FC = React.forwardRef((props, ref) => { const access = useHasProjectEnvironmentAccess( props.permission, props.projectId, props.environmentId, ); return ; }); const RootPermissionButton: React.FC = React.forwardRef( (props, ref) => { const access = useHasRootAccess( props.permission, props.projectId, props.environmentId, ); return ; }, ); const BasePermissionButton: React.FC = React.forwardRef( ( { permission, access, variant = 'contained', color = 'primary', onClick, children, disabled, projectId, environmentId, tooltipProps, hideLockIcon, ...rest }, ref, ) => { const id = useId(); const endIcon = getEndIcon(access, rest.endIcon, hideLockIcon); return ( ); }, ); const PermissionButton: React.FC = React.forwardRef( (props, ref) => { if ( typeof props.projectId !== 'undefined' && typeof props.environmentId !== 'undefined' ) { return ( ); } return ; }, ); export default PermissionButton;