@@ -12,6 +12,7 @@ import { Link as i18nLink } from '@/i18n/routing';
12
12
import { useGetUserCoursesQuery } from '@/lib/api' ;
13
13
import { PROGRESS_STATUS } from '@/lib/constants/enums' ;
14
14
import { useTypedSelector } from '@/lib/hooks/store' ;
15
+ import { Session } from '@/lib/store/coursesSlice' ;
15
16
import { getChatAccess } from '@/lib/utils/getChatAccess' ;
16
17
import { getSessionCompletion } from '@/lib/utils/getSessionCompletion' ;
17
18
import hasAccessToPage from '@/lib/utils/hasAccessToPage' ;
@@ -78,10 +79,11 @@ const StoryblokSessionPage = (props: StoryblokSessionPageProps) => {
78
79
const isLoggedIn = useTypedSelector ( ( state ) => Boolean ( state . user . id ) ) ;
79
80
const partnerAccesses = useTypedSelector ( ( state ) => state . partnerAccesses ) ;
80
81
const partnerAdmin = useTypedSelector ( ( state ) => state . partnerAdmin ) ;
82
+ const courseState = useTypedSelector ( ( state ) => state . courses ) ;
81
83
const { data : courses } = useGetUserCoursesQuery ( undefined , {
82
84
skip : ! isLoggedIn ,
83
85
} ) ;
84
-
86
+ const [ showFeedbackForm , setShowFeedbackForm ] = useState < boolean > ( ) ;
85
87
const [ userAccess , setUserAccess ] = useState < boolean > ( ) ;
86
88
const [ sessionId , setSessionId ] = useState < string > ( ) ; // database Session id
87
89
const [ sessionProgress , setSessionProgress ] = useState < PROGRESS_STATUS > (
@@ -128,6 +130,16 @@ const StoryblokSessionPage = (props: StoryblokSessionPageProps) => {
128
130
partnerAdmin ,
129
131
] ) ;
130
132
133
+ useEffect ( ( ) => {
134
+ const session = courseState . find ( ( c : any ) =>
135
+ c . sessions . find ( ( s : Session ) => s . storyblokUuid == storyUuid ) ,
136
+ ) ;
137
+ if ( session ) {
138
+ setShowFeedbackForm ( ! ! session ) ;
139
+ setSessionId ( session . id ) ;
140
+ }
141
+ } , [ courseState ] ) ;
142
+
131
143
useEffect ( ( ) => {
132
144
getSessionCompletion ( course , courses || [ ] , storyUuid , setSessionProgress , setSessionId ) ;
133
145
} , [ courses , course , storyUuid ] ) ;
@@ -218,7 +230,7 @@ const StoryblokSessionPage = (props: StoryblokSessionPageProps) => {
218
230
</ Box >
219
231
</ Container >
220
232
221
- { sessionId && (
233
+ { showFeedbackForm && sessionId && (
222
234
< Container sx = { { bgcolor : 'background.paper' } } >
223
235
< SessionFeedbackForm sessionId = { sessionId } />
224
236
</ Container >
0 commit comments