Skip to content

Commit

Permalink
fix: Post correct body to download-application endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Jan 24, 2024
1 parent de43957 commit b74a15a
Showing 1 changed file with 8 additions and 4 deletions.
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 {
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

0 comments on commit b74a15a

Please sign in to comment.