11import React , { useState } from 'react' ;
22import { useTranslation } from 'react-i18next' ;
3- import axios from 'axios' ;
4- import { getAuthConfig } from 'common/api/reportService' ;
53import ConfirmationModal from '../../../common/components/Modal/ConfirmationModal' ;
64
7- const API_URL = import . meta. env . VITE_BASE_URL_API || '' ;
8-
95interface ActionButtonsProps {
10- onDiscard : ( ) => void ;
11- onNewUpload : ( ) => void ;
6+ onDiscard : ( setIsProcessing : ( isProcessing : boolean ) => void ) => Promise < void > ;
7+ onNewUpload : ( setIsProcessing : ( isProcessing : boolean ) => void ) => Promise < void > ;
128 reportTitle ?: string ;
139 reportId ?: string ;
1410}
@@ -17,20 +13,20 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
1713 onDiscard,
1814 onNewUpload,
1915 reportTitle = '' ,
20- reportId,
2116} ) => {
2217 const { t } = useTranslation ( ) ;
2318 const [ showConfirmDiscard , setShowConfirmDiscard ] = useState ( false ) ;
2419 const [ showConfirmNewUpload , setShowConfirmNewUpload ] = useState ( false ) ;
25- const [ isDeleting , setIsDeleting ] = useState ( false ) ;
20+ const [ isProcessing , setIsProcessing ] = useState ( false ) ;
2621
2722 const handleDiscardClick = ( ) => {
2823 setShowConfirmDiscard ( true ) ;
2924 } ;
3025
31- const handleConfirmDiscard = ( ) => {
26+ const handleConfirmDiscard = async ( ) => {
3227 setShowConfirmDiscard ( false ) ;
33- onDiscard ( ) ;
28+
29+ await onDiscard ( setIsProcessing ) ;
3430 } ;
3531
3632 const handleCancelDiscard = ( ) => {
@@ -44,22 +40,7 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
4440 const handleConfirmNewUpload = async ( ) => {
4541 setShowConfirmNewUpload ( false ) ;
4642
47- // If we have a reportId, delete the current report before going to upload screen
48- if ( reportId ) {
49- try {
50- setIsDeleting ( true ) ;
51- await axios . delete ( `${ API_URL } /api/reports/${ reportId } ` , await getAuthConfig ( ) ) ;
52- } catch ( error ) {
53- console . error ( 'Error deleting report before new upload:' , error ) ;
54- } finally {
55- setIsDeleting ( false ) ;
56- // Even if delete failed, still go to upload screen
57- onNewUpload ( ) ;
58- }
59- } else {
60- // If no reportId, just navigate to upload
61- onNewUpload ( ) ;
62- }
43+ await onNewUpload ( setIsProcessing ) ;
6344 } ;
6445
6546 const handleCancelNewUpload = ( ) => {
@@ -72,14 +53,14 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
7253 < button
7354 className = "report-detail-page__action-button report-detail-page__action-button--discard"
7455 onClick = { handleDiscardClick }
75- disabled = { isDeleting }
56+ disabled = { isProcessing }
7657 >
7758 { t ( 'report.action.discard' , { ns : 'reportDetail' } ) }
7859 </ button >
7960 < button
8061 className = "report-detail-page__action-button report-detail-page__action-button--upload"
8162 onClick = { handleNewUploadClick }
82- disabled = { isDeleting }
63+ disabled = { isProcessing }
8364 >
8465 { t ( 'report.action.new-upload' , { ns : 'reportDetail' } ) }
8566 </ button >
0 commit comments