Skip to content

Download instead of view account statement #7633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions components/dashboard/src/admin/UserDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default function UserDetail(p: { user: User }) {
const [activity, setActivity] = useState(false);
const [user, setUser] = useState(p.user);
const [accountStatement, setAccountStatement] = useState<AccountStatement>();
const [viewAccountStatement, setViewAccountStatement] = useState(false);
const [isStudent, setIsStudent] = useState<boolean>();
const [editFeatureFlags, setEditFeatureFlags] = useState(false);
const [editRoles, setEditRoles] = useState(false);
Expand Down Expand Up @@ -86,6 +85,23 @@ export default function UserDetail(p: { user: User }) {
const flags = getFlags(user, updateUser);
const rop = getRopEntries(user, updateUser);

const downloadAccountStatement = async () => {
if (!accountStatement) {
return;
}
try {
const blob = new Blob([JSON.stringify(accountStatement)], { type: 'application/json' });
const fileDownloadUrl = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = fileDownloadUrl;
link.setAttribute('download', 'AccountStatement.json');
document.body.appendChild(link);
link.click();
} catch (error) {
console.error(`Error downloading account statement `, error);
}
}

return <>
<PageWithSubMenu subMenu={adminMenu} title="Users" subtitle="Search and manage all users.">
<div className="flex">
Expand All @@ -106,8 +122,8 @@ export default function UserDetail(p: { user: User }) {
<Property name="Remaining Hours"
actions={
accountStatement && [{
label: 'View Account Statement',
onClick: () => setViewAccountStatement(true)
label: 'Download Account Statement',
onClick: () => downloadAccountStatement()
}, {
label: 'Grant 20 Extra Hours',
onClick: async () => {
Expand Down Expand Up @@ -176,15 +192,6 @@ export default function UserDetail(p: { user: User }) {
}
</div>
</Modal>
<Modal visible={viewAccountStatement} onClose={() => setViewAccountStatement(false)} title="Edit Roles" buttons={[
<button className="secondary" onClick={() => setViewAccountStatement(false)}>Done</button>
]}>
<div className="flex flex-col">
{
JSON.stringify(accountStatement, null, ' ')
}
</div>
</Modal>
</>;
}

Expand Down