Skip to content

Commit

Permalink
feat: Updated some logic for the useCourseUpgrade() hook
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Dec 13, 2024
1 parent b0289f8 commit 342dde0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/hooks/use-course-upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,37 @@ import { useModel } from '@src/generic/model-store'; // eslint-disable-line impo
import { useSelector } from 'react-redux';
import { CourseInfoContext } from '../context';

const millisecondsInOneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds

export default function useCourseUpgrade() {
const { courseId, isUpgradeEligible } = useContext(CourseInfoContext);
const { offer } = useModel('coursewareMeta', courseId);
const { verifiedMode } = useModel('courseHomeMeta', courseId);
const {
auditTrialLengthDays,
auditTrial,
} = useSelector(state => state.learningAssistant);

const upgradeUrl = offer?.upgradeUrl || verifiedMode?.upgradeUrl;

if (!isUpgradeEligible || !upgradeUrl) { return { upgradeable: false }; }

let auditTrialExpired = false;
let auditTrialDaysRemaining;

if (auditTrial?.expirationDate) {
const auditTrialExpirationDate = new Date(auditTrial.expirationDate);
auditTrialDaysRemaining = Math.ceil((auditTrialExpirationDate - Date.now()) / millisecondsInOneDay);

auditTrialExpired = auditTrialDaysRemaining < 0;
}

return {
upgradeable: true,
auditTrialLengthDays,
auditTrialDaysRemaining,
auditTrialExpired,
auditTrial,
upgradeUrl,
};
}

0 comments on commit 342dde0

Please sign in to comment.