Skip to content

Commit

Permalink
fix(pci-billing): alert creation rights
Browse files Browse the repository at this point in the history
ref: DTCORE-2941
Signed-off-by: Florian Renaut <[email protected]>
  • Loading branch information
frenautvh committed Dec 17, 2024
1 parent a97b08f commit 68a1ca0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { useState } from 'react';
import { ApiError } from '@ovh-ux/manager-core-api';
import { useNotifications } from '@ovh-ux/manager-react-components';
import { Currency } from '@ovh-ux/manager-config';
import { useProjectRights } from '@ovh-ux/manager-pci-common';
import { AlertModalComponent } from '@/pages/billing/estimate/components/AlertModal.component';

import queryClient from '@/queryClient';
Expand Down Expand Up @@ -72,11 +73,13 @@ export const AlertsPart = ({
onCreate,
onUpdate,
onDelete,
isLoading,
isLoading: isAlertDataLoading,
}: TAlertsPart): JSX.Element => {
const { t: tEstimate } = useTranslation('estimate');

const { addError } = useNotifications();
const { hasReadWriteRights, isPending: isRightsPending } = useProjectRights();
const isLoading = isAlertDataLoading || isRightsPending;

const [isModalOpen, setIsModalOpen] = useState(false);

Expand Down Expand Up @@ -212,48 +215,54 @@ export const AlertsPart = ({
</ResponsiveContainer>
</div>
<div>
{hasReadWriteRights && (
<>
<OsdsButton
color={ODS_THEME_COLOR_INTENT.primary}
variant={ODS_BUTTON_VARIANT.stroked}
inline
size={ODS_BUTTON_SIZE.sm}
onClick={openModal}
>
{tEstimate('cpbe_estimate_alert_edit')}{' '}
</OsdsButton>
<OsdsButton
className="ml-2"
color={ODS_THEME_COLOR_INTENT.primary}
variant={ODS_BUTTON_VARIANT.flat}
inline
size={ODS_BUTTON_SIZE.sm}
onClick={() => remove()}
>
{tEstimate('cpbe_estimate_alert_delete')}{' '}
</OsdsButton>
</>
)}
</div>
</>
) : (
hasReadWriteRights && (
<div className="mt-8">
<OsdsButton
color={ODS_THEME_COLOR_INTENT.primary}
variant={ODS_BUTTON_VARIANT.stroked}
inline
size={ODS_BUTTON_SIZE.sm}
onClick={openModal}
>
{tEstimate('cpbe_estimate_alert_edit')}{' '}
</OsdsButton>
<OsdsButton
className="ml-2"
color={ODS_THEME_COLOR_INTENT.primary}
variant={ODS_BUTTON_VARIANT.flat}
inline
size={ODS_BUTTON_SIZE.sm}
onClick={() => remove()}
onClick={openModal}
disabled={!!currentPricesError || undefined}
>
{tEstimate('cpbe_estimate_alert_delete')}{' '}
<OsdsIcon
name={ODS_ICON_NAME.BELL}
size={ODS_ICON_SIZE.xs}
color={ODS_THEME_COLOR_INTENT.primary}
contrasted
aria-hidden="true"
className="mr-2"
/>
{tEstimate('cpbe_estimate_alert_create')}{' '}
</OsdsButton>
</div>
</>
) : (
<div className="mt-8">
<OsdsButton
color={ODS_THEME_COLOR_INTENT.primary}
variant={ODS_BUTTON_VARIANT.flat}
inline
size={ODS_BUTTON_SIZE.sm}
onClick={openModal}
disabled={!!currentPricesError || undefined}
>
<OsdsIcon
name={ODS_ICON_NAME.BELL}
size={ODS_ICON_SIZE.xs}
color={ODS_THEME_COLOR_INTENT.primary}
contrasted
aria-hidden="true"
className="mr-2"
/>
{tEstimate('cpbe_estimate_alert_create')}{' '}
</OsdsButton>
</div>
)
)}
</>
)}
Expand Down
5 changes: 5 additions & 0 deletions packages/manager/apps/pci-billing/src/setupTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ vi.mock('@ovh-ux/manager-pci-common', async () => {
projectName: 'project-name',
project_id: 'project-id',
}),
useProjectRights: vi.fn().mockReturnValue({
hasReadWriteRights: true,
isPending: false,
}),
};
});

Expand Down Expand Up @@ -63,6 +67,7 @@ vi.mock('react-i18next', () => ({
},
}),
Trans: ({ children }: { children: string }) => children,
Translation: ({ children }: { children: string }) => children,
}));

const mocks = vi.hoisted(() => ({
Expand Down

0 comments on commit 68a1ca0

Please sign in to comment.