From 3342ef52b1d3246abfd14b5ab0cb8524a85b06ab Mon Sep 17 00:00:00 2001 From: IrfanUddinAhmad Date: Mon, 10 Jul 2023 17:24:54 +0500 Subject: [PATCH] feat: ENT-7309 Added budget category based page for learner credit --- .../learner-credit-management/BudgetCard.jsx | 127 ++++++++++++++++++ .../MultipleBudgetsPage.jsx | 76 +++++++++++ .../MultipleBudgetsPicker.jsx | 42 ++++++ 3 files changed, 245 insertions(+) create mode 100644 src/components/learner-credit-management/BudgetCard.jsx create mode 100644 src/components/learner-credit-management/MultipleBudgetsPage.jsx create mode 100644 src/components/learner-credit-management/MultipleBudgetsPicker.jsx diff --git a/src/components/learner-credit-management/BudgetCard.jsx b/src/components/learner-credit-management/BudgetCard.jsx new file mode 100644 index 0000000000..4dd80977ec --- /dev/null +++ b/src/components/learner-credit-management/BudgetCard.jsx @@ -0,0 +1,127 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import moment from 'moment'; +import { Link } from 'react-router-dom'; +import { + Card, + Button, + Stack, + Row, + Col, +} from '@edx/paragon'; + +import classNames from 'classnames'; +import { useOfferSummary } from './data/hooks'; + +const BudgetCard = ({ + offer, + enterpriseUUID, + createActions, +}) => { + const { + name, + start, + end, + } = offer; + + const { + isLoading: isLoadingOfferSummary, + offerSummary, + } = useOfferSummary(enterpriseUUID, offer); + + const formattedStartDate = moment(start).format('MMMM D, YYYY'); + const formattedExpirationDate = moment(end).format('MMMM D, YYYY'); + + const renderActions = () => { + const actions = createActions?.(offer) || []; + + if (actions.length === 0) { + return null; + } + + return actions.map(action => ( + + )); + }; + + const renderCardHeader = () => { + const subtitle = ( +
+ + {formattedStartDate} - {formattedExpirationDate} + +
+ ); + + return ( + + {renderActions()} + + )} + /> + ); + }; + + const renderCardSection = () => { + + return ( + + + + Available + {offerSummary?.remainingFunds} + + + Spent + {offerSummary?.redeemedFunds} + + + + ); + }; + + return ( + + + + {renderCardHeader()} + {renderCardSection()} + + + + ); +}; + +BudgetCard.defaultProps = { + createActions: null, +}; + +BudgetCard.propTypes = { + offer: PropTypes.shape({ + id: PropTypes.string.isRequired, + name: PropTypes.string.isRequired, + start: PropTypes.string.isRequired, + end: PropTypes.string.isRequired, + }).isRequired, + enterpriseUUID: PropTypes.string.isRequired, + createActions: PropTypes.func, +}; + +export default BudgetCard; diff --git a/src/components/learner-credit-management/MultipleBudgetsPage.jsx b/src/components/learner-credit-management/MultipleBudgetsPage.jsx new file mode 100644 index 0000000000..3141109172 --- /dev/null +++ b/src/components/learner-credit-management/MultipleBudgetsPage.jsx @@ -0,0 +1,76 @@ +import React, { useContext } from 'react'; +import PropTypes from 'prop-types'; +import { + Row, + Col, + Card, + Hyperlink, +} from '@edx/paragon'; +import { connect } from 'react-redux'; + +import LoadingMessage from '../LoadingMessage'; +import MultipleBudgetsPicker from './MultipleBudgetsPicker'; +import { EnterpriseSubsidiesContext } from '../EnterpriseSubsidiesContext'; + +import { configuration } from '../../config'; + +const MultipleBudgetsPage = ({ + enterpriseUUID, + createActions, +}) => { + const { offers, isLoading } = useContext(EnterpriseSubsidiesContext); + + if (isLoading) { + return ; + } + + if (offers.length === 0) { + return ( + + + + +

No budgets for your organization

+

+ We were unable to find any budgets for your organization. Please contact + Customer Support if you have questions. +

+ + Contact support + + +
+
+
+ ); + } + + return ( + <> + + + ); +}; + +const mapStateToProps = state => ({ + enterpriseUUID: state.portalConfiguration.enterpriseId, +}); + +MultipleBudgetsPage.defaultProps = { + createActions: null, +}; + +MultipleBudgetsPage.propTypes = { + enterpriseUUID: PropTypes.string.isRequired, + createActions: PropTypes.func, +}; + +export default connect(mapStateToProps)(MultipleBudgetsPage); diff --git a/src/components/learner-credit-management/MultipleBudgetsPicker.jsx b/src/components/learner-credit-management/MultipleBudgetsPicker.jsx new file mode 100644 index 0000000000..aaf6cab967 --- /dev/null +++ b/src/components/learner-credit-management/MultipleBudgetsPicker.jsx @@ -0,0 +1,42 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { + Row, + Col, +} from '@edx/paragon'; + +import BudgetCard from './BudgetCard'; + +const MultipleBudgetPicker = ({ + offers, + enterpriseUUID, + createActions, +}) => ( + + +

Budgets

+ + + {offers.map(offer => ( + + ))} + +
+); + +MultipleBudgetsPicker.defaultProps = { + createActions: null, +}; + +MultipleBudgetsPicker.propTypes = { + offers: PropTypes.arrayOf(PropTypes.shape()).isRequired, + enterpriseUUID: PropTypes.string.isRequired, + createActions: PropTypes.func, +}; + +export default MultipleBudgetsPicker;