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: ENT-8091 hide course search in subsidy summary #894

Merged
merged 1 commit into from
Dec 13, 2023
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
36 changes: 34 additions & 2 deletions src/components/dashboard/sidebar/SubsidiesSummary.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import React, { useContext, useMemo } from 'react';
import React, {
useContext,
useEffect,
useMemo,
useState,
} from 'react';
import { Link } from 'react-router-dom';
import { AppContext } from '@edx/frontend-platform/react';

Expand All @@ -15,6 +20,8 @@
import { CourseEnrollmentsContext } from '../main-content/course-enrollments/CourseEnrollmentsContextProvider';
import { SubsidyRequestsContext, SUBSIDY_TYPE } from '../../enterprise-subsidy-requests';
import { getOfferExpiringFirst, getPolicyExpiringFirst } from './utils';
import getActiveAssignments from '../data/utils';
import { POLICY_TYPES } from '../../enterprise-user-subsidy/enterprise-offers/data/constants';

function getLearnerCreditSummaryCardData({ enterpriseOffers, redeemableLearnerCreditPolicies }) {
const learnerCreditPolicyExpiringFirst = getPolicyExpiringFirst(redeemableLearnerCreditPolicies);
Expand Down Expand Up @@ -55,6 +62,7 @@
couponCodes: { couponCodesCount },
enterpriseOffers,
canEnrollWithEnterpriseOffers,
hasCurrentEnterpriseOffers,
redeemableLearnerCreditPolicies,
} = useContext(UserSubsidyContext);

Expand Down Expand Up @@ -85,6 +93,30 @@
const hasAvailableSubsidyOrRequests = (
hasActiveLicenseOrLicenseRequest || hasAssignedCodesOrCodeRequests || learnerCreditSummaryCardData
);
const hasAutoAppliedLearnerCreditPolicies = (
redeemableLearnerCreditPolicies?.filter(policy => policy.policyType !== POLICY_TYPES.ASSIGNED_CREDIT).length > 0
);
irfanuddinahmad marked this conversation as resolved.
Show resolved Hide resolved

const [assignmentOnlyLearner, setAssignmentOnlyLearner] = useState(false);
useEffect(() => {
const assignmentsData = redeemableLearnerCreditPolicies?.flatMap(item => item?.learnerContentAssignments || []);
const { hasActiveAssignments } = getActiveAssignments(assignmentsData);
if (
!hasActiveLicenseOrLicenseRequest
&& !hasAssignedCodesOrCodeRequests
&& !hasCurrentEnterpriseOffers
&& !hasAutoAppliedLearnerCreditPolicies
&& hasActiveAssignments
) {
setAssignmentOnlyLearner(true);

Check warning on line 111 in src/components/dashboard/sidebar/SubsidiesSummary.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/dashboard/sidebar/SubsidiesSummary.jsx#L111

Added line #L111 was not covered by tests
}
}, [
redeemableLearnerCreditPolicies,
hasCurrentEnterpriseOffers,
hasAssignedCodesOrCodeRequests,
hasActiveLicenseOrLicenseRequest,
hasAutoAppliedLearnerCreditPolicies,
]);

if (!hasAvailableSubsidyOrRequests) {
return null;
Expand Down Expand Up @@ -136,7 +168,7 @@
/>
)}
</div>
{searchCoursesCta && (
{(searchCoursesCta && !assignmentOnlyLearner) && (
irfanuddinahmad marked this conversation as resolved.
Show resolved Hide resolved
<SidebarCard
cardClassNames="border-0 shadow-none"
>
Expand Down
6 changes: 6 additions & 0 deletions src/components/enterprise-user-subsidy/UserSubsidy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const UserSubsidy = ({ children }) => {
// Enterprise Offers
const {
enterpriseOffers,
currentEnterpriseOffers,
hasCurrentEnterpriseOffers,
canEnrollWithEnterpriseOffers,
hasLowEnterpriseOffersBalance,
hasNoEnterpriseOffersBalance,
Expand Down Expand Up @@ -75,6 +77,8 @@ const UserSubsidy = ({ children }) => {
subscriptionPlan,
couponCodes,
enterpriseOffers,
currentEnterpriseOffers,
hasCurrentEnterpriseOffers,
canEnrollWithEnterpriseOffers,
hasLowEnterpriseOffersBalance,
hasNoEnterpriseOffersBalance,
Expand All @@ -90,6 +94,8 @@ const UserSubsidy = ({ children }) => {
subscriptionPlan,
couponCodes,
enterpriseOffers,
currentEnterpriseOffers,
hasCurrentEnterpriseOffers,
canEnrollWithEnterpriseOffers,
hasLowEnterpriseOffersBalance,
hasNoEnterpriseOffersBalance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export const useEnterpriseOffers = ({
enableLearnerPortalOffers,
}) => {
const [enterpriseOffers, setEnterpriseOffers] = useState([]);
const [currentEnterpriseOffers, setCurrentEnterpriseOffers] = useState([]);
const [isLoadingOffers, setIsLoadingOffers] = useState(true);
const [canEnrollWithEnterpriseOffers, setCanEnrollWithEnterpriseOffers] = useState(false);
const [hasCurrentEnterpriseOffers, setHasCurrentEnterpriseOffers] = useState(false);
const [hasLowEnterpriseOffersBalance, setHasLowEnterpriseOffersBalance] = useState(false);
const [hasNoEnterpriseOffersBalance, setHasNoEnterpriseOffersBalance] = useState(false);

Expand Down Expand Up @@ -50,10 +52,12 @@ export const useEnterpriseOffers = ({
setCanEnrollWithEnterpriseOffers(true);
}

const currentEnterpriseOffers = enterpriseOffers.filter(offer => offer.isCurrent);
if (currentEnterpriseOffers.length > 0) {
const hasLowBalance = currentEnterpriseOffers.some(offer => offer.isLowOnBalance);
const hasNoBalance = currentEnterpriseOffers.every(offer => offer.isOutOfBalance);
const currentEntOffers = enterpriseOffers.filter(offer => offer.isCurrent);
if (currentEntOffers.length > 0) {
setCurrentEnterpriseOffers(currentEntOffers);
setHasCurrentEnterpriseOffers(true);
const hasLowBalance = currentEntOffers.some(offer => offer.isLowOnBalance);
const hasNoBalance = currentEntOffers.every(offer => offer.isOutOfBalance);
setHasLowEnterpriseOffersBalance(hasLowBalance);
setHasNoEnterpriseOffersBalance(hasNoBalance);
}
Expand All @@ -65,6 +69,8 @@ export const useEnterpriseOffers = ({

return {
enterpriseOffers,
currentEnterpriseOffers,
hasCurrentEnterpriseOffers,
canEnrollWithEnterpriseOffers,
hasLowEnterpriseOffersBalance,
hasNoEnterpriseOffersBalance,
Expand Down
Loading