76 lines
2.3 KiB
TypeScript
76 lines
2.3 KiB
TypeScript
// src/app/pages/register.component.ts
|
|
import { Component } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { FormBuilder, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
|
|
import { RouterLink } from '@angular/router';
|
|
|
|
@Component({
|
|
selector: 'app-register',
|
|
standalone: true,
|
|
imports: [CommonModule, ReactiveFormsModule, RouterLink],
|
|
templateUrl: './register.html',
|
|
styleUrls: ['./register.scss'] // ou .scss
|
|
})
|
|
export class Register {
|
|
|
|
registerForm: FormGroup;
|
|
isSubmitting = false;
|
|
|
|
constructor(private fb: FormBuilder) {
|
|
this.registerForm = this.fb.group({
|
|
fullName: ['', [Validators.required, Validators.minLength(3)]],
|
|
email: ['', [Validators.required, Validators.email]],
|
|
phone: ['', [Validators.required]],
|
|
password: ['', [Validators.required, Validators.minLength(6)]],
|
|
confirmPassword: ['', [Validators.required]]
|
|
}, {
|
|
validators: [this.passwordsMatchValidator]
|
|
});
|
|
}
|
|
|
|
// Validador para confirmar senha
|
|
private passwordsMatchValidator(group: FormGroup) {
|
|
const pass = group.get('password')?.value;
|
|
const confirm = group.get('confirmPassword')?.value;
|
|
return pass === confirm ? null : { passwordsMismatch: true };
|
|
}
|
|
|
|
onSubmit(): void {
|
|
if (this.registerForm.invalid) {
|
|
this.registerForm.markAllAsTouched();
|
|
return;
|
|
}
|
|
|
|
this.isSubmitting = true;
|
|
|
|
// Por enquanto: apenas exibe os dados e "simula" o envio
|
|
console.log('Dados de cadastro:', this.registerForm.value);
|
|
|
|
// TODO FUTURO: quando a API .NET estiver pronta,
|
|
// você injeta um AuthService e envia para o backend:
|
|
/*
|
|
this.authService.register(this.registerForm.value).subscribe({
|
|
next: () => { ... },
|
|
error: () => { ... },
|
|
complete: () => this.isSubmitting = false
|
|
});
|
|
*/
|
|
|
|
// Simulação de atraso só para UX (remova se quiser)
|
|
setTimeout(() => {
|
|
this.isSubmitting = false;
|
|
this.registerForm.reset();
|
|
alert('Cadastro realizado (simulado). Quando a API estiver pronta, isso irá de fato registrar o usuário.');
|
|
}, 800);
|
|
}
|
|
|
|
hasError(field: string, error?: string): boolean {
|
|
const control = this.registerForm.get(field);
|
|
if (!control) return false;
|
|
if (error) {
|
|
return control.touched && control.hasError(error);
|
|
}
|
|
return control.touched && control.invalid;
|
|
}
|
|
}
|