forked from tomalaforge/angular-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(challenge20): create challenge testing modal
- Loading branch information
thomas
committed
Apr 25, 2023
1 parent
3923cc4
commit f378ea0
Showing
7 changed files
with
111 additions
and
813 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,65 @@ | ||
import { NxWelcomeComponent } from './nx-welcome.component'; | ||
import { Component } from '@angular/core'; | ||
|
||
import { AsyncPipe } from '@angular/common'; | ||
import { Component, inject } from '@angular/core'; | ||
import { FormControl, ReactiveFormsModule } from '@angular/forms'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { MatDialog, MatDialogModule } from '@angular/material/dialog'; | ||
import { MatFormFieldModule } from '@angular/material/form-field'; | ||
import { MatInputModule } from '@angular/material/input'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { ErrorDialog } from './error.dialog'; | ||
import { ProfilConfirmationDialog } from './profil-confirmation.dialog'; | ||
@Component({ | ||
standalone: true, | ||
imports: [NxWelcomeComponent], | ||
imports: [ | ||
ReactiveFormsModule, | ||
MatDialogModule, | ||
MatFormFieldModule, | ||
MatInputModule, | ||
MatButtonModule, | ||
AsyncPipe, | ||
], | ||
selector: 'app-root', | ||
template: ` <app-nx-welcome></app-nx-welcome> `, | ||
styles: [], | ||
host: { | ||
class: 'p-4 block flex gap-4 items-center', | ||
}, | ||
template: ` | ||
<mat-form-field appearance="fill"> | ||
<mat-label>Name</mat-label> | ||
<input | ||
type="text" | ||
matInput | ||
[formControl]="name" | ||
placeholder="enter your name" /> | ||
</mat-form-field> | ||
<button (click)="confirm()" mat-flat-button color="primary">Confirm</button> | ||
<div>{{ result$ | async }}</div> | ||
`, | ||
}) | ||
export class AppComponent { | ||
title = 'testing-modal'; | ||
private modal = inject(MatDialog); | ||
private result = new BehaviorSubject<string>(''); | ||
result$ = this.result.asObservable(); | ||
|
||
name = new FormControl('', { nonNullable: true }); | ||
|
||
confirm() { | ||
if (!this.name.value) { | ||
this.modal.open(ErrorDialog); | ||
return; | ||
} | ||
|
||
this.modal | ||
.open(ProfilConfirmationDialog, { | ||
data: { | ||
name: this.name.value, | ||
}, | ||
}) | ||
.afterClosed() | ||
.subscribe((result) => | ||
this.result.next( | ||
result ? 'Name has been submitted' : 'Name is invalid !!' | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint-disable @angular-eslint/component-class-suffix */ | ||
import { Component } from '@angular/core'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { MatDialogModule } from '@angular/material/dialog'; | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [MatButtonModule, MatDialogModule], | ||
template: ` | ||
<h1 mat-dialog-title>Error</h1> | ||
<div mat-dialog-content> | ||
You must enter a <span class="font-bold">name</span> first!! | ||
</div> | ||
<div mat-dialog-actions> | ||
<button mat-button mat-dialog-close>OK</button> | ||
</div> | ||
`, | ||
}) | ||
export class ErrorDialog {} |
Oops, something went wrong.