diff --git a/src/app/main/component/user/components/profile/user-notifications/user-notifications.component.spec.ts b/src/app/main/component/user/components/profile/user-notifications/user-notifications.component.spec.ts
index fe773b312c..49f084eceb 100644
--- a/src/app/main/component/user/components/profile/user-notifications/user-notifications.component.spec.ts
+++ b/src/app/main/component/user/components/profile/user-notifications/user-notifications.component.spec.ts
@@ -155,7 +155,6 @@ describe('UserNotificationsComponent', () => {
});
it('should navigate to news page when notification type is ECONEWS', waitForAsync(() => {
- const event = new MouseEvent('click');
const target = document.createElement('div');
target.setAttribute('data-notificationType', 'ECONEWS');
target.setAttribute('data-targetid', '5');
@@ -176,7 +175,6 @@ describe('UserNotificationsComponent', () => {
}));
it('should navigate to habit editing page when notification type is HABIT', waitForAsync(() => {
- const event = new MouseEvent('click');
const target = document.createElement('div');
target.setAttribute('data-notificationType', 'HABIT');
target.setAttribute('data-targetid', '3');
diff --git a/src/app/main/component/user/components/profile/user-notifications/user-notifications.component.ts b/src/app/main/component/user/components/profile/user-notifications/user-notifications.component.ts
index b5b07b0e9a..aa12f4003e 100644
--- a/src/app/main/component/user/components/profile/user-notifications/user-notifications.component.ts
+++ b/src/app/main/component/user/components/profile/user-notifications/user-notifications.component.ts
@@ -33,7 +33,6 @@ export class UserNotificationsComponent implements OnInit, OnDestroy {
filterCriteriaOptions = filterCriteriaOptions;
notificationCriteriaOptions = notificationCriteriaOptions;
projects = projects;
- notificationTypes = NotificationCriteria;
notificationFriendRequest = NotificationCriteria.FRIEND_REQUEST_RECEIVED;
notificationHabitInvitation = NotificationCriteria.HABIT_INVITATION;
@@ -263,12 +262,35 @@ export class UserNotificationsComponent implements OnInit, OnDestroy {
}
}
+ isFriendRequest(notification: NotificationModel): boolean {
+ return notification.notificationType === this.notificationFriendRequest;
+ }
+
+ isHabitInvitation(notification: NotificationModel): boolean {
+ return notification.notificationType === this.notificationHabitInvitation;
+ }
+
acceptRequest(notification: NotificationModel): void {
- if (notification.notificationType === this.notificationFriendRequest) {
- let isAccepted = true;
+ if (this.isFriendRequest(notification)) {
+ this.handleFriendRequest(notification, 'accept');
+ } else if (this.isHabitInvitation(notification)) {
+ this.handleHabitInvitation(notification, 'accept');
+ }
+ }
+
+ declineRequest(notification: NotificationModel): void {
+ if (this.isFriendRequest(notification)) {
+ this.handleFriendRequest(notification, 'decline');
+ } else if (this.isHabitInvitation(notification)) {
+ this.handleHabitInvitation(notification, 'decline');
+ }
+ }
- const userId = notification.actionUserId[0];
+ private handleFriendRequest(notification: NotificationModel, action: 'accept' | 'decline'): void {
+ let isAccepted = true;
+ const userId = notification.actionUserId[0];
+ if (action === 'accept') {
this.userFriendsService.acceptRequest(userId).subscribe({
error: () => {
isAccepted = false;
@@ -279,43 +301,39 @@ export class UserNotificationsComponent implements OnInit, OnDestroy {
}
}
});
- } else if (notification.notificationType === this.notificationHabitInvitation) {
- const invitationId = notification.secondMessageId;
-
- this.habitService.acceptHabitInvitation(invitationId).subscribe({
- next: () => {
- this.matSnackBar.openSnackBar('habitAcceptRequest');
- },
+ } else {
+ this.userFriendsService.declineRequest(userId).subscribe({
error: () => {
- this.matSnackBar.openSnackBar('habitAcceptInValidRequest');
+ isAccepted = false;
+ },
+ complete: () => {
+ if (isAccepted) {
+ this.matSnackBar.openSnackBar('friendInValidRequest');
+ }
}
});
}
}
- declineRequest(notification: NotificationModel): void {
+ private handleHabitInvitation(notification: NotificationModel, action: 'accept' | 'decline'): void {
let isAccepted = true;
- const userId = notification.actionUserId[0];
- if (notification.notificationType === this.notificationFriendRequest) {
- this.userFriendsService.declineRequest(userId).subscribe({
+ const invitationId = notification.secondMessageId;
+ if (action === 'accept') {
+ this.habitService.acceptHabitInvitation(invitationId).subscribe({
error: () => {
isAccepted = false;
},
complete: () => {
- if (isAccepted) {
- this.matSnackBar.openSnackBar('friendInValidRequest');
- }
+ this.matSnackBar.openSnackBar(isAccepted ? 'habitAcceptRequest' : 'habitAcceptInValidRequest');
}
});
- } else if (notification.notificationType === this.notificationHabitInvitation) {
- const invitationId = notification.secondMessageId;
-
+ } else {
this.habitService.declineHabitInvitation(invitationId).subscribe({
- next: () => {
- this.matSnackBar.openSnackBar('habitDeclineRequest');
- },
error: () => {
- this.matSnackBar.openSnackBar('habitDeclineInValidRequest');
+ isAccepted = false;
+ },
+ complete: () => {
+ this.matSnackBar.openSnackBar(isAccepted ? 'habitDeclineRequest' : 'habitDeclineInValidRequest');
}
});
}
diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json
index c7010bfae7..fe6b4c326b 100644
--- a/src/assets/i18n/en.json
+++ b/src/assets/i18n/en.json
@@ -513,8 +513,6 @@
"error-create-address": "Oops, An error occurred while creating the address. Please try again.",
"habit-not-added": "This habit invitation can`t be accepted",
"habit-already-added": "This habit invitation can`t be declined",
- "habit-added-success": "Habit invitation was accepted",
- "habit-decline-success": "Habit invitation was declined",
"error-edit-address": "Oops, An error occurred while editing the address. Please try again."
},
"attention": {
@@ -538,7 +536,9 @@
"add-friend": "Friend request sent",
"cancel-request": "Your friend request has been canceled",
"joint-event-request": "The request to join the closed event has been successfully sent to the organizer",
- "create-news": "Your news has been successfully published"
+ "create-news": "Your news has been successfully published",
+ "habit-added-success": "Habit invitation was accepted",
+ "habit-decline-success": "Habit invitation was declined"
}
},
"user": {
diff --git a/src/assets/i18n/ua.json b/src/assets/i18n/ua.json
index 106671412f..03fdd4ae59 100644
--- a/src/assets/i18n/ua.json
+++ b/src/assets/i18n/ua.json
@@ -520,8 +520,6 @@
"error-create-address": "Упс! Виникла помилка при створенні адреси. Будь ласка, спробуйте ще раз.",
"habit-not-added": "Неможливо прийняти запрошення",
"habit-already-added": "Неможливо відхилити запрошення",
- "habit-added-success": "Запрошення прийнято",
- "habit-decline-success": "Запрошення відхилено",
"error-edit-address": "Упс! Виникла помилка при редагуванні адреси. Будь ласка, спробуйте ще раз."
},
"attention": {
@@ -547,7 +545,9 @@
"add-friend": "Запит на дружбу надіслано",
"cancel-request": "Запит на дружбу скасовано",
"joint-event-request": "Запит на приєднання до закритої події надіслано",
- "create-news": "Ваша новина успішно опублікована"
+ "create-news": "Ваша новина успішно опублікована",
+ "habit-added-success": "Запрошення прийнято",
+ "habit-decline-success": "Запрошення відхилено"
}
},
"user": {
From a1d3ecc54d76a7001d3298a1ef3aa6cdd630357b Mon Sep 17 00:00:00 2001
From: sofiia koval
Date: Fri, 22 Nov 2024 13:11:08 +0200
Subject: [PATCH 9/9] fix: comments
---
.../mat-snack-bar/mat-snack-bar.component.ts | 2 ++
.../user-notifications.component.ts | 8 ++----
.../notific-content-replace.directive.spec.ts | 15 ++++------
.../notific-content-replace.directive.ts | 5 ----
.../main/service/habit/habit.service.spec.ts | 28 ++++++++++++++++++-
src/app/main/service/habit/habit.service.ts | 2 +-
src/assets/i18n/en.json | 6 ++--
src/assets/i18n/ua.json | 6 ++--
8 files changed, 46 insertions(+), 26 deletions(-)
diff --git a/src/app/main/component/errors/mat-snack-bar/mat-snack-bar.component.ts b/src/app/main/component/errors/mat-snack-bar/mat-snack-bar.component.ts
index 9f4c902ebc..653f663243 100644
--- a/src/app/main/component/errors/mat-snack-bar/mat-snack-bar.component.ts
+++ b/src/app/main/component/errors/mat-snack-bar/mat-snack-bar.component.ts
@@ -74,6 +74,8 @@ export class MatSnackBarComponent {
addFriend: { classname: SnackbarClassName.success, key: 'snack-bar.success.add-friend' },
friendValidation: { classname: SnackbarClassName.error, key: 'snack-bar.error.friend-request' },
friendInValidRequest: { classname: SnackbarClassName.error, key: 'snack-bar.error.friend-already-added' },
+ friendRequestAccepted: { classname: SnackbarClassName.success, key: 'snack-bar.success.friend-added-success' },
+ friendRequestDeclined: { classname: SnackbarClassName.success, key: 'snack-bar.success.friend-declined-success' },
habitAcceptRequest: { classname: SnackbarClassName.success, key: 'snack-bar.success.habit-added-success' },
habitDeclineRequest: { classname: SnackbarClassName.success, key: 'snack-bar.success.habit-decline-success' },
habitAcceptInValidRequest: { classname: SnackbarClassName.error, key: 'snack-bar.error.habit-not-added' },
diff --git a/src/app/main/component/user/components/profile/user-notifications/user-notifications.component.ts b/src/app/main/component/user/components/profile/user-notifications/user-notifications.component.ts
index aa12f4003e..bc499f7784 100644
--- a/src/app/main/component/user/components/profile/user-notifications/user-notifications.component.ts
+++ b/src/app/main/component/user/components/profile/user-notifications/user-notifications.component.ts
@@ -296,9 +296,7 @@ export class UserNotificationsComponent implements OnInit, OnDestroy {
isAccepted = false;
},
complete: () => {
- if (isAccepted) {
- this.matSnackBar.openSnackBar('friendInValidRequest');
- }
+ this.matSnackBar.openSnackBar(isAccepted ? 'friendRequestAccepted' : 'friendInValidRequest');
}
});
} else {
@@ -307,9 +305,7 @@ export class UserNotificationsComponent implements OnInit, OnDestroy {
isAccepted = false;
},
complete: () => {
- if (isAccepted) {
- this.matSnackBar.openSnackBar('friendInValidRequest');
- }
+ this.matSnackBar.openSnackBar(isAccepted ? 'friendRequestDeclined' : 'friendInValidRequest');
}
});
}
diff --git a/src/app/main/component/user/directives/notific-content-replace.directive.spec.ts b/src/app/main/component/user/directives/notific-content-replace.directive.spec.ts
index ecc4b6e9e6..229b29fe83 100644
--- a/src/app/main/component/user/directives/notific-content-replace.directive.spec.ts
+++ b/src/app/main/component/user/directives/notific-content-replace.directive.spec.ts
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
-import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { NotificContentReplaceDirective } from './notific-content-replace.directive';
@Component({
@@ -30,7 +30,7 @@ describe('NotificContentReplaceDirective', () => {
viewed: false
};
- beforeEach(() => {
+ beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [TestComponent, NotificContentReplaceDirective]
});
@@ -39,7 +39,7 @@ describe('NotificContentReplaceDirective', () => {
fixture.detectChanges();
component = fixture.componentInstance;
paragrEl = fixture.nativeElement.querySelector('p');
- });
+ }));
it('should display multiple user replacements', () => {
component.notification = { ...notification, ...{ bodyText: '{user1} and {user2} liked your post' } };
@@ -74,7 +74,7 @@ describe('NotificContentReplaceDirective', () => {
component.notification = { ...notification, ...{ bodyText: 'commented event {message}' } };
fixture.detectChanges();
expect(paragrEl.textContent).toBe('commented event test message');
- expect(paragrEl.innerHTML).toBe('commented event test message');
+ expect(paragrEl.innerHTML).toBe('commented event test message');
});
it('should add property value to the content and anchor tag', () => {
@@ -83,10 +83,7 @@ describe('NotificContentReplaceDirective', () => {
...{ bodyText: '{user1},{user2} commented event {message}', actionUserId: [2, 3], actionUserText: ['testUser1', 'testUser2'] }
};
fixture.detectChanges();
- expect(paragrEl.textContent).toBe('testUser1,testUser2 commented event test message'); // Text content without tags
- expect(paragrEl.innerHTML).toBe(
- 'testUser1,testUser2 commented event ' +
- 'test message'
- );
+ expect(paragrEl.textContent).toBe('testUser1,testUser2 commented event test message');
+ expect(paragrEl.innerHTML).toBe('testUser1,testUser2 commented event test message');
});
});
diff --git a/src/app/main/component/user/directives/notific-content-replace.directive.ts b/src/app/main/component/user/directives/notific-content-replace.directive.ts
index 07bdf79dd3..a3c2e7e362 100644
--- a/src/app/main/component/user/directives/notific-content-replace.directive.ts
+++ b/src/app/main/component/user/directives/notific-content-replace.directive.ts
@@ -45,11 +45,6 @@ export class NotificContentReplaceDirective implements OnChanges {
userId: replacements.actionUserId[index]
});
}
- } else if (contentKey === 'message' && replacements.notificationType) {
- const linkAttributes = replacements.targetId
- ? { targetId: replacements.targetId, notificationType: replacements.notificationType }
- : null;
- result = this.buildReplacementString(result, contentKey, replacements[replacementKey], linkAttributes);
} else if (replacements.hasOwnProperty(replacementKey)) {
const linkAttributes = idToNavigate ? { userId: replacements[idToNavigate] } : null;
diff --git a/src/app/main/service/habit/habit.service.spec.ts b/src/app/main/service/habit/habit.service.spec.ts
index 3d3fab39b8..670312de13 100644
--- a/src/app/main/service/habit/habit.service.spec.ts
+++ b/src/app/main/service/habit/habit.service.spec.ts
@@ -1,5 +1,5 @@
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
-import { TestBed } from '@angular/core/testing';
+import { TestBed, waitForAsync } from '@angular/core/testing';
import { LocalStorageService } from '@global-service/localstorage/local-storage.service';
import { BehaviorSubject } from 'rxjs';
import { HabitService } from './habit.service';
@@ -255,4 +255,30 @@ describe('HabitService', () => {
expect(req.request.method).toBe('GET');
req.flush(HABITLIST);
});
+
+ it('should accept habit invitation', () => {
+ const invitationId = 123;
+ const mockResponse = 'Invitation accepted successfully';
+
+ habitService.acceptHabitInvitation(invitationId).subscribe((response) => {
+ expect(response).toEqual(mockResponse);
+ });
+
+ const req = httpMock.expectOne(`${habitLink}/invite/${invitationId}/accept`);
+ expect(req.request.method).toBe('PATCH');
+ req.flush(mockResponse);
+ });
+
+ it('should decline habit invitation', () => {
+ const invitationId = 456;
+ const mockResponse = 'Invitation declined successfully';
+
+ habitService.declineHabitInvitation(invitationId).subscribe((response) => {
+ expect(response).toEqual(mockResponse);
+ });
+
+ const req = httpMock.expectOne(`${habitLink}/invite/${invitationId}/reject`);
+ expect(req.request.method).toBe('DELETE');
+ req.flush(mockResponse);
+ });
});
diff --git a/src/app/main/service/habit/habit.service.ts b/src/app/main/service/habit/habit.service.ts
index 461a6504e8..304e2e7019 100644
--- a/src/app/main/service/habit/habit.service.ts
+++ b/src/app/main/service/habit/habit.service.ts
@@ -89,7 +89,7 @@ export class HabitService {
}
declineHabitInvitation(invitationId: number): Observable {
- return this.http.patch(`${habitLink}/invite/${invitationId}/reject`, {});
+ return this.http.delete(`${habitLink}/invite/${invitationId}/reject`);
}
private prepareCustomHabitRequest(habit: CustomHabit, lang: string): FormData {
diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json
index fe6b4c326b..8afc05583c 100644
--- a/src/assets/i18n/en.json
+++ b/src/assets/i18n/en.json
@@ -509,7 +509,7 @@
"exist-address": "This address has already been added",
"certificate-duration": "The duration of the certificate cant be more than 12 months",
"friend-request": "You cannot add this friend",
- "friend-already-added": "This friend has been already added",
+ "friend-already-added": "This friend invitation has been already accepted or declined",
"error-create-address": "Oops, An error occurred while creating the address. Please try again.",
"habit-not-added": "This habit invitation can`t be accepted",
"habit-already-added": "This habit invitation can`t be declined",
@@ -538,7 +538,9 @@
"joint-event-request": "The request to join the closed event has been successfully sent to the organizer",
"create-news": "Your news has been successfully published",
"habit-added-success": "Habit invitation was accepted",
- "habit-decline-success": "Habit invitation was declined"
+ "habit-decline-success": "Habit invitation was declined",
+ "friend-added-success": "Friend invitation accepted",
+ "friend-declined-success": "Friend invitation declined"
}
},
"user": {
diff --git a/src/assets/i18n/ua.json b/src/assets/i18n/ua.json
index 03fdd4ae59..6c01adecae 100644
--- a/src/assets/i18n/ua.json
+++ b/src/assets/i18n/ua.json
@@ -516,7 +516,7 @@
"exist-address": "Ця адреса вже додана",
"certificate-duration": "Термін дії сертифіката не може перевищувати 12 місяців",
"friend-request": "Ви не можете додати цього друга",
- "friend-already-added": "Цього друга вже було додано",
+ "friend-already-added": "Це запрошення друга вже було додано або відхилено",
"error-create-address": "Упс! Виникла помилка при створенні адреси. Будь ласка, спробуйте ще раз.",
"habit-not-added": "Неможливо прийняти запрошення",
"habit-already-added": "Неможливо відхилити запрошення",
@@ -547,7 +547,9 @@
"joint-event-request": "Запит на приєднання до закритої події надіслано",
"create-news": "Ваша новина успішно опублікована",
"habit-added-success": "Запрошення прийнято",
- "habit-decline-success": "Запрошення відхилено"
+ "habit-decline-success": "Запрошення відхилено",
+ "friend-added-success": "Запит на дружбу прийнято",
+ "friend-declined-success": "Запит на дружбу відхилено"
}
},
"user": {