Migrate from Redux to React Query and React Context. This modernizes state management while maintaining all existing functionality. All the redux code and files were removed, including all redux and related packages.
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
|
|
import track from 'tracking';
|
|
import { useCourseData, useCourseTrackingEvent } from 'hooks';
|
|
import useActionDisabledState from './hooks';
|
|
|
|
const { courseTitleClicked } = track.course;
|
|
|
|
export const CourseCardTitle = ({ cardId }) => {
|
|
const courseData = useCourseData(cardId);
|
|
const courseName = courseData?.course?.courseName;
|
|
const homeUrl = courseData?.courseRun?.homeUrl;
|
|
const handleTitleClicked = useCourseTrackingEvent(
|
|
courseTitleClicked,
|
|
cardId,
|
|
homeUrl,
|
|
);
|
|
const { disableCourseTitle } = useActionDisabledState(cardId);
|
|
return (
|
|
<h3>
|
|
{disableCourseTitle ? (
|
|
<span className="course-card-title" data-testid="CourseCardTitle">{courseName}</span>
|
|
) : (
|
|
<a
|
|
href={homeUrl}
|
|
className="course-card-title"
|
|
data-testid="CourseCardTitle"
|
|
onClick={handleTitleClicked}
|
|
>
|
|
{courseName}
|
|
</a>
|
|
)}
|
|
</h3>
|
|
);
|
|
};
|
|
|
|
CourseCardTitle.propTypes = {
|
|
cardId: PropTypes.string.isRequired,
|
|
};
|
|
|
|
CourseCardTitle.defaultProps = {};
|
|
|
|
export default CourseCardTitle;
|