creation-team incomplet

This commit is contained in:
Sana EL HIRI 2022-01-20 17:58:46 +01:00
parent 559be4fbd9
commit a344348b7a
11 changed files with 193 additions and 10 deletions

View file

@ -0,0 +1,30 @@
<app-header></app-header>
<app-side-bar></app-side-bar>
<div class="signup-form text-center">
<main class="form-signup">
<form (ngSubmit)="onSubmit()" [formGroup]="teamForm">
<h1>Créer votre team!</h1>
<div class="form-floating">
<input type="text"
class="form-control"
id="floatingInputName"
placeholder=""
name="name"
formControlName="nameFc"
[ngClass]="{'is-valid' : teamForm.controls['nameFc'].touched && teamForm.controls['nameFc'].valid,
'is-invalid': teamForm.controls['nameFc'].touched && !teamForm.controls['nameFc'].valid}">
<label for="floatingInputName">Nom</label>
</div>
<button class="w-100 btn btn-lg btn-success"
type="submit"
[disabled]="teamForm.invalid">Je crée ma team</button>
<p>
Value : {{ teamForm.value | json }}
</p>
<p>
Form valid : {{ teamForm.valid }}
</p>
</form>
</main>
</div>

View file

@ -0,0 +1,32 @@
.login-form {
height: 100vh;
padding-top: 40px;
background-color: #f5f5f5;
}
.form-signup {
width: 100%;
max-width: 330px;
padding: 15px;
margin: auto;
}
.form-signup .checkbox {
font-weight: 400;
}
.form-signup .form-floating:focus-within {
z-index: 2;
}
.form-signup input[type="email"] {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.form-signup input[type="password"] {
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}

View file

@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PageCreationTeamComponent } from './page-creation-team.component';
describe('PageCreationTeamComponent', () => {
let component: PageCreationTeamComponent;
let fixture: ComponentFixture<PageCreationTeamComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ PageCreationTeamComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(PageCreationTeamComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -0,0 +1,72 @@
import { Component, OnInit } from '@angular/core';
import {
FormBuilder,
FormControl,
FormGroup,
Validators,
} from '@angular/forms';
import { Router } from '@angular/router';
import { Team } from 'src/app/models/team';
import { AuthService } from '../../services/auth.service';
@Component({
selector: 'app-page-creation-team',
templateUrl: './page-creation-team.component.html',
styleUrls: ['./page-creation-team.component.scss'],
})
export class PageCreationTeamComponent implements OnInit {
public teamForm: FormGroup;
constructor(
private authService: AuthService,
private router: Router,
private fb: FormBuilder
) {
this.teamForm = new FormGroup({});
}
ngOnInit(): void {
// *********************************penser a changer group car déprécié********************************
this.teamForm = new FormGroup({
nameFc : new FormControl('', [Validators.required])
});
}
public onSubmit(): void {
console.log('value : ', this.teamForm.value);
console.log('form : ', this.teamForm);
const nameValue = this.teamForm.value['nameFc'];
const team: Team = {
nom : nameValue,
};
if (team.nom !== '' ) {
this.authService.creationTeam(team).subscribe((resp) => {
this.router.navigate(['compte']);
});
} else {
// affichage erreur
}
}
ConfirmedValidator(controlName: string, matchingControlName: string) {
return (formGroup: FormGroup) => {
const control = formGroup.controls[controlName];
const matchingControl = formGroup.controls[matchingControlName];
if (
matchingControl.errors &&
!matchingControl.errors['confirmedValidator']
) {
return;
}
if (control.value !== matchingControl.value) {
matchingControl.setErrors({ confirmedValidator: true });
} else {
matchingControl.setErrors(null);
}
};
}
}

View file

@ -25,7 +25,7 @@ export class PageSignupComponent implements OnInit {
}
ngOnInit(): void {
// *********************************pensser a changer group car déprécié********************************
// *********************************penser a changer group car déprécié********************************
this.signupForm = this.fb.group(
{
firstNameFc: new FormControl('', [Validators.required]),
@ -64,21 +64,22 @@ export class PageSignupComponent implements OnInit {
const teamNameValue = this.signupForm.value['teamNameFc'];
const profilValue = this.signupForm.value['profilFc'];
const passwordConfirmValue = this.signupForm.value['passwordConfirmFc'];
const teamValue = '';
const membre: Membre = {
firstName: firstNameValue,
lastName: lastNameValue,
nom: firstNameValue,
prenom: lastNameValue,
email: emailValue,
password: passwordValue,
dateNaissance: dateNaissanceValue,
teamName: teamNameValue,
profil: profilValue,
passwordConfirm: passwordConfirmValue,
roleList: ["ROLE_PARENT"]
};
if (membre.email !== '' && membre.password !== '') {
this.authService.signup(membre).subscribe((resp) => {
this.router.navigate(['account/signin']);
this.router.navigate(['accueil']);
});
} else {
// affichage erreur