Skip to content
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

fix: Post correct payload to /download-application endpoint #2698

Merged
merged 1 commit into from
Jan 24, 2024
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
12 changes: 8 additions & 4 deletions editor.planx.uk/src/ui/public/FileDownload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ const Root = styled(Box)(({ theme }) => ({
}));

// Render a button which lets the applicant download their application data as a CSV
export default function FileDownload(props: Props): FCReturn {
export default function FileDownload({
data,
filename,
text,
}: Props): FCReturn {
Comment on lines +20 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like how the props are extracted here!

const downloadCsv = (filename: string, content: string) => {
const csv = "data:text/csv;charset=utf-8," + content;
const data = encodeURI(csv);
Expand All @@ -39,15 +43,15 @@ export default function FileDownload(props: Props): FCReturn {
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify(props.data),
body: JSON.stringify({ data }),
})
.then((res) => res.text())
.then((data) => downloadCsv(props.filename, data))
.then((data) => downloadCsv(filename, data))
.catch((error) => console.log(error));
}}
>
<Typography variant="body2">
{props.text || "Download your application (.csv)"}
{text || "Download your application (.csv)"}
</Typography>
</Link>
</Root>
Expand Down
Loading