1- import React , { useState } from 'react' ;
1+ import React , { useEffect , useState } from 'react' ;
2+ import { useLocation } from 'react-router-dom' ;
23import PropTypes from 'prop-types' ;
34
45import { Form , Card , Icon } from '@edx/paragon' ;
6+ import { history } from '@edx/frontend-platform' ;
57import { sendTrackEvent } from '@edx/frontend-platform/analytics' ;
68import { getAuthenticatedUser } from '@edx/frontend-platform/auth' ;
79import { injectIntl , intlShape } from '@edx/frontend-platform/i18n' ;
@@ -32,8 +34,9 @@ function WeeklyLearningGoalCard({
3234 const [ daysPerWeekGoal , setDaysPerWeekGoal ] = useState ( daysPerWeek ) ;
3335 // eslint-disable-next-line react/prop-types
3436 const [ isGetReminderSelected , setGetReminderSelected ] = useState ( subscribedToReminders ) ;
37+ const location = useLocation ( ) ;
3538
36- function handleSelect ( days ) {
39+ function handleSelect ( days , triggeredFromEmail = false ) {
3740 // Set the subscription button if this is the first time selecting a goal
3841 const selectReminders = daysPerWeekGoal === null ? true : isGetReminderSelected ;
3942 setGetReminderSelected ( selectReminders ) ;
@@ -46,6 +49,7 @@ function WeeklyLearningGoalCard({
4649 is_staff : administrator ,
4750 num_days : days ,
4851 reminder_selected : selectReminders ,
52+ triggeredFromEmail,
4953 } ) ;
5054 }
5155 }
@@ -65,6 +69,21 @@ function WeeklyLearningGoalCard({
6569 }
6670 }
6771
72+ useEffect ( ( ) => {
73+ const currentParams = new URLSearchParams ( location . search ) ;
74+ const weeklyGoal = Number ( currentParams . get ( 'weekly_goal' ) ) ;
75+ if ( [ 1 , 3 , 5 ] . includes ( weeklyGoal ) ) {
76+ handleSelect ( weeklyGoal , true ) ;
77+
78+ // Deleting the weekly_goal query param as it only needs to be set once
79+ // whenever passed in query params.
80+ currentParams . delete ( 'weekly_goal' ) ;
81+ history . replace ( {
82+ search : currentParams . toString ( ) ,
83+ } ) ;
84+ }
85+ } , [ location . search ] ) ;
86+
6887 return (
6988 < Card
7089 id = "courseHome-weeklyLearningGoal"
0 commit comments