Skip to content

Commit

Permalink
fix: incorporate adam's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jajjibhai008 committed Sep 25, 2023
1 parent d53064d commit 84be93a
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 214 deletions.
2 changes: 1 addition & 1 deletion src/components/EnterpriseApp/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const BUDGET_STATUSES = {
upcoming: 'Upcoming',
};

export const OFFER_TYPES = {
export const BUDGET_TYPES = {
ecommerce: 'ecommerce',
subsidy: 'subsidy',
};
12 changes: 5 additions & 7 deletions src/components/EnterpriseSubsidiesContext/data/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { camelCaseObject } from '@edx/frontend-platform/utils';
import EcommerceApiService from '../../../data/services/EcommerceApiService';
import LicenseManagerApiService from '../../../data/services/LicenseManagerAPIService';
import SubsidyApiService from '../../../data/services/EnterpriseSubsidyApiService';
import { OFFER_TYPES } from '../../EnterpriseApp/data/constants';
import { BUDGET_TYPES } from '../../EnterpriseApp/data/constants';

export const useEnterpriseOffers = ({ enablePortalLearnerCreditManagementScreen, enterpriseId }) => {
const [offers, setOffers] = useState([]);
Expand All @@ -26,9 +26,7 @@ export const useEnterpriseOffers = ({ enablePortalLearnerCreditManagementScreen,
try {
const [enterpriseSubsidyResponse, ecommerceApiResponse] = await Promise.all([
SubsidyApiService.getSubsidyByCustomerUUID(enterpriseId, { subsidyType: 'learner_credit' }),
EcommerceApiService.fetchEnterpriseOffers({
isCurrent: true,
}),
EcommerceApiService.fetchEnterpriseOffers(),
]);

// We have to consider both type of offers active and inactive.
Expand All @@ -40,7 +38,7 @@ export const useEnterpriseOffers = ({ enablePortalLearnerCreditManagementScreen,

enterpriseSubsidyResults.forEach((result) => {
offerData.push({
source: OFFER_TYPES.subsidy,
source: BUDGET_TYPES.subsidy,
id: result.uuid,
name: result.title,
start: result.activeDatetime,
Expand All @@ -51,8 +49,8 @@ export const useEnterpriseOffers = ({ enablePortalLearnerCreditManagementScreen,

ecommerceOffersResults.forEach((result) => {
offerData.push({
source: OFFER_TYPES.ecommerce,
id: result.id,
source: BUDGET_TYPES.ecommerce,
id: (result.id).toString(),
name: result.displayName,
start: result.startDatetime,
end: result.endDatetime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('<BudgetDetailPage />', () => {
enterpriseSlug={enterpriseId}
offer={mockOffer}
/>);
expect(screen.getByText('Learner Credit Budget Detail'));
expect(screen.getByText('Learner Credit Management'));
expect(screen.getByText('Overview'));
expect(screen.getByText('No results found'));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useCoupons, useCustomerAgreement, useEnterpriseOffers } from '../hooks'
import EcommerceApiService from '../../../../data/services/EcommerceApiService';
import LicenseManagerApiService from '../../../../data/services/LicenseManagerAPIService';
import SubsidyApiService from '../../../../data/services/EnterpriseSubsidyApiService';
import { OFFER_TYPES } from '../../../EnterpriseApp/data/constants';
import { BUDGET_TYPES } from '../../../EnterpriseApp/data/constants';

jest.mock('@edx/frontend-platform/config', () => ({
getConfig: jest.fn(() => ({
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('useEnterpriseOffers', () => {
start: '2021-05-15T19:56:09Z',
end: '2100-05-15T19:56:09Z',
isCurrent: true,
source: OFFER_TYPES.ecommerce,
source: BUDGET_TYPES.ecommerce,
}];

SubsidyApiService.getSubsidyByCustomerUUID.mockResolvedValueOnce({
Expand All @@ -71,9 +71,7 @@ describe('useEnterpriseOffers', () => {

await waitForNextUpdate();

expect(EcommerceApiService.fetchEnterpriseOffers).toHaveBeenCalledWith({
isCurrent: true,
});
expect(EcommerceApiService.fetchEnterpriseOffers).toHaveBeenCalled();
expect(result.current).toEqual({
offers: mockOffers,
isLoading: false,
Expand Down Expand Up @@ -133,15 +131,15 @@ describe('useEnterpriseOffers', () => {
start: '2021-05-15T19:56:09Z',
end: '2100-05-15T19:56:09Z',
isCurrent: true,
source: OFFER_TYPES.subsidy,
source: BUDGET_TYPES.subsidy,
},
{
id: 'uuid',
name: 'offer-name',
start: '2021-05-15T19:56:09Z',
end: '2100-05-15T19:56:09Z',
isCurrent: true,
source: OFFER_TYPES.ecommerce,
source: BUDGET_TYPES.ecommerce,
},
];

Expand Down Expand Up @@ -216,15 +214,15 @@ describe('useEnterpriseOffers', () => {
start: '2005-05-15T19:56:09Z',
end: '2006-05-15T19:56:09Z',
isCurrent: false,
source: OFFER_TYPES.subsidy,
source: BUDGET_TYPES.subsidy,
},
{
id: 'offer-2',
name: 'offer-name-2',
start: '2006-05-15T19:56:09Z',
end: '2099-05-15T19:56:09Z',
isCurrent: true,
source: OFFER_TYPES.subsidy,
source: BUDGET_TYPES.subsidy,
},
];

Expand Down
74 changes: 24 additions & 50 deletions src/components/learner-credit-management/BudgetCard-V2.jsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,11 @@
/* eslint-disable */
/* eslint-disable react/jsx-no-useless-fragment */
/* eslint-disable no-nested-ternary */
import React from 'react';
import PropTypes from 'prop-types';
import {
Stack,
Col,
Card,
Skeleton,
} from '@edx/paragon';

import { useOfferSummary } from './data/hooks';
import SubBudgetCard from './Budgetcard-V3';
import { OFFER_TYPES } from '../EnterpriseApp/data/constants';
import SubBudgetCard from './SubBudgetCard';
import { BUDGET_TYPES } from '../EnterpriseApp/data/constants';

const LoadingCards = () => (
<Stack gap={4}>
<Col className="d-flex flex-column">
<Card className="h-100">
<Card.Section className="d-flex align-items-center">
<div className="w-100" data-testid="loading-skeleton-card-3">
<Skeleton height={60} />
</div>
</Card.Section>
</Card>
</Col>
<Col className="d-flex flex-column">
<Card className="h-100">
<Card.Section className="d-flex align-items-center">
<div className="w-100" data-testid="loading-skeleton-card-3">
<Skeleton height={60} />
</div>
</Card.Section>
</Card>
</Col>
</Stack>
);
const BudgetCard = ({
offer,
enterpriseUUID,
Expand All @@ -52,12 +24,11 @@ const BudgetCard = ({
} = useOfferSummary(enterpriseUUID, offer);

return (
<Stack gap={4} className='mt-4'>
{isLoadingOfferSummary ? (
<LoadingCards />
) : offerType === OFFER_TYPES.ecommerce ? (
<>
{offerType === BUDGET_TYPES.ecommerce ? (
<SubBudgetCard

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

View check run for this annotation

Codecov / codecov/patch

src/components/learner-credit-management/BudgetCard-V2.jsx#L29

Added line #L29 was not covered by tests
id={offerSummary.offerId}
isLoading={isLoadingOfferSummary}
id={offerSummary?.offerId}
start={start}
end={end}
available={offerSummary?.remainingFunds}
Expand All @@ -66,20 +37,23 @@ const BudgetCard = ({
enterpriseSlug={enterpriseSlug}
/>
) : (
offerSummary?.budgetsSummary.map((budget) => (
<SubBudgetCard
key={budget.subsidyAccessPolicyUuid}
id={budget.subsidyAccessPolicyUuid}
start={start}
end={end}
available={budget?.remainingFunds}
spent={budget?.redeemedFunds}
displayName={budget?.subsidyAccessPolicyDisplayName}
enterpriseSlug={enterpriseSlug}
/>
))
<>
{offerSummary?.budgetsSummary?.map((budget) => (
<SubBudgetCard
isLoading={isLoadingOfferSummary}
key={budget?.subsidyAccessPolicyUuid}
id={budget?.subsidyAccessPolicyUuid}
start={start}
end={end}
available={budget?.remainingFunds}
spent={budget?.redeemedFunds}
displayName={budget?.subsidyAccessPolicyDisplayName}
enterpriseSlug={enterpriseSlug}
/>
))}
</>
)}
</Stack>
</>
);
};

Expand Down
41 changes: 22 additions & 19 deletions src/components/learner-credit-management/BudgetDetailPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Row,
Col,
Breadcrumb,
Container,
} from '@edx/paragon';
import { connect } from 'react-redux';
import { Helmet } from 'react-helmet';
Expand All @@ -18,7 +19,7 @@ import { useOfferRedemptions } from './data/hooks';
import { isUUID } from './data/utils';
import { ROUTE_NAMES } from '../EnterpriseApp/data/constants';

const PAGE_TITLE = 'Learner Credit Budget Detail';
const PAGE_TITLE = 'Learner Credit Management';

const BudgetDetailPage = ({
enterpriseUUID,
Expand All @@ -45,24 +46,26 @@ const BudgetDetailPage = ({
<>
<Helmet title={PAGE_TITLE} />
<Hero title={PAGE_TITLE} />
<Row className="m-3">
<Col xs="12">
<Breadcrumb
ariaLabel="Learner Credit Management breadcrumb navigation"
links={links}
linkAs={Link}
activeLabel="Overview"
/>
</Col>
</Row>
<LearnerCreditAllocationTable
isLoading={isLoadingOfferRedemptions}
tableData={offerRedemptions}
fetchTableData={fetchOfferRedemptions}
enterpriseUUID={enterpriseUUID}
enterpriseSlug={enterpriseSlug}
enableLearnerPortal={enableLearnerPortal}
/>
<Container className="py-3" fluid>
<Row className="m-3">
<Col xs="12">
<Breadcrumb
ariaLabel="Learner Credit Management breadcrumb navigation"
links={links}
linkAs={Link}
activeLabel="Overview"
/>
</Col>
</Row>
<LearnerCreditAllocationTable
isLoading={isLoadingOfferRedemptions}
tableData={offerRedemptions}
fetchTableData={fetchOfferRedemptions}
enterpriseUUID={enterpriseUUID}
enterpriseSlug={enterpriseSlug}
enableLearnerPortal={enableLearnerPortal}
/>
</Container>
</>
);
};
Expand Down
101 changes: 0 additions & 101 deletions src/components/learner-credit-management/Budgetcard-V3.jsx

This file was deleted.

Loading

0 comments on commit 84be93a

Please sign in to comment.