Skip to content

Commit

Permalink
feat(HMS-2992): add confirmation modal
Browse files Browse the repository at this point in the history
During the domain registration wizard, when the
user click on cancel button, now a confirmation
modal dialog is showed up.

When the action is confirmed, if an initial resource
registration happened, then it is deleted; afterward
the modal dialog is closed and go to the main view.

When the action is not confirmed, the modal dialog
is closed with no additional action.

Signed-off-by: Alejandro Visiedo <[email protected]>
  • Loading branch information
avisiedo committed Apr 18, 2024
1 parent 5622e6a commit 9f3df3b
Showing 1 changed file with 116 additions and 20 deletions.
136 changes: 116 additions & 20 deletions src/Routes/WizardPage/WizardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@
import React, { useContext, useState } from 'react';
import { ExternalLinkAltIcon } from '@patternfly/react-icons/dist/esm/icons/external-link-alt-icon';

import { Button, Page, PageSection, PageSectionTypes, PageSectionVariants, Wizard, WizardStep } from '@patternfly/react-core';
import {
Button,
Modal,
ModalVariant,
Page,
PageSection,
PageSectionTypes,
PageSectionVariants,
Text,
Wizard,
WizardStep,
} from '@patternfly/react-core';

import { PageHeader, PageHeaderTitle } from '@redhat-cloud-services/frontend-components/PageHeader';

Expand Down Expand Up @@ -36,36 +47,86 @@ const WizardPage = () => {
const appContext = useContext(AppContext);
const domain = appContext?.wizard.domain;
const navigate = useNavigate();
const [isCancelConfirmationModalOpen, SetIsCancelConfirmationModalOpen] = useState<boolean>(false);

// FIXME Update the URL with the location for docs
const linkLearnMoreAbout = 'https://access.redhat.com/articles/1586893';
const linkLearnMoreAboutRemovingDirectoryAndDomainServices = 'https://access.redhat.com/articles/1586893';

/** Event triggered when Close button is clicked. */
const onCloseClick = () => {
// TODO A few things pending:
// - Modal confirmation
// - Confirm =>
// - if not registered, dismiss wizard
// - else => DELETE /domains/:domain_id
// - Cancel or close model => Do not dismiss wizard
/** Event triggered when we do click on continue button at cancel confirmation modal */
const onConfirmCancelWizardContinueButtonClick = () => {
SetIsCancelConfirmationModalOpen(false);
};

const onConfirmCancelWizardCancelButtonClick = () => {
if (domain?.domain_id) {
const domain_id: string = domain?.domain_id;
resources_api
.updateDomainUser(domain.domain_id, {
title: domain.title,
description: domain.description,
auto_enrollment_enabled: domain.auto_enrollment_enabled,
.readDomain(domain_id)
.then(() => {
resources_api
.deleteDomain(domain_id)
.then((response) => {
if (response.status >= 400) {
// TODO show-up notification with error message
} else {
// TODO show-up notification with registration cancelled?
}
SetIsCancelConfirmationModalOpen(false);
navigate('/domains');
})
.catch((error) => {

Check warning on line 78 in src/Routes/WizardPage/WizardPage.tsx

View workflow job for this annotation

GitHub Actions / validate

'error' is defined but never used
// TODO Notify error
SetIsCancelConfirmationModalOpen(false);
navigate('/domains');
});
})
.catch((error) => {

Check warning on line 84 in src/Routes/WizardPage/WizardPage.tsx

View workflow job for this annotation

GitHub Actions / validate

'error' is defined but never used
SetIsCancelConfirmationModalOpen(false);
navigate('/domains');
});
} else {
SetIsCancelConfirmationModalOpen(false);
navigate('/domains');
}
};

/** Event triggered when Finish button is clicked. */
const onWizardSave = () => {
console.log('onWizardSave fired');
if (domain?.domain_id) {
const domain_id: string = domain?.domain_id;
resources_api
.updateDomainUser(domain_id, {
title: domain?.title,
description: domain?.description,
auto_enrollment_enabled: domain?.auto_enrollment_enabled,
})
.then((response) => {
if (response.status >= 400) {
// TODO show-up notification with error message
// TODO Notify error
}
navigate('/domains');
})
.catch((error) => {
// TODO show-up notification with error message
console.log('error onClose: ' + error);
// TODO Notify error
navigate('/domains');
});
} else {
navigate('/domains');
}
navigate('/domains');
};

/** Event triggered when Cancel button is clicked on the wizard. */
const onWizardCancel = () => {
console.log('onWizardCancel fired');
SetIsCancelConfirmationModalOpen(true);
};

/** Event triggered when Cancel button is clicked on the wizard. */
const onWizardClose = () => {
console.log('onWizardClose fired');
SetIsCancelConfirmationModalOpen(true);
};

/** Event triggered when Back button is clicked. */
Expand All @@ -74,7 +135,7 @@ const WizardPage = () => {
_prevStep: { prevId?: string | number; prevName: React.ReactNode }
) => {
// TODO If not needed at the end clean-up onPreviousPage
console.log('onPreviousPage fired');
console.log('onPreviousPage fired for id=' + _newStep.id);
return;
};

Expand All @@ -84,7 +145,7 @@ const WizardPage = () => {
_prevStep: { prevId?: string | number; prevName: React.ReactNode }
) => {
// TODO If not needed at the end clean-up onPreviousPage
console.log('onGoToStep fired');
console.log('onGoToStep fired' + _newStep.id);
return;
};

Expand Down Expand Up @@ -240,11 +301,46 @@ const WizardPage = () => {
navAriaLabel={`${title} steps`}
mainAriaLabel={`${title} content`}
steps={steps}
onClose={onCloseClick}
onNext={onNextPage}
onBack={onPreviousPage}
onGoToStep={onGoToStep}
onAbort={onWizardCancel}
onSave={onWizardSave}
onClose={onWizardClose}
/>
<Modal
variant={ModalVariant.small}
title="Cancel identity domain registration"
titleIconVariant={'warning'}
isOpen={isCancelConfirmationModalOpen}
onClose={onConfirmCancelWizardContinueButtonClick}
ouiaId="ModalDesription"
actions={[
<Button key="cancel" variant="primary" onClick={onConfirmCancelWizardCancelButtonClick} ouiaId="ButtonModalCancelRegistrationCancel">
Cancel registration
</Button>,
<Button key="continue" variant="link" onClick={onConfirmCancelWizardContinueButtonClick} ouiaId="ButtonModalCancelRegistrationContinue">
Continue registration
</Button>,
]}
>
<Text>
Proceeding with the cancellation, your data will not be saved in the Red Hat Hybrid Cloud Console. However, this actions does not affect
not affect the identity server side if any action are done there.
</Text>
<Button
component="a"
target="_blank"
variant="link"
icon={<ExternalLinkAltIcon />}
iconPosition="right"
isInline
href={linkLearnMoreAboutRemovingDirectoryAndDomainServices}
ouiaId="ButtonPagePreparationPrerequisites"
>
Learn more about removing Directory and Domain Services Packages from your Red hat IdM server
</Button>
</Modal>
</PageSection>
</Page>
</>
Expand Down

0 comments on commit 9f3df3b

Please sign in to comment.