Skip to content

Commit dd745f0

Browse files
committed
add first config cancel call api in qr-payment component
1 parent 34f70be commit dd745f0

File tree

7 files changed

+48
-23
lines changed

7 files changed

+48
-23
lines changed

src/app/core/interceptors/config/ignoreApiHandleError.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export const IGNORE_ERROR_NOTIFICATION_URLS = [
44
'/submission/exercise/quiz/', // Bỏ qua tất cả endpoint chứa pattern này
55
'/profile/user/',
66
'/submission/exercise/coding/',
7+
'/notification/',
8+
'/ai/chat/',
79
// Ví dụ pattern regex: /\/submission\/exercise\/quiz\/\d+(\?.*)?$/
810
// Thêm các endpoint khác nếu cần
911
];

src/app/core/services/socket-service/notification-socket.service.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface NotificationEvent {
1414
}
1515

1616
@Injectable({ providedIn: 'root' })
17-
export class NotificationService {
17+
export class NotificationSocketService {
1818
private readonly url = `${NOTIFICATION_SOCKET_PORT}?token=${localStorage.getItem(
1919
'token'
2020
)}`;
@@ -26,4 +26,11 @@ export class NotificationService {
2626
listenNotifications(): Observable<NotificationEvent> {
2727
return this.socketService.on<NotificationEvent>(this.url, 'notification');
2828
}
29+
30+
listenNoticeCount(): Observable<{ unread: number }> {
31+
return this.socketService.on<{ unread: number }>(
32+
this.url,
33+
'notification-unread'
34+
);
35+
}
2936
}

src/app/features/admin/user-management/pages/user-list/user-list.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
[disabled]="false"
2222
[multiSelect]="true"
2323
[isDisplayCheckbox]="false"
24+
[removeSingleSelected]="true"
2425
(onSelect)="handleSelect(filterRoleKey, $event)"
2526
[isOpen]="activeDropdown === filterRoleKey"
2627
(toggle)="toggleDropdown(filterRoleKey)"
2728
[isDisplaySelectedOpptionLabels]="true"
28-
[isButtonControl]="true"
29+
[isButtonControl]="false"
2930
[isSearchable]="true"
3031
[minHeight]="true"
3132
[needIndexColor]="true"
@@ -132,7 +133,7 @@
132133
[amountDataPerPage]="itemsPerPage"
133134
[needNo]="true"
134135
[needDelete]="true"
135-
[needEdit]="true"
136+
[needEdit]="false"
136137
[needViewResult]="false"
137138
[needswitch]="true"
138139
[idSelect]="'userId'"

src/app/features/admin/user-management/pages/user-list/user-list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class UserListComponent {
118118

119119
// Pagination
120120
pageIndex: number = 1;
121-
itemsPerPage: number = 8;
121+
itemsPerPage: number = 10;
122122
totalDatas: number = 0;
123123
sortBy: EnumType['sort'] = 'CREATED_AT';
124124
asc: boolean = false;

src/app/features/organization/pages/org-blocks/org-blocks.component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ export class OrgBlocksComponent implements OnInit {
8686
next: (res) => {
8787
const result = res.result;
8888
this.totalPages = result.totalPages;
89-
this.blocks = loadMore ? [...this.blocks, ...result.data] : result.data;
89+
this.blocks = loadMore
90+
? [
91+
...this.blocks,
92+
...result.data.filter((data) => data.code !== 'UNASSIGNED'),
93+
]
94+
: result.data.filter((data) => data.code !== 'UNASSIGNED');
9095
this.isLoading = false;
9196
},
9297
error: () => (this.isLoading = false),

src/app/features/service-payment/pages/qr-payment/qr-payment.component.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Component, OnInit, OnDestroy } from '@angular/core';
1+
import {
2+
Component,
3+
OnInit,
4+
OnDestroy,
5+
inject,
6+
DestroyRef,
7+
} from '@angular/core';
28
import { Observable, Subscription, interval, of } from 'rxjs';
39

410
import { Store } from '@ngrx/store';
@@ -20,6 +26,7 @@ import {
2026
} from '../../validate/qr-payment.utils';
2127
import { decodeJWT } from '../../../../shared/utils/stringProcess';
2228
import { ModalNoticeService } from '../../../../shared/store/modal-notice-state/modal-notice.service';
29+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
2330

2431
@Component({
2532
selector: 'app-qr-payment',
@@ -29,6 +36,8 @@ import { ModalNoticeService } from '../../../../shared/store/modal-notice-state/
2936
styleUrls: ['./qr-payment.component.scss'],
3037
})
3138
export class QrPaymentComponent implements OnInit, OnDestroy {
39+
private destroyRef = inject(DestroyRef); //ngắt request khi thoát trang (thêm 2 dòng, dòng này và dòng pipe trong service)
40+
3241
amount: number | null = null; // Số tiền VNĐ người dùng nhập
3342
maxAmount: number = 20000000;
3443
qrTimeOut: boolean = true;
@@ -90,15 +99,19 @@ export class QrPaymentComponent implements OnInit, OnDestroy {
9099
this.countdownInterval?.unsubscribe();
91100
}
92101

102+
//có ngắt request khi thoát trang, (còn lại là pipe dưới để ngắt request)
93103
fetchCurrentMoney() {
94-
this.paymentService.getMyWallet().subscribe({
95-
next: (res) => {
96-
this.currentGp = res.result.balance;
97-
},
98-
error(err) {
99-
console.log(err);
100-
},
101-
});
104+
this.paymentService
105+
.getMyWallet()
106+
.pipe(takeUntilDestroyed(this.destroyRef))
107+
.subscribe({
108+
next: (res) => {
109+
this.currentGp = res.result.balance;
110+
},
111+
error(err) {
112+
console.log(err);
113+
},
114+
});
102115
}
103116

104117
paymentFailed() {

src/app/shared/components/my-shared/header/header.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ import { resetVariable } from '../../../store/variable-state/variable.actions';
1313
import { avatarUrlDefault } from '../../../../core/constants/value.constant';
1414
import { SetPasswordModalComponent } from '../../../../features/auth/components/modal/set-password-modal/set-password-modal.component';
1515
import { NotificationModalComponent } from './notification-modal/notification-modal.component';
16-
import {
17-
NotificationEvent,
18-
NotificationService,
19-
} from '../../../../core/services/socket-service/notification-socket.service';
16+
import { NotificationSocketService } from '../../../../core/services/socket-service/notification-socket.service';
2017
import { NotificationListService } from '../../../../core/services/api-service/notification-list.service';
2118

2219
@Component({
@@ -51,7 +48,7 @@ export class HeaderComponent {
5148
private profileService: ProfileService,
5249
private themeService: ThemeService,
5350
private store: Store,
54-
private notificationService: NotificationService,
51+
private notificationService: NotificationSocketService,
5552
private notificationListService: NotificationListService
5653
) {
5754
this.needReloadAvatar$ = this.store.select(
@@ -87,12 +84,12 @@ export class HeaderComponent {
8784

8885
// 👇 Đăng ký lắng nghe notification từ socket
8986
this.notificationService
90-
.listenNotifications()
91-
.subscribe((event: NotificationEvent) => {
92-
console.log('Header nhận notification:', event);
87+
.listenNoticeCount()
88+
.subscribe((event: { unread: number }) => {
89+
console.log('Header nhận count notification:', event.unread);
9390

9491
// Tăng counter
95-
this.notificationCount++;
92+
this.notificationCount = event.unread;
9693

9794
// Nếu muốn push vào modal hoặc show toast
9895
// this.notifications.unshift(event);

0 commit comments

Comments
 (0)