improvement: notification feature polished. feature tabs following the same notification socket emmited data to be updated.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
} from '@/components/lab/tasksViewDefaults';
|
||||
import { parseTasksSearchParams } from '@/components/lab/parseTasksSearchParams';
|
||||
import { useMarkTabReadOnVisit } from '@/lib/hooks/useTabBadgeCounts';
|
||||
import { notifyTabBadgesChanged } from '@/lib/tabBadgeUtils';
|
||||
import { notifyTabBadgesChanged, tabBadgesChangedEventName } from '@/lib/tabBadgeUtils';
|
||||
import { scrollWithinMainScrollContainer } from '@/components/shared/scrollWithinMain';
|
||||
import { getUserFacingError } from '@/components/shared/formatApiError';
|
||||
import { canEditTasks, canViewTasks } from '@/components/shared/permissions';
|
||||
@@ -199,17 +199,22 @@ export function TasksPage() {
|
||||
};
|
||||
}, [searchParams, canView]);
|
||||
|
||||
const loadTasks = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
const loadTasks = useCallback(async (options?: { silent?: boolean }) => {
|
||||
const silent = options?.silent ?? false;
|
||||
if (!silent) {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
}
|
||||
try {
|
||||
const response = await tasksApi.list(listParams);
|
||||
setTasks(response.data.items);
|
||||
setPagination(response.data.pagination);
|
||||
} catch (error: unknown) {
|
||||
showError(getUserFacingError(error, tErrors, tRef.current('errorLoadList')));
|
||||
if (!silent) {
|
||||
showError(getUserFacingError(error, tErrors, tRef.current('errorLoadList')));
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
if (!silent) setLoading(false);
|
||||
}
|
||||
}, [listParams, showError, setError, tErrors]);
|
||||
|
||||
@@ -221,6 +226,15 @@ export function TasksPage() {
|
||||
return () => clearTimeout(timeout);
|
||||
}, [canView, loadTasks, search]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!canView) return;
|
||||
const onBadgesChanged = () => {
|
||||
void loadTasks({ silent: true });
|
||||
};
|
||||
window.addEventListener(tabBadgesChangedEventName(), onBadgesChanged);
|
||||
return () => window.removeEventListener(tabBadgesChangedEventName(), onBadgesChanged);
|
||||
}, [canView, loadTasks]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!canView) return;
|
||||
void (async () => {
|
||||
|
||||
Reference in New Issue
Block a user