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

fix: Update threshold dates for displaying course runs #1317

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import React, { useCallback, useContext, useState } from 'react';
import PropTypes from 'prop-types';
import { generatePath, useNavigate, useParams } from 'react-router-dom';
import { sendEnterpriseTrackEvent } from '@edx/frontend-enterprise-utils';
import { getConfig } from '@edx/frontend-platform/config';
import { camelCaseObject, snakeCaseObject } from '@edx/frontend-platform/utils';
import {
ActionRow, Button, FullscreenModal, Hyperlink, StatefulButton, useToggle,
} from '@openedx/paragon';
import { sendEnterpriseTrackEvent } from '@edx/frontend-enterprise-utils';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { camelCaseObject, snakeCaseObject } from '@edx/frontend-platform/utils';
import PropTypes from 'prop-types';
import React, { useCallback, useContext, useState } from 'react';
import { connect } from 'react-redux';
import { getConfig } from '@edx/frontend-platform/config';
import { generatePath, useNavigate, useParams } from 'react-router-dom';

import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
import { logError } from '@edx/frontend-platform/logging';
import AssignmentModalContent from './AssignmentModalContent';
import EnterpriseAccessApiService from '../../../data/services/EnterpriseAccessApiService';
import EVENT_NAMES from '../../../eventTracking';
import { BudgetDetailPageContext } from '../BudgetDetailPageWrapper';
import {
getAssignableCourseRuns,
LEARNER_CREDIT_ROUTE,
learnerCreditManagementQueryKeys,
useBudgetId,
getAssignableCourseRuns, learnerCreditManagementQueryKeys, LEARNER_CREDIT_ROUTE, useBudgetId,
useSubsidyAccessPolicy,
} from '../data';
import AssignmentModalContent from './AssignmentModalContent';
import CreateAllocationErrorAlertModals from './CreateAllocationErrorAlertModals';
import { BudgetDetailPageContext } from '../BudgetDetailPageWrapper';
import EVENT_NAMES from '../../../eventTracking';
import NewAssignmentModalDropdown from './NewAssignmentModalDropdown';

const useAllocateContentAssignments = () => useMutation({
Expand Down Expand Up @@ -88,7 +85,7 @@ const NewAssignmentModalButton = ({ enterpriseId, course, children }) => {
setAssignmentRun(selectedCourseRun);
if (!selectedCourseRun) {
logError(`[handleOpenAssignmentModal]: Unable to open learner credit management allocation modal,
selectedCourseRun: ${selectedCourseRun},
selectedCourseRun: ${selectedCourseRun},
parentContentKey: ${course.key},
contentKey: ${selectedCourseRun.key},
enterpriseUuid: ${enterpriseId},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineMessages, useIntl } from '@edx/frontend-platform/i18n';
import { Dropdown, Stack } from '@openedx/paragon';
import dayjs from 'dayjs';
import PropTypes from 'prop-types';
import { defineMessages, useIntl } from '@edx/frontend-platform/i18n';
import { useState } from 'react';
import { SHORT_MONTH_DATE_FORMAT } from '../data';

Expand Down Expand Up @@ -29,7 +29,10 @@ const messages = defineMessages({
});

const NewAssignmentModalDropdown = ({
id: courseKey, onClick: openAssignmentModal, courseRuns, children,
id: courseKey,
onClick: openAssignmentModal,
courseRuns,
children,
}) => {
const intl = useIntl();
const [clickedDropdownItem, setClickedDropdownItem] = useState(null);
Expand Down
52 changes: 35 additions & 17 deletions src/components/learner-credit-management/data/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { v4 as uuidv4 } from 'uuid';
import dayjs from 'dayjs';
import { camelCaseObject } from '@edx/frontend-platform/utils';
import { logInfo } from '@edx/frontend-platform/logging';
import { camelCaseObject } from '@edx/frontend-platform/utils';
import dayjs from 'dayjs';
import { v4 as uuidv4 } from 'uuid';

import EnterpriseAccessApiService from '../../../data/services/EnterpriseAccessApiService';
import EnterpriseDataApiService from '../../../data/services/EnterpriseDataApiService';
import SubsidyApiService from '../../../data/services/EnterpriseSubsidyApiService';
import { isPlanApproachingExpiry } from '../../BudgetExpiryAlertAndModal/data/utils';
import { BUDGET_STATUSES } from '../../EnterpriseApp/data/constants';
import {
ASSIGNMENT_ENROLLMENT_DEADLINE,
COURSE_PACING_MAP,
Expand All @@ -13,11 +18,6 @@ import {
NO_BALANCE_REMAINING_DOLLAR_THRESHOLD,
START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS,
} from './constants';
import { BUDGET_STATUSES } from '../../EnterpriseApp/data/constants';
import EnterpriseAccessApiService from '../../../data/services/EnterpriseAccessApiService';
import EnterpriseDataApiService from '../../../data/services/EnterpriseDataApiService';
import SubsidyApiService from '../../../data/services/EnterpriseSubsidyApiService';
import { isPlanApproachingExpiry } from '../../BudgetExpiryAlertAndModal/data/utils';

/**
* Transforms subsidy (offer or Subsidy) summary from API for display in the UI, guarding
Expand Down Expand Up @@ -570,6 +570,26 @@ export const minimumEnrollByDateFromToday = ({ subsidyExpirationDatetime }) => M
dayjs(subsidyExpirationDatetime).subtract(MAX_ALLOWABLE_REFUND_THRESHOLD_DAYS, 'days').toDate(),
);

const subsidyExpirationRefundCutoffDate = ({ subsidyExpirationDatetime }) => dayjs(subsidyExpirationDatetime).subtract(MAX_ALLOWABLE_REFUND_THRESHOLD_DAYS, 'days').toDate();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could re-use this directly above in minimumEnrollByDateFromToday. Actually now that I'm looking at that function, is the min() doing anything?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the min portion was left in incase additional criteria would need to be added, for right now its determining a fallback enrollby date to display within getNormalizedEnrollByDate.

const startDateThreshold = ({ enrollmentStart, start, subsidyExpirationDatetime }) => {
const timeStampStartDate = dayjs(start).unix();
const timeStampEnrollmentStartDate = dayjs(enrollmentStart).unix();
const earliestStartDate = Math.min(timeStampStartDate, timeStampEnrollmentStartDate);
const isEarliestStartDateBeforeRefundDate = dayjs(
earliestStartDate,
).isBefore(subsidyExpirationRefundCutoffDate({ subsidyExpirationDatetime }), 'seconds');
return (!start && !enrollmentStart) || isEarliestStartDateBeforeRefundDate;
};
brobro10000 marked this conversation as resolved.
Show resolved Hide resolved

const enrollByDateThreshold = ({ enrollBy, isLateRedemptionAllowed = false }) => {
let enrollByCutoffDate = dayjs();
if (isLateRedemptionAllowed) {
brobro10000 marked this conversation as resolved.
Show resolved Hide resolved
enrollByCutoffDate = enrollByCutoffDate.subtract(LATE_ENROLLMENTS_BUFFER_DAYS, 'days');
}
return !enrollBy || dayjs(enrollBy).isAfter(enrollByCutoffDate, 'seconds');
};
brobro10000 marked this conversation as resolved.
Show resolved Hide resolved

export const isCourseSelfPaced = ({ pacingType }) => pacingType === COURSE_PACING_MAP.SELF_PACED;

export const hasTimeToComplete = ({ end, weeksToComplete }) => {
Expand Down Expand Up @@ -656,20 +676,18 @@ export const getAssignableCourseRuns = ({ courseRuns, subsidyExpirationDatetime,
upgradeDeadline: dayjs.unix(courseRun.upgradeDeadline).toISOString(),
}));
const assignableCourseRunsFilter = ({
enrollBy, isActive, hasEnrollBy, isLateEnrollmentEligible,
enrollBy, start, isActive, hasEnrollBy, isLateEnrollmentEligible,
}) => {
let isEligibleForEnrollment = true;
// Determine eligibility based on the provided enrollBy, start, and enrollmentStart date
isEligibleForEnrollment = enrollByDateThreshold({ enrollBy, isLateRedemptionAllowed }) && startDateThreshold({
enrollmentStart: dayjs().toDate(),
brobro10000 marked this conversation as resolved.
Show resolved Hide resolved
start,
brobro10000 marked this conversation as resolved.
Show resolved Hide resolved
subsidyExpirationDatetime,
});
if (hasEnrollBy) {
const enrollByDate = dayjs(enrollBy);
// Determine eligibility based on the provided enrollBy is and the subsidy expiration date - refund threshold
isEligibleForEnrollment = (
!isDateBeforeToday(enrollByDate)
&& enrollByDate.isBefore(minimumEnrollByDateFromToday({ subsidyExpirationDatetime }))
);
// Late redemption filter
if (isDateBeforeToday(enrollBy) && isLateRedemptionAllowed) {
const lateEnrollmentCutoff = dayjs().subtract(LATE_ENROLLMENTS_BUFFER_DAYS, 'days');
isEligibleForEnrollment = enrollByDate.isAfter(lateEnrollmentCutoff);
return isLateEnrollmentEligible && isEligibleForEnrollment;
}
}
Expand Down
Loading