Commit d48cd22a authored by Raul Granados's avatar Raul Granados

validate if showForm

parent 80df34a6
......@@ -11,7 +11,7 @@
</button>
<span>Intercambio TingSoluciones!</span>
</mat-toolbar>
<mat-horizontal-stepper [linear]="isLinear" #stepper>
<mat-horizontal-stepper [linear]="isLinear" #stepper *ngIf="config.showForm">
<mat-step [stepControl]="emailForm">
<ng-template matStepLabel>Ingresa tus datos!</ng-template>
<form [formGroup]="emailForm" (ngSubmit)="onSubmit()" *ngIf="assignedPapers.length === 0">
......@@ -33,5 +33,13 @@
</ul>
</mat-step>
</mat-horizontal-stepper>
<mat-card>
<mat-card-title>Participantes confirmados ({{people.length}})</mat-card-title>
<mat-card-content>
<mat-list role="list">
<mat-list-item role="listitem" *ngFor="let person of people">{{ person.name}}</mat-list-item>
</mat-list>
</mat-card-content>
</mat-card>
</mat-sidenav-content>
</mat-sidenav-container>
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { FirestoreService } from './services/firestore/firestore.service';
import { MatSnackBar } from '@angular/material';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
emailForm: FormGroup;
isLinear = true;
......@@ -16,8 +18,12 @@ export class AppComponent implements OnInit {
extraPapers = [];
assignedPapers = [];
hasChallenge = false;
config = { showForm: false };
constructor(private formBuilder: FormBuilder, private firestoreService: FirestoreService) {
constructor(
private formBuilder: FormBuilder,
private firestoreService: FirestoreService,
private snackBar: MatSnackBar ) {
}
......@@ -27,6 +33,11 @@ export class AppComponent implements OnInit {
this.firestoreService.addPaper({ name: 'Armando Hernandez', kind: 0 });
this.firestoreService.addPaper({ name: 'Eva Garcia', kind: 0 });
this.firestoreService.addPaper({ name: 'Patricia Fajardo', kind: 0 }); */
this.firestoreService.getSettings('OGG4a2Fp33oqein7nAFo').subscribe((settingsSnapshot) => {
this.config.showForm = settingsSnapshot.payload.data().showForm;
});
this.firestoreService.getPapers().subscribe((papersSnapshot) => {
this.papers = [];
papersSnapshot.forEach((paperData: any) => {
......@@ -82,17 +93,23 @@ export class AppComponent implements OnInit {
}
const people = this.people.find( people => people.phone === this.emailForm.value.phone)
if (people === undefined) {
alert('Alejate grinch!');
this.snackBar.open('Datos incorrectos', 'ok', {
duration: 2000,
});
return;
}
if (people.password !== this.emailForm.value.password) {
alert('Contraseña incorrecta!!');
this.snackBar.open('Contraseña incorrecta', 'ok', {
duration: 2000,
});
return;
}
if (people.hasPaper) {
alert('Pinche tramposooooooo!!!!');
this.snackBar.open('No sea trampos@ señor@', 'ok', {
duration: 2000,
});
return;
}
people.hasPaper = true;
......
......@@ -2,7 +2,7 @@ import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { MatToolbarModule, MatButtonModule, MatStepperModule, MatGridListModule, MatSidenavModule, MatInputModule, MatFormFieldModule, MatIconModule, MatListModule, MatCardModule } from '@angular/material';
import { MatToolbarModule, MatDividerModule, MatButtonModule, MatStepperModule, MatSnackBarModule, MatGridListModule, MatSidenavModule, MatInputModule, MatFormFieldModule, MatIconModule, MatListModule, MatCardModule } from '@angular/material';
import { AngularFireModule } from 'angularfire2';
import { AngularFirestore } from 'angularfire2/firestore';
......@@ -32,7 +32,9 @@ import { LayoutModule } from '@angular/cdk/layout';
MatFormFieldModule,
MatInputModule,
MatGridListModule,
MatStepperModule
MatStepperModule,
MatSnackBarModule,
MatDividerModule
],
providers: [AngularFirestore],
bootstrap: [AppComponent]
......
......@@ -10,6 +10,10 @@ export class FirestoreService {
constructor(private firestore: AngularFirestore) { }
public getSettings(documentId: string) {
return this.firestore.collection('config').doc(documentId).snapshotChanges();
}
public getPerson(documentId: string) {
return this.firestore.collection('people').doc(documentId).snapshotChanges();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment