-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathResumeButton.jsx
More file actions
46 lines (42 loc) · 1.59 KB
/
Copy pathResumeButton.jsx
File metadata and controls
46 lines (42 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import { useIntl } from '@edx/frontend-platform/i18n';
import { EXECUTIVE_EDUCATION_COURSE_MODES } from 'data/constants/course';
import { baseAppUrl } from 'data/services/lms/urls';
import track from 'tracking';
import { useCourseTrackingEvent, useCourseData } from 'hooks';
import { useInitializeLearnerHome } from 'data/hooks';
import useActionDisabledState from '../hooks';
import ActionButton from './ActionButton';
import messages from './messages';
export const ResumeButton = ({ cardId }) => {
const { formatMessage } = useIntl();
const { data: learnerData } = useInitializeLearnerHome();
const courseData = useCourseData(cardId);
const resumeUrl = courseData?.courseRun?.resumeUrl;
const execEdTrackingParam = useMemo(() => {
const isExecEd2UCourse = EXECUTIVE_EDUCATION_COURSE_MODES.includes(courseData.enrollment.mode);
const { authOrgId } = learnerData.enterpriseDashboard || {};
return isExecEd2UCourse ? `?org_id=${authOrgId}` : '';
}, [courseData.enrollment.mode, learnerData.enterpriseDashboard]);
const { disableResumeCourse } = useActionDisabledState(cardId);
const handleClick = useCourseTrackingEvent(
track.course.enterCourseClicked,
cardId,
baseAppUrl(resumeUrl) + execEdTrackingParam,
);
return (
<ActionButton
disabled={disableResumeCourse}
as="a"
href="#"
onClick={handleClick}
>
{formatMessage(messages.resume)}
</ActionButton>
);
};
ResumeButton.propTypes = {
cardId: PropTypes.string.isRequired,
};
export default ResumeButton;