From dff9013f0903997e718bdb67b445073c1cfe3f45 Mon Sep 17 00:00:00 2001
From: Meis
Date: Thu, 29 Sep 2022 14:23:05 -0600
Subject: [PATCH] WIP - IRS File Proxy redesign
---
src/filing/api/fetch.js | 11 ++--
src/filing/submission/irs/DownloadIRS.jsx | 65 +++++++++++++++++++++++
src/filing/submission/irs/IRSReport.css | 10 ++++
src/filing/submission/irs/index.jsx | 45 +++++++++++-----
4 files changed, 113 insertions(+), 18 deletions(-)
create mode 100644 src/filing/submission/irs/DownloadIRS.jsx
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)}>
+
+
+ {' '}
+ When ready, the IRS will be available for download here.
+
+
+ )
+
+ return (
+
+
+
+
+ )
+}
+
+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 (
@@ -17,18 +40,12 @@ const IRSReport = props => {
will not be available immediately. Please check back shortly after
submitting your data to access your IRS.
-
- 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