-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ENT-7309 Added budget category based page for learner credit
- Loading branch information
IrfanUddinAhmad
committed
Jul 11, 2023
1 parent
8edb622
commit 3342ef5
Showing
3 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
src/components/learner-credit-management/BudgetCard.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 => ( | ||
<Button | ||
key={action.to} | ||
variant={action.variant} | ||
as={Link} | ||
to={action.to} | ||
> | ||
{action.buttonText} | ||
</Button> | ||
)); | ||
}; | ||
|
||
const renderCardHeader = () => { | ||
const subtitle = ( | ||
<div className="d-flex flex-wrap align-items-center"> | ||
<span> | ||
{formattedStartDate} - {formattedExpirationDate} | ||
</span> | ||
</div> | ||
); | ||
|
||
return ( | ||
<Card.Header | ||
title={name} | ||
subtitle={subtitle} | ||
actions={( | ||
<div> | ||
{renderActions()} | ||
</div> | ||
)} | ||
/> | ||
); | ||
}; | ||
|
||
const renderCardSection = () => { | ||
Check failure on line 76 in src/components/learner-credit-management/BudgetCard.jsx GitHub Actions / tests (16, 8.5.x)
Check failure on line 76 in src/components/learner-credit-management/BudgetCard.jsx GitHub Actions / tests (16, 8.5.x)
|
||
|
||
return ( | ||
<Card.Section | ||
title="Balance" | ||
muted | ||
> | ||
<Row className="d-flex flex-row justify-content-between w-md-75"> | ||
<Col xs="6" md="auto" className="d-flex flex-column mb-3 mb-md-0"> | ||
<span className="small">Available</span> | ||
<span>{offerSummary?.remainingFunds}</span> | ||
</Col> | ||
<Col xs="6" md="auto" className="d-flex flex-column mb-3 mb-md-0"> | ||
<span className="small">Spent</span> | ||
<span>{offerSummary?.redeemedFunds}</span> | ||
</Col> | ||
</Row> | ||
</Card.Section> | ||
); | ||
}; | ||
|
||
return ( | ||
<Card | ||
orientation="horizontal" | ||
className={classNames('budget-card', className)} | ||
> | ||
<Card.Body> | ||
<Stack gap={4}> | ||
{renderCardHeader()} | ||
{renderCardSection()} | ||
</Stack> | ||
</Card.Body> | ||
</Card> | ||
); | ||
}; | ||
|
||
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; |
76 changes: 76 additions & 0 deletions
76
src/components/learner-credit-management/MultipleBudgetsPage.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <LoadingMessage className="offers" />; | ||
} | ||
|
||
if (offers.length === 0) { | ||
return ( | ||
<Card> | ||
<Card.Section className="text-center"> | ||
<Row> | ||
<Col xs={12} lg={{ span: 8, offset: 2 }}> | ||
<h3 className="mb-3">No budgets for your organization</h3> | ||
<p> | ||
We were unable to find any budgets for your organization. Please contact | ||
Customer Support if you have questions. | ||
</p> | ||
<Hyperlink | ||
className="btn btn-brand" | ||
target="_blank" | ||
destination={configuration.ENTERPRISE_SUPPORT_URL} | ||
> | ||
Contact support | ||
</Hyperlink> | ||
</Col> | ||
</Row> | ||
</Card.Section> | ||
</Card> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<MultipleBudgetsPicker | ||
offers={offers} | ||
enterpriseUUID= {enterpriseUUID} | ||
createActions={createActions} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
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); |
42 changes: 42 additions & 0 deletions
42
src/components/learner-credit-management/MultipleBudgetsPicker.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}) => ( | ||
<Row> | ||
<Col xs="12"> | ||
<h2>Budgets</h2> | ||
</Col> | ||
<Col lg="10"> | ||
{offers.map(offer => ( | ||
<BudgetCard | ||
key={offer.id} | ||
offer={offer} | ||
enterpriseUUID={enterpriseUUID} | ||
createActions={createActions} | ||
/> | ||
))} | ||
</Col> | ||
</Row> | ||
); | ||
|
||
MultipleBudgetsPicker.defaultProps = { | ||
createActions: null, | ||
}; | ||
|
||
MultipleBudgetsPicker.propTypes = { | ||
offers: PropTypes.arrayOf(PropTypes.shape()).isRequired, | ||
enterpriseUUID: PropTypes.string.isRequired, | ||
createActions: PropTypes.func, | ||
}; | ||
|
||
export default MultipleBudgetsPicker; |