Skip to content

Commit 7d74217

Browse files
committed
Split into dumb and smart components
1 parent f213484 commit 7d74217

12 files changed

Lines changed: 128 additions & 77 deletions

src/app/login/login-form/login-form.component.html renamed to src/app/login/component/login-form/login-form.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="card">
33
<h4 class="card-header">Login</h4>
44
<div class="card-body">
5-
<form [formGroup]="form" (ngSubmit)="onSubmit()">
5+
<form [formGroup]="form" (ngSubmit)="onLogin()">
66
<div class="form-group">
77
<label for="username">Username</label>
88
<input type="text" formControlName="username" class="form-control"

src/app/login/login-form/login-form.component.sass renamed to src/app/login/component/login-form/login-form.component.sass

File renamed without changes.

src/app/login/login-form/login-form.component.spec.ts renamed to src/app/login/component/login-form/login-form.component.spec.ts

File renamed without changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { Component, EventEmitter, Input, Output } from '@angular/core';
2+
import { FormBuilder, Validators } from '@angular/forms';
3+
import { LoginUser } from '@app/login/model/login-user';
4+
5+
@Component({
6+
selector: 'login-form',
7+
templateUrl: './login-form.component.html',
8+
styleUrls: ['./login-form.component.sass']
9+
})
10+
export class LoginFormComponent {
11+
12+
@Input() public loading = false;
13+
14+
@Input() public error = '';
15+
16+
@Output() public login = new EventEmitter<LoginUser>();
17+
18+
public form = this.formBuilder.group({
19+
username: ['', Validators.required],
20+
password: ['', Validators.required]
21+
});
22+
23+
constructor(
24+
private formBuilder: FormBuilder
25+
) { }
26+
27+
public onLogin() {
28+
if (this.form.valid) {
29+
this.login.emit(this.form.value);
30+
}
31+
}
32+
33+
public isFormInvalid(): boolean {
34+
return this.form.invalid && (this.form.dirty || this.form.touched);
35+
}
36+
37+
public canLogin(): boolean {
38+
return this.form.valid;
39+
}
40+
41+
}

src/app/login/login-form/login-form.component.ts

Lines changed: 0 additions & 72 deletions
This file was deleted.

src/app/login/login-routing.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { NgModule } from '@angular/core';
22
import { RouterModule, Routes } from '@angular/router';
3-
import { LoginFormComponent } from './login-form/login-form.component';
3+
import { LoginViewComponent } from './view/login-view/login-view.component';
44

55

66
const routes: Routes = [
77
{
8-
path: '', component: LoginFormComponent
8+
path: '', component: LoginViewComponent
99
}
1010
];
1111

src/app/login/login.module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ import { CommonModule } from '@angular/common';
22
import { NgModule } from '@angular/core';
33
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
44
import { AuthenticationModule } from '@app/authentication/authentication.module';
5-
import { LoginFormComponent } from './login-form/login-form.component';
5+
import { LoginFormComponent } from './component/login-form/login-form.component';
66
import { LoginRoutingModule } from './login-routing.module';
77
import { LogoutButtonComponent } from './logout-button/logout-button.component';
8+
import { LoginViewComponent } from './view/login-view/login-view.component';
89

910

1011

1112
@NgModule({
1213
declarations: [
1314
LoginFormComponent,
14-
LogoutButtonComponent
15+
LogoutButtonComponent,
16+
LoginViewComponent
1517
],
1618
imports: [
1719
LoginRoutingModule,

src/app/login/model/login-user.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export class LoginUser {
2+
username: string = '';
3+
password: string = '';
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<login-form (login)="onLogin($event)" [error]="error" [loading]="loading"></login-form>

src/app/login/view/login-view/login-view.component.sass

Whitespace-only changes.

0 commit comments

Comments
 (0)