Skip to content

Commit

Permalink
chore: Updated based on Code Review
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Dec 16, 2024
1 parent 1e56ec3 commit ba7a021
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/Disclosure/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Disclosure = ({ children }) => {
const { upgradeable, upgradeUrl, auditTrialLengthDays } = useCourseUpgrade();
const { track } = useTrackEvent();

const handleClick = () => track('edx.ui.lms.learning_assistant.message');
const handleClick = () => track('edx.ui.lms.learning_assistant.disclosure_upgrade_click');
const freeDays = auditTrialLengthDays === 1 ? '1 day' : `${auditTrialLengthDays} days`;

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Disclosure/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('<TrialDisclosure />', () => {

fireEvent.click(upgradeCta);

expect(mockedTrackEvent).toHaveBeenCalledWith('edx.ui.lms.learning_assistant.message');
expect(mockedTrackEvent).toHaveBeenCalledWith('edx.ui.lms.learning_assistant.disclosure_upgrade_click');
});

it('should match snapshot', () => {
Expand Down
23 changes: 23 additions & 0 deletions src/hooks/use-course-upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ import { CourseInfoContext } from '../context';

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

/**
* @typedef AuditTrial
* @type {object}
* @property {string} startDate Date String with the Trial start date.
* @property {string} expirationDate Date String with the Trial expiration date.
*/

/**
* @typedef CourseUpgradeInfo
* @type {object}
* @property {boolean} upgradeable Should this user see a trial/upgrade option?.
* @property {number} [auditTrialLengthDays] Audit Trial full length in days.
* @property {number} [auditTrialDaysRemaining] Remaining day for the current trial (if any).
* @property {boolean} [auditTrialExpired] True means that the audit has been taken and expired.
* @property {AuditTrial} [auditTrial] The Audit trial information. Undefined if there's no trial for this user.
* @property {string} [upgradeUrl] URL to redirect the user in case there's intention to upgrade.
*/

/**
* This hook returns related data for the Course Upgrade.
*
* @returns {CourseUpgradeInfo}
*/
export default function useCourseUpgrade() {
const { courseId, isUpgradeEligible } = useContext(CourseInfoContext);
const { offer } = useModel('coursewareMeta', courseId);
Expand Down
11 changes: 11 additions & 0 deletions src/hooks/use-track-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
import { CourseInfoContext } from '../context';

/**
* @typedef Tracker
* @type {object}
* @property {(eventName: string, details?: object)} track Calls sendTrackEvent with user and course context.
*/

/**
* This hook returns a track method to track events.
*
* @returns {Tracker}
*/
export default function useTrackEvent() {
const { courseId, moduleId } = useContext(CourseInfoContext);
const { userId } = getAuthenticatedUser();
Expand Down

0 comments on commit ba7a021

Please sign in to comment.