Skip to content

refactor: change to useIntl #1634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/alerts/access-expiration-alert/AccessExpirationAlert.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import PropTypes from 'prop-types';
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
import {
FormattedMessage, FormattedDate, injectIntl, intlShape,
} from '@edx/frontend-platform/i18n';
import { FormattedMessage, FormattedDate, useIntl } from '@edx/frontend-platform/i18n';
import { Alert, Hyperlink } from '@openedx/paragon';
import { Info } from '@openedx/paragon/icons';

import messages from './messages';

const AccessExpirationAlert = ({ intl, payload }) => {
const AccessExpirationAlert = ({ payload }) => {
const intl = useIntl();

Check warning on line 10 in src/alerts/access-expiration-alert/AccessExpirationAlert.jsx

View check run for this annotation

Codecov / codecov/patch

src/alerts/access-expiration-alert/AccessExpirationAlert.jsx#L9-L10

Added lines #L9 - L10 were not covered by tests
const {
accessExpiration,
courseId,
Expand Down Expand Up @@ -119,7 +118,6 @@
};

AccessExpirationAlert.propTypes = {
intl: intlShape.isRequired,
payload: PropTypes.shape({
accessExpiration: PropTypes.shape({
expirationDate: PropTypes.string.isRequired,
Expand All @@ -134,4 +132,4 @@
}).isRequired,
};

export default injectIntl(AccessExpirationAlert);
export default AccessExpirationAlert;
8 changes: 4 additions & 4 deletions src/alerts/active-enteprise-alert/ActiveEnterpriseAlert.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';
import { FormattedMessage, injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
import PropTypes from 'prop-types';
import { Alert, Hyperlink } from '@openedx/paragon';
import { WarningFilled } from '@openedx/paragon/icons';

import { getConfig } from '@edx/frontend-platform';
import genericMessages from './messages';

const ActiveEnterpriseAlert = ({ intl, payload }) => {
const ActiveEnterpriseAlert = ({ payload }) => {
const intl = useIntl();
const { text, courseId } = payload;
const changeActiveEnterprise = (
<Hyperlink
Expand Down Expand Up @@ -38,11 +39,10 @@ const ActiveEnterpriseAlert = ({ intl, payload }) => {
};

ActiveEnterpriseAlert.propTypes = {
intl: intlShape.isRequired,
payload: PropTypes.shape({
text: PropTypes.string,
courseId: PropTypes.string,
}).isRequired,
};

export default injectIntl(ActiveEnterpriseAlert);
export default ActiveEnterpriseAlert;
8 changes: 4 additions & 4 deletions src/alerts/enrollment-alert/EnrollmentAlert.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { useIntl } from '@edx/frontend-platform/i18n';
import PropTypes from 'prop-types';
import { Alert, Button } from '@openedx/paragon';
import { Info, WarningFilled } from '@openedx/paragon/icons';
Expand All @@ -11,7 +11,8 @@
import messages from './messages';
import useEnrollClickHandler from './clickHook';

const EnrollmentAlert = ({ intl, payload }) => {
const EnrollmentAlert = ({ payload }) => {
const intl = useIntl();

Check warning on line 15 in src/alerts/enrollment-alert/EnrollmentAlert.jsx

View check run for this annotation

Codecov / codecov/patch

src/alerts/enrollment-alert/EnrollmentAlert.jsx#L14-L15

Added lines #L14 - L15 were not covered by tests
const {
canEnroll,
courseId,
Expand Down Expand Up @@ -58,7 +59,6 @@
};

EnrollmentAlert.propTypes = {
intl: intlShape.isRequired,
payload: PropTypes.shape({
canEnroll: PropTypes.bool,
courseId: PropTypes.string,
Expand All @@ -67,4 +67,4 @@
}).isRequired,
};

export default injectIntl(EnrollmentAlert);
export default EnrollmentAlert;
13 changes: 4 additions & 9 deletions src/alerts/logistration-alert/AccountActivationAlert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import {
Icon,
} from '@openedx/paragon';
import { Check, ArrowForward } from '@openedx/paragon/icons';
import { FormattedMessage, injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
import { sendActivationEmail } from '../../courseware/data';
import messages from './messages';

const AccountActivationAlert = ({
intl,
}) => {
const AccountActivationAlert = () => {
const intl = useIntl();
const [showModal, setShowModal] = useState(false);
const [showSpinner, setShowSpinner] = useState(false);
const [showCheck, setShowCheck] = useState(false);
Expand Down Expand Up @@ -125,8 +124,4 @@ const AccountActivationAlert = ({
);
};

AccountActivationAlert.propTypes = {
intl: intlShape.isRequired,
};

export default injectIntl(AccountActivationAlert);
export default AccountActivationAlert;
11 changes: 4 additions & 7 deletions src/alerts/logistration-alert/LogistrationAlert.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';
import { getConfig } from '@edx/frontend-platform';
import { injectIntl, intlShape, FormattedMessage } from '@edx/frontend-platform/i18n';
import { useIntl, FormattedMessage } from '@edx/frontend-platform/i18n';
import { getLoginRedirectUrl } from '@edx/frontend-platform/auth';
import { Alert, Hyperlink } from '@openedx/paragon';
import { WarningFilled } from '@openedx/paragon/icons';

import genericMessages from '../../generic/messages';

const LogistrationAlert = ({ intl }) => {
const LogistrationAlert = () => {
const intl = useIntl();

Check warning on line 11 in src/alerts/logistration-alert/LogistrationAlert.jsx

View check run for this annotation

Codecov / codecov/patch

src/alerts/logistration-alert/LogistrationAlert.jsx#L10-L11

Added lines #L10 - L11 were not covered by tests
const signIn = (
<Hyperlink
style={{ textDecoration: 'underline' }}
Expand Down Expand Up @@ -43,8 +44,4 @@
);
};

LogistrationAlert.propTypes = {
intl: intlShape.isRequired,
};

export default injectIntl(LogistrationAlert);
export default LogistrationAlert;
11 changes: 4 additions & 7 deletions src/course-home/courseware-search/CoursewareResultsFilter.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo } from 'react';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { useIntl } from '@edx/frontend-platform/i18n';
import { Tabs, Tab } from '@openedx/paragon';

import { useParams } from 'react-router';
Expand All @@ -13,7 +13,8 @@ const filterTypes = ['text', 'video', 'sequence'];
const filterOther = 'other';
const validFilters = [filterAll, ...filterTypes, filterOther];

export const CoursewareSearchResultsFilter = ({ intl }) => {
export const CoursewareSearchResultsFilter = () => {
const intl = useIntl();
const { courseId } = useParams();
const lastSearch = useModel('contentSearchResults', courseId);
const { filter: filterKeyword, setFilter } = useCoursewareSearchParams();
Expand Down Expand Up @@ -73,8 +74,4 @@ export const CoursewareSearchResultsFilter = ({ intl }) => {
);
};

CoursewareSearchResultsFilter.propTypes = {
intl: intlShape.isRequired,
};

export default injectIntl(CoursewareSearchResultsFilter);
export default CoursewareSearchResultsFilter;
19 changes: 9 additions & 10 deletions src/course-home/courseware-search/CoursewareSearchEmpty.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React from 'react';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { useIntl } from '@edx/frontend-platform/i18n';
import messages from './messages';

const CoursewareSearchEmpty = ({ intl }) => (
<div className="courseware-search-results">
<p className="courseware-search-results__empty" data-testid="no-results">{intl.formatMessage(messages.searchResultsNone)}</p>
</div>
);

CoursewareSearchEmpty.propTypes = {
intl: intlShape.isRequired,
const CoursewareSearchEmpty = () => {
const intl = useIntl();
return (
<div className="courseware-search-results">
<p className="courseware-search-results__empty" data-testid="no-results">{intl.formatMessage(messages.searchResultsNone)}</p>
</div>
);
};

export default injectIntl(CoursewareSearchEmpty);
export default CoursewareSearchEmpty;
13 changes: 4 additions & 9 deletions src/course-home/courseware-search/CoursewareSearchToggle.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import React, { useEffect } from 'react';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { useIntl } from '@edx/frontend-platform/i18n';
import { Button } from '@openedx/paragon';
import { ManageSearch } from '@openedx/paragon/icons';
import { useDispatch } from 'react-redux';
import messages from './messages';
import { useCoursewareSearchFeatureFlag, useCoursewareSearchParams } from './hooks';
import { setShowSearch } from '../data/slice';

const CoursewareSearchToggle = ({
intl,
}) => {
const CoursewareSearchToggle = () => {
const intl = useIntl();
const dispatch = useDispatch();
const enabled = useCoursewareSearchFeatureFlag();
const { query } = useCoursewareSearchParams();
Expand Down Expand Up @@ -41,8 +40,4 @@ const CoursewareSearchToggle = ({
);
};

CoursewareSearchToggle.propTypes = {
intl: intlShape.isRequired,
};

export default injectIntl(CoursewareSearchToggle);
export default CoursewareSearchToggle;
11 changes: 4 additions & 7 deletions src/course-home/dates-tab/DatesTab.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { useSelector } from 'react-redux';
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { useIntl } from '@edx/frontend-platform/i18n';

import messages from './messages';
import Timeline from './timeline/Timeline';
Expand All @@ -14,7 +14,8 @@ import ShiftDatesAlert from '../suggested-schedule-messaging/ShiftDatesAlert';
import UpgradeToCompleteAlert from '../suggested-schedule-messaging/UpgradeToCompleteAlert';
import UpgradeToShiftDatesAlert from '../suggested-schedule-messaging/UpgradeToShiftDatesAlert';

const DatesTab = ({ intl }) => {
const DatesTab = () => {
const intl = useIntl();
const {
courseId,
} = useSelector(state => state.courseHome);
Expand Down Expand Up @@ -59,8 +60,4 @@ const DatesTab = ({ intl }) => {
);
};

DatesTab.propTypes = {
intl: intlShape.isRequired,
};

export default injectIntl(DatesTab);
export default DatesTab;
8 changes: 3 additions & 5 deletions src/course-home/dates-tab/timeline/Day.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { useSelector } from 'react-redux';
import {
FormattedDate,
FormattedTime,
injectIntl,
intlShape,
useIntl,
} from '@edx/frontend-platform/i18n';
import { Tooltip, OverlayTrigger } from '@openedx/paragon';
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons';
Expand All @@ -20,10 +19,10 @@ import { isLearnerAssignment } from '../utils';
const Day = ({
date,
first,
intl,
items,
last,
}) => {
const intl = useIntl();
const {
courseId,
} = useSelector(state => state.courseHome);
Expand Down Expand Up @@ -108,7 +107,6 @@ const Day = ({
Day.propTypes = {
date: PropTypes.objectOf(Date).isRequired,
first: PropTypes.bool,
intl: intlShape.isRequired,
items: PropTypes.arrayOf(PropTypes.shape({
date: PropTypes.string,
dateType: PropTypes.string,
Expand All @@ -126,4 +124,4 @@ Day.defaultProps = {
last: false,
};

export default injectIntl(Day);
export default Day;
5 changes: 1 addition & 4 deletions src/course-home/discussion-tab/DiscussionTab.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getConfig } from '@edx/frontend-platform';
import { injectIntl } from '@edx/frontend-platform/i18n';
import React, { useState } from 'react';
import { useSelector } from 'react-redux';
import { useParams, generatePath, useNavigate } from 'react-router-dom';
Expand Down Expand Up @@ -30,6 +29,4 @@ const DiscussionTab = () => {
);
};

DiscussionTab.propTypes = {};

export default injectIntl(DiscussionTab);
export default DiscussionTab;
11 changes: 4 additions & 7 deletions src/course-home/goal-unsubscribe/GoalUnsubscribe.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { useIntl } from '@edx/frontend-platform/i18n';

import HeaderSlot from '../../plugin-slots/HeaderSlot';
import PageLoading from '../../generic/PageLoading';
Expand All @@ -10,7 +10,8 @@ import { unsubscribeFromCourseGoal } from '../data/api';
import messages from './messages';
import ResultPage from './ResultPage';

const GoalUnsubscribe = ({ intl }) => {
const GoalUnsubscribe = () => {
const intl = useIntl();
const { token } = useParams();
const [error, setError] = useState(false);
const [isLoading, setIsLoading] = useState(true);
Expand Down Expand Up @@ -51,8 +52,4 @@ const GoalUnsubscribe = ({ intl }) => {
);
};

GoalUnsubscribe.propTypes = {
intl: intlShape.isRequired,
};

export default injectIntl(GoalUnsubscribe);
export default GoalUnsubscribe;
37 changes: 17 additions & 20 deletions src/course-home/goal-unsubscribe/ResultPage.jsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import PropTypes from 'prop-types';
import { getConfig } from '@edx/frontend-platform';
import { FormattedMessage, injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { useIntl } from '@edx/frontend-platform/i18n';
import { Button, Hyperlink } from '@openedx/paragon';

import messages from './messages';
import { ReactComponent as UnsubscribeIcon } from './unsubscribe.svg';

const ResultPage = ({ courseTitle, error, intl }) => {
const errorDescription = (
<FormattedMessage
id="learning.goals.unsubscribe.errorDescription"
defaultMessage="We were unable to unsubscribe you from goal reminder emails. Please try again later or {contactSupport} for help."
values={{
contactSupport: (
<Hyperlink
className="text-reset"
style={{ textDecoration: 'underline' }}
destination={`${getConfig().CONTACT_URL}`}
>
{intl.formatMessage(messages.contactSupport)}
</Hyperlink>
),
}}
/>
const ResultPage = ({ courseTitle, error }) => {
const intl = useIntl();
const errorDescription = intl.formatMessage(
messages.errorDescription,
{
contactSupport: (
<Hyperlink
className="text-reset"
style={{ textDecoration: 'underline' }}
destination={`${getConfig().CONTACT_URL}`}
>
{intl.formatMessage(messages.contactSupport)}
</Hyperlink>
),
},
);

const header = error
Expand Down Expand Up @@ -54,7 +52,6 @@ ResultPage.defaultProps = {
ResultPage.propTypes = {
courseTitle: PropTypes.string,
error: PropTypes.bool,
intl: intlShape.isRequired,
};

export default injectIntl(ResultPage);
export default ResultPage;
Loading