Skip to content

Commit

Permalink
Merge pull request #419 from openedx/knguyen2/ent-9476
Browse files Browse the repository at this point in the history
feat: update learner credit plan cards to use subsidies
  • Loading branch information
katrinan029 authored Sep 25, 2024
2 parents f95bcb7 + 21bf852 commit 28257fe
Show file tree
Hide file tree
Showing 20 changed files with 233 additions and 147 deletions.
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ENTERPRISE_ACCESS_BASE_URL='http://localhost:18270'
LANGUAGE_PREFERENCE_COOKIE_NAME='openedx-language-preference'
LMS_BASE_URL='http://localhost:18000'
LICENSE_MANAGER_URL='http://localhost:18170'
LICENSE_MANAGER_DJANGO_URL='http://localhost:18170'
SUPPORT_CONFLUENCE='localhost:18450'
SUPPORT_CUSTOMER_REQUEST='localhost:18450'
DISCOVERY_API_BASE_URL='http://localhost:18381'
Expand All @@ -30,6 +31,7 @@ REFRESH_ACCESS_TOKEN_ENDPOINT='http://localhost:18000/login_refresh'
SEGMENT_KEY=null
SITE_NAME='edX'
SUBSIDY_BASE_URL='http://localhost:18280'
SUBSIDY_BASE_DJANGO_URL='http://localhost:18280'
USER_INFO_COOKIE_NAME='edx-user-info'
PUBLISHER_BASE_URL='http://localhost:18400'
APP_ID='support-tools'
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@fortawesome/free-solid-svg-icons": "5.15.1",
"@fortawesome/react-fontawesome": "^0.1.14",
"@openedx/paragon": "21.13.1",
"axios": "^1.7.7",
"babel-polyfill": "6.26.0",
"classnames": "2.2.6",
"dayjs": "1.11.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const SubscriptionCheckIcon = ({ row }) => {
return null;
};

const PolicyCheckIcon = ({ row }) => {
if (row.original.hasActivePolicies) {
const SubsidyCheckIcon = ({ row }) => {
if (row.original.hasActiveSubsidies) {
return <Icon src={Check} screenReaderText="policy check" />;
}
return null;
Expand Down Expand Up @@ -73,8 +73,8 @@ const CustomerDetailRowSubComponent = ({ row }) => {
},
{
Header: 'Learner Credit',
accessor: 'hasActivePolicies',
Cell: PolicyCheckIcon,
accessor: 'hasActiveSubsidies',
Cell: SubsidyCheckIcon,
},
{
Header: OtherSubsidies,
Expand Down Expand Up @@ -105,10 +105,10 @@ SubscriptionCheckIcon.propTypes = {
}).isRequired,
};

PolicyCheckIcon.propTypes = {
SubsidyCheckIcon.propTypes = {
row: PropTypes.shape({
original: PropTypes.shape({
hasActivePolicies: PropTypes.bool,
hasActiveSubsidies: PropTypes.bool,
}),
}).isRequired,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('CustomerDetailRowSubComponent', () => {
isLoading: false,
data: {
hasActiveSubscriptions: true,
hasActivePolicies: true,
hasActiveSubsidies: true,
hasActiveOtherSubsidies: true,
},
});
Expand All @@ -53,7 +53,7 @@ describe('CustomerDetailRowSubComponent', () => {
isLoading: false,
data: {
hasActiveSubscriptions: false,
hasActivePolicies: true,
hasActiveSubsidies: true,
hasActiveOtherSubsidies: true,
},
});
Expand All @@ -75,7 +75,7 @@ describe('CustomerDetailRowSubComponent', () => {
isLoading: false,
data: {
hasActiveSubscriptions: true,
hasActivePolicies: false,
hasActiveSubsidies: false,
hasActiveOtherSubsidies: true,
},
});
Expand All @@ -97,7 +97,7 @@ describe('CustomerDetailRowSubComponent', () => {
isLoading: false,
data: {
hasActiveSubscriptions: true,
hasActivePolicies: true,
hasActiveSubsidies: true,
hasActiveOtherSubsidies: false,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ import SubscriptionPlanCard from './SubscriptionPlanCard';

const CustomerPlanContainer = ({
slug,
activePolicies,
activeSubsidies,
activeSubscriptions,
inactivePolicies,
inactiveSubsidies,
inactiveSubscriptions,
isLoading,
}) => {
const [showInactive, setShowInactive] = useState(false);
const countOfActivePlans = activeSubscriptions.length + activePolicies.length;
const countOfInactivePlans = inactiveSubscriptions.length + inactivePolicies.length;
const countOfActivePlans = activeSubscriptions.length + activeSubsidies.length;
const countOfInactivePlans = inactiveSubscriptions.length + activeSubsidies.length;
const countOfAllPlans = countOfActivePlans + countOfInactivePlans;
useEffect(() => {
if (!countOfActivePlans && countOfAllPlans) {
setShowInactive(true);
}
}, []);
const renderActivePoliciesCard = activePolicies.map(policy => (
<LearnerCreditPlanCard key={policy.uuid} isActive slug={slug} policy={policy} />
const renderActiveSubsidiesCard = activeSubsidies.map(subsidy => (
<LearnerCreditPlanCard key={subsidy.uuid} isActive slug={slug} subsidy={subsidy} />
));
const renderInactivePoliciesCard = inactivePolicies.map(policy => (
<LearnerCreditPlanCard key={policy.uuid} isActive={false} slug={slug} policy={policy} />
const renderInactiveSubsidiesCard = inactiveSubsidies.map(subsidy => (
<LearnerCreditPlanCard key={subsidy.uuid} isActive={false} slug={slug} subsidy={subsidy} />
));
const renderActiveSubscriptions = activeSubscriptions.map(subscription => (
<SubscriptionPlanCard key={subscription.uuid} isActive slug={slug} subscription={subscription} />
Expand Down Expand Up @@ -54,11 +54,11 @@ const CustomerPlanContainer = ({
) : null}
</div>
<hr />
{renderActivePoliciesCard}
{renderActiveSubsidiesCard}
{renderActiveSubscriptions}
{showInactive ? (
<div>
{renderInactivePoliciesCard}
{renderInactiveSubsidiesCard}
{renderInActiveSubscriptions}
</div>
) : null}
Expand All @@ -70,11 +70,10 @@ const CustomerPlanContainer = ({

CustomerPlanContainer.propTypes = {
slug: PropTypes.string.isRequired,
activePolicies: PropTypes.arrayOf(PropTypes.shape({
activeSubsidies: PropTypes.arrayOf(PropTypes.shape({
uuid: PropTypes.string.isRequired,
subsidyActiveDatetime: PropTypes.string.isRequired,
subsidyExpirationDatetime: PropTypes.string.isRequired,
policyType: PropTypes.string.isRequired,
activeDatetime: PropTypes.string.isRequired,
expirationDatetime: PropTypes.string.isRequired,
created: PropTypes.string.isRequired,
})).isRequired,
activeSubscriptions: PropTypes.arrayOf(PropTypes.shape({
Expand All @@ -83,11 +82,10 @@ CustomerPlanContainer.propTypes = {
expirationDate: PropTypes.string.isRequired,
created: PropTypes.string.isRequired,
})).isRequired,
inactivePolicies: PropTypes.arrayOf(PropTypes.shape({
inactiveSubsidies: PropTypes.arrayOf(PropTypes.shape({
uuid: PropTypes.string.isRequired,
subsidyActiveDatetime: PropTypes.string.isRequired,
subsidyExpirationDatetime: PropTypes.string.isRequired,
policyType: PropTypes.string.isRequired,
activeDatetime: PropTypes.string.isRequired,
expirationDatetime: PropTypes.string.isRequired,
created: PropTypes.string.isRequired,
})).isRequired,
inactiveSubscriptions: PropTypes.arrayOf(PropTypes.shape({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { Launch } from '@openedx/paragon/icons';
import { getConfig } from '@edx/frontend-platform';
import { formatDate } from '../data/utils';

const LearnerCreditPlanCard = ({ isActive, policy, slug }) => {
const { ADMIN_PORTAL_BASE_URL, ENTERPRISE_ACCESS_BASE_URL } = getConfig();
const startDate = formatDate(policy.subsidyActiveDatetime);
const endDate = formatDate(policy.subsidyExpirationDatetime);
const createdDate = formatDate(policy.created);
const LearnerCreditPlanCard = ({ isActive, subsidy, slug }) => {
const { ADMIN_PORTAL_BASE_URL, SUBSIDY_BASE_DJANGO_URL } = getConfig();
const startDate = formatDate(subsidy.activeDatetime);
const endDate = formatDate(subsidy.expirationDatetime);
const createdDate = formatDate(subsidy.created);

return (
<Card className="mb-4">
Expand All @@ -25,7 +25,7 @@ const LearnerCreditPlanCard = ({ isActive, policy, slug }) => {
<Button
data-testid="admin-portal-button"
as="a"
href={`${ADMIN_PORTAL_BASE_URL}/${slug}/admin/learner-credit/${policy.uuid}`}
href={`${ADMIN_PORTAL_BASE_URL}/${slug}/admin/learner-credit/`}
target="_blank"
rel="noopener noreferrer"
variant="inverse-primary"
Expand All @@ -34,7 +34,7 @@ const LearnerCreditPlanCard = ({ isActive, policy, slug }) => {
<Button
data-testid="django-button"
as="a"
href={`${ENTERPRISE_ACCESS_BASE_URL}/admin/subsidy_access_policy/${policy.policyType.toLowerCase()}/${policy.uuid}`}
href={`${SUBSIDY_BASE_DJANGO_URL}/admin/subsidy/subsidy/${subsidy.uuid}/change/`}
variant="primary"
target="_blank"
rel="noopener noreferrer"
Expand All @@ -61,11 +61,10 @@ const LearnerCreditPlanCard = ({ isActive, policy, slug }) => {

LearnerCreditPlanCard.propTypes = {
isActive: PropTypes.bool.isRequired,
policy: PropTypes.shape({
subsidy: PropTypes.shape({
uuid: PropTypes.string.isRequired,
subsidyActiveDatetime: PropTypes.string.isRequired,
subsidyExpirationDatetime: PropTypes.string.isRequired,
policyType: PropTypes.string.isRequired,
activeDatetime: PropTypes.string.isRequired,
expirationDatetime: PropTypes.string.isRequired,
created: PropTypes.string.isRequired,
}).isRequired,
slug: PropTypes.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getConfig } from '@edx/frontend-platform';
import { formatDate } from '../data/utils';

const SubscriptionPlanCard = ({ isActive, subscription, slug }) => {
const { ADMIN_PORTAL_BASE_URL, LICENSE_MANAGER_URL } = getConfig();
const { ADMIN_PORTAL_BASE_URL, LICENSE_MANAGER_DJANGO_URL } = getConfig();
const startDate = formatDate(subscription.startDate);
const endDate = formatDate(subscription.expirationDate);
const createdDate = formatDate(subscription.created);
Expand All @@ -31,7 +31,7 @@ const SubscriptionPlanCard = ({ isActive, subscription, slug }) => {
</Button>
<Button
as="a"
href={`${LICENSE_MANAGER_URL}/admin/subscriptions/subscriptionplan/${subscription.uuid}/change`}
href={`${LICENSE_MANAGER_DJANGO_URL}/admin/subscriptions/subscriptionplan/${subscription.uuid}/change`}
variant="primary"
target="_blank"
rel="noopener noreferrer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@ describe('CustomerPlanContainer', () => {

getConfig.mockImplementation(() => ({
ADMIN_PORTAL_BASE_URL: 'http://www.testportal.com',
ENTERPRISE_ACCESS_BASE_URL: 'http:www.enterprise-access.com',
LICENSE_MANAGER_URL: 'http:www.license-manager.com',
SUBSIDY_BASE_DJANGO_URL: 'http:www.enterprise-subsidy.com',
LICENSE_MANAGER_DJANGO_URL: 'http:www.license-manager.com',
}));
const mockProps = {
isLoading: false,
activePolicies: [{
subsidyActiveDatetime: '2024-08-23T20:02:57.651943Z',
activeSubsidies: [{
activeDatetime: '2024-08-23T20:02:57.651943Z',
created: '2024-08-22T20:02:57.651943Z',
subsidyExpirationDatetime: '2024-08-24T20:02:57.651943Z',
expirationDatetime: '2024-08-24T20:02:57.651943Z',
uuid: 'test-uuid',
policyType: 'learnerCredit',
isSubsidyActive: true,
isActive: true,
}],
activeSubscriptions: [{
startDate: '2024-09-01T20:02:57.651943Z',
Expand All @@ -57,13 +56,12 @@ describe('CustomerPlanContainer', () => {
countOfActivePlans: 2,
countOfAllPlans: 3,
inactiveSubscriptions: [],
inactivePolicies: [{
subsidyActiveDatetime: '2024-08-23T20:02:57.651943Z',
inactiveSubsidies: [{
activeDatetime: '2024-08-23T20:02:57.651943Z',
created: '2024-08-23T20:02:57.651943Z',
subsidyExpirationDatetime: '2024-08-23T20:02:57.651943Z',
expirationDatetime: '2024-08-23T20:02:57.651943Z',
uuid: 'test-uuid',
policyType: 'learnerCredit',
isSubsidyActive: false,
isActive: false,
}],
};
render(
Expand All @@ -78,8 +76,8 @@ describe('CustomerPlanContainer', () => {
expect(screen.getByText('LEARNER CREDIT PLAN')).toBeInTheDocument();
expect(screen.getByText('Aug 23, 2024 - Aug 24, 2024')).toBeInTheDocument();
expect(screen.getByText('Created Aug 22, 2024')).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'View budgets' })).toHaveAttribute('href', 'http://www.testportal.com/test-slug/admin/learner-credit/test-uuid');
expect(djangoLinks[0]).toHaveAttribute('href', 'http:www.enterprise-access.com/admin/subsidy_access_policy/learnercredit/test-uuid');
expect(screen.getByRole('link', { name: 'View budgets' })).toHaveAttribute('href', 'http://www.testportal.com/test-slug/admin/learner-credit/');
expect(djangoLinks[0]).toHaveAttribute('href', 'http:www.enterprise-subsidy.com/admin/subsidy/subsidy/test-uuid/change/');
// Subscription Plan
expect(screen.getByText('SUBSCRIPTION PLAN')).toBeInTheDocument();
expect(screen.getByText('Sep 1, 2024 - Sep 2, 2024')).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ jest.mock('@edx/frontend-platform', () => ({

const mockData = {
isActive: true,
policy: {
subsidyActiveDatetime: '2024-08-23T20:02:57.651943Z',
subsidy: {
activeDatetime: '2024-08-23T20:02:57.651943Z',
created: '2024-08-23T20:02:57.651943Z',
subsidyExpirationDatetime: '2024-08-23T20:02:57.651943Z',
expirationDatetime: '2024-08-23T20:02:57.651943Z',
uuid: 'test-uuid',
policyType: 'learnerCredit',
},
slug: 'test-customer-slug',
};
Expand All @@ -32,7 +31,7 @@ describe('LearnerCreditPlanCard', () => {
formatDate.mockReturnValue('Aug 23, 2024');
getConfig.mockImplementation(() => ({
ADMIN_PORTAL_BASE_URL: 'http://www.testportal.com',
ENTERPRISE_ACCESS_BASE_URL: 'http:www.enterprise-access.com',
SUBSIDY_BASE_DJANGO_URL: 'http://www.enterprise-subsidy.com',
}));
render(
<IntlProvider locale="en">
Expand All @@ -42,8 +41,8 @@ describe('LearnerCreditPlanCard', () => {
expect(screen.getByText('LEARNER CREDIT PLAN')).toBeInTheDocument();
expect(screen.getByText('Aug 23, 2024 - Aug 23, 2024')).toBeInTheDocument();
expect(screen.getByText('Created Aug 23, 2024')).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'View budgets' })).toHaveAttribute('href', 'http://www.testportal.com/test-customer-slug/admin/learner-credit/test-uuid');
expect(screen.getByRole('link', { name: 'Open in Django' })).toHaveAttribute('href', 'http:www.enterprise-access.com/admin/subsidy_access_policy/learnercredit/test-uuid');
expect(screen.getByRole('link', { name: 'View budgets' })).toHaveAttribute('href', 'http://www.testportal.com/test-customer-slug/admin/learner-credit/');
expect(screen.getByRole('link', { name: 'Open in Django' })).toHaveAttribute('href', 'http://www.enterprise-subsidy.com/admin/subsidy/subsidy/test-uuid/change/');
});

it('renders inactive LearnerCreditPlanCard data', () => {
Expand All @@ -54,7 +53,7 @@ describe('LearnerCreditPlanCard', () => {
formatDate.mockReturnValue('Aug 23, 2024');
getConfig.mockImplementation(() => ({
ADMIN_PORTAL_BASE_URL: 'http://www.testportal.com',
ENTERPRISE_ACCESS_BASE_URL: 'http:www.enterprise-access.com',
SUBSIDY_BASE_DJANGO_URL: 'http://www.enterprise-subsidy.com',
}));
render(
<IntlProvider locale="en">
Expand All @@ -65,7 +64,7 @@ describe('LearnerCreditPlanCard', () => {
expect(screen.getByText('LEARNER CREDIT PLAN')).toBeInTheDocument();
expect(screen.getByText('Aug 23, 2024 - Aug 23, 2024')).toBeInTheDocument();
expect(screen.getByText('Created Aug 23, 2024')).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'View budgets' })).toHaveAttribute('href', 'http://www.testportal.com/test-customer-slug/admin/learner-credit/test-uuid');
expect(screen.getByRole('link', { name: 'Open in Django' })).toHaveAttribute('href', 'http:www.enterprise-access.com/admin/subsidy_access_policy/learnercredit/test-uuid');
expect(screen.getByRole('link', { name: 'View budgets' })).toHaveAttribute('href', 'http://www.testportal.com/test-customer-slug/admin/learner-credit/');
expect(screen.getByRole('link', { name: 'Open in Django' })).toHaveAttribute('href', 'http://www.enterprise-subsidy.com/admin/subsidy/subsidy/test-uuid/change/');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('SubscriptionPlanCard', () => {
formatDate.mockReturnValue('Aug 23, 2024');
getConfig.mockImplementation(() => ({
ADMIN_PORTAL_BASE_URL: 'http://www.testportal.com',
LICENSE_MANAGER_URL: 'http:www.license-manager.com',
LICENSE_MANAGER_DJANGO_URL: 'http:www.license-manager.com',
}));
render(
<IntlProvider locale="en">
Expand All @@ -53,7 +53,7 @@ describe('SubscriptionPlanCard', () => {
};
getConfig.mockImplementation(() => ({
ADMIN_PORTAL_BASE_URL: 'http://www.testportal.com',
LICENSE_MANAGER_URL: 'http:www.license-manager.com',
LICENSE_MANAGER_DJANGO_URL: 'http:www.license-manager.com',
}));
render(
<IntlProvider locale="en">
Expand Down
Loading

0 comments on commit 28257fe

Please sign in to comment.