diff --git a/src/app/settings/settings.page.ts b/src/app/settings/settings.page.ts index f8fa8c099b17abd0a2d64d7b17e178a7ddc32f5e..04147353221bfacc0323cff7cdfae25f9075ea2a 100644 --- a/src/app/settings/settings.page.ts +++ b/src/app/settings/settings.page.ts @@ -1,6 +1,11 @@ import { Component, OnInit } from '@angular/core'; import { Router, LoadChildrenCallback } from '@angular/router'; import { ToastService } from '../services/toast.service'; +import { AlertController } from '@ionic/angular'; +import { RestService } from '../rest.service'; +import { Observable, Subject } from 'rxjs'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Storage } from '@ionic/storage'; @Component({ selector: 'app-settings', templateUrl: './settings.page.html', @@ -8,15 +13,56 @@ import { ToastService } from '../services/toast.service'; }) export class SettingsPage implements OnInit { - constructor(private router: Router,private toastService: ToastService) { } + constructor(private router: Router,private toastService: ToastService,public alertController: AlertController, + public restService: RestService, + public httpClient: HttpClient, + private storage: Storage,) { } ngOnInit() { } ChangePassword() { this.router.navigateByUrl('/reset-password'); } - DeactivateUser(){ - this.toastService.showToast("Account Deactivated Sucessfully"); - this.router.navigateByUrl('/logout'); + async DeactivateUser(){ + const alert = await this.alertController.create({ + header: 'Deactivation!', + message: 'Do you really want to deactivate your account?', + buttons: [ + { + text: 'Not Now', + role: 'cancel', + cssClass: 'secondary', + handler: (blah) => { + console.log('Confirm Cancel: blah'); + this.router.navigateByUrl('/settings'); + } + }, { + text: 'Yes', + handler: () => { + console.log('Confirm Okay'); + this.storage.get('token').then((token) => { + let url = 'http://193.196.52.237:8081/deactivate-account'; + const headers = new HttpHeaders().set("Authorization", "Bearer " + token); + let deactivateApi = this.httpClient.delete(url, { headers }); + deactivateApi.subscribe((resp:any) => { + console.log('my data: ', resp); + this.router.navigateByUrl('/login'); + this.toastService.showToast("User account has been deactivated!"); + + }, (error) => { + console.log(error); + + }); + }); + + + } + } + ] + }); + + await alert.present(); + + } }