Skip to content

Commit 7b887e1

Browse files
committed
fix: show feedback form after course has been started
1 parent ad49882 commit 7b887e1

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

components/storyblok/StoryblokSessionPage.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Link as i18nLink } from '@/i18n/routing';
1212
import { useGetUserCoursesQuery } from '@/lib/api';
1313
import { PROGRESS_STATUS } from '@/lib/constants/enums';
1414
import { useTypedSelector } from '@/lib/hooks/store';
15+
import { Session } from '@/lib/store/coursesSlice';
1516
import { getChatAccess } from '@/lib/utils/getChatAccess';
1617
import { getSessionCompletion } from '@/lib/utils/getSessionCompletion';
1718
import hasAccessToPage from '@/lib/utils/hasAccessToPage';
@@ -78,10 +79,11 @@ const StoryblokSessionPage = (props: StoryblokSessionPageProps) => {
7879
const isLoggedIn = useTypedSelector((state) => Boolean(state.user.id));
7980
const partnerAccesses = useTypedSelector((state) => state.partnerAccesses);
8081
const partnerAdmin = useTypedSelector((state) => state.partnerAdmin);
82+
const courseState = useTypedSelector((state) => state.courses);
8183
const { data: courses } = useGetUserCoursesQuery(undefined, {
8284
skip: !isLoggedIn,
8385
});
84-
86+
const [showFeedbackForm, setShowFeedbackForm] = useState<boolean>();
8587
const [userAccess, setUserAccess] = useState<boolean>();
8688
const [sessionId, setSessionId] = useState<string>(); // database Session id
8789
const [sessionProgress, setSessionProgress] = useState<PROGRESS_STATUS>(
@@ -128,6 +130,16 @@ const StoryblokSessionPage = (props: StoryblokSessionPageProps) => {
128130
partnerAdmin,
129131
]);
130132

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+
131143
useEffect(() => {
132144
getSessionCompletion(course, courses || [], storyUuid, setSessionProgress, setSessionId);
133145
}, [courses, course, storyUuid]);
@@ -218,7 +230,7 @@ const StoryblokSessionPage = (props: StoryblokSessionPageProps) => {
218230
</Box>
219231
</Container>
220232

221-
{sessionId && (
233+
{showFeedbackForm && sessionId && (
222234
<Container sx={{ bgcolor: 'background.paper' }}>
223235
<SessionFeedbackForm sessionId={sessionId} />
224236
</Container>

0 commit comments

Comments
 (0)