|
|
@ -1,4 +1,5 @@ |
|
|
|
import { Component, OnDestroy, OnInit } from '@angular/core'; |
|
|
|
import { ApiService } from '../../../../api/api.service'; |
|
|
|
import { PanelService } from '../../services/panel.service'; |
|
|
|
|
|
|
|
@Component({ |
|
|
@ -18,7 +19,9 @@ export class ProfileComponent implements OnInit, OnDestroy { |
|
|
|
public Clicks: number = 10 |
|
|
|
private _ClickTimeout: any; |
|
|
|
|
|
|
|
constructor(private _PanelService: PanelService) { } |
|
|
|
private _ToastTimeout: any |
|
|
|
|
|
|
|
constructor(private _PanelService: PanelService, private _ApiSerive: ApiService) { } |
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
this._PanelService.Background = 'white' |
|
|
@ -28,12 +31,44 @@ export class ProfileComponent implements OnInit, OnDestroy { |
|
|
|
this._PanelService.Background = 'transparent' |
|
|
|
} |
|
|
|
|
|
|
|
public async Edit(): Promise<void> { |
|
|
|
public Toast(message: string): void { |
|
|
|
clearTimeout(this._ToastTimeout) |
|
|
|
if (document.getElementById('toast')) document.body.removeChild(document.getElementById('toast')!) |
|
|
|
let div = document.createElement('div') |
|
|
|
div.id = 'toast' |
|
|
|
div.innerText = message |
|
|
|
document.body.appendChild(div) |
|
|
|
this._ToastTimeout = setTimeout(() => |
|
|
|
document.body.removeChild(document.getElementById('toast')!) |
|
|
|
, 3000); |
|
|
|
} |
|
|
|
|
|
|
|
public async Edit(): Promise<void> { |
|
|
|
try { |
|
|
|
if (this.Fullname.length == 0) return this.Toast('Full name cannot be empty.') |
|
|
|
this.Loading = true |
|
|
|
this.Loading = false |
|
|
|
} catch (error: any) { |
|
|
|
this.Loading = false |
|
|
|
if (error.message) return this.Toast(error.message) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public async ChangePassword(): Promise<void> { |
|
|
|
|
|
|
|
try { |
|
|
|
if (this.Password.length == 0) return this.Toast('Password cannot be empty.') |
|
|
|
if (this.Password.length < 8) return this.Toast('Password cannot be less than 8 characters.') |
|
|
|
if (this.Password != this.ConfirmPassword) return this.Toast('Password must be same.') |
|
|
|
this.Loading = true |
|
|
|
let res = await this._ApiSerive.ResetPassword({ password: this.Password }) |
|
|
|
this.Loading = false |
|
|
|
// error happent
|
|
|
|
if ([400, 401].includes((res as any).code)) return this.Toast((res as any).message) |
|
|
|
this.Toast('Password changed successfully!') |
|
|
|
} catch (error: any) { |
|
|
|
this.Loading = false |
|
|
|
if (error.message) return this.Toast(error.message) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public async DeleteAccount(): Promise<void> { |
|
|
|