diff --git a/src/components/Sidebar/index.jsx b/src/components/Sidebar/index.jsx index fa5b2002..70292ca8 100644 --- a/src/components/Sidebar/index.jsx +++ b/src/components/Sidebar/index.jsx @@ -16,6 +16,7 @@ import APIError from '../APIError'; import ChatBox from '../ChatBox'; import Disclosure from '../Disclosure'; import MessageForm from '../MessageForm'; +import { useCourseUpgrade, useTrackEvent } from '../../hooks'; import { ReactComponent as XpertLogo } from '../../assets/xpert-logo.svg'; import './Sidebar.scss'; @@ -28,12 +29,11 @@ const Sidebar = ({ }) => { const { apiError, - auditTrial, disclosureAcknowledged, messageList, } = useSelector(state => state.learningAssistant); - const auditTrialExpirationDate = new Date(auditTrial.expirationDate); + const { upgradeUrl, auditTrialDaysRemaining } = useCourseUpgrade(); const chatboxContainerRef = useRef(null); @@ -93,20 +93,27 @@ const Sidebar = ({ ); - const getDaysRemainingMessage = (auditTrialExpirationDate) => { - const millisecondsInOneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds - const daysRemaining = Math.ceil((auditTrialExpirationDate - Date.now()) / millisecondsInOneDay); + /** + * isUpgradeEligible - can they have an audit trial? + not staff + enrolled as audit or honor + course has verified mode + enable xpert audit setting is true + if isUpgradeEligible: + show all the audit trial data, expired or not. + */ + const getDaysRemainingMessage = () => { const upgradeURL = offer ? offer.upgradeUrl : verifiedMode.upgradeUrl; - if (daysRemaining > 1) { + if (auditTrialDaysRemaining > 1) { const irtl = new Intl.RelativeTimeFormat({ style: 'long' }); return (
- Your trial ends {irtl.format(daysRemaining, 'day')}. Upgrade for full access to Xpert. + Your trial ends {irtl.format(auditTrialDaysRemaining, 'day')}. Upgrade for full access to Xpert.
); - } if (daysRemaining === 1) { + } if (auditTrialDaysRemaining === 1) { return (
Your trial ends today! Upgrade for full access to Xpert. @@ -121,11 +128,6 @@ const Sidebar = ({ ); }; - /** - * if no audit trial, and chat message endpoint success, - * we know an audit trial just started so write "[xpert_trial_length] days" - * and re-call the chat summary endpoint - */ const getSidebar = () => (
@@ -133,9 +135,9 @@ const Sidebar = ({
{isUpgradeEligible && ( -
- {getDaysRemainingMessage(auditTrialExpirationDate)} -
+
+ {getDaysRemainingMessage()} +
)} { describe('addChatMessage()', () => { const mockDate = new Date(2024, 1, 1); + beforeEach(async () => { setModel('coursewareMeta', Factory.build('coursewareMeta')); setModel('courseHomeMeta', Factory.build('courseHomeMeta'));