1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/component/segments/EditSegmentButton/EditSegmentButton.tsx
Nuno Góis 2c2da4ad3f
Feat project segments permissions (#3346)
- Adds `UPDATE_PROJECT_SEGMENT` permission checks;
- Allows `PermissionIconButton` to evaluate multiple permissions, just
like `PermissionButton`;
- Also includes a possible fix for `hasAccess` in `AccessProvider`.
2023-03-17 17:43:48 +00:00

38 lines
1.2 KiB
TypeScript

import { ISegment } from 'interfaces/segment';
import { Edit } from '@mui/icons-material';
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
import {
UPDATE_SEGMENT,
UPDATE_PROJECT_SEGMENT,
} from 'component/providers/AccessProvider/permissions';
import { useNavigate } from 'react-router-dom';
import { useOptionalPathParam } from 'hooks/useOptionalPathParam';
interface IEditSegmentButtonProps {
segment: ISegment;
}
export const EditSegmentButton = ({ segment }: IEditSegmentButtonProps) => {
const projectId = useOptionalPathParam('projectId');
const navigate = useNavigate();
return (
<PermissionIconButton
onClick={() => {
if (projectId) {
navigate(
`/projects/${projectId}/settings/segments/edit/${segment.id}`
);
} else {
navigate(`/segments/edit/${segment.id}`);
}
}}
permission={[UPDATE_SEGMENT, UPDATE_PROJECT_SEGMENT]}
projectId={projectId}
tooltipProps={{ title: 'Edit segment' }}
>
<Edit data-loading />
</PermissionIconButton>
);
};