Skip to content

Commit

Permalink
feat: check savings plan before delete pci project
Browse files Browse the repository at this point in the history
ref: feat/TAPC-1281

Signed-off-by: Lionel Bueno <[email protected]>
  • Loading branch information
Lionel Bueno committed Aug 29, 2024
1 parent 3f963e5 commit 953fda0
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
trackClick: '<',
trackPage: '<',
isDiscoveryProject: '<',
projectId: '<',
},
controller,
template,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { SUPPORT_URL } from '../../../new/constants';
import { MESSAGES_CONTAINER_NAME } from '../edit.constant';

export default class {
/* @ngInject */
constructor($translate, CucCloudMessage) {
constructor(
$translate,
CucCloudMessage,
OvhApiCloudProject,
$http,
coreConfig,
) {
this.$translate = $translate;
this.CucCloudMessage = CucCloudMessage;
this.OvhApiCloudProject = OvhApiCloudProject;
this.isLoading = false;
this.canDeleteProject = true;
this.$http = $http;
this.coreConfig = coreConfig;
}

cancel() {
Expand All @@ -15,48 +26,97 @@ export default class {
this.goBack();
}

$onInit() {
this.isLoading = true;
return this.$http({
url: '/services',
params: {
resourceName: this.projectId,
},
}).then(({ data }) => {
if (data.length) {
this.checkSavingsPlan(data[0]);
} else {
this.isLoading = false;
}
});
}

checkSavingsPlan(serviceId) {
this.$http({
url: `/services/${serviceId}/savingsPlans/subscribed`,
}).then(({ data }) => {
this.isLoading = false;
if (data.length) {
const activePlan = data.some((p) => p.status === 'ACTIVE');
if (activePlan) {
this.canDeleteProject = false;
}
}
});
}

getTranslationKey() {
if (!this.canDeleteProject) {
return 'pci_projects_project_discovery_edit_savings_plan';
}
return `pci_projects_project_${
this.isDiscoveryProject ? 'discovery_' : ''
}edit_remove_please_note`;
}

getPrimaryButtonLabel() {
if (!this.canDeleteProject) {
return 'pci_projects_project_edit_remove_submit_client_service';
}
return 'pci_projects_project_edit_remove_submit';
}

remove() {
this.isLoading = true;
this.trackClick(
'PublicCloud::pci::projects::project::edit::remove::confirm',
);
if (!this.canDeleteProject) {
window.open(
SUPPORT_URL + this.coreConfig.getUser().ovhSubsidiary,
'_blank',
'noopener',
);
this.goBack();
} else {
this.trackClick(
'PublicCloud::pci::projects::project::edit::remove::confirm',
);

const promises = [this.delete()];
const promises = [this.delete()];

if (
this.defaultProject &&
this.defaultProject.projectId === this.serviceName
) {
promises.push(this.unFavProject());
}
if (
this.defaultProject &&
this.defaultProject.projectId === this.serviceName
) {
promises.push(this.unFavProject());
}

return Promise.all(promises)
.then(() => {
this.trackPage(
'PublicCloud::pci::projects::project::edit::remove-success',
);
return this.CucCloudMessage.success(
this.$translate.instant('pci_projects_project_edit_remove_success'),
MESSAGES_CONTAINER_NAME,
);
})
.catch(({ data }) => {
this.trackPage(
'PublicCloud::pci::projects::project::edit::remove-error',
);
return this.CucCloudMessage.error(
this.$translate.instant('pci_projects_project_edit_remove_error', {
error: data.message,
}),
MESSAGES_CONTAINER_NAME,
);
})
.finally(() => this.goBack());
return Promise.all(promises)
.then(() => {
this.trackPage(
'PublicCloud::pci::projects::project::edit::remove-success',
);
return this.CucCloudMessage.success(
this.$translate.instant('pci_projects_project_edit_remove_success'),
MESSAGES_CONTAINER_NAME,
);
})
.catch(({ data }) => {
this.trackPage(
'PublicCloud::pci::projects::project::edit::remove-error',
);
return this.CucCloudMessage.error(
this.$translate.instant('pci_projects_project_edit_remove_error', {
error: data.message,
}),
MESSAGES_CONTAINER_NAME,
);
})
.finally(() => this.goBack());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<oui-modal
data-heading="{{:: 'pci_projects_project_edit_remove_title' | translate}}"
data-primary-action="$ctrl.remove()"
data-primary-label="{{:: 'pci_projects_project_edit_remove_submit' | translate }}"
data-primary-label="{{ $ctrl.getPrimaryButtonLabel() | translate }}"
data-primary-disabled="$ctrl.isLoading"
data-secondary-action="$ctrl.cancel()"
data-secondary-label="{{:: 'pci_projects_project_edit_remove_cancel' | translate }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"pci_projects_project_edit_remove_title": "Supprimer le projet",
"pci_projects_project_edit_remove_please_note": "Il est important de noter que tous vos services, ressources, paramètres et données seront détruits, sans possibilité de restauration ultérieure, à l'exception des IP Failovers, qui seront parkées.",
"pci_projects_project_discovery_edit_remove_please_note": "Veuillez noter que la suppression de votre projet est irréversible. Vous devrez en recréer un pour profiter à nouveau de l’univers Public Cloud.",
"pci_projects_project_discovery_edit_savings_plan": "Vous avez un savings plan en cours sur ce projet vous ne pouvez pas le supprimer. Veuillez contacter le service client pour connaître la procédure de suppressions.",
"pci_projects_project_edit_remove_submit": "Supprimer le projet",
"pci_projects_project_edit_remove_submit_client_service": "Contacter le service client",
"pci_projects_project_edit_remove_cancel": "Annuler",
"pci_projects_project_edit_remove_error": "Une erreur est survenue lors de la suppression du projet : {{ error }}",
"pci_projects_project_edit_remove_success": "Une confirmation de suppression vient de vous être envoyée par e-mail."
Expand Down

0 comments on commit 953fda0

Please sign in to comment.