diff --git a/packages/manager/apps/key-management-service/src/components/Modal/terminate/TerminateModal.component.tsx b/packages/manager/apps/key-management-service/src/components/Modal/terminate/TerminateModal.component.tsx deleted file mode 100644 index 29df84dfd14b..000000000000 --- a/packages/manager/apps/key-management-service/src/components/Modal/terminate/TerminateModal.component.tsx +++ /dev/null @@ -1,119 +0,0 @@ -import { ODS_THEME_COLOR_INTENT } from '@ovhcloud/ods-common-theming'; -import { - ButtonType, - PageLocation, - useOvhTracking, -} from '@ovh-ux/manager-react-shell-client'; -import { - ODS_BUTTON_TYPE, - ODS_BUTTON_VARIANT, - ODS_INPUT_TYPE, - ODS_SPINNER_SIZE, - ODS_TEXT_LEVEL, - OdsInputValueChangeEvent, -} from '@ovhcloud/ods-components'; -import { - OsdsButton, - OsdsInput, - OsdsModal, - OsdsSpinner, - OsdsText, -} from '@ovhcloud/ods-components/react'; -import React, { useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { terminateValue } from './TerminateModal.constants'; - -export type TerminateModalProps = { - closeModal: () => void; - isLoading?: boolean; - onConfirmTerminate: () => void; -}; - -export const TerminateModal: React.FC = ({ - closeModal, - isLoading, - onConfirmTerminate, -}) => { - const { trackClick } = useOvhTracking(); - const { t } = useTranslation('key-management-service/terminate'); - const [terminateInput, setTerminateInput] = useState(''); - - const close = () => { - setTerminateInput(''); - closeModal(); - }; - - return ( - -
- {isLoading ? ( -
- -
- ) : ( - <> - - {t('key_management_service_terminate_description', { - terminateKeyword: terminateValue, - })} - - - setTerminateInput(e.detail.value) - } - /> - - )} -
- { - trackClick({ - location: PageLocation.popup, - buttonType: ButtonType.button, - actionType: 'navigation', - actions: ['delete_kms', 'cancel'], - }); - close(); - }} - > - {t('key_management_service_terminate_cancel')} - - { - trackClick({ - location: PageLocation.popup, - buttonType: ButtonType.button, - actionType: 'navigation', - actions: ['delete_kms', 'confirm'], - }); - setTerminateInput(''); - onConfirmTerminate(); - }} - > - {t('key_management_service_terminate_confirm')} - -
- ); -}; diff --git a/packages/manager/apps/key-management-service/src/components/Modal/terminate/TerminateModal.constants.ts b/packages/manager/apps/key-management-service/src/components/Modal/terminate/TerminateModal.constants.ts deleted file mode 100644 index b12864b664ed..000000000000 --- a/packages/manager/apps/key-management-service/src/components/Modal/terminate/TerminateModal.constants.ts +++ /dev/null @@ -1 +0,0 @@ -export const terminateValue = 'TERMINATE'; diff --git a/packages/manager/apps/key-management-service/src/components/layout-helpers/Dashboard/GeneralInformationsTiles/BillingInformationsTile.tsx b/packages/manager/apps/key-management-service/src/components/layout-helpers/Dashboard/GeneralInformationsTiles/BillingInformationsTile.tsx index c0334ef1e19c..36b856b43fdc 100644 --- a/packages/manager/apps/key-management-service/src/components/layout-helpers/Dashboard/GeneralInformationsTiles/BillingInformationsTile.tsx +++ b/packages/manager/apps/key-management-service/src/components/layout-helpers/Dashboard/GeneralInformationsTiles/BillingInformationsTile.tsx @@ -10,19 +10,16 @@ import { ODS_ICON_SIZE, ODS_TEXT_COLOR_INTENT, } from '@ovhcloud/ods-components'; +import { Outlet, useNavigate } from 'react-router-dom'; import { OsdsChip, OsdsIcon, OsdsLink } from '@ovhcloud/ods-components/react'; import React, { useContext, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { ButtonType, PageLocation, - PageType, ShellContext, useOvhTracking, } from '@ovh-ux/manager-react-shell-client'; -import { OKMS } from '@/types/okms.type'; -import { useTerminateOKms } from '@/data/hooks/useTerminateOKms'; -import { TerminateModal } from '@/components/Modal/terminate/TerminateModal.component'; import { OkmsServiceState } from '../okmsServiceState/OkmsServiceState.component'; import { Tile } from '@/components/dashboard/tile/tile.component'; import { TileItem } from '@/components/dashboard/tile-item/tileItem.component'; @@ -30,47 +27,25 @@ import { TileValue } from '@/components/dashboard/tile-value/tileValue.component import { TileSeparator } from '@/components/dashboard/tile-separator/tileSeparator'; import { TileValueDate } from '@/components/dashboard/tile-value-date/tileValueDate.component'; import { DISPLAY_CONTACTS_MANAGEMENT_KEY } from './BillingInformationsTile.constants'; +import { ROUTES_URLS } from '@/routes/routes.constants'; type BillingInformationsTileProps = { - okmsData?: OKMS; okmsService?: ServiceDetails; }; const BillingInformationsTile = ({ - okmsData, okmsService, }: BillingInformationsTileProps) => { const { t } = useTranslation('key-management-service/dashboard'); - const { trackClick, trackPage } = useOvhTracking(); + const navigate = useNavigate(); + const { trackClick } = useOvhTracking(); const [contactUrl, setContactUrl] = useState(''); - const [showTerminationModal, setShowTerminationModal] = useState(false); const { data: availability } = useFeatureAvailability([ DISPLAY_CONTACTS_MANAGEMENT_KEY, ]); const { shell: { navigation }, } = useContext(ShellContext); - const closeTerminateModal = () => { - setShowTerminationModal(false); - }; - - const { terminateKms, isPending } = useTerminateOKms({ - okmsId: okmsData.id, - onSuccess: () => { - trackPage({ - pageType: PageType.bannerSuccess, - pageName: 'delete_kms_success', - }); - closeTerminateModal(); - }, - onError: () => { - trackPage({ - pageType: PageType.bannerError, - pageName: 'delete_kms_error', - }); - closeTerminateModal(); - }, - }); const dateFormat: Intl.DateTimeFormatOptions = { day: '2-digit', @@ -90,7 +65,7 @@ const BillingInformationsTile = ({ actionType: 'navigation', actions: ['delete_kms'], }); - setShowTerminationModal(true); + navigate(ROUTES_URLS.terminateOkms); }, }, ]; @@ -212,13 +187,7 @@ const BillingInformationsTile = ({ )} - {showTerminationModal && ( - - )} + ); }; diff --git a/packages/manager/apps/key-management-service/src/data/hooks/useTerminateOKms.ts b/packages/manager/apps/key-management-service/src/data/hooks/useTerminateOKms.ts index a862377f09d9..c3f4e751017b 100644 --- a/packages/manager/apps/key-management-service/src/data/hooks/useTerminateOKms.ts +++ b/packages/manager/apps/key-management-service/src/data/hooks/useTerminateOKms.ts @@ -1,6 +1,10 @@ import { ApiError, ApiResponse } from '@ovh-ux/manager-core-api'; import { useNotifications } from '@ovh-ux/manager-react-components'; -import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { + MutationOptions, + useMutation, + useQueryClient, +} from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; import { getOkmsServicesResourceListQueryKey } from '../api/okms'; import { @@ -10,15 +14,14 @@ import { terminateOKmsQueryKey, } from '../api/okmsService'; +export type UseTerminateOkmsParams = { + okmsId: string; +} & MutationOptions, ApiError>; + export const useTerminateOKms = ({ okmsId, - onSuccess, - onError, -}: { - okmsId: string; - onSuccess?: () => void; - onError?: () => void; -}) => { + ...options +}: UseTerminateOkmsParams) => { const queryClient = useQueryClient(); const { addError, addSuccess, clearNotifications } = useNotifications(); const { t } = useTranslation('key-management-service/terminate'); @@ -34,7 +37,7 @@ export const useTerminateOKms = ({ }); return terminateOKms({ serviceId: servicesId[0] }); }, - onSuccess: () => { + onSuccess: (...params) => { clearNotifications(); addSuccess( t('key_management_service_terminate_success_banner', { @@ -45,9 +48,9 @@ export const useTerminateOKms = ({ queryClient.invalidateQueries({ queryKey: getOkmsServicesResourceListQueryKey, }); - onSuccess?.(); + options?.onSuccess?.(...params); }, - onError: (result: ApiError) => { + onError: (result: ApiError, ...params) => { clearNotifications(); addError( t('key_management_service_terminate_error', { @@ -55,8 +58,9 @@ export const useTerminateOKms = ({ }), true, ); - onError?.(); + options?.onError?.(result, ...params); }, + ...options, }); return { diff --git a/packages/manager/apps/key-management-service/src/pages/dashboard/KmsDashboard.page.spec.tsx b/packages/manager/apps/key-management-service/src/pages/dashboard/KmsDashboard.page.spec.tsx index 5a8dfdaa55fe..698c515e6871 100644 --- a/packages/manager/apps/key-management-service/src/pages/dashboard/KmsDashboard.page.spec.tsx +++ b/packages/manager/apps/key-management-service/src/pages/dashboard/KmsDashboard.page.spec.tsx @@ -1,9 +1,9 @@ import { act, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { renderTestApp } from '@/utils/tests/renderTestApp'; -import '@testing-library/jest-dom'; import { labels } from '@/utils/tests/init.i18n'; import { okmsMock } from '@/mocks/kms/okms.mock'; +import '@testing-library/jest-dom'; describe('KMS dashboard test suite', () => { it('should display an error if the API is KO', async () => { @@ -134,12 +134,12 @@ describe('KMS dashboard test suite', () => { await waitFor( () => expect( - screen.getByText( + screen.getAllByText( labels.serviceKeys[ 'key_management_service_service-keys_dashboard_field_name' ], ), - ).toBeVisible(), + ).toHaveLength(2), { timeout: 30_000, }, diff --git a/packages/manager/apps/key-management-service/src/pages/dashboard/generalInformations/GeneralInformations.tsx b/packages/manager/apps/key-management-service/src/pages/dashboard/generalInformations/GeneralInformations.tsx index 64853d40c477..3f7e3329a5dd 100644 --- a/packages/manager/apps/key-management-service/src/pages/dashboard/generalInformations/GeneralInformations.tsx +++ b/packages/manager/apps/key-management-service/src/pages/dashboard/generalInformations/GeneralInformations.tsx @@ -36,10 +36,7 @@ function GeneralInformationsTab() { okmsData={okms.data} okmsServiceInfos={okmsService.data} /> - + ); } diff --git a/packages/manager/apps/key-management-service/src/pages/listing/terminate/TerminateKms.tsx b/packages/manager/apps/key-management-service/src/pages/listing/terminate/TerminateKms.tsx index d829aff8b300..89b6c6c7fcbf 100644 --- a/packages/manager/apps/key-management-service/src/pages/listing/terminate/TerminateKms.tsx +++ b/packages/manager/apps/key-management-service/src/pages/listing/terminate/TerminateKms.tsx @@ -1,17 +1,23 @@ import React from 'react'; -import { PageType, useOvhTracking } from '@ovh-ux/manager-react-shell-client'; +import { + ButtonType, + PageLocation, + PageType, + useOvhTracking, +} from '@ovh-ux/manager-react-shell-client'; import { useNavigate, useParams } from 'react-router-dom'; -import { TerminateModal } from '@/components/Modal/terminate/TerminateModal.component'; +import { useTranslation } from 'react-i18next'; +import { + DeleteModal, + defaultDeleteModalTerminateValue, +} from '@ovh-ux/manager-react-components'; import { useTerminateOKms } from '@/data/hooks/useTerminateOKms'; export default function TerminateKms() { const navigate = useNavigate(); - const { trackPage } = useOvhTracking(); + const { t } = useTranslation('key-management-service/terminate'); const { okmsId } = useParams(); - - const closeModal = () => { - navigate('..'); - }; + const { trackPage, trackClick } = useOvhTracking(); const { terminateKms, isPending } = useTerminateOKms({ okmsId, @@ -20,22 +26,43 @@ export default function TerminateKms() { pageType: PageType.bannerSuccess, pageName: 'delete_kms_success', }); - closeModal(); }, onError: () => { trackPage({ pageType: PageType.bannerError, pageName: 'delete_kms_error', }); - closeModal(); + }, + onSettled: () => { + navigate('..'); }, }); return ( - { + trackClick({ + location: PageLocation.popup, + buttonType: ButtonType.button, + actionType: 'navigation', + actions: ['delete_kms', 'cancel'], + }); + navigate('..'); + }} isLoading={isPending} + onConfirmDelete={() => { + trackClick({ + location: PageLocation.popup, + buttonType: ButtonType.button, + actionType: 'navigation', + actions: ['delete_kms', 'confirm'], + }); + terminateKms(); + }} + deleteInputLabel={t('key_management_service_terminate_description', { + terminateKeyword: defaultDeleteModalTerminateValue, + })} /> ); } diff --git a/packages/manager/apps/key-management-service/src/routes/routes.constants.ts b/packages/manager/apps/key-management-service/src/routes/routes.constants.ts index 0041c5ff8b1e..f9847cc3ec15 100644 --- a/packages/manager/apps/key-management-service/src/routes/routes.constants.ts +++ b/packages/manager/apps/key-management-service/src/routes/routes.constants.ts @@ -2,7 +2,7 @@ export const ROUTES_URLS = { root: '/', listing: '/', onboarding: '/onboarding', - terminateOkms: '/terminate', + terminateOkms: 'terminate', createKeyManagementService: 'create', okmsId: ':okmsId', okmsUpdateName: 'update-name', diff --git a/packages/manager/apps/key-management-service/src/routes/routes.tsx b/packages/manager/apps/key-management-service/src/routes/routes.tsx index fddde97f6f77..015abd04f327 100644 --- a/packages/manager/apps/key-management-service/src/routes/routes.tsx +++ b/packages/manager/apps/key-management-service/src/routes/routes.tsx @@ -99,6 +99,18 @@ export default [ }, }, }, + { + path: ROUTES_URLS.terminateOkms, + ...lazyRouteConfig(() => + import('@/pages/listing/terminate/TerminateKms'), + ), + handle: { + tracking: { + pageName: 'terminate', + pageType: PageType.popup, + }, + }, + }, ], }, {