Skip to content

Commit

Permalink
feat: ENT-7309 Added budget category based page for learner credit
Browse files Browse the repository at this point in the history
  • Loading branch information
IrfanUddinAhmad committed Jul 11, 2023
1 parent 8edb622 commit 3342ef5
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 0 deletions.
127 changes: 127 additions & 0 deletions src/components/learner-credit-management/BudgetCard.jsx
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 = ({

Check warning on line 16 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L16

Added line #L16 was not covered by tests
offer,
enterpriseUUID,
createActions,
}) => {

Check warning on line 20 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L20

Added line #L20 was not covered by tests
const {
name,
start,
end,
} = offer;

Check warning on line 25 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L25

Added line #L25 was not covered by tests

const {
isLoading: isLoadingOfferSummary,

Check failure on line 28 in src/components/learner-credit-management/BudgetCard.jsx

View workflow job for this annotation

GitHub Actions / tests (16, 8.5.x)

'isLoadingOfferSummary' is assigned a value but never used
offerSummary,
} = useOfferSummary(enterpriseUUID, offer);

Check warning on line 30 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L30

Added line #L30 was not covered by tests

const formattedStartDate = moment(start).format('MMMM D, YYYY');
const formattedExpirationDate = moment(end).format('MMMM D, YYYY');

Check warning on line 33 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L32-L33

Added lines #L32 - L33 were not covered by tests

Check failure on line 34 in src/components/learner-credit-management/BudgetCard.jsx

View workflow job for this annotation

GitHub Actions / tests (16, 8.5.x)

Trailing spaces not allowed
const renderActions = () => {

Check warning on line 35 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L35

Added line #L35 was not covered by tests
const actions = createActions?.(offer) || [];

if (actions.length === 0) {
return null;

Check warning on line 39 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L39

Added line #L39 was not covered by tests
}

return actions.map(action => (
<Button

Check warning on line 43 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L42-L43

Added lines #L42 - L43 were not covered by tests
key={action.to}
variant={action.variant}
as={Link}
to={action.to}
>
{action.buttonText}
</Button>
));
};

const renderCardHeader = () => {

Check warning on line 54 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L54

Added line #L54 was not covered by tests
const subtitle = (
<div className="d-flex flex-wrap align-items-center">

Check warning on line 56 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L56

Added line #L56 was not covered by tests
<span>

Check failure on line 57 in src/components/learner-credit-management/BudgetCard.jsx

View workflow job for this annotation

GitHub Actions / tests (16, 8.5.x)

Expected indentation of 8 space characters but found 10
{formattedStartDate} - {formattedExpirationDate}
</span>
</div>
);

return (

Check warning on line 63 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L63

Added line #L63 was not covered by tests
<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

View workflow job for this annotation

GitHub Actions / tests (16, 8.5.x)

Block must not be padded by blank lines

Check failure on line 76 in src/components/learner-credit-management/BudgetCard.jsx

View workflow job for this annotation

GitHub Actions / tests (16, 8.5.x)

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`

Check warning on line 76 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L76

Added line #L76 was not covered by tests

Check failure on line 77 in src/components/learner-credit-management/BudgetCard.jsx

View workflow job for this annotation

GitHub Actions / tests (16, 8.5.x)

Trailing spaces not allowed
return (

Check warning on line 78 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L78

Added line #L78 was not covered by tests
<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">

Check failure on line 84 in src/components/learner-credit-management/BudgetCard.jsx

View workflow job for this annotation

GitHub Actions / tests (16, 8.5.x)

Expected indentation of 10 space characters but found 12
<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">

Check failure on line 88 in src/components/learner-credit-management/BudgetCard.jsx

View workflow job for this annotation

GitHub Actions / tests (16, 8.5.x)

Expected indentation of 10 space characters but found 12
<span className="small">Spent</span>
<span>{offerSummary?.redeemedFunds}</span>
</Col>
</Row>
</Card.Section>
);
};

return (

Check warning on line 97 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L97

Added line #L97 was not covered by tests
<Card
orientation="horizontal"
className={classNames('budget-card', className)}

Check failure on line 100 in src/components/learner-credit-management/BudgetCard.jsx

View workflow job for this annotation

GitHub Actions / tests (16, 8.5.x)

'className' is not defined
>
<Card.Body>
<Stack gap={4}>
{renderCardHeader()}
{renderCardSection()}
</Stack>
</Card.Body>
</Card>
);
};

BudgetCard.defaultProps = {

Check warning on line 112 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L112

Added line #L112 was not covered by tests
createActions: null,
};

BudgetCard.propTypes = {

Check warning on line 116 in src/components/learner-credit-management/BudgetCard.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard.jsx#L116

Added line #L116 was not covered by tests
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 src/components/learner-credit-management/MultipleBudgetsPage.jsx
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 = ({

Check warning on line 17 in src/components/learner-credit-management/MultipleBudgetsPage.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/MultipleBudgetsPage.jsx#L17

Added line #L17 was not covered by tests
enterpriseUUID,
createActions,
}) => {
const { offers, isLoading } = useContext(EnterpriseSubsidiesContext);

Check warning on line 21 in src/components/learner-credit-management/MultipleBudgetsPage.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/MultipleBudgetsPage.jsx#L20-L21

Added lines #L20 - L21 were not covered by tests

if (isLoading) {
return <LoadingMessage className="offers" />;

Check warning on line 24 in src/components/learner-credit-management/MultipleBudgetsPage.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/MultipleBudgetsPage.jsx#L24

Added line #L24 was not covered by tests
}

if (offers.length === 0) {
return (

Check warning on line 28 in src/components/learner-credit-management/MultipleBudgetsPage.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/MultipleBudgetsPage.jsx#L28

Added line #L28 was not covered by tests
<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 (

Check warning on line 52 in src/components/learner-credit-management/MultipleBudgetsPage.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/MultipleBudgetsPage.jsx#L52

Added line #L52 was not covered by tests
<>

Check failure on line 53 in src/components/learner-credit-management/MultipleBudgetsPage.jsx

View workflow job for this annotation

GitHub Actions / tests (16, 8.5.x)

Fragments should contain more than one child - otherwise, there’s no need for a Fragment at all
<MultipleBudgetsPicker
offers={offers}
enterpriseUUID= {enterpriseUUID}
createActions={createActions}
/>
</>
);
};

const mapStateToProps = state => ({

Check warning on line 63 in src/components/learner-credit-management/MultipleBudgetsPage.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/MultipleBudgetsPage.jsx#L63

Added line #L63 was not covered by tests
enterpriseUUID: state.portalConfiguration.enterpriseId,
});

MultipleBudgetsPage.defaultProps = {

Check warning on line 67 in src/components/learner-credit-management/MultipleBudgetsPage.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/MultipleBudgetsPage.jsx#L67

Added line #L67 was not covered by tests
createActions: null,
};

MultipleBudgetsPage.propTypes = {

Check warning on line 71 in src/components/learner-credit-management/MultipleBudgetsPage.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/MultipleBudgetsPage.jsx#L71

Added line #L71 was not covered by tests
enterpriseUUID: PropTypes.string.isRequired,
createActions: PropTypes.func,
};

export default connect(mapStateToProps)(MultipleBudgetsPage);
42 changes: 42 additions & 0 deletions src/components/learner-credit-management/MultipleBudgetsPicker.jsx
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 = ({

Check warning on line 10 in src/components/learner-credit-management/MultipleBudgetsPicker.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/MultipleBudgetsPicker.jsx#L10

Added line #L10 was not covered by tests
offers,
enterpriseUUID,
createActions,
}) => (
<Row>

Check warning on line 15 in src/components/learner-credit-management/MultipleBudgetsPicker.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/MultipleBudgetsPicker.jsx#L15

Added line #L15 was not covered by tests
<Col xs="12">
<h2>Budgets</h2>
</Col>
<Col lg="10">
{offers.map(offer => (
<BudgetCard

Check warning on line 21 in src/components/learner-credit-management/MultipleBudgetsPicker.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/MultipleBudgetsPicker.jsx#L21

Added line #L21 was not covered by tests
key={offer.id}
offer={offer}
enterpriseUUID={enterpriseUUID}
createActions={createActions}
/>
))}
</Col>
</Row>
);

MultipleBudgetsPicker.defaultProps = {

Check warning on line 32 in src/components/learner-credit-management/MultipleBudgetsPicker.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/MultipleBudgetsPicker.jsx#L32

Added line #L32 was not covered by tests
createActions: null,
};

MultipleBudgetsPicker.propTypes = {

Check warning on line 36 in src/components/learner-credit-management/MultipleBudgetsPicker.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/MultipleBudgetsPicker.jsx#L36

Added line #L36 was not covered by tests
offers: PropTypes.arrayOf(PropTypes.shape()).isRequired,
enterpriseUUID: PropTypes.string.isRequired,
createActions: PropTypes.func,
};

export default MultipleBudgetsPicker;

0 comments on commit 3342ef5

Please sign in to comment.