Skip to content

Commit df5f3b4

Browse files
committed
Add OFX/QFX import to UI
1 parent f2262f3 commit df5f3b4

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

web/src/Accounts.css

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
text-align: right;
2121
}
2222

23-
.accounts .add-new {
23+
.account-actions {
2424
margin-top: 1.5em;
25+
margin-left: 0;
26+
}
27+
28+
.account-actions .btn {
29+
margin-right: 0.5em;
2530
}

web/src/Accounts.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Button from 'react-bootstrap/Button';
88
import Col from 'react-bootstrap/Col';
99
import Container from 'react-bootstrap/Container';
1010
import Crumb from './Breadcrumb';
11+
import ImportAccounts from './ImportAccounts';
1112
import Row from 'react-bootstrap/Row';
1213

1314
export default function Accounts({ match }) {
@@ -67,13 +68,17 @@ export default function Accounts({ match }) {
6768
</Row>
6869
)}
6970
<Row>
70-
<Col><Link to={`${match.url}/new`} className="btn btn-primary add-new">Add new</Link></Col>
71+
<Col className="account-actions">
72+
<Link to={`${match.url}/new`} className="btn btn-primary add-new">Add new</Link>
73+
<Link to={`${match.url}/import`} className="btn btn-secondary import">Import</Link>
74+
</Col>
7175
</Row>
7276
</Container>
7377
</>
7478
} />
7579
<Route path={`${match.path}/edit/:id`} component={props => <AccountEditor updated={accountUpdated} {...props} />} />
7680
<Route path={`${match.path}/new`} component={props => <NewAccount created={accountCreated} {...props} />} />
81+
<Route path={`${match.path}/import`} component={Import} />
7782
</>
7883
)
7984
}
@@ -108,3 +113,12 @@ function AccountEditor({ updated, match }) {
108113
</>
109114
)
110115
}
116+
117+
function Import({ match }) {
118+
return (
119+
<>
120+
<Crumb title="Import" match={match} />
121+
<ImportAccounts />
122+
</>
123+
)
124+
}

web/src/ImportAccounts.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import axios from 'axios';
2+
import React from 'react';
3+
import Button from 'react-bootstrap/Button';
4+
import Col from 'react-bootstrap/Col';
5+
import Container from 'react-bootstrap/Container';
6+
import Form from 'react-bootstrap/Form';
7+
import Row from 'react-bootstrap/Row';
8+
9+
export default function ImportAccounts() {
10+
return (
11+
<Container>
12+
<Row><Col><h2>Import</h2></Col></Row>
13+
<Row>
14+
<Col>
15+
<p>Import OFX or QFX files. Typically, you can download these from your financial institution's "Quicken" or "Microsoft Money" downloads.</p>
16+
</Col>
17+
</Row>
18+
<Form
19+
noValidate
20+
onSubmit={e => {
21+
e.preventDefault()
22+
e.stopPropagation()
23+
const form = e.currentTarget
24+
if (form.checkValidity() !== false) {
25+
const formFiles = form.querySelector('[type=file]')
26+
const files = formFiles.files;
27+
if (files.length !== 1) {
28+
throw Error("Must provide one file to import")
29+
}
30+
axios.post('/api/v1/import', files[0])
31+
.then(() => window.location.reload())
32+
.catch(e => {
33+
if (!e.response.data || !e.response.data.Error) {
34+
throw e
35+
}
36+
alert(e.response.data.Error)
37+
})
38+
}
39+
}}
40+
>
41+
<Form.Row>
42+
<Form.Control type="file" required />
43+
</Form.Row>
44+
&nbsp;
45+
<Form.Row>
46+
<Col><Button type="submit">Import</Button></Col>
47+
</Form.Row>
48+
</Form>
49+
</Container>
50+
)
51+
}

0 commit comments

Comments
 (0)