Skip to content
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

fix: removes duplicate redirect #904

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions src/components/course/routes/CoursePageRoutes.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';
import { Switch, useRouteMatch } from 'react-router-dom';
import { PageRoute } from '@edx/frontend-platform/react';

import CourseAbout from './CourseAbout';
import ExternalCourseEnrollment from './ExternalCourseEnrollment';
import ExternalCourseEnrollmentConfirmation from './ExternalCourseEnrollmentConfirmation';
import CourseAbout from './CourseAbout';
import NotFoundPage from '../../NotFoundPage';

const CoursePageRoutes = () => {
Expand Down
21 changes: 12 additions & 9 deletions src/components/course/routes/ExternalCourseEnrollment.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useContext, useEffect, useRef } from 'react';
import { useHistory } from 'react-router-dom';
import { generatePath, useHistory, useRouteMatch } from 'react-router-dom';
import {
Alert, Button, Col, Container, Hyperlink, Row,
} from '@edx/paragon';
Expand All @@ -20,6 +20,7 @@ import { features } from '../../../config';
const ExternalCourseEnrollment = () => {
const config = getConfig();
const history = useHistory();
const routeMatch = useRouteMatch();
const {
state: {
activeCourseRun,
Expand All @@ -31,9 +32,13 @@ const ExternalCourseEnrollment = () => {
externalCourseFormSubmissionError,
} = useContext(CourseContext);
const {
enterpriseConfig: { authOrgId },
enterpriseConfig: { authOrgId, slug },
} = useContext(AppContext);
const { redeemableLearnerCreditPolicies } = useContext(UserSubsidyContext);
const completeEnrollmentUrl = generatePath(
`${routeMatch.path}/complete`,
{ enterpriseSlug: slug, courseType: course.courseType, courseKey: course.key },
);
const isCourseAssigned = useIsCourseAssigned(redeemableLearnerCreditPolicies?.learnerContentAssignments, course?.key);

const courseMetadata = useMinimalCourseMetadata();
Expand Down Expand Up @@ -62,15 +67,14 @@ const ExternalCourseEnrollment = () => {
}
}, [externalCourseFormSubmissionError, containerRef]);

const handleCheckoutSuccess = () => {
history.push('enroll/complete');
};

useEffect(() => {
// Once a redemption has successfully completed and the can-redeem query has been invalidated or
// a user attempts to navigate directly to :slug/executive-education-2u/course/:courseKey/enroll,
// it will run this conditional and perform the redirect
if (hasSuccessfulRedemption) {
history.push('enroll/complete');
history.push({ pathname: completeEnrollmentUrl });
brobro10000 marked this conversation as resolved.
Show resolved Hide resolved
}
}, [hasSuccessfulRedemption, history]);
}, [completeEnrollmentUrl, course.key, hasSuccessfulRedemption, history, routeMatch.path, slug]);

return (
<div className="fill-vertical-space page-light-bg">
Expand Down Expand Up @@ -120,7 +124,6 @@ const ExternalCourseEnrollment = () => {
<RegistrationSummaryCard priceDetails={courseMetadata.priceDetails} />
<UserEnrollmentForm
productSKU={courseEntitlementProductSku}
onCheckoutSuccess={handleCheckoutSuccess}
activeCourseRun={activeCourseRun}
userSubsidyApplicableToCourse={userSubsidyApplicableToCourse}
/>
Expand Down
7 changes: 5 additions & 2 deletions src/components/executive-education-2u/UserEnrollmentForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ const UserEnrollmentForm = ({
await queryClient.invalidateQueries({
queryKey: enterpriseUserSubsidyQueryKeys.policy(),
});
onCheckoutSuccess(newTransaction);
if (onCheckoutSuccess) {
onCheckoutSuccess(newTransaction);
}
};

const { redeem } = useStatefulEnroll({
Expand Down Expand Up @@ -394,7 +396,7 @@ const UserEnrollmentForm = ({
UserEnrollmentForm.propTypes = {
className: PropTypes.string,
productSKU: PropTypes.string.isRequired,
onCheckoutSuccess: PropTypes.func.isRequired,
onCheckoutSuccess: PropTypes.func,
activeCourseRun: PropTypes.shape({
key: PropTypes.string.isRequired,
}).isRequired,
Expand All @@ -406,6 +408,7 @@ UserEnrollmentForm.propTypes = {
UserEnrollmentForm.defaultProps = {
className: undefined,
userSubsidyApplicableToCourse: undefined,
onCheckoutSuccess: undefined,
};

export default UserEnrollmentForm;
Loading