diff --git a/src/app/components/contacts/contact-edit/contact-edit.component.html b/src/app/components/contacts/contact-edit/contact-edit.component.html index 9c04436..29b785d 100644 --- a/src/app/components/contacts/contact-edit/contact-edit.component.html +++ b/src/app/components/contacts/contact-edit/contact-edit.component.html @@ -5,23 +5,23 @@

Edit contact

-
-
- {{ - userService.getUserDetails(sharedService.currentUserId, "initials") - }} +
+
+
+ {{ userService.getUserDetails(currentUserId, "initials") }} +
- +
diff --git a/src/app/components/contacts/contact-edit/contact-edit.component.scss b/src/app/components/contacts/contact-edit/contact-edit.component.scss index 33c93cc..3dd1339 100644 --- a/src/app/components/contacts/contact-edit/contact-edit.component.scss +++ b/src/app/components/contacts/contact-edit/contact-edit.component.scss @@ -61,3 +61,17 @@ section { } } } + +.badge { + display: flex; + justify-content: center; + align-items: center; + width: 30%; +} + +.form { + display: flex; + justify-content: center; + align-items: center; + width: 70%; +} diff --git a/src/app/components/contacts/contact-edit/contact-edit.component.ts b/src/app/components/contacts/contact-edit/contact-edit.component.ts index 035ee52..4b64e91 100644 --- a/src/app/components/contacts/contact-edit/contact-edit.component.ts +++ b/src/app/components/contacts/contact-edit/contact-edit.component.ts @@ -12,10 +12,7 @@ import { SharedService } from '../../../services/shared.service'; styleUrl: './contact-edit.component.scss', }) export class ContactEditComponent { - @Input() currentUserId!: string | undefined; + @Input() currentUserId!: string; - constructor( - public userService: UserService, - public sharedService: SharedService - ) {} + constructor(public userService: UserService) {} } diff --git a/src/app/components/contacts/contact-form/contact-form.component.html b/src/app/components/contacts/contact-form/contact-form.component.html index 6098735..952e5c5 100644 --- a/src/app/components/contacts/contact-form/contact-form.component.html +++ b/src/app/components/contacts/contact-form/contact-form.component.html @@ -1 +1,91 @@ -

contact-form works!

+
+
+
+ + @if (!firstName.valid && firstName.touched) { + {{ "form.invalid-name" | translate }} + } + + @if (!lastName.valid && lastName.touched) { + {{ "form.invalid-name" | translate }} + } +
+ + @if (!email.valid && email.touched) { + {{ "form.invalid-email" | translate }} + } + + @if (!phone.valid && phone.touched) { + {{ "form.invalid-msg" | translate }} + } +
+
+ +
+
+ +
+
+
+
diff --git a/src/app/components/contacts/contact-form/contact-form.component.scss b/src/app/components/contacts/contact-form/contact-form.component.scss index e69de29..a31142d 100644 --- a/src/app/components/contacts/contact-form/contact-form.component.scss +++ b/src/app/components/contacts/contact-form/contact-form.component.scss @@ -0,0 +1,94 @@ +section { + display: flex; + flex-direction: column; + align-items: center; +} + +span { + font-size: 14px; + font-weight: 400; + color: red; + padding: 0 0 10px 20px; +} + +.name { + display: flex; +} + +.contact-formular { + display: flex; + flex-direction: column; + min-width: 480px; + .btn-delete { + padding: 12px; + margin: 12px 12px; + border-radius: 10px; + color: var(--red); + background-color: var(--white); + border: 1px solid var(--red); + font-size: 23px; + font-weight: 400; + cursor: pointer; + &:hover { + color: var(--white); + background-color: var(--red); + border-color: var(--black); + } + } + input { + background-color: var(--white); + border: 1px solid var(--gray); + border-radius: 10px; + font-size: 20px; + font-weight: 400; + padding: 12px; + margin: 12px 12px; + width: 90%; + &:hover { + border-color: var(--light-blue); + } + &:focus { + border-color: var(--light-blue); + outline: none; + } + } +} + +.btns { + display: flex; + justify-content: center; + align-items: center; +} + +.btn { + display: flex; + flex-direction: column; + align-items: center; + width: 111px; + height: 57px; + margin: 0 24px; + font-size: 21px; + font-weight: 400; +} + +.btn-save { + padding: 15px 30px; + margin-top: 12px; + border-radius: 10px; + border-color: var(--black); + background-color: var(--light-gray); + font-size: 23px; + font-weight: 400; + transition: 200ms ease-in-out; + &:hover:not(:disabled) { + background-color: var(--light-blue) !important; + cursor: pointer; + } + &:not(:disabled) { + background-color: var(--very-dark-blue) !important; + color: var(--white); + } + &:hover { + cursor: default; + } +} diff --git a/src/app/components/contacts/contact-form/contact-form.component.ts b/src/app/components/contacts/contact-form/contact-form.component.ts index 8389df8..a195b7f 100644 --- a/src/app/components/contacts/contact-form/contact-form.component.ts +++ b/src/app/components/contacts/contact-form/contact-form.component.ts @@ -1,12 +1,67 @@ -import { Component } from '@angular/core'; +import { Component, Input, OnChanges, SimpleChanges } from '@angular/core'; +import { FormsModule, NgForm } from '@angular/forms'; +import { TranslateModule } from '@ngx-translate/core'; +import { UserService } from '../../../services/user.service'; +import { SharedService } from '../../../services/shared.service'; @Component({ selector: 'app-contact-form', standalone: true, - imports: [], + imports: [TranslateModule, FormsModule], templateUrl: './contact-form.component.html', - styleUrl: './contact-form.component.scss' + styleUrl: './contact-form.component.scss', }) -export class ContactFormComponent { +export class ContactFormComponent implements OnChanges { + @Input() currentUserId!: string; + constructor( + public userService: UserService, + private sharedService: SharedService + ) { + this.updateContactData(); + } + + contactData = { + firstName: '', + lastName: '', + email: '', + phone: '', + }; + + ngOnChanges(changes: SimpleChanges) { + if (changes['currentUserId']) { + this.updateContactData(); + } + } + + private updateContactData() { + this.contactData.firstName = this.userService + .getUserDetails(this.currentUserId, 'firstName') + .join(', '); + this.contactData.lastName = this.userService + .getUserDetails(this.currentUserId, 'lastName') + .join(', '); + this.contactData.email = this.userService + .getUserDetails(this.currentUserId, 'email') + .join(', '); + this.contactData.phone = this.userService + .getUserDetails(this.currentUserId, 'phone') + .join(', '); + } + + onSubmit(ngForm: NgForm) { + if (ngForm.submitted && ngForm.form.valid) { + this.userService.updateUserData(this.currentUserId, this.contactData); + this.closeEditDialog(); + } + } + + deleteContact() { + this.closeEditDialog(); + } + + closeEditDialog() { + this.sharedService.isEditDialogOpen = false; + this.sharedService.isAnyDialogOpen = false; + } } diff --git a/src/app/services/shared.service.ts b/src/app/services/shared.service.ts index 53ef0c7..51ab91c 100644 --- a/src/app/services/shared.service.ts +++ b/src/app/services/shared.service.ts @@ -4,8 +4,8 @@ import { Injectable } from '@angular/core'; providedIn: 'root', }) export class SharedService { - isAnyDialogOpen: boolean = true; - isEditDialogOpen: boolean = true; + isAnyDialogOpen: boolean = false; + isEditDialogOpen: boolean = false; currentUserId: string = ''; constructor() {} diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts index d736156..972f729 100644 --- a/src/app/services/user.service.ts +++ b/src/app/services/user.service.ts @@ -1,5 +1,11 @@ import { Injectable, OnDestroy, inject } from '@angular/core'; -import { Firestore, collection, onSnapshot } from '@angular/fire/firestore'; +import { + Firestore, + collection, + doc, + onSnapshot, + updateDoc, +} from '@angular/fire/firestore'; import { User } from '../interfaces/user.interface'; @Injectable({ @@ -44,6 +50,15 @@ export class UserService implements OnDestroy { .map((user) => user[query]); } + async updateUserData(userId: string, data: any) { + await updateDoc( + doc(collection(this.firestore, 'users'), userId), + data + ).catch((err) => { + console.error(err); + }); + } + ngOnDestroy() { this.unsubUser(); } diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 817797d..47c21cf 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -9,6 +9,16 @@ "english": "English", "german": "German" }, + "form": { + "btn-delete": "Delete", + "btn-save": "Save", + "invalid-name": "Your name is required!", + "invalid-email": "Your email is required!", + "invalid-msg": "More than 10 letters are required!", + "invalid-checkbox": "Please accept the privacy policy!", + "msg-send0": "Your message has been sent successfully.", + "msg-send1": "I will contact you shortly." + }, "summary": { "headlineDescription": "Key Metrics at a Glance", "morning": "Good Morning", diff --git a/src/styles.scss b/src/styles.scss index d534af4..285d9d1 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -10,6 +10,7 @@ --white: #fff; --black: #000; --gray: #a8a8a8; + --red: #ff3d00; --light-gray: #cdcdcd; --light-blue: #29abe2; --dark-blue: #2b3647;