@@ -5,7 +5,7 @@ import { SUBMISSION_STATE } from '../../../../types/pages/documentSearchResultsP
55import { useNavigate } from 'react-router-dom' ;
66import getPresignedUrlForZip from '../../../../helpers/requests/getPresignedUrlForZip' ;
77import { AxiosError } from 'axios' ;
8- import { useEffect , useRef , useState } from 'react' ;
8+ import { useEffect , useState } from 'react' ;
99import useBaseAPIHeaders from '../../../../helpers/hooks/useBaseAPIHeaders' ;
1010import useBaseAPIUrl from '../../../../helpers/hooks/useBaseAPIUrl' ;
1111import { errorToParams } from '../../../../helpers/utils/errorToParams' ;
@@ -17,20 +17,10 @@ type Props = {
1717 updateDownloadState : ( newState : SUBMISSION_STATE ) => void ;
1818} ;
1919
20- interface DownloadLinkAttributes {
21- url : string ;
22- filename : string ;
23- }
24-
2520const DocumentSearchResultsOptions = ( props : Props ) : React . JSX . Element => {
2621 const navigate = useNavigate ( ) ;
2722 const baseUrl = useBaseAPIUrl ( ) ;
2823 const baseHeaders = useBaseAPIHeaders ( ) ;
29- const [ linkAttributes , setLinkAttributes ] = useState < DownloadLinkAttributes > ( {
30- url : '' ,
31- filename : '' ,
32- } ) ;
33- const linkRef = useRef < HTMLAnchorElement | null > ( null ) ;
3424 const [ statusMessage , setStatusMessage ] = useState ( '' ) ;
3525 useEffect ( ( ) => {
3626 switch ( props . downloadState ) {
@@ -48,12 +38,6 @@ const DocumentSearchResultsOptions = (props: Props): React.JSX.Element => {
4838 }
4939 } , [ props . downloadState ] ) ;
5040
51- useEffect ( ( ) => {
52- if ( linkRef . current && linkAttributes . url ) {
53- linkRef . current . click ( ) ;
54- }
55- } , [ linkAttributes ] ) ;
56-
5741 const downloadAll = async ( ) : Promise < void > => {
5842 props . updateDownloadState ( SUBMISSION_STATE . PENDING ) ;
5943 try {
@@ -66,7 +50,12 @@ const DocumentSearchResultsOptions = (props: Props): React.JSX.Element => {
6650
6751 const filename = `patient-record-${ props . nhsNumber } ` ;
6852
69- setLinkAttributes ( { url : preSignedUrl , filename : filename } ) ;
53+ const anchor = document . createElement ( 'a' ) ;
54+ anchor . href = preSignedUrl ;
55+ anchor . download = filename ;
56+ document . body . appendChild ( anchor ) ;
57+ anchor . click ( ) ;
58+ anchor . remove ( ) ;
7059
7160 props . updateDownloadState ( SUBMISSION_STATE . SUCCEEDED ) ;
7261 } catch ( e ) {
@@ -101,15 +90,6 @@ const DocumentSearchResultsOptions = (props: Props): React.JSX.Element => {
10190 Download all documents
10291 </ Button >
10392 ) }
104- < a
105- hidden
106- id = "download-link"
107- ref = { linkRef }
108- href = { linkAttributes . url }
109- download = { linkAttributes . filename }
110- >
111- Download Manifest URL
112- </ a >
11393 < Button
11494 className = "nhsuk-button nhsuk-button--secondary left-margin"
11595 data-testid = "delete-all-documents-btn"
0 commit comments