-
Notifications
You must be signed in to change notification settings - Fork 5
/
DownloadTreasuryFiles.tsx
50 lines (45 loc) · 1.4 KB
/
DownloadTreasuryFiles.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import Button from 'react-bootstrap/Button'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
const DOWNLOAD_TREASURY_FILE = gql`
mutation DownloadTreasuryFile($input: DownloadTreasuryFileInput!) {
downloadTreasuryFile(input: $input) {
fileLink
}
}
`
const DownloadTreasuryFiles = () => {
const [downloadTreasuryFile] = useMutation(DOWNLOAD_TREASURY_FILE, {
onCompleted: ({ downloadTreasuryFile }) => {
const { fileLink } = downloadTreasuryFile
window.open(fileLink, '_blank').focus()
},
onError: (error) => {
toast.error(error.message)
},
})
const onClick = (event) => {
downloadTreasuryFile({
variables: { input: { fileType: event.target.getAttribute('name') } },
})
}
return (
<div className="rw-segment">
<div className="rw-button-group">
<Button name="1A" onClick={onClick} className="rw-button">
Download Project 1A file
</Button>
<Button name="1B" onClick={onClick} className="rw-button">
Download Project 1B file
</Button>
<Button name="1C" onClick={onClick} className="rw-button">
Download Project 1C file
</Button>
<Button name="Subrecipient" onClick={onClick} className="rw-button">
Download Subrecipient file
</Button>
</div>
</div>
)
}
export default DownloadTreasuryFiles