Skip to content

Commit

Permalink
fix: removes duplicate redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Dec 14, 2023
1 parent 5e55008 commit 2973e69
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/components/course/routes/CourseAbout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const CourseAbout = () => {
subscriptionPlan,
subscriptionLicense,
} = useContext(UserSubsidyContext);

const isCourseAssigned = useIsCourseAssigned(redeemableLearnerCreditPolicies?.learnerContentAssignments, course?.key);
const hideCourseSearch = isDisableCourseSearch(
redeemableLearnerCreditPolicies,
Expand Down
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 });
}
}, [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;

0 comments on commit 2973e69

Please sign in to comment.