Skip to content

Commit

Permalink
se arreglo el formulario para mobiles
Browse files Browse the repository at this point in the history
  • Loading branch information
matias1305 committed Dec 11, 2018
1 parent 267c0d3 commit c7e7f14
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 22 deletions.
11 changes: 11 additions & 0 deletions src/app/register/register.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@
.ms-container {
width: 100%;
}

@media screen and (max-width: 480px) {
.hidden-contenedor {
display: none;
}

.contenedor {
margin-left: 20%;
}

}
4 changes: 2 additions & 2 deletions src/app/register/register.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ <h3 class="box-title m-b-40">Categorías de interés <span>(Min. 3)</span></h3>
</select>
</div>
<div class="ms-selection">
<select class="ms-list contenedor" multiple='multiple' formControlName="categories">
<select class="ms-list contenedor hidden-contenedor" multiple='multiple' formControlName="categories">
<option [value]='sc' class="ms-elem-selection"
*ngFor="let sc of selected_categories; let i = index;"
(click)="removeCategory(i)"> {{ sc.name }} </option>
</select>
</div>
</div>
<p *ngIf="selected_categories.length < 3 && submit2" class="text-danger">
<p *ngIf="(selected_categories.length < 3 || form.value.categories.length < 3) && submit2" class="text-danger">
Debe seleccionar al menos 3 categorias
</p>

Expand Down
67 changes: 47 additions & 20 deletions src/app/register/register.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,43 +86,68 @@ export class RegisterComponent implements OnInit {

if (this.form.valid) {
let form=this.form.value;

if( form.categories.length > 1 ) {
console.log(form.categories);
}

this.afAuth.auth.createUserWithEmailAndPassword( form.email, form.password )
.then( (resp:any) => {

// FIXME: Esto hace que se seleccione un emoji aleatorio para la imagen del nuevo usuario.
let num = Math.floor((Math.random() * 47) + 1);
let path_img = "../assets/images/emojis/emoji("+num+").png";
console.log(path_img);

let user:any;


// Guarda el form para validarlo
const USER:Users = {
uid: resp.user.uid,
rut: form.rut,
name: form.name.toLowerCase(),
last_name1: form.last_name1.toLowerCase(),
last_name2: form.last_name2.toLowerCase(),
email: form.email.toLowerCase(),
categories: this.selected_categories,
// phone: form.phone,
firtSession: false,
google: false,
status: true,
role: 'normal',
created_date: this._dateService.actual_date(),
img: path_img
};
if( form.categories.length > 1 ) { // si es mayor a uno es mobile.
user = {
uid: resp.user.uid,
rut: form.rut,
name: form.name.toLowerCase(),
last_name1: form.last_name1.toLowerCase(),
last_name2: form.last_name2.toLowerCase(),
email: form.email.toLowerCase(),
categories: form.categories,
// phone: form.phone,
firtSession: false,
google: false,
status: true,
role: 'normal',
created_date: this._dateService.actual_date(),
img: path_img
};
} else {
user = {
uid: resp.user.uid,
rut: form.rut,
name: form.name.toLowerCase(),
last_name1: form.last_name1.toLowerCase(),
last_name2: form.last_name2.toLowerCase(),
email: form.email.toLowerCase(),
categories: this.selected_categories,
// phone: form.phone,
firtSession: false,
google: false,
status: true,
role: 'normal',
created_date: this._dateService.actual_date(),
img: path_img
};
}

if( !this.form.value.conditions ){
swal("Importante", "Debe aceptar los términos y condiciones", "warning");
return;
}

// Guarda al usuario en DB
this._dbService.addDataIdCustom('users', USER.uid, USER)
this._dbService.addDataIdCustom('users', user.uid, user)
.then( () => {
console.log("Se guardó el usuario");
swal('Cuenta creada con éxito', USER.email, 'success');
swal('Cuenta creada con éxito', user.email, 'success');
this.afAuth.auth.signOut();
this.router.navigate([ '/login' ]);

Expand Down Expand Up @@ -171,10 +196,12 @@ export class RegisterComponent implements OnInit {
this.submit1 = true;
if( form.controls['name'].valid && form.controls['last_name1'].valid && form.controls['last_name2'].valid && form.controls['rut'].valid)
this.register_pages = 'page_2';


break;
case 'page_3':
this.submit2 = true;
if( this.selected_categories.length >= 3 )
if( this.selected_categories.length >= 3 || this.form.value.categories.length >= 3 )
this.register_pages = 'page_3';
break;
}
Expand Down

0 comments on commit c7e7f14

Please sign in to comment.