-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add invoice pdf download on purchase lists #1021
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||
| * limitations under the License. | ||||||||||||||||||||||||||||||||||||||||||||||
| * */ | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| import React, { useEffect } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import React, { useEffect, useState } from "react"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { connect } from "react-redux"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import T from "i18n-react/dist/i18n-react"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { Breadcrumb } from "react-breadcrumbs"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -26,18 +26,22 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||
| import DownloadIcon from "@mui/icons-material/Download"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import MuiTable from "openstack-uicore-foundation/lib/components/mui/table"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import SearchInput from "openstack-uicore-foundation/lib/components/mui/search-input"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { useSnackbarMessage } from "openstack-uicore-foundation/lib/components/mui/snackbar-notification"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { generateInvoicePDF } from "openstack-uicore-foundation/lib/components/order-invoice-pdf"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import history from "../../../history"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||
| approveSponsorPurchase, | ||||||||||||||||||||||||||||||||||||||||||||||
| exportAllSponsorPurchases, | ||||||||||||||||||||||||||||||||||||||||||||||
| getAllSponsorPurchases, | ||||||||||||||||||||||||||||||||||||||||||||||
| getSponsorOrder, | ||||||||||||||||||||||||||||||||||||||||||||||
| rejectSponsorPurchase | ||||||||||||||||||||||||||||||||||||||||||||||
| } from "../../../actions/sponsor-purchases-actions"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||||||||||||||||
| DEFAULT_CURRENT_PAGE, | ||||||||||||||||||||||||||||||||||||||||||||||
| PURCHASE_METHODS, | ||||||||||||||||||||||||||||||||||||||||||||||
| PURCHASE_STATUS | ||||||||||||||||||||||||||||||||||||||||||||||
| } from "../../../utils/constants"; | ||||||||||||||||||||||||||||||||||||||||||||||
| import logoInvoice from "../../../assets/fn-invoice-header.png"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const ShowPurchaseListPage = ({ | ||||||||||||||||||||||||||||||||||||||||||||||
| match, | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -49,14 +53,19 @@ const ShowPurchaseListPage = ({ | |||||||||||||||||||||||||||||||||||||||||||||
| perPage, | ||||||||||||||||||||||||||||||||||||||||||||||
| totalCount, | ||||||||||||||||||||||||||||||||||||||||||||||
| getAllSponsorPurchases, | ||||||||||||||||||||||||||||||||||||||||||||||
| getSponsorOrder, | ||||||||||||||||||||||||||||||||||||||||||||||
| exportAllSponsorPurchases, | ||||||||||||||||||||||||||||||||||||||||||||||
| approveSponsorPurchase, | ||||||||||||||||||||||||||||||||||||||||||||||
| rejectSponsorPurchase | ||||||||||||||||||||||||||||||||||||||||||||||
| rejectSponsorPurchase, | ||||||||||||||||||||||||||||||||||||||||||||||
| currentSummit | ||||||||||||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
| getAllSponsorPurchases(); | ||||||||||||||||||||||||||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const { errorMessage } = useSnackbarMessage(); | ||||||||||||||||||||||||||||||||||||||||||||||
| const [loadingPDF, setLoadingPDF] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const handlePageChange = (page) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| getAllSponsorPurchases(term, page, perPage, order, orderDir); | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -87,8 +96,17 @@ const ShowPurchaseListPage = ({ | |||||||||||||||||||||||||||||||||||||||||||||
| history.push(`${item.sponsor_id}/purchases/${item.id}`); | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const handleMenu = (item) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| console.log("MENU : ", item); | ||||||||||||||||||||||||||||||||||||||||||||||
| const handleInvoiceDownload = (purchaseOrder) => { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (loadingPDF) return; | ||||||||||||||||||||||||||||||||||||||||||||||
| setLoadingPDF(true); | ||||||||||||||||||||||||||||||||||||||||||||||
| getSponsorOrder(purchaseOrder.id, purchaseOrder.sponsor_id) | ||||||||||||||||||||||||||||||||||||||||||||||
| .then(({ response: fetchedOrder }) => | ||||||||||||||||||||||||||||||||||||||||||||||
| generateInvoicePDF(fetchedOrder, currentSummit, { | ||||||||||||||||||||||||||||||||||||||||||||||
| logoSrc: logoInvoice | ||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||
| .catch(() => errorMessage(t("errors.invoice_generation"))) | ||||||||||||||||||||||||||||||||||||||||||||||
| .finally(() => setLoadingPDF(false)); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+99
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Use the imported translation instance in the failure handler. Line 108 references undefined - .catch(() => errorMessage(t("errors.invoice_generation")))
+ .catch(() => errorMessage(T.translate("errors.invoice_generation")))📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const handleStatusChange = (sponsorId, purchaseId, newStatus) => { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -184,7 +202,7 @@ const ShowPurchaseListPage = ({ | |||||||||||||||||||||||||||||||||||||||||||||
| <IconButton | ||||||||||||||||||||||||||||||||||||||||||||||
| size="large" | ||||||||||||||||||||||||||||||||||||||||||||||
| sx={{ color: "primary.main" }} | ||||||||||||||||||||||||||||||||||||||||||||||
| onClick={() => handleMenu(row)} | ||||||||||||||||||||||||||||||||||||||||||||||
| onClick={() => handleInvoiceDownload(row)} | ||||||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||||||
| <DownloadIcon fontSize="large" /> | ||||||||||||||||||||||||||||||||||||||||||||||
| </IconButton> | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
202
to
208
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Add an accessible name to both invoice-download buttons. Screen-reader users cannot identify icon-only controls without an
📍 Affects 2 files
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -248,12 +266,14 @@ const ShowPurchaseListPage = ({ | |||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| const mapStateToProps = ({ showPurchaseListState }) => ({ | ||||||||||||||||||||||||||||||||||||||||||||||
| ...showPurchaseListState | ||||||||||||||||||||||||||||||||||||||||||||||
| const mapStateToProps = ({ showPurchaseListState, currentSummitState }) => ({ | ||||||||||||||||||||||||||||||||||||||||||||||
| ...showPurchaseListState, | ||||||||||||||||||||||||||||||||||||||||||||||
| currentSummit: currentSummitState.currentSummit | ||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| export default connect(mapStateToProps, { | ||||||||||||||||||||||||||||||||||||||||||||||
| getAllSponsorPurchases, | ||||||||||||||||||||||||||||||||||||||||||||||
| getSponsorOrder, | ||||||||||||||||||||||||||||||||||||||||||||||
| exportAllSponsorPurchases, | ||||||||||||||||||||||||||||||||||||||||||||||
| approveSponsorPurchase, | ||||||||||||||||||||||||||||||||||||||||||||||
| rejectSponsorPurchase | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Prioritize the explicit purchase sponsor ID.
The global purchase list passes the row’s
purchaseOrder.sponsor_id, but Line 308 ignores it whenever Redux still holds a previously viewed sponsor. That can fetch the order through the wrong sponsor URL. Prefer the explicit argument, with Redux only as the fallback.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents