Skip to content

Commit 53fce36

Browse files
authored
enhance(apps/frontend-pwa): add functionality to log out of created temporary live quiz account (#4734)
1 parent 5b703c1 commit 53fce36

21 files changed

Lines changed: 202 additions & 18 deletions

File tree

apps/frontend-pwa/src/components/Layout.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface LayoutProps {
2727
data?: { cy?: string; test?: string }
2828
}[]
2929
setActiveMobilePage?: (value: string) => void
30-
previewMode?: boolean
30+
liveQuizId?: string
3131
className?: { header?: string; body?: string }
3232
}
3333

@@ -37,7 +37,7 @@ function Layout({
3737
course,
3838
mobileMenuItems,
3939
setActiveMobilePage,
40-
previewMode = false,
40+
liveQuizId,
4141
className,
4242
}: LayoutProps) {
4343
const { data: dataParticipant } = useQuery(SelfDocument)
@@ -67,10 +67,15 @@ function Layout({
6767

6868
<div className={twMerge('flex-none', className?.header)}>
6969
<Header
70-
participant={dataParticipant?.self || undefined}
70+
participant={
71+
dataParticipant?.self &&
72+
(dataParticipant.self.role === UserRole.Participant || liveQuizId)
73+
? dataParticipant.self
74+
: undefined
75+
}
7176
title={displayName}
7277
course={course}
73-
previewMode={previewMode}
78+
liveQuizId={liveQuizId}
7479
/>
7580
</div>
7681

apps/frontend-pwa/src/components/common/Header.tsx

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import {
1212
Course,
1313
LocaleType,
1414
LogoutParticipantDocument,
15+
LogoutTemporaryParticipantDocument,
1516
Participant,
17+
SelfDocument,
1618
StudentCourse,
1719
UserRole,
1820
} from '@klicker-uzh/graphql/dist/ops'
19-
import { Button, Dropdown, H1, H2 } from '@uzh-bf/design-system'
21+
import { Button, Dropdown, H1, H2, toast } from '@uzh-bf/design-system'
2022
import { useTranslations } from 'next-intl'
2123
import Image from 'next/image'
2224
import Link from 'next/link'
@@ -31,14 +33,14 @@ interface HeaderProps {
3133
course?:
3234
| Partial<Course>
3335
| (Omit<StudentCourse, 'owner'> & { owner: { shortname: string } })
34-
previewMode?: boolean
36+
liveQuizId?: string
3537
}
3638

3739
function Header({
3840
participant,
3941
title,
4042
course,
41-
previewMode = false,
43+
liveQuizId,
4244
}: HeaderProps): React.ReactElement {
4345
const router = useRouter()
4446
const { pathname, asPath, query } = router
@@ -50,6 +52,8 @@ function Header({
5052
const [logoutParticipant, { loading: loggingOut }] = useMutation(
5153
LogoutParticipantDocument
5254
)
55+
const [logoutTemporaryParticipant, { loading: loggingOutTemporary }] =
56+
useMutation(LogoutTemporaryParticipantDocument)
5357

5458
const pageInFrame =
5559
global?.window &&
@@ -144,6 +148,28 @@ function Header({
144148
</div>
145149
}
146150
items={[
151+
...(participant
152+
? [
153+
{
154+
id: 'loggedInAs',
155+
type: 'label' as 'label',
156+
label: (
157+
<div className="">
158+
<div>{t('pwa.profile.loggedInAs')}</div>
159+
<div className="font-normal">
160+
{`${participant?.username}${participant.role === UserRole.TemporaryParticipant ? ` (${t('pwa.profile.temporaryPseudonym')})` : ''}`}
161+
</div>
162+
</div>
163+
),
164+
className: { item: '!h-max py-0.5' },
165+
},
166+
{
167+
id: 'separator',
168+
type: 'separator' as 'separator',
169+
className: { item: '!h-1.5' },
170+
},
171+
]
172+
: []),
147173
...(showProfileSetup
148174
? [
149175
{
@@ -284,7 +310,60 @@ function Header({
284310
},
285311
]
286312
: []),
287-
// TODO: add functionality to log out of temporary account and delete corresponding temporary leaderboard entry
313+
...(participant?.role === UserRole.TemporaryParticipant &&
314+
liveQuizId
315+
? [
316+
{
317+
id: 'logout',
318+
type: 'standard' as 'standard',
319+
disabled: loggingOutTemporary,
320+
label: (
321+
<div className="text-red-500">
322+
<FontAwesomeIcon
323+
icon={faRightFromBracket}
324+
className="mr-2 w-4"
325+
/>
326+
<span>{t('shared.generic.logout')}</span>
327+
</div>
328+
),
329+
onClick: async () => {
330+
try {
331+
// log out temporary participant for this live quiz
332+
const { data } = await logoutTemporaryParticipant({
333+
variables: { liveQuizId },
334+
refetchQueries: [{ query: SelfDocument }],
335+
})
336+
337+
if (data?.logoutTemporaryParticipant) {
338+
// remove local storage entry for temporary participant
339+
localStorage.removeItem(`login-state-${liveQuizId}`)
340+
341+
router.reload()
342+
} else {
343+
toast({
344+
type: 'error',
345+
message: t(
346+
'pwa.profile.errorLogoutTemporaryParticipant'
347+
),
348+
})
349+
}
350+
} catch (e) {
351+
console.error(
352+
'Error logging out temporary participant:',
353+
e
354+
)
355+
toast({
356+
type: 'error',
357+
message: t(
358+
'pwa.profile.errorLogoutTemporaryParticipant'
359+
),
360+
})
361+
}
362+
},
363+
data: { cy: 'logout' },
364+
},
365+
]
366+
: []),
288367
]}
289368
className={{ item: 'h-8 text-sm md:h-8 md:text-base' }}
290369
data={{ cy: 'header-avatar' }}

apps/frontend-pwa/src/components/common/LiveQuizLeaderboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function LiveQuizLeaderboard({
8686

8787
const leaderboard = data.liveQuizLeaderboard ?? []
8888
return (
89-
<div className={twMerge('space-y-4', className)}>
89+
<div className={twMerge('space-y-4 pt-4', className)}>
9090
<H2>{t('shared.leaderboard.lqLeaderboard')}</H2>
9191
<div>
9292
{leaderboard.length && leaderboard.length > 0 ? (

apps/frontend-pwa/src/components/liveQuiz/AccountSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ function AccountSelector({
301301
className="w-full overflow-visible"
302302
setApi={setApi}
303303
>
304-
<CarouselContent className="mt-4 overflow-visible px-10">
304+
<CarouselContent className="mt-4 overflow-visible px-10 pb-0.5">
305305
{AVAILABLE_AVATARS.map((avatar, index) => (
306306
<div
307307
key={avatar}

apps/frontend-pwa/src/components/liveQuiz/FeedbackArea.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ function FeedbackArea({
226226
}
227227

228228
return (
229-
<div className="h-full w-full">
229+
<div className="h-full w-full pt-4">
230230
<H2>{t('pwa.feedbacks.title')}</H2>
231231

232232
<FeedbackAreaSubscriber

apps/frontend-pwa/src/components/liveQuiz/QuestionArea.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function QuestionArea({
202202

203203
return (
204204
<div className="min-h-content h-full w-full">
205-
<H2 className={{ root: 'mb-0 hidden md:block' }}>
205+
<H2 className={{ root: 'mb-0 hidden pt-4 md:block' }}>
206206
{t('shared.generic.question')}
207207
</H2>
208208

apps/frontend-pwa/src/pages/course/[courseId]/microlearning/[id]/[ix].tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ function MicrolearningInstance() {
7171
<Layout
7272
displayName={microLearning.displayName}
7373
course={microLearning.course ?? undefined}
74-
previewMode={previewMode}
7574
>
7675
<MicroLearningSubscriber
7776
activityId={microLearning.id}

apps/frontend-pwa/src/pages/course/[courseId]/microlearning/[id]/evaluation.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ function MicrolearningEvaluation() {
5252
<Layout
5353
displayName={microlearning.displayName}
5454
course={microlearning.course ?? undefined}
55-
previewMode={microlearning.isOwner ?? undefined}
5655
>
5756
<div className="flex flex-col gap-3 md:mx-auto md:mb-4 md:w-full md:max-w-6xl md:rounded md:border md:p-8 md:pt-6">
5857
{microlearning.isOwner ? (

apps/frontend-pwa/src/pages/course/[courseId]/microlearning/[id]/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ function MicrolearningIntroduction({
8585
<Layout
8686
displayName={microLearning.displayName}
8787
course={microLearning.course ?? undefined}
88-
previewMode={microLearning.isOwner ?? undefined}
8988
>
9089
<MicroLearningSubscriber
9190
activityId={microLearning.id}

apps/frontend-pwa/src/pages/course/[courseId]/quiz/[id].tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ function PracticeQuizPage({
9393
<Layout
9494
displayName={data.practiceQuiz.displayName}
9595
course={data.practiceQuiz.course ?? undefined}
96-
previewMode={data.practiceQuiz.isOwner ?? undefined}
9796
>
9897
<PracticeQuiz
9998
showResetLocalStorage

0 commit comments

Comments
 (0)