diff --git a/src/app/components/contacts/contacts.component.ts b/src/app/components/contacts/contacts.component.ts
index 7974463..16d0d1a 100644
--- a/src/app/components/contacts/contacts.component.ts
+++ b/src/app/components/contacts/contacts.component.ts
@@ -1,14 +1,12 @@
import { Component, HostListener } from '@angular/core';
import { User } from '../../interfaces/user.interface';
import { CommonModule } from '@angular/common';
-import { ActivatedRoute, RouterLink } from '@angular/router';
import { ContactDetailComponent } from './contact-detail/contact-detail.component';
-import { SharedService } from '../../services/shared.service';
import { FirebaseService } from '../../services/firebase.service';
import { TranslateModule } from '@ngx-translate/core';
-import { ApiService } from '../../services/api.service';
import { UserService } from '../../services/user.service';
import { finalize } from 'rxjs';
+import { OverlayService } from '../../services/overlay.service';
@Component({
selector: 'app-contacts',
@@ -27,7 +25,7 @@ export class ContactsComponent {
constructor(
public firebaseService: FirebaseService,
private userService: UserService,
- public sharedService: SharedService
+ private overlayService: OverlayService
) {}
/**
@@ -95,15 +93,8 @@ export class ContactsComponent {
return uniqueFirstLetters;
}
- /**
- * Opens the new contact dialog.
- * This function sets the isAnyDialogOpen and isNewContactDialogOpen
- * properties of the shared service to true, which will open the new contact
- * dialog.
- */
- openNewContactDialog() {
- this.sharedService.isAnyDialogOpen = true;
- this.sharedService.isNewContactDialogOpen = true;
+ addNewContact() {
+ this.overlayService.setOverlayData('contactOverlay', 'new');
}
@HostListener('window:resize', ['$event'])
diff --git a/src/app/components/login/forgot-pw/forgot-pw.component.html b/src/app/components/login/forgot-pw/forgot-pw.component.html
index 0521ebc..50460ce 100644
--- a/src/app/components/login/forgot-pw/forgot-pw.component.html
+++ b/src/app/components/login/forgot-pw/forgot-pw.component.html
@@ -57,7 +57,7 @@
[disabled]="
mail.invalid ||
!pwResetData.mail ||
- sharedService.isBtnDisabled ||
+ isButtonDisabled() ||
!checkIfUserEmailIsValid(pwResetData.mail)
"
>
diff --git a/src/app/components/login/forgot-pw/forgot-pw.component.ts b/src/app/components/login/forgot-pw/forgot-pw.component.ts
index b20a6c2..d23cc90 100644
--- a/src/app/components/login/forgot-pw/forgot-pw.component.ts
+++ b/src/app/components/login/forgot-pw/forgot-pw.component.ts
@@ -6,8 +6,8 @@ import { FooterComponent } from '../footer/footer.component';
import { HeaderComponent } from '../header/header.component';
import { TranslateModule } from '@ngx-translate/core';
import { LoginService } from '../../../services/login.service';
-import { SharedService } from '../../../services/shared.service';
import { BtnBackComponent } from '../../../shared/components/buttons/btn-back/btn-back.component';
+import { ButtonStateService } from '../../../services/button-state.service';
@Component({
selector: 'app-forgot-pw',
@@ -31,16 +31,20 @@ export class ForgotPwComponent {
constructor(
public loginService: LoginService,
- public sharedService: SharedService
+ private buttonStateService: ButtonStateService
) {}
onSubmit(ngForm: NgForm) {
- this.sharedService.isBtnDisabled = true;
+ this.buttonStateService.enableButton();
if (ngForm.submitted && ngForm.form.valid) {
this.loginService.passwordReset(this.pwResetData.mail.toLowerCase());
}
}
+ isButtonDisabled() {
+ return this.buttonStateService.isButtonDisabled;
+ }
+
checkIfUserEmailIsValid(emailValue: string) {
const emailRegex = /^[\w.%+-]+@[\w.-]+\.[a-zA-Z]{2,}$/;
if (emailRegex.test(emailValue)) {
diff --git a/src/app/components/login/forgot-pw/pw-reset/pw-reset.component.html b/src/app/components/login/forgot-pw/pw-reset/pw-reset.component.html
index 6c979b2..23b5944 100644
--- a/src/app/components/login/forgot-pw/pw-reset/pw-reset.component.html
+++ b/src/app/components/login/forgot-pw/pw-reset/pw-reset.component.html
@@ -92,7 +92,7 @@
!pwResetData.password ||
passwordConfirm.invalid ||
!pwResetData.passwordConfirm ||
- sharedService.isBtnDisabled ||
+ isButtonDisabled() ||
pwResetData.password.length < 6 ||
pwResetData.password !== pwResetData.passwordConfirm
"
diff --git a/src/app/components/login/forgot-pw/pw-reset/pw-reset.component.ts b/src/app/components/login/forgot-pw/pw-reset/pw-reset.component.ts
index 18771e7..2225a61 100644
--- a/src/app/components/login/forgot-pw/pw-reset/pw-reset.component.ts
+++ b/src/app/components/login/forgot-pw/pw-reset/pw-reset.component.ts
@@ -5,11 +5,10 @@ import { FormBtnComponent } from '../../../../shared/components/buttons/form-btn
import { FooterComponent } from '../../footer/footer.component';
import { HeaderComponent } from '../../header/header.component';
import { TranslateModule } from '@ngx-translate/core';
-import { FirebaseService } from '../../../../services/firebase.service';
import { LoginService } from '../../../../services/login.service';
-import { ActivatedRoute, Router } from '@angular/router';
-import { SharedService } from '../../../../services/shared.service';
+import { ActivatedRoute } from '@angular/router';
import { Subscription } from 'rxjs';
+import { ButtonStateService } from '../../../../services/button-state.service';
@Component({
selector: 'app-pw-reset',
@@ -35,11 +34,9 @@ export class PwResetComponent {
};
constructor(
- private firebaseService: FirebaseService,
public loginService: LoginService,
- public sharedService: SharedService,
- private route: ActivatedRoute,
- private router: Router
+ private buttonStateService: ButtonStateService,
+ private route: ActivatedRoute
) {}
ngOnInit(): void {
@@ -50,8 +47,12 @@ export class PwResetComponent {
);
}
+ isButtonDisabled() {
+ return this.buttonStateService.isButtonDisabled;
+ }
+
onSubmit(ngForm: NgForm) {
- this.sharedService.isBtnDisabled = true;
+ this.buttonStateService.enableButton();
if (ngForm.submitted && ngForm.form.valid) {
this.loginService.newPassword(this.pwResetData.password, this.oobCode);
}
diff --git a/src/app/components/login/loading-dialog/loading-dialog.component.html b/src/app/components/login/loading-dialog/loading-dialog.component.html
index 4b6fb65..8a65c3d 100644
--- a/src/app/components/login/loading-dialog/loading-dialog.component.html
+++ b/src/app/components/login/loading-dialog/loading-dialog.component.html
@@ -1,4 +1,4 @@
-@if (sharedService.isBtnDisabled) {
+@if (isButtonDisabled()) {
diff --git a/src/app/components/login/loading-dialog/loading-dialog.component.ts b/src/app/components/login/loading-dialog/loading-dialog.component.ts
index bc45acb..d149931 100644
--- a/src/app/components/login/loading-dialog/loading-dialog.component.ts
+++ b/src/app/components/login/loading-dialog/loading-dialog.component.ts
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
-import { SharedService } from '../../../services/shared.service';
import { TranslateModule } from '@ngx-translate/core';
+import { ButtonStateService } from '../../../services/button-state.service';
@Component({
selector: 'app-loading-dialog',
@@ -10,5 +10,9 @@ import { TranslateModule } from '@ngx-translate/core';
styleUrl: './loading-dialog.component.scss',
})
export class LoadingDialogComponent {
- constructor(public sharedService: SharedService) {}
+ constructor(private buttonStateService: ButtonStateService) {}
+
+ isButtonDisabled() {
+ return this.buttonStateService.isButtonDisabled;
+ }
}
diff --git a/src/app/components/login/login.component.html b/src/app/components/login/login.component.html
index 7327398..41057b7 100644
--- a/src/app/components/login/login.component.html
+++ b/src/app/components/login/login.component.html
@@ -33,14 +33,14 @@
![]()
}
- @if (!mail.valid && mail.touched && !sharedService.isBtnDisabled) {
+ @if (!mail.valid && mail.touched && !isButtonDisabled()) {
{{ "login.errorMail0" | translate }}
} @if (loginService.errorCode == 'auth/invalid-email' &&
- !sharedService.isBtnDisabled) {
+ !isButtonDisabled()) {
{{ "login.errorMail1" | translate }}
} @if (mail.valid && mail.touched &&
!checkIfUserEmailIsValid(loginData.email.toLowerCase()) &&
- !sharedService.isBtnDisabled) {
+ !isButtonDisabled()) {
{{ "login.errorMail2" | translate }}
}
@@ -73,11 +73,10 @@
/>
}
- @if (!password.valid && password.touched &&
- !sharedService.isBtnDisabled) {
+ @if (!password.valid && password.touched && !isButtonDisabled()) {
{{ "login.errorPassword0" | translate }}
} @if (loginService.errorCode == 'auth/invalid-credential' &&
- !sharedService.isBtnDisabled) {
+ !isButtonDisabled()) {
{{ "login.errorPassword1" | translate }}
}
@@ -120,7 +119,7 @@
!loginData.email ||
password.invalid ||
!loginData.password ||
- sharedService.isBtnDisabled ||
+ isButtonDisabled() ||
!checkIfUserEmailIsValid(loginData.email)
"
>
@@ -128,7 +127,7 @@
[class]="'btn-guest-login'"
[type]="'button'"
[value]="'login.guest' | translate"
- [disabled]="sharedService.isBtnDisabled"
+ [disabled]="isButtonDisabled()"
(click)="guestLogin()"
>
diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts
index 5f60dc7..f4cad55 100644
--- a/src/app/components/login/login.component.ts
+++ b/src/app/components/login/login.component.ts
@@ -2,10 +2,8 @@ import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { FormsModule, NgForm } from '@angular/forms';
import { FormBtnComponent } from '../../shared/components/buttons/form-btn/form-btn.component';
-import { FirebaseService } from '../../services/firebase.service';
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
import { LoginService } from '../../services/login.service';
-import { SharedService } from '../../services/shared.service';
import { FooterComponent } from './footer/footer.component';
import { HeaderComponent } from './header/header.component';
import { TranslateModule } from '@ngx-translate/core';
@@ -13,6 +11,7 @@ import { LoadingDialogComponent } from './loading-dialog/loading-dialog.componen
import { OverlayService } from '../../services/overlay.service';
import { AuthService } from '../../services/auth.service';
import { TokenService } from '../../services/token.service';
+import { ButtonStateService } from '../../services/button-state.service';
@Component({
selector: 'app-login',
@@ -43,8 +42,8 @@ export class LoginComponent {
private authService: AuthService,
public loginService: LoginService,
private tokenService: TokenService,
- public sharedService: SharedService,
private overlayService: OverlayService,
+ private buttonStateService: ButtonStateService,
private route: ActivatedRoute,
private router: Router
) {}
@@ -65,26 +64,30 @@ export class LoginComponent {
});
}
+ isButtonDisabled() {
+ return this.buttonStateService.isButtonDisabled;
+ }
+
deleteTokens() {
this.tokenService.deleteAuthToken();
this.tokenService.deleteUserId();
}
async onSubmit(ngForm: NgForm) {
- this.sharedService.isBtnDisabled = true;
+ this.buttonStateService.enableButton();
if (ngForm.submitted && ngForm.form.valid) {
try {
await this.authService.login(this.loginData, this.checkboxRememberMe);
this.router.navigate(['/summary']);
- this.sharedService.isBtnDisabled = false;
+ this.buttonStateService.disableButton();
} catch (error) {
- this.sharedService.isBtnDisabled = false;
+ this.buttonStateService.disableButton();
}
}
}
guestLogin() {
- this.sharedService.isBtnDisabled = true;
+ this.buttonStateService.enableButton();
this.loginData.email = 'guest@guestaccount.com';
this.loginData.password = 'guest@guestaccount.com';
this.isPasswordIconVisible = !this.isPasswordIconVisible;
diff --git a/src/app/components/login/register/register.component.html b/src/app/components/login/register/register.component.html
index 2bdd1c4..413dc68 100644
--- a/src/app/components/login/register/register.component.html
+++ b/src/app/components/login/register/register.component.html
@@ -39,11 +39,10 @@
![]()
}
- @if (name.hasError('pattern') && name.touched &&
- !sharedService.isBtnDisabled) {
+ @if (name.hasError('pattern') && name.touched && !isButtonDisabled())
+ {
{{ "register.errorPattern" | translate }}
- } @else { @if (!name.valid && name.touched &&
- !sharedService.isBtnDisabled) {
+ } @else { @if (!name.valid && name.touched && !isButtonDisabled()) {
{{ "register.errorName" | translate }}
}}
@@ -70,15 +69,15 @@
@if(!mail.valid && mail.touched &&
!checkIfUserEmailIsValid(registerData.mail.toLowerCase()) &&
- !sharedService.isBtnDisabled) {
+ !isButtonDisabled()) {
{{ "register.errorMail0" | translate }}
} @else { @if (mail.touched &&
!checkIfUserEmailIsValid(registerData.mail.toLowerCase()) &&
- !sharedService.isBtnDisabled) {
+ !isButtonDisabled()) {
{{ "register.errorMail1" | translate }}
} @else { @if
(existEmailOnServer(registerData.mail.toLowerCase()).length > 0 &&
- !sharedService.isBtnDisabled) {
+ !isButtonDisabled()) {
{{ "register.errorMail2" | translate }}
} } }
@@ -109,11 +108,10 @@
/>
}
- @if (!password.valid && password.touched &&
- !sharedService.isBtnDisabled) {
+ @if (!password.valid && password.touched && !isButtonDisabled()) {
{{ "register.errorPassword0" | translate }}
} @else { @if (registerData.password.length < 6 && password.touched &&
- !sharedService.isBtnDisabled) {
+ !isButtonDisabled()) {
{{ "register.errorPassword1" | translate }}
} }
@@ -145,11 +143,11 @@
}
@if (!passwordConfirm.valid && passwordConfirm.touched &&
- !sharedService.isBtnDisabled) {
+ !isButtonDisabled()) {
{{ "register.errorPassword0" | translate }}
} @if (registerData.password !== registerData.passwordConfirm &&
registerData.password !== "" && registerData.passwordConfirm !== "" &&
- !sharedService.isBtnDisabled) {
+ !isButtonDisabled()) {
{{ "register.errorPassword2" | translate }}
}
@@ -188,7 +186,7 @@
password.invalid ||
!registerData.password ||
!checkbox.valid ||
- sharedService.isBtnDisabled ||
+ isButtonDisabled() ||
registerData.password.length < 6 ||
registerData.password !== registerData.passwordConfirm ||
!checkIfUserEmailIsValid(registerData.mail)
diff --git a/src/app/components/login/register/register.component.ts b/src/app/components/login/register/register.component.ts
index 9f2f84a..da081b4 100644
--- a/src/app/components/login/register/register.component.ts
+++ b/src/app/components/login/register/register.component.ts
@@ -6,11 +6,11 @@ import { CommonModule } from '@angular/common';
import { FormBtnComponent } from '../../../shared/components/buttons/form-btn/form-btn.component';
import { FirebaseService } from '../../../services/firebase.service';
import { LoginService } from '../../../services/login.service';
-import { SharedService } from '../../../services/shared.service';
import { BtnBackComponent } from '../../../shared/components/buttons/btn-back/btn-back.component';
import { RouterModule } from '@angular/router';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { LoadingDialogComponent } from '../loading-dialog/loading-dialog.component';
+import { ButtonStateService } from '../../../services/button-state.service';
@Component({
selector: 'app-register',
@@ -43,18 +43,22 @@ export class RegisterComponent {
constructor(
private firebaseService: FirebaseService,
public loginService: LoginService,
- public sharedService: SharedService,
- public translateService: TranslateService
+ public translateService: TranslateService,
+ private buttonStateService: ButtonStateService
) {}
onSubmit(ngForm: NgForm) {
- this.sharedService.isBtnDisabled = true;
+ this.buttonStateService.enableButton();
if (ngForm.submitted && ngForm.form.valid) {
this.splitName();
this.loginService.register(this.registerData);
}
}
+ isButtonDisabled() {
+ return this.buttonStateService.isButtonDisabled;
+ }
+
splitName() {
const names = this.registerData.name.split(' ');
this.registerData.firstName = names[0];
diff --git a/src/app/components/main-layout/main-layout.component.html b/src/app/components/main-layout/main-layout.component.html
index 2a0e3e4..9ba4853 100644
--- a/src/app/components/main-layout/main-layout.component.html
+++ b/src/app/components/main-layout/main-layout.component.html
@@ -1,8 +1,4 @@
-
+
-@if (sharedService.isNewContactDialogOpen) {
-
-} @if (sharedService.isEditContactDialogOpen) {
-
-} @if (sharedService.isDeleteContactDialogOpen) {
-
-}
+
diff --git a/src/app/components/main-layout/main-layout.component.ts b/src/app/components/main-layout/main-layout.component.ts
index 0deaaa0..593b3f9 100644
--- a/src/app/components/main-layout/main-layout.component.ts
+++ b/src/app/components/main-layout/main-layout.component.ts
@@ -1,15 +1,14 @@
import { Component } from '@angular/core';
-import { NavigationEnd, Router, RouterOutlet } from '@angular/router';
+import { RouterOutlet } from '@angular/router';
import { CommonModule } from '@angular/common';
-import { filter } from 'rxjs';
-import { FirebaseService } from '../../services/firebase.service';
+
import { LanguageService } from '../../services/language.service';
-import { SharedService } from '../../services/shared.service';
import { SidebarMobileComponent } from '../../shared/components/sidebar/sidebar-mobile/sidebar-mobile.component';
import { SidebarComponent } from '../../shared/components/sidebar/sidebar.component';
-import { ContactDeleteComponent } from '../contacts/contact-delete/contact-delete.component';
-import { ContactEditNewComponent } from '../contacts/contact-edit-new/contact-edit-new.component';
import { HeaderComponent } from '../../shared/components/header/header.component';
+import { UserService } from '../../services/user.service';
+import { User } from '../../interfaces/user.interface';
+import { OverlayComponent } from '../../shared/components/overlay/overlay.component';
@Component({
selector: 'app-main-layout',
@@ -19,83 +18,27 @@ import { HeaderComponent } from '../../shared/components/header/header.component
HeaderComponent,
SidebarComponent,
SidebarMobileComponent,
- ContactEditNewComponent,
- ContactDeleteComponent,
CommonModule,
+ OverlayComponent,
],
templateUrl: './main-layout.component.html',
styleUrl: './main-layout.component.scss',
})
export class MainLayoutComponent {
- isLoggedIn: string = '';
+ currentUser: User | null = null;
constructor(
public langService: LanguageService,
- public sharedService: SharedService,
- private firebaseService: FirebaseService,
- private router: Router
- ) {
- this.checkAndClearLocalStorage();
- this.isLoggedIn = this.firebaseService.getCurrentUserId();
+ private userService: UserService
+ ) {}
+
+ ngOnInit(): void {
+ this.loadCurrentUser();
}
- /**
- * Lifecycle hook that is called after the component has been initialized.
- *
- * Checks if the user is logged in by verifying the `isLoggedIn` property.
- */
- ngOnInit() {
- if (this.isLoggedIn === null) {
- this.checkPwResetRoute();
- } else {
- this.router.navigate(['/summary']);
- this.sharedService.isBtnDisabled = false;
- }
- }
-
- /**
- * Clears the local storage after a certain time period (12h) has
- * passed since the last login.
- */
- checkAndClearLocalStorage() {
- const startTime = localStorage.getItem('sessionTimeJOIN');
-
- if (startTime) {
- const startTimeMills = parseInt(startTime);
- const currentTime = new Date().getTime();
- const timeDifference = 12 * 60 * 60 * 1000; // 12h
- if (currentTime - startTimeMills > timeDifference) {
- localStorage.clear();
- }
- }
- }
-
- /**
- * Listens to router events and checks if the current route is one of the
- * allowed routes for password reset, registration, forgotten password,
- * or login. If it is not, it navigates to the login page.
- */
- checkPwResetRoute() {
- this.router.events
- .pipe(filter((event) => event instanceof NavigationEnd))
- .subscribe(() => {
- const urlTree = this.router.parseUrl(this.router.url);
- const firstSegment = this.getFirstSegment(urlTree);
- const allowedRoutes = ['pw-reset', 'register', 'forgot-pw', 'login'];
-
- if (!allowedRoutes.includes(firstSegment)) {
- this.router.navigate(['/login']);
- }
- });
- }
-
- /**
- * Returns the first segment of the current URL or an empty string if it does not exist.
- *
- * @param urlTree The current URL tree.
- * @returns The first segment of the current URL or an empty string if it does not exist.
- */
- private getFirstSegment(urlTree: any): string {
- return urlTree.root.children['primary']?.segments[0]?.path || '';
+ loadCurrentUser(): void {
+ this.userService.getCurrentUser().subscribe((userData) => {
+ this.currentUser = userData;
+ });
}
}
diff --git a/src/app/services/button-state.service.ts b/src/app/services/button-state.service.ts
new file mode 100644
index 0000000..cdf30e0
--- /dev/null
+++ b/src/app/services/button-state.service.ts
@@ -0,0 +1,16 @@
+import { Injectable } from '@angular/core';
+
+@Injectable({
+ providedIn: 'root',
+})
+export class ButtonStateService {
+ isButtonDisabled: boolean = false;
+
+ disableButton() {
+ this.isButtonDisabled = true;
+ }
+
+ enableButton() {
+ this.isButtonDisabled = false;
+ }
+}
diff --git a/src/app/services/color.service.ts b/src/app/services/color.service.ts
deleted file mode 100644
index 0c7b672..0000000
--- a/src/app/services/color.service.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { Injectable } from '@angular/core';
-
-@Injectable({
- providedIn: 'root',
-})
-export class ColorService {
- generateRandomColor(): string {
- const letters = '0123456789ABCDEF';
- let color = '#';
- let isGrayScale = true;
-
- while (isGrayScale) {
- for (let i = 0; i < 6; i++) {
- color += letters[Math.floor(Math.random() * 16)];
- }
- const rgb = this.hexToRgb(color);
- if (rgb.r !== rgb.g || rgb.g !== rgb.b) {
- isGrayScale = false;
- } else {
- color = '#';
- }
- }
-
- return color;
- }
-
- hexToRgb(hex: string): { r: number; g: number; b: number } {
- const bigint = parseInt(hex.substring(1), 16);
- const r = (bigint >> 16) & 255;
- const g = (bigint >> 8) & 255;
- const b = bigint & 255;
- return { r, g, b };
- }
-}
diff --git a/src/app/services/login.service.ts b/src/app/services/login.service.ts
index fae8fca..5d1dac8 100644
--- a/src/app/services/login.service.ts
+++ b/src/app/services/login.service.ts
@@ -19,13 +19,12 @@ import {
updateDoc,
where,
} from '@angular/fire/firestore';
-import { SharedService } from './shared.service';
import { User } from '../interfaces/user.interface';
import { Router } from '@angular/router';
import CryptoES from 'crypto-es';
import { CryptoESSecretKey } from '../environments/config';
import { catchError, map, Observable, of } from 'rxjs';
-import { ColorService } from './color.service';
+import { ButtonStateService } from './button-state.service';
@Injectable({
providedIn: 'root',
@@ -40,8 +39,7 @@ export class LoginService {
constructor(
private firebaseService: FirebaseService,
- private colorService: ColorService,
- public sharedService: SharedService,
+ private buttonStateService: ButtonStateService,
private router: Router
) {}
@@ -83,7 +81,7 @@ export class LoginService {
})
.catch((error) => {
this.errorCode = error.code;
- this.sharedService.isBtnDisabled = false;
+ this.buttonStateService.disableButton();
});
}
@@ -126,13 +124,13 @@ export class LoginService {
? registerData.firstName.slice(0, 1).toUpperCase() +
registerData.lastName.slice(0, 1).toUpperCase()
: '',
- color: this.colorService.generateRandomColor(),
+ color: '',
lastLogin: new Date().getTime(),
};
this.createUserInFirestore(userDataToSave);
})
.catch((error) => {
- this.sharedService.isBtnDisabled = false;
+ this.buttonStateService.disableButton();
});
}
@@ -171,7 +169,7 @@ export class LoginService {
isOnline: true,
phone: '',
initials: firstName.slice(0, 1) + lastName.slice(0, 1),
- color: this.colorService.generateRandomColor(),
+ color: '',
lastLogin: 0,
});
} else {
@@ -180,7 +178,7 @@ export class LoginService {
});
})
.catch((error) => {
- this.sharedService.isBtnDisabled = false;
+ this.buttonStateService.disableButton();
});
}
@@ -333,10 +331,10 @@ export class LoginService {
sendPasswordResetEmail(auth, email, actionCodeSettings)
.then(() => {
this.router.navigate(['/login/notice/pw-send']);
- this.sharedService.isBtnDisabled = false;
+ this.buttonStateService.disableButton();
})
.catch((error) => {
- this.sharedService.isBtnDisabled = false;
+ this.buttonStateService.disableButton();
});
}
@@ -357,10 +355,10 @@ export class LoginService {
confirmPasswordReset(auth, oobCode, newPW)
.then(() => {
this.router.navigate(['/login/notice/pw-change']);
- this.sharedService.isBtnDisabled = false;
+ this.buttonStateService.disableButton();
})
.catch((error) => {
- this.sharedService.isBtnDisabled = false;
+ this.buttonStateService.disableButton();
});
}
}
diff --git a/src/app/services/shared.service.ts b/src/app/services/shared.service.ts
deleted file mode 100644
index 8453438..0000000
--- a/src/app/services/shared.service.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { Injectable } from '@angular/core';
-
-@Injectable({
- providedIn: 'root',
-})
-export class SharedService {
- isBtnDisabled: boolean = false;
- isAnyDialogOpen: boolean = false;
- isMobileNavbarOpen: boolean = false;
- isNewContactDialogOpen: boolean = false;
- isEditContactDialogOpen: boolean = false;
- isDeleteContactDialogOpen: boolean = false;
- currentUserId: string = '';
-}
diff --git a/src/app/shared/components/buttons/btn-close/btn-close.component.html b/src/app/shared/components/buttons/btn-close/btn-close.component.html
index 2b55494..526de44 100644
--- a/src/app/shared/components/buttons/btn-close/btn-close.component.html
+++ b/src/app/shared/components/buttons/btn-close/btn-close.component.html
@@ -1,3 +1,3 @@
-
+
diff --git a/src/app/shared/components/buttons/btn-close/btn-close.component.ts b/src/app/shared/components/buttons/btn-close/btn-close.component.ts
index 440bf43..bf47b3e 100644
--- a/src/app/shared/components/buttons/btn-close/btn-close.component.ts
+++ b/src/app/shared/components/buttons/btn-close/btn-close.component.ts
@@ -1,5 +1,4 @@
import { Component, Input } from '@angular/core';
-import { SharedService } from '../../../../services/shared.service';
@Component({
selector: 'app-btn-close',
@@ -9,19 +8,5 @@ import { SharedService } from '../../../../services/shared.service';
styleUrl: './btn-close.component.scss',
})
export class BtnCloseComponent {
- @Input() isContactDialogOpen: boolean = false;
-
- constructor(private sharedService: SharedService) {}
-
- /**
- * Called when the close button is clicked.
- * Sets isAnyDialogOpen to false and sets
- * isEditContactDialogOpen and isNewContactDialogOpen
- * to the value of isContactDialogOpen.
- */
- closeClicked() {
- this.sharedService.isAnyDialogOpen = false;
- this.sharedService.isEditContactDialogOpen = this.isContactDialogOpen;
- this.sharedService.isNewContactDialogOpen = this.isContactDialogOpen;
- }
+ constructor() {}
}
diff --git a/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.html b/src/app/shared/components/overlay/contact-overlay/contact-form/contact-form.component.html
similarity index 97%
rename from src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.html
rename to src/app/shared/components/overlay/contact-overlay/contact-form/contact-form.component.html
index 65462ad..783932a 100644
--- a/src/app/components/contacts/contact-edit-new/contact-form/contact-form.component.html
+++ b/src/app/shared/components/overlay/contact-overlay/contact-form/contact-form.component.html
@@ -121,13 +121,12 @@
}
- @if (currentUserId && currentUserId !==
- firebaseService.getCurrentUserId()){
+ @if (selectedUser && selectedUser !== firebaseService.getCurrentUserId()){
} @else {
();
+ @Output() closeDialogEmitter = new EventEmitter();
constructor(
- private router: Router,
public firebaseService: FirebaseService,
- public resizeService: ResizeService,
- public sharedService: SharedService
- ) {
- this.updateContactData();
- }
+ public resizeService: ResizeService
+ ) {}
contactData = {
firstName: '',
@@ -68,7 +63,8 @@ export class ContactFormComponent implements OnInit, OnChanges {
* properties of the userData object.
*/
ngOnInit() {
- if (!this.currentUserId) {
+ this.updateContactData();
+ if (!this.selectedUser) {
this.userData = {
...this.userData,
color: this.randomColor,
@@ -84,7 +80,7 @@ export class ContactFormComponent implements OnInit, OnChanges {
* @param changes an object containing the changed input properties
*/
ngOnChanges(changes: SimpleChanges) {
- if (changes['currentUserId']) {
+ if (changes['selectedUser']) {
this.updateContactData();
}
}
@@ -109,7 +105,7 @@ export class ContactFormComponent implements OnInit, OnChanges {
? this.contactData.firstName.slice(0, 1).toUpperCase() +
this.contactData.lastName.slice(0, 1).toUpperCase()
: '';
- if (!this.currentUserId) {
+ if (!this.selectedUser) {
this.userData = {
...this.userData,
initials: initials,
@@ -130,7 +126,7 @@ export class ContactFormComponent implements OnInit, OnChanges {
* object. Otherwise, it updates the contactData object.
*/
updateUserData() {
- if (!this.currentUserId) {
+ if (!this.selectedUser) {
this.userData = {
...this.userData,
firstName: this.capitalizeFirstLetter(this.contactData.firstName),
@@ -193,21 +189,11 @@ export class ContactFormComponent implements OnInit, OnChanges {
* joined into strings using a comma separator.
*/
private updateContactData() {
- this.contactData.firstName = this.firebaseService
- .getUserDetails(this.currentUserId, 'firstName')
- .join(', ');
- this.contactData.lastName = this.firebaseService
- .getUserDetails(this.currentUserId, 'lastName')
- .join(', ');
- this.contactData.email = this.firebaseService
- .getUserDetails(this.currentUserId, 'email')
- .join(', ');
- this.contactData.phone = this.firebaseService
- .getUserDetails(this.currentUserId, 'phone')
- .join(', ');
- this.contactData.initials = this.firebaseService
- .getUserDetails(this.currentUserId, 'initials')
- .join(', ');
+ this.contactData.firstName = this.selectedUser.firstName;
+ this.contactData.lastName = this.selectedUser.lastName;
+ this.contactData.email = this.selectedUser.email;
+ this.contactData.phone = this.selectedUser.phone;
+ this.contactData.initials = this.selectedUser.initials;
}
/**
@@ -220,45 +206,15 @@ export class ContactFormComponent implements OnInit, OnChanges {
*/
onSubmit(ngForm: NgForm) {
if (ngForm.submitted && ngForm.form.valid) {
- if (this.currentUserId) {
- console.log(this.newColor, this.currentColor);
-
- this.newColor !== ''
- ? (this.contactData.color = this.newColor)
- : (this.contactData.color = this.currentColor);
- this.firebaseService.updateUserData(
- this.currentUserId,
- this.contactData
- );
- } else {
- this.newColor !== ''
- ? (this.userData.color = this.newColor)
- : (this.userData.color = this.randomColor);
- const { id, ...taskWithoutIds } = this.userData;
- this.firebaseService.addNewUser(taskWithoutIds).then((docRef) => {
- this.router.navigate([`/contacts/${docRef.id}`]);
- });
- }
+ this.newColor !== ''
+ ? (this.contactData.color = this.newColor)
+ : (this.contactData.color = this.currentColor);
+ console.log('Save');
this.closeDialog();
}
}
- /**
- * Closes the delete contact dialog and the main dialog overlay.
- */
- deleteContact() {
- this.sharedService.isDeleteContactDialogOpen = false;
- this.sharedService.isAnyDialogOpen = false;
- }
-
- /**
- * Closes the contact dialog by updating the shared service flags
- * to indicate that no dialog, edit contact dialog, or new contact dialog
- * is currently open.
- */
closeDialog() {
- this.sharedService.isAnyDialogOpen = false;
- this.sharedService.isEditContactDialogOpen = false;
- this.sharedService.isNewContactDialogOpen = false;
+ this.closeDialogEmitter.emit('');
}
}
diff --git a/src/app/components/contacts/contact-edit-new/contact-edit-new.component.html b/src/app/shared/components/overlay/contact-overlay/contact-overlay.component.html
similarity index 76%
rename from src/app/components/contacts/contact-edit-new/contact-edit-new.component.html
rename to src/app/shared/components/overlay/contact-overlay/contact-overlay.component.html
index 1a2b247..0833f5a 100644
--- a/src/app/components/contacts/contact-edit-new/contact-edit-new.component.html
+++ b/src/app/shared/components/overlay/contact-overlay/contact-overlay.component.html
@@ -1,23 +1,22 @@
-@if (currentUserId) { @for (user of
-firebaseService.getUserDataFromId(currentUserId); track user) {
+@if (overlayData !== "new") {
{{ "contacts.notice" | translate }}
-} } @else {
+} @else {
diff --git a/src/app/components/contacts/contact-edit-new/contact-edit-new.component.scss b/src/app/shared/components/overlay/contact-overlay/contact-overlay.component.scss
similarity index 100%
rename from src/app/components/contacts/contact-edit-new/contact-edit-new.component.scss
rename to src/app/shared/components/overlay/contact-overlay/contact-overlay.component.scss
diff --git a/src/app/components/contacts/contact-edit-new/contact-edit-new.component.spec.ts b/src/app/shared/components/overlay/contact-overlay/contact-overlay.component.spec.ts
similarity index 50%
rename from src/app/components/contacts/contact-edit-new/contact-edit-new.component.spec.ts
rename to src/app/shared/components/overlay/contact-overlay/contact-overlay.component.spec.ts
index da5f817..a23afbb 100644
--- a/src/app/components/contacts/contact-edit-new/contact-edit-new.component.spec.ts
+++ b/src/app/shared/components/overlay/contact-overlay/contact-overlay.component.spec.ts
@@ -1,16 +1,16 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
-import { ContactEditNewComponent } from './contact-edit-new.component';
+import { ContactOverlayComponent } from './contact-overlay.component';
-describe('ContactEditComponent', () => {
- let component: ContactEditNewComponent;
- let fixture: ComponentFixture
;
+describe('ContactOverlayComponent', () => {
+ let component: ContactOverlayComponent;
+ let fixture: ComponentFixture;
beforeEach(async () => {
await TestBed.configureTestingModule({
- imports: [ContactEditNewComponent],
+ imports: [ContactOverlayComponent],
}).compileComponents();
- fixture = TestBed.createComponent(ContactEditNewComponent);
+ fixture = TestBed.createComponent(ContactOverlayComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
diff --git a/src/app/components/contacts/contact-edit-new/contact-edit-new.component.ts b/src/app/shared/components/overlay/contact-overlay/contact-overlay.component.ts
similarity index 56%
rename from src/app/components/contacts/contact-edit-new/contact-edit-new.component.ts
rename to src/app/shared/components/overlay/contact-overlay/contact-overlay.component.ts
index 4b3f5c0..3fe3ce2 100644
--- a/src/app/components/contacts/contact-edit-new/contact-edit-new.component.ts
+++ b/src/app/shared/components/overlay/contact-overlay/contact-overlay.component.ts
@@ -1,15 +1,13 @@
-import { Component, Input, OnInit } from '@angular/core';
+import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { CommonModule } from '@angular/common';
-import { BtnCloseComponent } from '../../../shared/components/buttons/btn-close/btn-close.component';
-import { FirebaseService } from '../../../services/firebase.service';
-import { TranslateModule } from '@ngx-translate/core';
import { ContactFormComponent } from './contact-form/contact-form.component';
-import { SharedService } from '../../../services/shared.service';
+import { BtnCloseComponent } from '../../buttons/btn-close/btn-close.component';
+import { TranslateModule } from '@ngx-translate/core';
import { ColorPickerModule } from 'ngx-color-picker';
-import { ColorService } from '../../../services/color.service';
+import { FirebaseService } from '../../../../services/firebase.service';
@Component({
- selector: 'app-contact-edit',
+ selector: 'app-contact-overlay',
standalone: true,
imports: [
CommonModule,
@@ -18,22 +16,19 @@ import { ColorService } from '../../../services/color.service';
TranslateModule,
ColorPickerModule,
],
- templateUrl: './contact-edit-new.component.html',
- styleUrl: './contact-edit-new.component.scss',
+ templateUrl: './contact-overlay.component.html',
+ styleUrl: './contact-overlay.component.scss',
})
-export class ContactEditNewComponent implements OnInit {
- @Input() currentUserId: string = '';
- @Input() currentColor: string = '';
+export class ContactOverlayComponent implements OnInit {
+ @Input() overlayData: any = [];
+ @Input() overlayType: string = '';
+ @Output() closeDialogEmitter = new EventEmitter();
randomColor: string = '';
userInitials: string = '';
newColor: string = '';
- constructor(
- public firebaseService: FirebaseService,
- public sharedService: SharedService,
- private colorService: ColorService
- ) {}
+ constructor(public firebaseService: FirebaseService) {}
/**
* Lifecycle hook that is called after data-bound properties of a directive are
@@ -41,7 +36,16 @@ export class ContactEditNewComponent implements OnInit {
* This method sets a random color for the user to be edited.
*/
ngOnInit() {
- this.randomColor = this.colorService.generateRandomColor();
+ this.randomColor = this.getRandomColor();
+ }
+
+ getRandomColor(): string {
+ const letters = '0123456789ABCDEF';
+ let color = '#';
+ for (let i = 0; i < 6; i++) {
+ color += letters[Math.floor(Math.random() * 16)];
+ }
+ return color;
}
/**
@@ -55,6 +59,10 @@ export class ContactEditNewComponent implements OnInit {
this.userInitials = emitter;
}
+ closeDialog() {
+ this.closeDialogEmitter.emit('');
+ }
+
/**
* Updates the newColor variable with the newly selected color.
*
diff --git a/src/app/shared/components/overlay/dialog-overlay/dialog-overlay.component.ts b/src/app/shared/components/overlay/dialog-overlay/dialog-overlay.component.ts
index 9761a78..5dc0eef 100644
--- a/src/app/shared/components/overlay/dialog-overlay/dialog-overlay.component.ts
+++ b/src/app/shared/components/overlay/dialog-overlay/dialog-overlay.component.ts
@@ -1,5 +1,4 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
-import { SharedService } from '../../../../services/shared.service';
import { BtnCloseComponent } from '../../buttons/btn-close/btn-close.component';
import { Router } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
@@ -16,7 +15,7 @@ export class DialogOverlayComponent {
@Input() overlayType: string = '';
@Output() closeDialogEmitter = new EventEmitter();
- constructor(public sharedService: SharedService, private router: Router) {}
+ constructor(private router: Router) {}
/**
* Navigates to the login route and emits an empty string via the
diff --git a/src/app/shared/components/overlay/overlay.component.html b/src/app/shared/components/overlay/overlay.component.html
index bdd368d..d10cabd 100644
--- a/src/app/shared/components/overlay/overlay.component.html
+++ b/src/app/shared/components/overlay/overlay.component.html
@@ -18,12 +18,18 @@
[overlayType]="overlayType"
(closeDialogEmitter)="onCloseOverlay($event)"
>
- }@if (overlayType === "dialog") {
+ } @if (overlayType === "dialog") {
+ } @if (overlayType === "contactOverlay") {
+
}
diff --git a/src/app/shared/components/overlay/overlay.component.ts b/src/app/shared/components/overlay/overlay.component.ts
index 534e520..20f91be 100644
--- a/src/app/shared/components/overlay/overlay.component.ts
+++ b/src/app/shared/components/overlay/overlay.component.ts
@@ -5,6 +5,7 @@ import { TaskOverlayComponent } from './task-overlay/task-overlay.component';
import { TaskEditOverlayComponent } from './task-edit-overlay/task-edit-overlay.component';
import { Router } from '@angular/router';
import { DialogOverlayComponent } from './dialog-overlay/dialog-overlay.component';
+import { ContactOverlayComponent } from './contact-overlay/contact-overlay.component';
@Component({
selector: 'app-overlay',
@@ -14,6 +15,7 @@ import { DialogOverlayComponent } from './dialog-overlay/dialog-overlay.componen
TaskOverlayComponent,
TaskEditOverlayComponent,
DialogOverlayComponent,
+ ContactOverlayComponent,
],
templateUrl: './overlay.component.html',
styleUrl: './overlay.component.scss',