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

feat: add billable metrics role guard #1507

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/components/billableMetrics/BillableMetricItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { useInternationalization } from '~/hooks/core/useInternationalization'
import { ListKeyNavigationItemProps } from '~/hooks/ui/useListKeyNavigation'
import { useOrganizationInfos } from '~/hooks/useOrganizationInfos'
import { usePermissions } from '~/hooks/usePermissions'
import {
BaseListItem,
ItemContainer,
Expand Down Expand Up @@ -55,6 +56,7 @@ export const BillableMetricItem = memo(
const { id: billableMetricId, name, code, createdAt } = billableMetric
const { translate } = useInternationalization()
const { formatTimeOrgaTZ } = useOrganizationInfos()
const { hasPermissions } = usePermissions()

return (
<ItemContainer>
Expand Down Expand Up @@ -108,17 +110,19 @@ export const BillableMetricItem = memo(
>
{translate('text_6256de3bba111e00b3bfa531')}
</ButtonLink>
<Button
startIcon="trash"
variant="quaternary"
align="left"
onClick={() => {
deleteDialogRef.current?.openDialog(billableMetric)
closePopper()
}}
>
{translate('text_6256de3bba111e00b3bfa533')}
</Button>
{hasPermissions(['billableMetricsDelete']) && (
<Button
startIcon="trash"
variant="quaternary"
align="left"
onClick={() => {
deleteDialogRef.current?.openDialog(billableMetric)
closePopper()
}}
>
{translate('text_6256de3bba111e00b3bfa533')}
</Button>
)}
</MenuPopper>
)}
</Popper>
Expand Down
2 changes: 2 additions & 0 deletions src/core/router/ObjectsRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const objectListRoutes: CustomRouteObject[] = [
path: [BILLABLE_METRICS_ROUTE],
private: true,
element: <BillableMetricsList />,
permissions: ['billableMetricsView'],
},
{
path: PLANS_ROUTE,
Expand Down Expand Up @@ -139,6 +140,7 @@ export const objectCreationRoutes: CustomRouteObject[] = [
path: [CREATE_BILLABLE_METRIC_ROUTE, UPDATE_BILLABLE_METRIC_ROUTE],
private: true,
element: <CreateBillableMetric />,
permissions: ['billableMetricsCreate', 'billableMetricsUpdate'],
},
{
path: [CREATE_PLAN_ROUTE, UPDATE_PLAN_ROUTE],
Expand Down
2 changes: 1 addition & 1 deletion src/core/router/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export interface CustomRouteObject extends Omit<RouteObject, 'children' | 'path'
invitation?: boolean
redirect?: string
children?: CustomRouteObject[]
permissions?: [keyof TMembershipPermissions]
permissions?: Array<keyof TMembershipPermissions>
}
17 changes: 11 additions & 6 deletions src/layouts/SideNavLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,17 @@ const SideNav = () => {
]
: []),

{
title: translate('text_623b497ad05b960101be3448'),
icon: 'pulse',
link: BILLABLE_METRICS_ROUTE,
match: [BILLABLE_METRICS_ROUTE],
},
...(hasPermissions(['billableMetricsView'])
? [
{
title: translate('text_623b497ad05b960101be3448'),
icon: 'pulse',
link: BILLABLE_METRICS_ROUTE,
match: [BILLABLE_METRICS_ROUTE],
} as TabProps,
]
: []),

{
title: translate('text_62442e40cea25600b0b6d85a'),
icon: 'board',
Expand Down
Loading