diff --git a/src/filing/api/fetch.js b/src/filing/api/fetch.js index 9f06fcb9e..d65075be5 100644 --- a/src/filing/api/fetch.js +++ b/src/filing/api/fetch.js @@ -27,7 +27,8 @@ export function fetchData(options = { method: 'GET' }) { options.querystring = createQueryString(options.params) } - const url = makeUrl(options) + const url = options.url || makeUrl(options) + if (typeof options.body === 'object' && !isFormData) options.body = JSON.stringify(options.body) @@ -60,10 +61,12 @@ export function fetchData(options = { method: 'GET' }) { } return fetch(url, fetchOptions) - .then(response => { - return new Promise(resolve => { - log('got res', response, response.status) + .then(response => { + return new Promise(resolve => { if (response.status === 401 || response.status === 403) login() + if (fetchOptions.method === 'HEAD') { + return resolve(response.status === 200) // 304? + } if (response.status > 399) return resolve(response) if (options.params && options.params.format === 'csv') { return resolve(response.text()) diff --git a/src/filing/submission/irs/DownloadIRS.jsx b/src/filing/submission/irs/DownloadIRS.jsx new file mode 100644 index 000000000..03f695c89 --- /dev/null +++ b/src/filing/submission/irs/DownloadIRS.jsx @@ -0,0 +1,65 @@ +import { fetchData } from '../../api/fetch.js' +import { IRS } from '../../../common/s3/fileProxy.js' +import FileSaver from 'file-saver' +import { GoCloudDownload } from 'react-icons/go' +import { IoWarningOutline } from 'react-icons/io5' + +/** + * Download an Institution's IRS file (CSV) + * @param {String} period YearQuarter + * @param {String} lei Institution identifier + */ +const download = (period, lei) => { + const options = { + url: IRS.buildURL(period, lei), + params: { + format: 'csv', + }, + } + + // Endpoint requires Authentication and the fetchData method encapsulates that + fetchData(options).then(data => { + console.log('Response: ', data) + + if (data && typeof data !== 'object') { + console.log('Saving file!') + FileSaver.saveAs( + new Blob([data], { type: 'text/csv;charset=utf-16' }), + `${period}-${lei}-nationwide-irs.csv` + ) + } + }) +} + +const DownloadIRS = ({ period, lei, isReady, setIrsReady }) => { + if (!isReady) return ( +
setIrsReady(true)}>
+
+ + +
+ ) +} + +export default DownloadIRS \ No newline at end of file diff --git a/src/filing/submission/irs/IRSReport.css b/src/filing/submission/irs/IRSReport.css index afb4a9af9..fed29484d 100644 --- a/src/filing/submission/irs/IRSReport.css +++ b/src/filing/submission/irs/IRSReport.css @@ -50,3 +50,13 @@ .IRSReport button:hover { color: #205493; } + +.IRSReport .download-irs { + display: flex; + align-items: center; +} + +.IRSReport .flex-inline { + display:flex; + flex-direction: row; +} diff --git a/src/filing/submission/irs/index.jsx b/src/filing/submission/irs/index.jsx index 6c9054ecf..d4e64687d 100644 --- a/src/filing/submission/irs/index.jsx +++ b/src/filing/submission/irs/index.jsx @@ -1,11 +1,34 @@ -import React from 'react' import PropTypes from 'prop-types' +import React, { useEffect, useState } from 'react' import { isBeta } from '../../../common/Beta.jsx' +import { IRS } from '../../../common/s3/fileProxy.js' +import DownloadIRS from './DownloadIRS.jsx' +import { fetchData } from '../../api/fetch.js' import './IRSReport.css' +// Check if IRS file exists +// TODO: Needs Proxy service to support HEAD +const checkStatusIRS = (period, lei, handleResponse) => { + const options = { + method: 'HEAD', + url: IRS.buildURL(period, lei), + } + + fetchData(options).then(data => { + console.log('checkStatusIRS Response: ', data) + handleResponse(data) + }) +} + const IRSReport = props => { - const filingPeriod=props.filingPeriod + const filingPeriod = props.filingPeriod + const [irsReady, setIrsReady] = useState(false) + + useEffect(() => { + checkStatusIRS(filingPeriod, props.lei, setIrsReady) + }, []) + if(isBeta()) return null return (- When ready, the IRS will be available for{' '} - - download here - - . -
+Loan amounts in the IRS are binned and disclosed in accordance with the 2018 HMDA data publication policy guidance. An overview