added code to support account delete functionality

pull/3/head
Chris Veilleux 2019-03-26 14:27:53 -05:00
parent dbae142ae8
commit df342fe288
5 changed files with 89 additions and 15 deletions

View File

@ -4,19 +4,19 @@ import { FormGroup } from '@angular/forms';
import { MatSnackBar } from '@angular/material';
import { Observable, Subject, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { catchError, tap } from 'rxjs/operators';
import { Account } from '@account/models/account.model';
import { AccountMembership } from '@account/models/account-membership.model';
import { Agreement } from '@account/models/agreement.model';
import { environment } from '../../../environments/environment';
import { Account } from '../../shared/models/account.model';
import { AccountMembership } from '../../shared/models/account-membership.model';
import { Agreement } from '../../shared/models/agreement.model';
import { MembershipType } from '../../shared/models/membership.model';
import { MembershipType } from '@account/models/membership.model';
// URLs for the http requests
const accountUrl = '/api/account';
const agreementUrl = '/api/agreement/';
const membershipTypesUrl = '/api/memberships';
const ACCOUNT_URL = '/api/account';
const AGREEMENT_URL = '/api/agreement/';
const MEMBERSHIP_URL = '/api/memberships';
const fiveSeconds = 5000;
@ -88,7 +88,7 @@ export class ProfileService {
}
addAccount(newAcctForm: FormGroup) {
return this.http.post<any>(accountUrl, newAcctForm.value).pipe(
return this.http.post<any>(ACCOUNT_URL, newAcctForm.value).pipe(
catchError(this.handle400Error)
);
}
@ -97,7 +97,7 @@ export class ProfileService {
* API call to retrieve account info to display.
*/
getAccount(): Observable<Account> {
return this.http.get<Account>(accountUrl).pipe(
return this.http.get<Account>(ACCOUNT_URL).pipe(
catchError(this.handleError)
);
}
@ -109,19 +109,23 @@ export class ProfileService {
} else {
url_suffix = 'privacy-policy';
}
return this.http.get<Agreement>(agreementUrl + url_suffix);
return this.http.get<Agreement>(AGREEMENT_URL + url_suffix);
}
getMembershipTypes(): Observable<MembershipType[]> {
return this.http.get<MembershipType[]>(membershipTypesUrl);
return this.http.get<MembershipType[]>(MEMBERSHIP_URL);
}
updateAccount(accountChanges: any) {
return this.http.patch(accountUrl, {accountChanges}).pipe(
return this.http.patch(ACCOUNT_URL, {accountChanges}).pipe(
catchError(this.handleError)
);
}
deleteAccount() {
return this.http.delete(ACCOUNT_URL);
}
setSelectedMembershipType(accountMembership: AccountMembership, membershipTypes: MembershipType[]) {
let selectedMembership: MembershipType;
if (accountMembership) {

View File

@ -0,0 +1,21 @@
<mat-dialog-content>
<h2 class="mat-h2">Are you sure?</h2>
<p class="mat-body">
You know how this goes. You click a button, we make sure you meant to do it.
Deleting your account is nasty business with no "undo" button.
</p>
<p class="mat-body">
We'd hate to lose you so we hope you are seeing this as a result of an unintended mouse
click (those buttons can be touchy!). If so, click the "cancel" button below to continue
enjoying your Mycroft experience.
</p>
<p class="mat-body">
If you really do want to delete your account, that's a bummer. We hope to see you back some
time. Click the "confirm" button below and all data related to your account will
be sent to the great bit bucket in the sky.
</p>
</mat-dialog-content>
<mat-dialog-actions>
<button id="cancel-button" mat-button (click)="onCancel()">CANCEL</button>
<button id="confirm-button" mat-button (click)="onConfirm()">CONFIRM</button>
</mat-dialog-actions>

View File

@ -0,0 +1,11 @@
@import "~@angular/material/theming";
@import "mycroft-colors";
@import "components/buttons";
.mat-h2 {
color: mat-color($mycroft-warn);
}
#confirm-button {
@include action-button-warn;
}

View File

@ -0,0 +1,35 @@
import { Component, OnInit } from '@angular/core';
import { MatDialogRef } from '@angular/material';
import { environment } from '@account/environments/environment';
import { ProfileService } from '@account/http/profile.service';
@Component({
selector: 'account-delete-confirm',
templateUrl: './delete-confirm.component.html',
styleUrls: ['./delete-confirm.component.scss']
})
export class DeleteConfirmComponent implements OnInit {
constructor(
public confirmDialogRef: MatDialogRef<DeleteConfirmComponent>,
private profileService: ProfileService
) {
}
ngOnInit() {
}
onCancel(): void {
this.confirmDialogRef.close();
}
onConfirm(): void {
this.profileService.deleteAccount().subscribe(
() => {
this.confirmDialogRef.close();
window.location.href = environment.mycroftUrls.singleSignOn + '/login?redirect=' + environment.mycroftUrls.account;
}
);
}
}

View File

@ -37,6 +37,7 @@ import { SharedModule } from 'shared';
import { SupportStepComponent } from './components/views/support-step/support-step.component';
import { UsernameStepComponent } from './components/views/username-step/username-step.component';
import { VerifyCardDialogComponent } from './components/views/payment/verify-card-dialog.component';
import { DeleteConfirmComponent } from './components/modals/delete-confirm/delete-confirm.component';
@NgModule({
declarations: [
@ -58,9 +59,11 @@ import { VerifyCardDialogComponent } from './components/views/payment/verify-car
// Stuff used in both edit and add components
MembershipOptionsComponent,
PaymentComponent,
VerifyCardDialogComponent
VerifyCardDialogComponent,
DeleteConfirmComponent
],
entryComponents: [
DeleteConfirmComponent,
NewComponent,
EditComponent,
PaymentComponent,