File tree Expand file tree Collapse file tree 2 files changed +20
-9
lines changed
app/(dashboard)/dashboard/interviews/_components Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ export const ExportInterviewsDialog = ({
75
75
}
76
76
77
77
// Download the zip file
78
- download ( result . data . url , result . data . name ) ;
78
+ await download ( result . data . url , result . data . name ) ;
79
79
} catch ( error ) {
80
80
toast ( {
81
81
icon : < XCircle /> ,
Original file line number Diff line number Diff line change 1
1
import { useCallback } from 'react' ;
2
2
3
3
export const useDownload = ( ) => {
4
- const download = useCallback ( ( url : string , nameWithExtension : string ) => {
5
- const link = document . createElement ( 'a' ) ;
6
- link . href = url ;
7
- link . download = nameWithExtension ;
8
- document . body . appendChild ( link ) ;
9
- link . click ( ) ;
10
- document . body . removeChild ( link ) ;
11
- } , [ ] ) ;
4
+ const download = useCallback (
5
+ async ( url : string , nameWithExtension : string ) => {
6
+ try {
7
+ const response = await fetch ( url ) ;
8
+ const blob = await response . blob ( ) ;
9
+ const blobUrl = URL . createObjectURL ( blob ) ;
10
+ const link = document . createElement ( 'a' ) ;
11
+ link . href = blobUrl ;
12
+ link . download = nameWithExtension ;
13
+ document . body . appendChild ( link ) ;
14
+ link . click ( ) ;
15
+ URL . revokeObjectURL ( blobUrl ) ;
16
+ document . body . removeChild ( link ) ;
17
+ } catch ( error ) {
18
+ throw new Error ( 'Failed to download file' ) ;
19
+ }
20
+ } ,
21
+ [ ] ,
22
+ ) ;
12
23
13
24
return download ;
14
25
} ;
You can’t perform that action at this time.
0 commit comments