2022-05-27 08:57:30 +02:00
|
|
|
import { ISegment } from 'interfaces/segment';
|
|
|
|
import { Edit } from '@mui/icons-material';
|
|
|
|
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
|
2023-03-17 18:43:48 +01:00
|
|
|
import {
|
|
|
|
UPDATE_SEGMENT,
|
|
|
|
UPDATE_PROJECT_SEGMENT,
|
|
|
|
} from 'component/providers/AccessProvider/permissions';
|
2022-05-27 08:57:30 +02:00
|
|
|
import { useNavigate } from 'react-router-dom';
|
2023-03-17 09:23:27 +01:00
|
|
|
import { useOptionalPathParam } from 'hooks/useOptionalPathParam';
|
2022-05-27 08:57:30 +02:00
|
|
|
|
|
|
|
interface IEditSegmentButtonProps {
|
|
|
|
segment: ISegment;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const EditSegmentButton = ({ segment }: IEditSegmentButtonProps) => {
|
2023-03-17 09:23:27 +01:00
|
|
|
const projectId = useOptionalPathParam('projectId');
|
2022-05-27 08:57:30 +02:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<PermissionIconButton
|
2023-03-17 09:23:27 +01:00
|
|
|
onClick={() => {
|
|
|
|
if (projectId) {
|
|
|
|
navigate(
|
|
|
|
`/projects/${projectId}/settings/segments/edit/${segment.id}`
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
navigate(`/segments/edit/${segment.id}`);
|
|
|
|
}
|
|
|
|
}}
|
2023-03-17 18:43:48 +01:00
|
|
|
permission={[UPDATE_SEGMENT, UPDATE_PROJECT_SEGMENT]}
|
|
|
|
projectId={projectId}
|
2022-05-27 08:57:30 +02:00
|
|
|
tooltipProps={{ title: 'Edit segment' }}
|
|
|
|
>
|
|
|
|
<Edit data-loading />
|
|
|
|
</PermissionIconButton>
|
|
|
|
);
|
|
|
|
};
|