1
1
import { IonPage , IonContent } from '@ionic/react' ;
2
- import { useState } from 'react' ;
2
+ import { FC , useState } from 'react' ;
3
3
import { useHistory , useParams } from 'react-router-dom' ;
4
4
import './ReportDetailPage.scss' ;
5
- import { useQuery , useQueryClient } from '@tanstack/react-query' ;
5
+ import { useQuery } from '@tanstack/react-query' ;
6
6
import axios from 'axios' ;
7
7
import { MedicalReport } from '../../common/models/medicalReport' ;
8
8
import { useTranslation } from 'react-i18next' ;
9
9
import { getAuthConfig } from 'common/api/reportService' ;
10
- import { useToasts } from 'common/hooks/useToasts' ;
11
10
import AiAssistantNotice from './components/AiAssistantNotice' ;
12
11
import ReportHeader from './components/ReportHeader' ;
13
12
import ReportTabs from './components/ReportTabs' ;
@@ -20,42 +19,47 @@ import { QueryKey } from 'common/utils/constants';
20
19
21
20
const API_URL = import . meta. env . VITE_BASE_URL_API || '' ;
22
21
23
- // Function to fetch report by ID
24
- const fetchReportById = async ( id : string ) : Promise < MedicalReport > => {
25
- const response = await axios . get < MedicalReport > (
26
- `${ API_URL } /api/reports/${ id } ` ,
27
- await getAuthConfig ( ) ,
28
- ) ;
29
- return response . data ;
30
- } ;
31
-
32
22
/**
33
23
* Page component for displaying detailed medical report analysis.
34
24
* This shows AI insights and original report data with flagged values.
35
25
*/
36
- const ReportDetailPage : React . FC = ( ) => {
26
+ const ReportDetailPage : FC = ( ) => {
37
27
const { reportId } = useParams < { reportId : string } > ( ) ;
38
28
const history = useHistory ( ) ;
39
29
const { t } = useTranslation ( ) ;
40
- const { createToast } = useToasts ( ) ;
41
30
const [ isUploadModalOpen , setIsUploadModalOpen ] = useState ( false ) ;
42
- const queryClient = useQueryClient ( ) ;
31
+ const [ activeTab , setActiveTab ] = useState < 'ai' | 'original' > ( 'ai' ) ;
43
32
44
33
const handleUploadComplete = ( ) => {
45
34
setIsUploadModalOpen ( false ) ;
46
35
history . push ( '/tabs/home' ) ;
47
36
} ;
48
37
38
+ // Handle tab selection
39
+ const handleTabChange = ( tab : 'ai' | 'original' ) => {
40
+ setActiveTab ( tab ) ;
41
+ } ;
42
+
43
+ // Function to fetch report by ID
44
+ const fetchReportById = async ( id : string ) : Promise < MedicalReport > => {
45
+ const response = await axios . get < MedicalReport > (
46
+ `${ API_URL } /api/reports/${ id } ` ,
47
+ await getAuthConfig ( ) ,
48
+ ) ;
49
+ return response . data ;
50
+ } ;
51
+
49
52
// Fetch report data using react-query
50
- const { data, isLoading, error } = useQuery < MedicalReport > ( {
53
+ const {
54
+ data : reportData ,
55
+ isLoading,
56
+ error,
57
+ } = useQuery < MedicalReport > ( {
51
58
queryKey : [ QueryKey . ReportDetail , reportId ] ,
52
59
queryFn : ( ) => fetchReportById ( reportId ! ) ,
53
60
enabled : ! ! reportId ,
54
61
} ) ;
55
62
56
- // State to track expanded sections
57
- const [ activeTab , setActiveTab ] = useState < 'ai' | 'original' > ( 'ai' ) ;
58
-
59
63
// Handle loading and error states
60
64
if ( isLoading ) {
61
65
return < IonPage > </ IonPage > ;
@@ -71,7 +75,7 @@ const ReportDetailPage: React.FC = () => {
71
75
) ;
72
76
}
73
77
74
- if ( ! data ) {
78
+ if ( ! reportData ) {
75
79
return (
76
80
< IonPage >
77
81
< IonContent className = "ion-padding" >
@@ -81,77 +85,11 @@ const ReportDetailPage: React.FC = () => {
81
85
) ;
82
86
}
83
87
84
- const reportData = data ;
85
-
86
- // Handle tab selection
87
- const handleTabChange = ( tab : 'ai' | 'original' ) => {
88
- setActiveTab ( tab ) ;
89
- } ;
90
-
91
- // Handle close button
92
- const handleClose = ( ) => {
93
- history . push ( '/tabs/home' ) ;
94
- } ;
95
-
96
- // Handle action buttons
97
- const handleDiscard = async ( setIsProcessing : ( isProcessing : boolean ) => void ) => {
98
- try {
99
- setIsProcessing ( true ) ;
100
- await axios . delete ( `${ API_URL } /api/reports/${ reportId } ` , await getAuthConfig ( ) ) ;
101
- setIsProcessing ( false ) ;
102
-
103
- // Show toast notification
104
- createToast ( {
105
- message : t ( 'report.discard.success' , {
106
- ns : 'reportDetail' ,
107
- defaultValue : 'Report deleted successfully' ,
108
- } ) ,
109
- duration : 2000 ,
110
- } ) ;
111
-
112
- queryClient . invalidateQueries ( { queryKey : [ QueryKey . Reports ] } ) ;
113
- queryClient . invalidateQueries ( { queryKey : [ QueryKey . LatestReports ] } ) ;
114
- queryClient . invalidateQueries ( { queryKey : [ QueryKey . ReportDetail , reportId ] } ) ;
115
-
116
- // Navigate back
117
- history . push ( '/tabs/home' ) ;
118
- } catch ( error ) {
119
- setIsProcessing ( false ) ;
120
-
121
- console . error ( 'Error discarding report:' , error ) ;
122
- createToast ( {
123
- message : t ( 'report.discard.error' , {
124
- ns : 'reportDetail' ,
125
- defaultValue : 'Failed to delete report' ,
126
- } ) ,
127
- duration : 2000 ,
128
- color : 'danger' ,
129
- } ) ;
130
- }
131
- } ;
132
-
133
- const handleNewUpload = async ( setIsProcessing : ( isProcessing : boolean ) => void ) => {
134
- try {
135
- setIsProcessing ( true ) ;
136
- await axios . delete ( `${ API_URL } /api/reports/${ reportId } ` , await getAuthConfig ( ) ) ;
137
- setIsProcessing ( false ) ;
138
-
139
- queryClient . invalidateQueries ( { queryKey : [ QueryKey . Reports ] } ) ;
140
- queryClient . invalidateQueries ( { queryKey : [ QueryKey . LatestReports ] } ) ;
141
- queryClient . invalidateQueries ( { queryKey : [ QueryKey . ReportDetail , reportId ] } ) ;
142
-
143
- setIsUploadModalOpen ( true ) ;
144
- } catch ( error ) {
145
- setIsProcessing ( false ) ;
146
- console . error ( 'Error deleting report before new upload:' , error ) ;
147
- }
148
- } ;
149
-
150
88
return (
151
89
< IonPage className = "report-detail-page" >
152
90
< IonContent fullscreen >
153
91
{ /* Header component */ }
154
- < ReportHeader reportData = { reportData } onClose = { handleClose } />
92
+ < ReportHeader reportData = { reportData } />
155
93
156
94
{ /* Tab selector for AI Insights vs Original Report */ }
157
95
< ReportTabs activeTab = { activeTab } onTabChange = { handleTabChange } />
@@ -172,9 +110,9 @@ const ReportDetailPage: React.FC = () => {
172
110
173
111
{ /* Action buttons at the bottom */ }
174
112
< ActionButtons
175
- onDiscard = { handleDiscard }
176
- onNewUpload = { handleNewUpload }
113
+ reportId = { reportId }
177
114
reportTitle = { reportData . title }
115
+ setIsUploadModalOpen = { setIsUploadModalOpen }
178
116
/>
179
117
180
118
< UploadModal
0 commit comments