Skip to content

Commit

Permalink
[FEATURE] Appeler l'API d'anonymisation de compte à partir de la moda…
Browse files Browse the repository at this point in the history
…le de confirmation (PIX-14914)

 #10681
  • Loading branch information
pix-service-auto-merge authored Dec 3, 2024
2 parents e65a74f + 94ce81a commit eaedbfa
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 18 deletions.
41 changes: 38 additions & 3 deletions mon-pix/app/components/user-account/delete-account-section.gjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import PixButton from '@1024pix/pix-ui/components/pix-button';
import PixMessage from '@1024pix/pix-ui/components/pix-message';
import PixModal from '@1024pix/pix-ui/components/pix-modal';
import { action } from '@ember/object';
import { service } from '@ember/service';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { t } from 'ember-intl';
import ENV from 'mon-pix/config/environment';

export default class DeleteAccountSection extends Component {
@service url;
@service requestManager;
@service router;

@tracked modalOpen = false;
@tracked isLoading = false;
@tracked globalError;

get supportHomeUrl() {
return this.url.supportHomeUrl;
Expand All @@ -28,11 +35,31 @@ export default class DeleteAccountSection extends Component {
this.modalOpen = false;
}

@action
async selfDeleteUserAccount() {
try {
await this.requestManager.request({
url: `${ENV.APP.API_HOST}/api/users/me`,
method: 'DELETE',
});

this.router.replaceWith('logout');
} catch (error) {
if (error.status === 403) {
this.globalError = 'pages.user-account.delete-account.modal.error-403';
} else {
this.globalError = 'common.api-error-messages.internal-server-error';
}
} finally {
this.isLoading = false;
}
}

<template>
<section class="delete-account-section">
<h2>{{t "pages.user-account.delete-account.title"}}</h2>

<p>
<p class="delete-account-section__content">
{{#if this.hasEmail}}
{{t
"pages.user-account.delete-account.warning-email"
Expand All @@ -51,7 +78,7 @@ export default class DeleteAccountSection extends Component {
{{/if}}
</p>

<p>
<p class="delete-account-section__content">
{{t "pages.user-account.delete-account.more-information"}}
<a href="{{this.supportHomeUrl}}" target="_blank" rel="noopener noreferrer">
{{t "pages.user-account.delete-account.more-information-contact-support"}}
Expand Down Expand Up @@ -84,13 +111,21 @@ export default class DeleteAccountSection extends Component {
{{/if}}
<p>{{t "pages.user-account.delete-account.modal.warning-1"}}</p>
<p>{{t "pages.user-account.delete-account.modal.warning-2"}}</p>

{{#if this.globalError}}
<PixMessage @type="error" @withIcon={{true}} role="alert" class="delete-account-modal__error">
{{t this.globalError}}
</PixMessage>
{{/if}}
</:content>

<:footer>
<PixButton @variant="secondary" @isBorderVisible={{true}} @triggerAction={{this.closeModal}}>
{{t "common.actions.cancel"}}
</PixButton>
<PixButton @variant="error">{{t "pages.user-account.delete-account.actions.delete"}}</PixButton>
<PixButton @variant="error" @triggerAction={{this.selfDeleteUserAccount}} @isLoading={{this.isLoading}}>{{t
"pages.user-account.delete-account.actions.delete"
}}</PixButton>
</:footer>
</PixModal>
</section>
Expand Down
23 changes: 10 additions & 13 deletions mon-pix/app/components/user-account/delete-account-section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
gap: var(--pix-spacing-6x);
align-items: start;

h2 {
@extend %pix-title-xs;
&__content {
color: var(--pix-neutral-500);
}

p {
color: var(--pix-neutral-500);
h2 {
@extend %pix-title-xs;
}

a {
text-decoration: underline;

&:focus
&:hover {
&:focus &:hover {
color: var(--pix-primary-500);
}
}
Expand All @@ -25,6 +24,10 @@
width: 560px;
border-radius: var(--pix-spacing-2x);

&__error {
margin-top: var(--pix-spacing-4x);
}

.pix-modal__header {
align-items: center;
}
Expand All @@ -33,12 +36,6 @@
display: flex;
flex-direction: column;
gap: var(--pix-spacing-2x);

p {
color: var(--pix-neutral-800);
}


}

.pix-modal__footer {
Expand All @@ -48,4 +45,4 @@
padding-bottom: var(--pix-spacing-4x);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { clickByName, render, within } from '@1024pix/ember-testing-library';
import { click } from '@ember/test-helpers';
import { t } from 'ember-intl/test-support';
import DeleteAccountSection from 'mon-pix/components/user-account/delete-account-section';
import { module, test } from 'qunit';
import sinon from 'sinon';

import setupIntlRenderingTest from '../../../helpers/setup-intl-rendering';
import { waitForDialog, waitForDialogClose } from '../../../helpers/wait-for.js';
Expand Down Expand Up @@ -126,4 +128,114 @@ module('Integration | Component | UserAccount | DeleteAccountSection', function
assert.ok(true);
});
});

module('selfDeleteUserAccount button', function (hooks) {
let requestManagerService;
let router;

hooks.beforeEach(function () {
requestManagerService = this.owner.lookup('service:requestManager');
sinon.stub(requestManagerService, 'request');

router = this.owner.lookup('service:router');
router.replaceWith = sinon.stub();
});

module('when the action is a success', function () {
test('it logouts the user', async function (assert) {
// given
requestManagerService.request.resolves({ response: { ok: true, status: 204 } });

const user = {
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
profile: { pixScore: 42 },
};
const screen = await render(<template><DeleteAccountSection @user={{user}} /></template>);

await clickByName(t('pages.user-account.delete-account.actions.delete'));
await waitForDialog();

// when
const dialog = screen.getByRole('dialog');
const button = within(dialog).getByRole('button', {
name: t('pages.user-account.delete-account.actions.delete'),
});
await click(button);

// then
sinon.assert.calledWithExactly(router.replaceWith, 'logout');
assert.ok(true);
});
});

module('when the user is not allowed to self delete their account', function () {
test('it displays a forbidden message', async function (assert) {
// given
requestManagerService.request.rejects({ status: 403 });

const user = {
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
profile: { pixScore: 42 },
};
const screen = await render(<template><DeleteAccountSection @user={{user}} /></template>);

await clickByName(t('pages.user-account.delete-account.actions.delete'));
await waitForDialog();

// when
const dialog = screen.getByRole('dialog');
const button = within(dialog).getByRole('button', {
name: t('pages.user-account.delete-account.actions.delete'),
});
await click(button);

// then
assert
.dom(
screen.getByRole('alert', {
value: t('pages.user-account.delete-account.modal.error-403'),
}),
)
.exists();
});
});

module('when there is an internal server error', function () {
test('it displays an internal server error message', async function (assert) {
// given
requestManagerService.request.rejects({ status: 500 });

const user = {
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
profile: { pixScore: 42 },
};
const screen = await render(<template><DeleteAccountSection @user={{user}} /></template>);

await clickByName(t('pages.user-account.delete-account.actions.delete'));
await waitForDialog();

// when
const dialog = screen.getByRole('dialog');
const button = within(dialog).getByRole('button', {
name: t('pages.user-account.delete-account.actions.delete'),
});
await click(button);

// then
assert
.dom(
screen.getByRole('alert', {
value: t('common.api-error-messages.internal-server-error'),
}),
)
.exists();
});
});
});
});
1 change: 1 addition & 0 deletions mon-pix/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,7 @@
},
"menu-link-title": "Delete my account",
"modal": {
"error-403": "You are not allowed to delete your account. Please contact the support.",
"question": "Are you sure you want to delete your account?",
"title": "You’re about to delete your account",
"warning-1": "Please note that the account cannot be recovered after deletion.",
Expand Down
3 changes: 2 additions & 1 deletion mon-pix/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -2146,7 +2146,8 @@
"title": "You’re about to delete your account",
"question": "Are you sure you want to delete your account?",
"warning-1": "Please note that the account cannot be recovered after deletion.",
"warning-2": "As soon as you confirm, you will be automatically disconnected and your request will be taken into account immediately."
"warning-2": "As soon as you confirm, you will be automatically disconnected and your request will be taken into account immediately.",
"error-403": "You are not allowed to delete your account. Please contact the support."
},
"more-information": "For more information, ",
"more-information-contact-support": "please contact support.",
Expand Down
1 change: 1 addition & 0 deletions mon-pix/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2142,6 +2142,7 @@
},
"menu-link-title": "Supprimer mon compte",
"modal": {
"error-403": "Vous ne pouvez pas supprimer votre compte. Veuillez contacter le support de Pix.",
"question": "Êtes-vous sûr(e) de vouloir supprimer votre compte ?",
"title": "Vous êtes sur le point de supprimer votre compte",
"warning-1": "Veuillez noter que le compte ne pourra pas être récupéré après la suppression.",
Expand Down
3 changes: 2 additions & 1 deletion mon-pix/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -2142,7 +2142,8 @@
"title": "You’re about to delete your account",
"question": "Are you sure you want to delete your account?",
"warning-1": "Please note that the account cannot be recovered after deletion.",
"warning-2": "As soon as you confirm, you will be automatically disconnected and your request will be taken into account immediately."
"warning-2": "As soon as you confirm, you will be automatically disconnected and your request will be taken into account immediately.",
"error-403": "You are not allowed to delete your account. Please contact the support."
},
"more-information": "For more information, ",
"more-information-contact-support": "please contact support.",
Expand Down

0 comments on commit eaedbfa

Please sign in to comment.