Browse Source

change alert to matdialog in demo page

pull/1358/head
rizkyrajitha 3 years ago
parent
commit
af9cf8bb9d
  1. 1
      apps/client/src/app/pages/demo/demo-page-dialog.html
  2. 31
      apps/client/src/app/pages/demo/demo-page.component.ts
  3. 3
      apps/client/src/app/pages/demo/demo-page.module.ts

1
apps/client/src/app/pages/demo/demo-page-dialog.html

@ -0,0 +1 @@
<h3 mat-dialog-title>{{text}}</h3>

31
apps/client/src/app/pages/demo/demo-page.component.ts

@ -4,6 +4,7 @@ import { DataService } from '@ghostfolio/client/services/data.service';
import { TokenStorageService } from '@ghostfolio/client/services/token-storage.service'; import { TokenStorageService } from '@ghostfolio/client/services/token-storage.service';
import { InfoItem } from '@ghostfolio/common/interfaces'; import { InfoItem } from '@ghostfolio/common/interfaces';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
@Component({ @Component({
host: { class: 'page' }, host: { class: 'page' },
@ -17,24 +18,21 @@ export class DemoPageComponent implements OnDestroy {
public constructor( public constructor(
private dataService: DataService, private dataService: DataService,
private router: Router, private tokenStorageService: TokenStorageService,
private tokenStorageService: TokenStorageService public dialog: MatDialog
) { ) {
this.info = this.dataService.fetchInfo(); this.info = this.dataService.fetchInfo();
} }
public ngOnInit() { public ngOnInit() {
const hasToken = this.tokenStorageService.getToken()?.length > 0; const hasToken = this.tokenStorageService.getToken()?.length > 0;
if (hasToken) { if (hasToken) {
alert( this.dialog.open(DialogAnimationsExampleDialog, {
$localize`As you are already logged in, you cannot access the demo account.` width: '50%'
); });
} else { } else {
this.tokenStorageService.saveToken(this.info.demoAuthToken, true); this.tokenStorageService.saveToken(this.info.demoAuthToken, true);
} }
this.router.navigate(['/']);
} }
public ngOnDestroy() { public ngOnDestroy() {
@ -42,3 +40,20 @@ export class DemoPageComponent implements OnDestroy {
this.unsubscribeSubject.complete(); this.unsubscribeSubject.complete();
} }
} }
@Component({
selector: 'demo-page-dialog',
templateUrl: './demo-page-dialog.html'
})
export class DialogAnimationsExampleDialog {
public text: String;
constructor(
public dialogRef: MatDialogRef<DialogAnimationsExampleDialog>,
private router: Router
) {
this.text = $localize`As you are already logged in, you cannot access the demo account.`;
dialogRef.afterClosed().subscribe(() => {
this.router.navigate(['/']);
});
}
}

3
apps/client/src/app/pages/demo/demo-page.module.ts

@ -3,10 +3,11 @@ import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { DemoPageRoutingModule } from './demo-page-routing.module'; import { DemoPageRoutingModule } from './demo-page-routing.module';
import { DemoPageComponent } from './demo-page.component'; import { DemoPageComponent } from './demo-page.component';
import { MatDialogModule } from '@angular/material/dialog';
@NgModule({ @NgModule({
declarations: [DemoPageComponent], declarations: [DemoPageComponent],
imports: [CommonModule, DemoPageRoutingModule], imports: [CommonModule, DemoPageRoutingModule, MatDialogModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA] schemas: [CUSTOM_ELEMENTS_SCHEMA]
}) })
export class DemoPageModule {} export class DemoPageModule {}

Loading…
Cancel
Save