Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Retired workflow on the list policy screens #1213

Merged
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
3 changes: 3 additions & 0 deletions src/components/learner-credit-management/BudgetCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const BudgetCard = ({ original }) => {
id,
isAssignable,
isRetired,
retiredAt,
name,
source,
start,
Expand All @@ -51,6 +52,7 @@ const BudgetCard = ({ original }) => {
enterpriseSlug={enterpriseSlug}
isAssignable={isAssignable}
isRetired={isRetired}
retiredAt={retiredAt}
/>
);
}
Expand Down Expand Up @@ -107,6 +109,7 @@ BudgetCard.propTypes = {
}),
isAssignable: PropTypes.bool,
isRetired: PropTypes.bool,
retiredAt: PropTypes.string,
enterpriseUUID: PropTypes.string.isRequired,
enterpriseSlug: PropTypes.string.isRequired,
status: PropTypes.string,
Expand Down
151 changes: 89 additions & 62 deletions src/components/learner-credit-management/SubBudgetCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const BaseSubBudgetCard = ({
isLoading,
isAssignable,
isRetired,
retiredAt,
}) => {
const { isFetching: isFetchingBudgets } = useEnterpriseBudgets({
enablePortalLearnerCreditManagementScreen,
Expand All @@ -79,6 +80,7 @@ const BaseSubBudgetCard = ({
startDateStr: start,
endDateStr: end,
isBudgetRetired: isRetired,
retiredDateStr: retiredAt,
});
const formattedDate = budgetLabel?.date ? intl.formatDate(
dayjs(budgetLabel?.date).toDate(),
Expand All @@ -89,18 +91,36 @@ const BaseSubBudgetCard = ({
},
) : undefined;

const hasBudgetAggregatesSection = () => {
const { status } = budgetLabel;

return (
status === BUDGET_STATUSES.active
|| status === BUDGET_STATUSES.expiring
|| status === BUDGET_STATUSES.retired
);
};

const renderActions = (budgetId) => (
<Button
data-testid="view-budget"
as={Link}
to={`/${enterpriseSlug}/admin/${ROUTE_NAMES.learnerCredit}/${budgetId}`}
variant={[BUDGET_STATUSES.expired, BUDGET_STATUSES.retired].includes(budgetLabel.status) ? 'outline-primary' : 'primary'}
>
<FormattedMessage
id="lcm.budgets.budget.card.view.budget"
defaultMessage="View budget"
description="Button text to view a budget"
/>
{(isRetired) ? (
<FormattedMessage
id="lcm.budgets.budget.card.view.budget.history"
defaultMessage="View budget history"
description="Button text to view budget history"
/>
) : (
<FormattedMessage
id="lcm.budgets.budget.card.view.budget"
defaultMessage="View budget"
description="Button text to view a budget"
/>
)}
</Button>
);

Expand All @@ -116,88 +136,94 @@ const BaseSubBudgetCard = ({
</Stack>
);

const showActions = budgetLabel.status !== BUDGET_STATUSES.scheduled;

return (
<Card.Header
title={<BackgroundFetchingWrapper>{budgetType}</BackgroundFetchingWrapper>}
subtitle={<BackgroundFetchingWrapper>{subtitle}</BackgroundFetchingWrapper>}
actions={
budgetLabel.status !== BUDGET_STATUSES.scheduled
? renderActions(budgetId)
: undefined
}
className={classNames('align-items-center', {
'mb-4.5': budgetLabel.status !== BUDGET_STATUSES.active && budgetLabel.status !== BUDGET_STATUSES.expiring,
})}
actions={showActions ? renderActions(budgetId) : undefined}
className={classNames('align-items-center', { 'mb-4.5': !hasBudgetAggregatesSection })}
/>
);
};

const renderCardSection = () => (
<Card.Section
title={(
<h4>
<FormattedMessage
id="lcm.budgets.budget.card.balance"
defaultMessage="Balance"
description="Header for the balance section of the budget card"
/>
</h4>
)}
muted
>
<Col className="d-flex justify-content-start w-md-75">
<Col xs="6" md="auto" className="mb-3 mb-md-0 ml-n4.5">
<div className="small font-weight-bold">
const renderCardSection = () => {
if (!hasBudgetAggregatesSection()) {
return null;
}

return (
<Card.Section
title={!isRetired && (
<h4>
<FormattedMessage
id="lcm.budgets.budget.card.available"
defaultMessage="Available"
description="Label for the available balance on the budget card"
id="lcm.budgets.budget.card.balance"
defaultMessage="Balance"
description="Header for the balance section of the budget card"
/>
</div>
<span className="small">
{isFetchingBudgets ? <Skeleton /> : formatPrice(available)}
</span>
</Col>
{isAssignable && (
<Col xs="6" md="auto" className="mb-3 mb-md-0">
<div className="small font-weight-bold">
</h4>
)}
muted
>
<Col className="d-flex justify-content-start w-md-75" data-testid="aggregates-section">
{!isRetired && (
<>
<Col xs="6" md="auto" className="mb-3 mb-md-0 ml-n4.5">
<div className="small font-weight-bold">
<FormattedMessage
id="lcm.budgets.budget.card.available"
defaultMessage="Available"
description="Label for the available balance on the budget card"
/>
</div>
<span className="small">
{isFetchingBudgets ? <Skeleton /> : formatPrice(available)}
</span>
</Col>
{isAssignable && (
<Col xs="6" md="auto" className="mb-3 mb-md-0">
<div className="small font-weight-bold">
<FormattedMessage
id="lcm.budgets.budget.card.assigned"
defaultMessage="Assigned"
description="Label for the assigned balance on the budget card"
/>
</div>
<span className="small">
{isFetchingBudgets ? <Skeleton /> : formatPrice(pending)}
</span>
</Col>
)}
</>
)}
<Col xs="6" md="auto" className={classNames('mb-3 mb-md-0', { 'ml-n4.5': isRetired })}>
<div className={classNames('font-weight-bold', { h4: isRetired, small: !isRetired })}>
<FormattedMessage
id="lcm.budgets.budget.card.assigned"
defaultMessage="Assigned"
description="Label for the assigned balance on the budget card"
id="lcm.budgets.budget.card.spent"
defaultMessage="Spent"
description="Label for the spent balance on the budget card"
/>
</div>
<span className="small">
{isFetchingBudgets ? <Skeleton /> : formatPrice(pending)}
<span className={classNames({ 'font-size-base': isRetired })}>
{isFetchingBudgets ? <Skeleton /> : formatPrice(spent)}
</span>
</Col>
)}
<Col xs="6" md="auto" className="mb-3 mb-md-0">
<div className="small font-weight-bold">
<FormattedMessage
id="lcm.budgets.budget.card.spent"
defaultMessage="Spent"
description="Label for the spent balance on the budget card"
/>
</div>
<span className="small">
{isFetchingBudgets ? <Skeleton /> : formatPrice(spent)}
</span>
</Col>
</Col>
</Card.Section>
);
</Card.Section>
);
};

return (
<Card
orientation="horizontal"
isLoading={isLoading}
data-testid="balance-detail-section"
>
<Card.Body>
<Stack gap={4.5}>
{renderCardHeader(displayName || 'Overview', id)}
{(budgetLabel.status === BUDGET_STATUSES.active || budgetLabel.status === BUDGET_STATUSES.expiring)
&& renderCardSection()}
{renderCardSection()}
</Stack>
</Card.Body>
</Card>
Expand All @@ -219,6 +245,7 @@ BaseSubBudgetCard.propTypes = {
displayName: PropTypes.string,
isAssignable: PropTypes.bool,
isRetired: PropTypes.bool,
retiredAt: PropTypes.string,
};

BaseSubBudgetCard.defaultProps = {
Expand Down
14 changes: 10 additions & 4 deletions src/components/learner-credit-management/data/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export const getBudgetStatus = ({
endDateStr,
isBudgetRetired,
currentDate = new Date(),
retiredDateStr = null,
}) => {
const startDate = new Date(startDateStr);
const endDate = new Date(endDateStr);
Expand All @@ -171,10 +172,9 @@ export const getBudgetStatus = ({
if (isBudgetRetired) {
return {
status: BUDGET_STATUSES.retired,
badgeVariant: 'info',
// no term or date for retired budgets
term: null,
date: null,
badgeVariant: 'light',
term: 'Retired',
date: retiredDateStr,
};
}

Expand Down Expand Up @@ -532,6 +532,12 @@ export const getTranslatedBudgetTerm = (intl, term) => {
defaultMessage: 'Expired',
description: 'Term for when a budget has expired',
});
case 'Retired':
return intl.formatMessage({
id: 'lcm.budgets.budget.card.term.retired',
defaultMessage: 'Retired',
description: 'Term for when a budget has retired',
});
default:
return '';
}
Expand Down
Loading
Loading