Skip to content

Commit b8b11d9

Browse files
author
Laurie T. Malau
committed
Download instead of view account statement
1 parent 94f3b38 commit b8b11d9

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

components/dashboard/src/admin/UserDetail.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ export default function UserDetail(p: { user: User }) {
8686
const flags = getFlags(user, updateUser);
8787
const rop = getRopEntries(user, updateUser);
8888

89+
const downloadAccountStatement = async () => {
90+
if (!accountStatement) {
91+
return;
92+
}
93+
try {
94+
const blob = new Blob([JSON.stringify(accountStatement)], { type: 'application/json' });
95+
const fileDownloadUrl = URL.createObjectURL(blob);
96+
const link = document.createElement('a');
97+
link.href = fileDownloadUrl;
98+
link.setAttribute('download', 'AccountStatement.json');
99+
document.body.appendChild(link);
100+
link.click();
101+
} catch (error) {
102+
console.error(`Error downloading account statement `, error);
103+
}
104+
}
105+
89106
return <>
90107
<PageWithSubMenu subMenu={adminMenu} title="Users" subtitle="Search and manage all users.">
91108
<div className="flex">
@@ -106,8 +123,8 @@ export default function UserDetail(p: { user: User }) {
106123
<Property name="Remaining Hours"
107124
actions={
108125
accountStatement && [{
109-
label: 'View Account Statement',
110-
onClick: () => setViewAccountStatement(true)
126+
label: 'Download Account Statement',
127+
onClick: () => downloadAccountStatement()
111128
}, {
112129
label: 'Grant 20 Extra Hours',
113130
onClick: async () => {
@@ -176,15 +193,6 @@ export default function UserDetail(p: { user: User }) {
176193
}
177194
</div>
178195
</Modal>
179-
<Modal visible={viewAccountStatement} onClose={() => setViewAccountStatement(false)} title="Edit Roles" buttons={[
180-
<button className="secondary" onClick={() => setViewAccountStatement(false)}>Done</button>
181-
]}>
182-
<div className="flex flex-col">
183-
{
184-
JSON.stringify(accountStatement, null, ' ')
185-
}
186-
</div>
187-
</Modal>
188196
</>;
189197
}
190198

0 commit comments

Comments
 (0)