Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"moment-duration-format": "^2.3.2",
"moment-timezone": "^0.5.33",
"mui-color-input": "^9.0.0",
"openstack-uicore-foundation": "5.0.43",
"openstack-uicore-foundation": "5.0.46-beta.2",
"p-limit": "^6.1.0",
"path-browserify": "^1.0.1",
"postcss-loader": "^6.2.1",
Expand Down Expand Up @@ -180,7 +180,7 @@
"src/**/*.{js,jsx,mjs}"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/src/__mocks__/fileMock.js",
"\\.(css)$": "identity-obj-proxy"
},
"transformIgnorePatterns": [
Expand Down
48 changes: 26 additions & 22 deletions src/actions/sponsor-purchases-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,29 +297,33 @@ export const rejectSponsorPurchase =
});
};

export const getSponsorOrder = (orderId) => async (dispatch, getState) => {
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const { entity: sponsor } = currentSponsorState;
const accessToken = await getAccessTokenSafely();

dispatch(startLoading());

const params = {
access_token: accessToken,
expand:
"forms,forms.items,forms.items.meta_fields,forms.items.type,refunds,payments,notes,fees"
};
export const getSponsorOrder =
(orderId, sponsorId = null) =>
async (dispatch, getState) => {
const { currentSummitState, currentSponsorState } = getState();
const { currentSummit } = currentSummitState;
const { entity: sponsor } = currentSponsorState;
const accessToken = await getAccessTokenSafely();

return getRequest(
null,
createAction(RECEIVE_SPONSOR_ORDER),
`${window.PURCHASES_API_URL}/api/v2/summits/${currentSummit.id}/sponsors/${sponsor.id}/purchases/${orderId}`,
authErrorHandler
)(params)(dispatch).finally(() => {
dispatch(stopLoading());
});
};
const sponsor_id = sponsorId || (sponsor && sponsor.id);

dispatch(startLoading());

const params = {
access_token: accessToken,
expand:
"forms,forms.items,forms.items.meta_fields,forms.items.type,refunds,payments,notes,fees"
};

return getRequest(
null,
createAction(RECEIVE_SPONSOR_ORDER),
`${window.PURCHASES_API_URL}/api/v2/summits/${currentSummit.id}/sponsors/${sponsor_id}/purchases/${orderId}`,
authErrorHandler
)(params)(dispatch).finally(() => {
dispatch(stopLoading());
});
};

export const clearSponsorOrder = () => async (dispatch) => {
dispatch(createAction(CLEAR_SPONSOR_ORDER)({}));
Expand Down
Binary file added src/assets/fn-invoice-header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"entity_not_found": "The entity you are looking for was not found.",
"maximum_files": "Maximum number of files has been reached",
"payment_profile_not_found_title": "Payment Profile not found",
"payment_profile_not_found": "Missing payment profile for summit {{summitName}}. Please contact support."
"payment_profile_not_found": "Missing payment profile for summit {{summitName}}. Please contact support.",
"invoice_generation": "Invoice could not be generated. Please contact support."
},
"general": {
"summit": "Event",
Expand Down Expand Up @@ -61,6 +62,7 @@
"save_and_publish": "Save & Publish",
"save_and_add_next": "Save & Add Next",
"export": "Export",
"download_invoice": "Download Invoice",
"are_you_sure": "Are you sure?",
"yes_delete": "Yes, delete.",
"yes_remove": "Yes, remove.",
Expand Down
36 changes: 29 additions & 7 deletions src/pages/sponsors/show-purchase-list-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -26,18 +26,23 @@ 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 { normalizeOrder } from "../sponsor-page/utils";
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,
Expand All @@ -49,14 +54,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);
};
Expand Down Expand Up @@ -87,8 +97,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(normalizeOrder(fetchedOrder), currentSummit, {
logoSrc: logoInvoice
})
)
.catch(() => errorMessage(T.translate("errors.invoice_generation")))
.finally(() => setLoadingPDF(false));
};

const handleStatusChange = (sponsorId, purchaseId, newStatus) => {
Expand Down Expand Up @@ -184,7 +203,8 @@ const ShowPurchaseListPage = ({
<IconButton
size="large"
sx={{ color: "primary.main" }}
onClick={() => handleMenu(row)}
onClick={() => handleInvoiceDownload(row)}
aria-label={T.translate("general.download_invoice")}
>
<DownloadIcon fontSize="large" />
</IconButton>
Expand Down Expand Up @@ -248,12 +268,14 @@ const ShowPurchaseListPage = ({
);
};

const mapStateToProps = ({ showPurchaseListState }) => ({
...showPurchaseListState
const mapStateToProps = ({ showPurchaseListState, currentSummitState }) => ({
...showPurchaseListState,
currentSummit: currentSummitState.currentSummit
});

export default connect(mapStateToProps, {
getAllSponsorPurchases,
getSponsorOrder,
exportAllSponsorPurchases,
approveSponsorPurchase,
rejectSponsorPurchase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ jest.mock("../../../../../../actions/sponsor-purchases-actions", () => ({
rejectSponsorPurchase: jest.fn(() => () => Promise.resolve())
}));

jest.mock(
"openstack-uicore-foundation/lib/components/mui/snackbar-notification",
() => ({
useSnackbarMessage: () => ({ errorMessage: jest.fn() })
})
);

/**
* SearchInput mock: plain <input> that fires onSearch on Enter key,
* matching the real component behaviour without TextField overhead.
Expand Down Expand Up @@ -87,6 +94,9 @@ const createInitialState = (overrides = {}) => {
sponsorPagePurchaseListState: state,
currentSponsorState: {
entity: { id: 123 }
},
currentSummitState: {
currentSummit: { id: 1 }
}
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -25,17 +25,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 { normalizeOrder } from "../../utils";
import {
approveSponsorPurchase,
getSponsorPurchases,
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 SponsorPurchasesTab = ({
sponsor,
Expand All @@ -46,14 +51,19 @@ const SponsorPurchasesTab = ({
currentPage,
perPage,
totalCount,
currentSummit,
getSponsorPurchases,
getSponsorOrder,
approveSponsorPurchase,
rejectSponsorPurchase
}) => {
useEffect(() => {
getSponsorPurchases();
}, [sponsor?.id]);

const { errorMessage } = useSnackbarMessage();
const [loadingPDF, setLoadingPDF] = useState(false);

const handlePageChange = (page) => {
getSponsorPurchases(term, page, perPage, order, orderDir);
};
Expand All @@ -80,8 +90,17 @@ const SponsorPurchasesTab = ({
history.push(`purchases/${item.id}`);
};

const handleMenu = (item) => {
console.log("MENU : ", item);
const handleInvoiceDownload = (item) => {
if (loadingPDF) return;
setLoadingPDF(true);
getSponsorOrder(item.id, sponsor.id)
.then(({ response: fetchedOrder }) =>
generateInvoicePDF(normalizeOrder(fetchedOrder), currentSummit, {
logoSrc: logoInvoice
})
)
.catch(() => errorMessage(T.translate("errors.invoice_generation")))
.finally(() => setLoadingPDF(false));
};

const handleStatusChange = (purchaseId, newStatus) => {
Expand Down Expand Up @@ -167,7 +186,8 @@ const SponsorPurchasesTab = ({
<IconButton
size="large"
sx={{ color: "primary.main" }}
onClick={() => handleMenu(row)}
onClick={() => handleInvoiceDownload(row)}
aria-label={T.translate("general.download_invoice")}
>
<DownloadIcon fontSize="large" />
</IconButton>
Expand Down Expand Up @@ -218,14 +238,17 @@ const SponsorPurchasesTab = ({

const mapStateToProps = ({
sponsorPagePurchaseListState,
currentSponsorState
currentSponsorState,
currentSummitState
}) => ({
...sponsorPagePurchaseListState,
sponsor: currentSponsorState.entity
sponsor: currentSponsorState.entity,
currentSummit: currentSummitState.currentSummit
});

export default connect(mapStateToProps, {
getSponsorPurchases,
getSponsorOrder,
approveSponsorPurchase,
rejectSponsorPurchase
})(SponsorPurchasesTab);
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9068,10 +9068,10 @@ open@^10.0.3:
is-inside-container "^1.0.0"
wsl-utils "^0.1.0"

openstack-uicore-foundation@5.0.43:
version "5.0.43"
resolved "https://registry.yarnpkg.com/openstack-uicore-foundation/-/openstack-uicore-foundation-5.0.43.tgz#a0f870bd2d1dd7a97a1b6e78009b5248ca27baab"
integrity sha512-UBIENc7nEhhKEsmaGRKdEIziNhnGypy5bf9ydssEgFB/Fe6Q6gH07x1U8m5s1nXYV9OCneMvLTBH98tprUXlOg==
openstack-uicore-foundation@5.0.46-beta.2:
version "5.0.46-beta.2"
resolved "https://registry.yarnpkg.com/openstack-uicore-foundation/-/openstack-uicore-foundation-5.0.46-beta.2.tgz#14ef22899ebb91c54e265c9dbebf90ca682c6951"
integrity sha512-IhNOFYCNQIiqgxc7iMru0AnPZkV2MRjC+kt3jWiIDGtn5zCUbXQ5QJ8ipGNDJaLCzHILNd5J2Wdr6JXiETY7YA==
dependencies:
use-sync-external-store "^1.6.0"

Expand Down
Loading