diff --git a/src/app/features/auth/components/register/register.html b/src/app/features/auth/components/register/register.html index 60c0aee..83a02af 100644 --- a/src/app/features/auth/components/register/register.html +++ b/src/app/features/auth/components/register/register.html @@ -1,45 +1,51 @@ -
+

Register

-

Sign up with your
email address to get started

+

Sign up with your
email address to get started

+
+ @for (error of errors(); track error) { +

{{ error }}

+ } +
-
+
Name - +
Mobile Number - +
Email - +

your-email-address@email.com

Password - +
Confirm Password - +
City - +
Already have an account ? LoginAlready have an account ? Login
diff --git a/src/app/features/auth/components/register/register.ts b/src/app/features/auth/components/register/register.ts index d6e4f60..4b14aa6 100644 --- a/src/app/features/auth/components/register/register.ts +++ b/src/app/features/auth/components/register/register.ts @@ -1,7 +1,7 @@ -import { Component, inject } from "@angular/core"; -import { FormControl, FormGroup, ReactiveFormsModule } from "@angular/forms"; -import { AuthService } from "../../services/auth-service"; -import { RegisterUserRequest } from "../../../../core/models/user.model"; +import {Component, inject, signal} from "@angular/core"; +import {FormControl, FormGroup, ReactiveFormsModule} from "@angular/forms"; +import {AuthService} from "../../services/auth-service"; +import {RegisterUserRequest} from "../../../../core/models/user.model"; @Component({ selector: "app-register", @@ -12,19 +12,28 @@ import { RegisterUserRequest } from "../../../../core/models/user.model"; export class Register { authService = inject(AuthService); + errors = signal([]); registerForm = new FormGroup({ - name :new FormControl(''), - email :new FormControl(''), - mobile_number : new FormControl(''), - password : new FormControl(''), - password_confirmation : new FormControl(''), - city : new FormControl(''), + name: new FormControl(''), + email: new FormControl(''), + mobile_number: new FormControl(''), + password: new FormControl(''), + password_confirmation: new FormControl(''), + city: new FormControl(''), }); registerUser() { this.authService.register(this.registerForm.value as RegisterUserRequest) - .subscribe(); + .subscribe({ + next: () => console.log('success'), + error: (error) => { + const errors: Record = error?.error?.errors || {}; + const errorMessages :string[] = Object.values(errors).flat(); + this.errors.set(errorMessages) ; + } + }); } + }