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 7d87d7d
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 189 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',
};
10 changes: 4 additions & 6 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,7 +49,7 @@ export const useEnterpriseOffers = ({ enablePortalLearnerCreditManagementScreen,

ecommerceOffersResults.forEach((result) => {
offerData.push({
source: OFFER_TYPES.ecommerce,
source: BUDGET_TYPES.ecommerce,
id: result.id,
name: result.displayName,
start: result.startDatetime,
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
76 changes: 26 additions & 50 deletions src/components/learner-credit-management/BudgetCard-V2.jsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,14 @@
/* eslint-disable */
/* 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,33 +27,34 @@ const BudgetCard = ({
} = useOfferSummary(enterpriseUUID, offer);

return (
<Stack gap={4} className='mt-4'>
{isLoadingOfferSummary ? (
<LoadingCards />
) : offerType === OFFER_TYPES.ecommerce ? (
<SubBudgetCard
id={offerSummary.offerId}
start={start}
end={end}
available={offerSummary?.remainingFunds}
spent={offerSummary?.redeemedFunds}
displayName={displayName}
enterpriseSlug={enterpriseSlug}
/>
) : (
offerSummary?.budgetsSummary.map((budget) => (
<Stack gap={4} className="mb-3">
{!isLoadingOfferSummary
&& (offerType === BUDGET_TYPES.ecommerce ? (
<SubBudgetCard

Check warning on line 33 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#L33

Added line #L33 was not covered by tests
key={budget.subsidyAccessPolicyUuid}
id={budget.subsidyAccessPolicyUuid}
isLoading={isLoadingOfferSummary}
id={offerSummary?.offerId}
start={start}
end={end}
available={budget?.remainingFunds}
spent={budget?.redeemedFunds}
displayName={budget?.subsidyAccessPolicyDisplayName}
available={offerSummary?.remainingFunds}
spent={offerSummary?.redeemedFunds}
displayName={displayName}
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
101 changes: 0 additions & 101 deletions src/components/learner-credit-management/Budgetcard-V3.jsx

This file was deleted.

43 changes: 23 additions & 20 deletions src/components/learner-credit-management/MultipleBudgetsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Col,
Card,
Hyperlink,
Container,
} from '@edx/paragon';
import { connect } from 'react-redux';
import { Helmet } from 'react-helmet';
Expand Down Expand Up @@ -35,26 +36,28 @@ const MultipleBudgetsPage = ({
<Stack>
<Helmet title={PAGE_TITLE} />
<Hero title={PAGE_TITLE} />
<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>
<Container className="py-3" fluid>
<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>
</Container>
</Stack>
);
}
Expand Down
Loading

0 comments on commit 7d87d7d

Please sign in to comment.