2026-07-13 01:03:26 +03:30
|
|
|
'use client';
|
|
|
|
|
|
2026-07-13 22:53:23 +03:30
|
|
|
import { useEffect } from 'react';
|
2026-07-13 01:03:26 +03:30
|
|
|
import { LabCaseCommentsPanel } from '@/components/ui/lab/LabCaseCommentsPanel';
|
|
|
|
|
import { treatmentsApi } from '@/lib/api/treatments';
|
2026-07-13 22:53:23 +03:30
|
|
|
import { notificationsApi } from '@/lib/api/notifications';
|
|
|
|
|
import { notifyTabBadgesChanged } from '@/lib/tabBadgeUtils';
|
2026-07-13 01:03:26 +03:30
|
|
|
|
|
|
|
|
interface DetailLabCaseCommentsSectionProps {
|
2026-07-13 22:53:23 +03:30
|
|
|
labCaseId: string;
|
2026-07-13 01:03:26 +03:30
|
|
|
canPost: boolean;
|
2026-07-13 22:53:23 +03:30
|
|
|
deferSubmit?: boolean;
|
|
|
|
|
composerValue?: string;
|
|
|
|
|
onComposerValueChange?: (value: string) => void;
|
2026-07-13 01:03:26 +03:30
|
|
|
onError?: (message: string) => void;
|
2026-07-13 22:53:23 +03:30
|
|
|
onMarkRead?: (labCaseId: string) => void;
|
|
|
|
|
onActivityChange?: () => void;
|
2026-07-13 01:03:26 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function DetailLabCaseCommentsSection({
|
2026-07-13 22:53:23 +03:30
|
|
|
labCaseId,
|
2026-07-13 01:03:26 +03:30
|
|
|
canPost,
|
2026-07-13 22:53:23 +03:30
|
|
|
deferSubmit = false,
|
|
|
|
|
composerValue,
|
|
|
|
|
onComposerValueChange,
|
2026-07-13 01:03:26 +03:30
|
|
|
onError,
|
2026-07-13 22:53:23 +03:30
|
|
|
onMarkRead,
|
|
|
|
|
onActivityChange,
|
2026-07-13 01:03:26 +03:30
|
|
|
}: DetailLabCaseCommentsSectionProps) {
|
2026-07-13 22:53:23 +03:30
|
|
|
useEffect(() => {
|
|
|
|
|
if (!labCaseId) return;
|
|
|
|
|
void notificationsApi.markCaseRead(labCaseId).then(() => {
|
|
|
|
|
notifyTabBadgesChanged();
|
|
|
|
|
onMarkRead?.(labCaseId);
|
|
|
|
|
});
|
|
|
|
|
}, [labCaseId, onMarkRead]);
|
2026-07-13 01:03:26 +03:30
|
|
|
|
|
|
|
|
return (
|
2026-07-13 22:53:23 +03:30
|
|
|
<div className="border-t border-border/60 pt-4">
|
2026-07-13 01:03:26 +03:30
|
|
|
<LabCaseCommentsPanel
|
2026-07-13 22:53:23 +03:30
|
|
|
caseId={labCaseId}
|
2026-07-13 01:03:26 +03:30
|
|
|
canPost={canPost}
|
|
|
|
|
canToggleVisibility={false}
|
2026-07-13 22:53:23 +03:30
|
|
|
deferSubmit={deferSubmit}
|
|
|
|
|
composerValue={composerValue}
|
|
|
|
|
onComposerValueChange={onComposerValueChange}
|
2026-07-13 01:03:26 +03:30
|
|
|
loadComments={async () => {
|
2026-07-13 22:53:23 +03:30
|
|
|
const response = await treatmentsApi.listLabCaseComments(labCaseId);
|
2026-07-13 01:03:26 +03:30
|
|
|
return response.data;
|
|
|
|
|
}}
|
|
|
|
|
onPost={async (body) => {
|
2026-07-13 22:53:23 +03:30
|
|
|
const response = await treatmentsApi.addLabCaseComment(labCaseId, { body });
|
|
|
|
|
notifyTabBadgesChanged();
|
|
|
|
|
onActivityChange?.();
|
2026-07-13 01:03:26 +03:30
|
|
|
return response.data;
|
|
|
|
|
}}
|
|
|
|
|
onError={onError}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|