Skip to content

Commit

Permalink
temp: progressing on using new audit trial hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ilee2u committed Dec 13, 2024
1 parent 20464ea commit bf791da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/components/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);

Expand Down Expand Up @@ -93,20 +93,27 @@ const Sidebar = ({
<MessageForm courseId={courseId} shouldAutofocus unitId={unitId} />
);

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 (
<div>
Your trial ends {irtl.format(daysRemaining, 'day')}. <a target="_blank" href={upgradeURL} rel="noreferrer">Upgrade</a> for full access to Xpert.
Your trial ends {irtl.format(auditTrialDaysRemaining, 'day')}. <a target="_blank" href={upgradeURL} rel="noreferrer">Upgrade</a> for full access to Xpert.
</div>
);
} if (daysRemaining === 1) {
} if (auditTrialDaysRemaining === 1) {
return (
<div>
Your trial ends today! <a target="_blank" href={upgradeURL} rel="noreferrer">Upgrade</a> for full access to Xpert.
Expand All @@ -121,21 +128,16 @@ 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 = () => (
<div className="h-100 d-flex flex-column justify-content-stretch" data-testid="sidebar-xpert">
<div className="p-3 sidebar-header" data-testid="sidebar-xpert-header">
<XpertLogo />
</div>
{isUpgradeEligible
&& (
<div className="p-3 trial-header">
{getDaysRemainingMessage(auditTrialExpirationDate)}
</div>
<div className="p-3 trial-header">
{getDaysRemainingMessage()}
</div>
)}
<span className="separator" />
<ChatBox
Expand Down
1 change: 1 addition & 0 deletions src/data/thunks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('Thunks unit tests', () => {

describe('addChatMessage()', () => {
const mockDate = new Date(2024, 1, 1);

beforeEach(async () => {
setModel('coursewareMeta', Factory.build('coursewareMeta'));
setModel('courseHomeMeta', Factory.build('courseHomeMeta'));
Expand Down

0 comments on commit bf791da

Please sign in to comment.