@@ -3,8 +3,8 @@ import { Component, ChangeDetectionStrategy, inject, signal } from '@angular/cor
33import { CommonModule , DOCUMENT } from '@angular/common' ;
44import { FormBuilder , ReactiveFormsModule , Validators } from '@angular/forms' ;
55import { Router } from '@angular/router' ;
6- import { AuthService } from '@ shared/services/auth.service' ;
7- import { LanguageSwitcherComponent } from '@ features/language-selection/language-switcher.component' ;
6+ import { AuthService } from '../../ shared/services/auth.service' ;
7+ import { LanguageSwitcherComponent } from '../../ features/language-selection/language-switcher.component' ;
88
99@Component ( {
1010 selector : 'app-auth' ,
@@ -25,15 +25,56 @@ export class AuthComponent {
2525 isLoading = signal ( false ) ;
2626 showPassword = signal ( false ) ;
2727 isDarkMode = signal ( this . document . documentElement . classList . contains ( 'dark' ) ) ;
28+
29+ // 'signin' or 'signup' mode
30+ authMode = signal < 'signin' | 'signup' > ( 'signin' ) ;
2831
2932 loginForm = this . fb . group ( {
33+ firstName : [ '' ] ,
34+ lastName : [ '' ] ,
35+ phone : [ '' ] ,
3036 email : [ 'admin@mavluda.beauty' , [ Validators . required , Validators . email ] ] ,
3137 password : [ 'password123' , [ Validators . required , Validators . minLength ( 6 ) ] ] ,
3238 rememberMe : [ false ]
3339 } ) ;
3440
35- setRole ( role : 'admin' | 'client' ) {
36- this . authService . currentUserRole . set ( role ) ;
41+ setAuthMode ( mode : 'signin' | 'signup' ) {
42+ this . authMode . set ( mode ) ;
43+ const firstNameControl = this . loginForm . get ( 'firstName' ) ;
44+ const lastNameControl = this . loginForm . get ( 'lastName' ) ;
45+ const phoneControl = this . loginForm . get ( 'phone' ) ;
46+
47+ if ( mode === 'signup' ) {
48+ firstNameControl ?. setValidators ( [ Validators . required ] ) ;
49+ lastNameControl ?. setValidators ( [ Validators . required ] ) ;
50+ phoneControl ?. setValidators ( [ Validators . required ] ) ;
51+
52+ // Clear defaults for signup
53+ if ( this . loginForm . get ( 'email' ) ?. value === 'admin@mavluda.beauty' ) {
54+ this . loginForm . patchValue ( {
55+ firstName : '' ,
56+ lastName : '' ,
57+ phone : '' ,
58+ email : '' ,
59+ password : ''
60+ } ) ;
61+ }
62+ } else {
63+ firstNameControl ?. clearValidators ( ) ;
64+ lastNameControl ?. clearValidators ( ) ;
65+ phoneControl ?. clearValidators ( ) ;
66+
67+ // Restore default admin credentials for demo convenience if empty
68+ if ( ! this . loginForm . get ( 'email' ) ?. value ) {
69+ this . loginForm . patchValue ( {
70+ email : 'admin@mavluda.beauty' ,
71+ password : 'password123'
72+ } ) ;
73+ }
74+ }
75+ firstNameControl ?. updateValueAndValidity ( ) ;
76+ lastNameControl ?. updateValueAndValidity ( ) ;
77+ phoneControl ?. updateValueAndValidity ( ) ;
3778 }
3879
3980 togglePassword ( ) {
@@ -54,6 +95,15 @@ export class AuthComponent {
5495 onSubmit ( ) {
5596 if ( this . loginForm . valid ) {
5697 this . isLoading . set ( true ) ;
98+
99+ // Auto-determine role based on email credential for MVP demo
100+ const email = this . loginForm . get ( 'email' ) ?. value || '' ;
101+ if ( email . includes ( 'admin' ) ) {
102+ this . authService . currentUserRole . set ( 'admin' ) ;
103+ } else {
104+ this . authService . currentUserRole . set ( 'client' ) ;
105+ }
106+
57107 // Simulate API call
58108 setTimeout ( ( ) => {
59109 this . isLoading . set ( false ) ;
0 commit comments