Skip to content

Commit

Permalink
add button to download invoice for individual order
Browse files Browse the repository at this point in the history
  • Loading branch information
mbpictures committed Oct 1, 2024
1 parent f0af42f commit ff96c51
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/admin/dialogs/OrderDetailsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { getEventTitle } from "../../../constants/util";
import { ConfirmDialog } from "./ConfirmDialog";
import { useSnackbar } from "notistack";
import axios from "axios";
import { SaveButton } from "../SaveButton";

export const OrderDetailsDialog = ({
order,
Expand Down Expand Up @@ -53,6 +54,12 @@ export const OrderDetailsDialog = ({
}
}

const downloadInvoice = async () => {
const response = await axios.get("/api/admin/order/" + order.id + "/invoice");
const blob = await (await fetch(response.data)).blob()
window.open(URL.createObjectURL(blob));
}

return (
<>
<Dialog open={true} onClose={handleClose} fullWidth>
Expand Down Expand Up @@ -93,6 +100,9 @@ export const OrderDetailsDialog = ({
order.user.customFields && Object.entries(JSON.parse(order.user.customFields)).map(field => `${field[0]}: ${field[1]}`)
}
</Typography>
<SaveButton action={downloadInvoice}>
Download Invoice
</SaveButton>
<Button color={"error"} onClick={() => setDeleteOpen(true)}>
Delete
</Button>
Expand Down

0 comments on commit ff96c51

Please # to comment.