-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show all enterprise budgets regardless of plan and route correctly
- Loading branch information
1 parent
f19a8fe
commit 120ec59
Showing
10 changed files
with
184 additions
and
135 deletions.
There are no files selected for viewing
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
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
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
160 changes: 82 additions & 78 deletions
160
src/components/learner-credit-management/Budgetcard-V3.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 |
---|---|---|
@@ -1,99 +1,103 @@ | ||
/* eslint-disable */ | ||
import { Link } from 'react-router-dom'; | ||
import PropTypes from 'prop-types'; | ||
import dayjs from 'dayjs'; | ||
import { | ||
Card, | ||
Button, | ||
Stack, | ||
Row, | ||
Col, | ||
Card, | ||
Button, | ||
Stack, | ||
Row, | ||
Col, | ||
} from '@edx/paragon'; | ||
|
||
import { ROUTE_NAMES } from '../EnterpriseApp/data/constants'; | ||
import { BUDGET_STATUSES, ROUTE_NAMES } from '../EnterpriseApp/data/constants'; | ||
import { getBudgetStatus } from './data/utils'; | ||
|
||
const SubBudgetCard = ({ | ||
id, | ||
start, | ||
end, | ||
available, | ||
spent, | ||
enterpriseSlug, | ||
id, | ||
start, | ||
end, | ||
available, | ||
spent, | ||
displayName, | ||
enterpriseSlug, | ||
}) => { | ||
const formattedStartDate = dayjs(start).format('MMMM D, YYYY'); | ||
const formattedExpirationDate = dayjs(end).format('MMMM D, YYYY'); | ||
const formattedStartDate = dayjs(start).format('MMMM D, YYYY'); | ||
const formattedExpirationDate = dayjs(end).format('MMMM D, YYYY'); | ||
const budgetStatus = getBudgetStatus(start, end); | ||
|
||
const renderActions = (id) => ( | ||
<Button | ||
data-testid="view-budget" | ||
as={Link} | ||
to={`/${enterpriseSlug}/admin/${ROUTE_NAMES.learnerCredit}/${id}`} | ||
> | ||
View budget | ||
</Button> | ||
); | ||
|
||
const renderCardHeader = (budgetType, id) => { | ||
const subtitle = ( | ||
<div className="d-flex flex-wrap align-items-center"> | ||
<span data-testid="offer-date"> | ||
{formattedStartDate} - {formattedExpirationDate} | ||
</span> | ||
</div> | ||
const renderActions = (id) => ( | ||
<Button | ||
data-testid="view-budget" | ||
as={Link} | ||
to={`/${enterpriseSlug}/admin/${ROUTE_NAMES.learnerCredit}/${id}`} | ||
> | ||
View budget | ||
</Button> | ||
); | ||
|
||
return ( | ||
<Card.Header | ||
title={budgetType} | ||
subtitle={subtitle} | ||
actions={( | ||
<div> | ||
{renderActions(id)} | ||
</div> | ||
const renderCardHeader = (budgetType, id) => { | ||
const subtitle = ( | ||
<div className="d-flex flex-wrap align-items-center"> | ||
<span data-testid="offer-date"> | ||
{formattedStartDate} - {formattedExpirationDate} | ||
</span> | ||
</div> | ||
); | ||
|
||
return ( | ||
<Card.Header | ||
title={budgetType} | ||
subtitle={subtitle} | ||
actions={( | ||
<div> | ||
{budgetStatus !== BUDGET_STATUSES.upcoming && renderActions(id)} | ||
</div> | ||
)} | ||
/> | ||
); | ||
}; | ||
/> | ||
); | ||
}; | ||
|
||
const renderCardSection = (available, spent) => ( | ||
<Card.Section | ||
title="Balance" | ||
muted | ||
> | ||
<Row className="d-flex flex-row justify-content-start w-md-75"> | ||
<Col xs="6" md="auto" className="d-flex flex-column mb-3 mb-md-0"> | ||
<span className="small">Available</span> | ||
<span>{available}</span> | ||
</Col> | ||
<Col xs="6" md="auto" className="d-flex flex-column mb-3 mb-md-0"> | ||
<span className="small">Spent</span> | ||
<span>{spent}</span> | ||
</Col> | ||
</Row> | ||
</Card.Section> | ||
); | ||
const renderCardSection = (available, spent) => ( | ||
<Card.Section | ||
title="Balance" | ||
muted | ||
> | ||
<Row className="d-flex flex-row justify-content-start w-md-75"> | ||
<Col xs="6" md="auto" className="d-flex flex-column mb-3 mb-md-0"> | ||
<span className="small">Available</span> | ||
<span>{available}</span> | ||
</Col> | ||
<Col xs="6" md="auto" className="d-flex flex-column mb-3 mb-md-0"> | ||
<span className="small">Spent</span> | ||
<span>{spent}</span> | ||
</Col> | ||
</Row> | ||
</Card.Section> | ||
); | ||
|
||
return ( | ||
<Card | ||
orientation="horizontal" | ||
> | ||
<Card.Body> | ||
<Stack gap={4}> | ||
{renderCardHeader('Overview', id)} | ||
{renderCardSection(available, spent)} | ||
</Stack> | ||
</Card.Body> | ||
</Card> | ||
); | ||
return ( | ||
<Card | ||
orientation="horizontal" | ||
> | ||
<Card.Body> | ||
<Stack gap={4}> | ||
{renderCardHeader(displayName || 'Overview', id)} | ||
{budgetStatus !== BUDGET_STATUSES.upcoming && renderCardSection(available, spent)} | ||
</Stack> | ||
</Card.Body> | ||
</Card> | ||
); | ||
}; | ||
|
||
SubBudgetCard.propTypes = { | ||
enterpriseSlug: PropTypes.string.isRequired, | ||
id: PropTypes.string, | ||
start: PropTypes.string, | ||
end: PropTypes.string, | ||
spent: PropTypes.number, | ||
available: PropTypes.number, | ||
|
||
enterpriseSlug: PropTypes.string.isRequired, | ||
id: PropTypes.string, | ||
start: PropTypes.string, | ||
end: PropTypes.string, | ||
spent: PropTypes.number, | ||
available: PropTypes.number, | ||
displayName: PropTypes.string, | ||
}; | ||
|
||
export default SubBudgetCard; |
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
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
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
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
Oops, something went wrong.