improvement: notification feature polished. feature tabs following the same notification socket emmited data to be updated.

This commit is contained in:
2026-07-18 16:57:13 +03:30
parent 9f6ec193d2
commit 9941dca849
23 changed files with 506 additions and 63 deletions

View File

@@ -16,7 +16,7 @@ import {
} from '@/components/lab/caseDetailUtils';
import { LabCaseDueDateBadge } from '@/components/lab/LabCaseDueDateBadge';
import { notificationsApi } from '@/lib/api/notifications';
import { notifyTabBadgesChanged } from '@/lib/tabBadgeUtils';
import { notifyTabBadgesChanged, tabBadgesChangedEventName } from '@/lib/tabBadgeUtils';
import { casesApi } from '@/lib/api/cases';
import { tasksApi } from '@/lib/api/tasks';
import { prosthesisCatalogApi } from '@/lib/api/prosthesis-catalog';
@@ -106,16 +106,22 @@ export function CasesPage() {
search.trim() || clinicId || prosthesisTypeCode || sentFrom || sentTo,
);
const loadCases = async (params: {
q: string;
clinicOrganizationId: string;
prosthesisTypeCode: string;
sentFrom: string;
sentTo: string;
page: number;
}) => {
setLoadingList(true);
toast.setError('');
const loadCases = async (
params: {
q: string;
clinicOrganizationId: string;
prosthesisTypeCode: string;
sentFrom: string;
sentTo: string;
page: number;
},
options?: { silent?: boolean },
) => {
const silent = options?.silent ?? false;
if (!silent) {
setLoadingList(true);
toast.setError('');
}
try {
const response = await casesApi.list({
q: params.q.trim() || undefined,
@@ -129,9 +135,11 @@ export function CasesPage() {
setCases(response.data.items);
setPagination(response.data.pagination);
} catch (error: unknown) {
toast.showError(getUserFacingError(error, tErrors, t('errorLoadList')));
if (!silent) {
toast.showError(getUserFacingError(error, tErrors, t('errorLoadList')));
}
} finally {
setLoadingList(false);
if (!silent) setLoadingList(false);
}
};
@@ -213,6 +221,28 @@ export function CasesPage() {
// eslint-disable-next-line react-hooks/exhaustive-deps -- debounced search + filter reload
}, [search, clinicId, prosthesisTypeCode, sentFrom, sentTo, page]);
useEffect(() => {
const onBadgesChanged = () => {
void loadCases(
{
q: search,
clinicOrganizationId: clinicId,
prosthesisTypeCode,
sentFrom,
sentTo,
page,
},
{ silent: true },
);
if (selectedCaseId) {
void loadDetail(selectedCaseId, { silent: true });
}
};
window.addEventListener(tabBadgesChangedEventName(), onBadgesChanged);
return () => window.removeEventListener(tabBadgesChangedEventName(), onBadgesChanged);
// eslint-disable-next-line react-hooks/exhaustive-deps -- soft refresh from live inbox socket
}, [search, clinicId, prosthesisTypeCode, sentFrom, sentTo, page, selectedCaseId]);
useEffect(() => {
if (!selectedCaseId) {
setMobileDetailOpen(false);