fix: minor bug fixes & migrated contact deletion to Django REST framework
This commit is contained in:
parent
db242700e0
commit
ce2f9ed228
8 changed files with 56 additions and 30 deletions
|
|
@ -7,12 +7,12 @@
|
|||
{{ "contacts.headlineDescription" | translate }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-back">
|
||||
<img
|
||||
<div
|
||||
class="btn-back"
|
||||
[ngClass]="{ 'd-none': !selectedUserId }"
|
||||
(click)="closeUserDetails()"
|
||||
src="./../../../../assets/img/arrow-left.svg"
|
||||
/>
|
||||
>
|
||||
<img src="./../../../../assets/img/arrow-left.svg" />
|
||||
</div>
|
||||
</div>
|
||||
@if (selectedUser && selectedUserId) {
|
||||
|
|
@ -57,7 +57,7 @@
|
|||
</div>
|
||||
@if (selectedUser.isContactOnly || currentUser && selectedUser.id !==
|
||||
currentUser.id) {
|
||||
<div class="btn btn-delete" (click)="openDeleteContactDialog()">
|
||||
<div class="btn btn-delete" (click)="deleteContact(selectedUserId)">
|
||||
<img src="./../../../../assets/img/contact/delete.svg" alt="" />
|
||||
<p>
|
||||
{{ "contacts.btnDelete0" | translate }}
|
||||
|
|
|
|||
|
|
@ -177,6 +177,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
.d-none {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/*------------- ANIMATION -------------*/
|
||||
|
||||
.animation-coming-in {
|
||||
|
|
|
|||
|
|
@ -9,9 +9,11 @@ import { CommonModule } from '@angular/common';
|
|||
import { FirebaseService } from '../../../services/firebase.service';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { UserService } from '../../../services/user.service';
|
||||
import { finalize } from 'rxjs';
|
||||
import { finalize, lastValueFrom } from 'rxjs';
|
||||
import { User } from '../../../interfaces/user.interface';
|
||||
import { OverlayService } from '../../../services/overlay.service';
|
||||
import { ApiService } from '../../../services/api.service';
|
||||
import { ToastNotificationService } from '../../../services/toast-notification.servic';
|
||||
|
||||
@Component({
|
||||
selector: 'app-contact-detail',
|
||||
|
|
@ -32,7 +34,9 @@ export class ContactDetailComponent {
|
|||
constructor(
|
||||
public firebaseService: FirebaseService,
|
||||
private overlayService: OverlayService,
|
||||
private userService: UserService
|
||||
private userService: UserService,
|
||||
private apiService: ApiService,
|
||||
private toastNotificationService: ToastNotificationService
|
||||
) {}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
|
|
@ -97,8 +101,13 @@ export class ContactDetailComponent {
|
|||
* Opens the delete contact dialog by setting the appropriate flags in the shared service.
|
||||
* This method is used by the contact details component to open the delete contact dialog when the user clicks the delete button.
|
||||
*/
|
||||
openDeleteContactDialog() {
|
||||
// TODO
|
||||
this.isMobileNavbarOpen = false;
|
||||
async deleteContact(userId: string) {
|
||||
try {
|
||||
await lastValueFrom(this.apiService.deleteUserById(userId));
|
||||
this.toastNotificationService.deleteContactSuccessToast();
|
||||
this.closeUserDetails();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,4 +73,8 @@ export class ApiService {
|
|||
ids: userIds.join(','),
|
||||
});
|
||||
}
|
||||
|
||||
deleteUserById(userId: string): Observable<User> {
|
||||
return this.request<User>('DELETE', `/api/users/${userId}/`);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,16 @@ export class ToastNotificationService {
|
|||
this.createInfoToast('Task successfully moved!', 'Task Moved');
|
||||
}
|
||||
|
||||
// Contacts
|
||||
|
||||
createContactSuccessToast(): void {
|
||||
this.createSuccessToast('Contact created successfully!', 'Contact Created');
|
||||
}
|
||||
|
||||
deleteContactSuccessToast(): void {
|
||||
this.createSuccessToast('Contact deleted successfully!', 'Contact Deleted');
|
||||
}
|
||||
|
||||
// Helperfunctions
|
||||
|
||||
createSuccessToast(message: string, title: string = 'Success'): void {
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@
|
|||
}
|
||||
</div>
|
||||
<div class="btns">
|
||||
@if (selectedUser && selectedUser !== firebaseService.getCurrentUserId()){
|
||||
@if (selectedUserExists) {
|
||||
<app-form-btn
|
||||
class="btn-delete"
|
||||
type="button"
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import { ResizeService } from '../../../../../services/resize.service';
|
|||
styleUrl: './contact-form.component.scss',
|
||||
})
|
||||
export class ContactFormComponent implements OnInit, OnChanges {
|
||||
@Input() selectedUser: any = [];
|
||||
@Input() selectedUser: any = {};
|
||||
@Input() randomColor: string = '';
|
||||
@Input() newColor: string = '';
|
||||
@Input() currentColor: string = '';
|
||||
|
|
@ -63,8 +63,7 @@ export class ContactFormComponent implements OnInit, OnChanges {
|
|||
* properties of the userData object.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.updateContactData();
|
||||
if (!this.selectedUser) {
|
||||
if (this.selectedUserExists) {
|
||||
this.userData = {
|
||||
...this.userData,
|
||||
color: this.randomColor,
|
||||
|
|
@ -73,6 +72,10 @@ export class ContactFormComponent implements OnInit, OnChanges {
|
|||
}
|
||||
}
|
||||
|
||||
get selectedUserExists() {
|
||||
return !!this.selectedUser && Object.keys(this.selectedUser).length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lifecycle hook that is called whenever the input properties of the component change.
|
||||
*
|
||||
|
|
@ -101,10 +104,12 @@ export class ContactFormComponent implements OnInit, OnChanges {
|
|||
* Finally, it emits an event containing the initials.
|
||||
*/
|
||||
updateInitials() {
|
||||
const initials = this.contactData
|
||||
? this.contactData.firstName.slice(0, 1).toUpperCase() +
|
||||
this.contactData.lastName.slice(0, 1).toUpperCase()
|
||||
: '';
|
||||
const firstName = this.contactData?.firstName || '';
|
||||
const lastName = this.contactData?.lastName || '';
|
||||
const initials = (
|
||||
firstName.slice(0, 1) + lastName.slice(0, 1)
|
||||
).toUpperCase();
|
||||
|
||||
if (!this.selectedUser) {
|
||||
this.userData = {
|
||||
...this.userData,
|
||||
|
|
@ -150,7 +155,8 @@ export class ContactFormComponent implements OnInit, OnChanges {
|
|||
* @param {string} name - The string to modify.
|
||||
* @return {string} The modified string.
|
||||
*/
|
||||
capitalizeFirstLetter(name: string) {
|
||||
capitalizeFirstLetter(name?: string): string {
|
||||
if (!name) return ''; // Return an empty string if name is undefined or null
|
||||
return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,20 +24,13 @@ export class ContactOverlayComponent implements OnInit {
|
|||
@Input() overlayType: string = '';
|
||||
@Output() closeDialogEmitter = new EventEmitter<string>();
|
||||
|
||||
randomColor: string = '';
|
||||
randomColor: string = this.getRandomColor();
|
||||
userInitials: string = '';
|
||||
newColor: string = '';
|
||||
|
||||
constructor(public firebaseService: FirebaseService) {}
|
||||
|
||||
/**
|
||||
* Lifecycle hook that is called after data-bound properties of a directive are
|
||||
* initialized.
|
||||
* This method sets a random color for the user to be edited.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.randomColor = this.getRandomColor();
|
||||
}
|
||||
ngOnInit() {}
|
||||
|
||||
getRandomColor(): string {
|
||||
const letters = '0123456789ABCDEF';
|
||||
|
|
|
|||
Loading…
Reference in a new issue