diff --git a/mon-pix/app/components/user-account/delete-account-section.gjs b/mon-pix/app/components/user-account/delete-account-section.gjs index eb18614f614..571c09d1474 100644 --- a/mon-pix/app/components/user-account/delete-account-section.gjs +++ b/mon-pix/app/components/user-account/delete-account-section.gjs @@ -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; @@ -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; + } + } +