Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions frontend/src/pages/profile/profile.groupChange.page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useConfigContext } from '@/api/contexts/config/ConfigContext.tsx'
import type { Profile } from '@/api/contexts/config/types.ts'
import { useServiceContext } from '@/api/contexts/service/ServiceContext'
import { useGroupChangeMutation } from '@/api/hooks/group-change/useGroupChangeMutation'
import { useProfileQuery } from '@/api/hooks/profile/useProfileQuery.ts'
import { ComponentUnavailable } from '@/common-components/ComponentUnavailable.tsx'
import { CmschPage } from '@/common-components/layout/CmschPage'
import { LinkButton } from '@/common-components/LinkButton'
import { PageStatus } from '@/common-components/PageStatus.tsx'
Expand All @@ -16,13 +19,25 @@
export function ProfileGroupChangePage() {
const { isLoading, isError, data: profile, refetch } = useProfileQuery()

const config = useConfigContext()?.components
const component = config?.profile

if (!component) return <ComponentUnavailable />
if (isError || isLoading || !profile) return <PageStatus isLoading={isLoading} isError={isError} />
if (!profile || !profile.groupSelectionAllowed) return <Navigate to={AbsolutePaths.PROFILE} />

return <ProfileGroupChangeBody profile={profile} refetch={refetch} />
return <ProfileGroupChangeBody profile={profile} profileComponent={component} refetch={refetch} />
}

function ProfileGroupChangeBody({ profile, refetch }: { profile: ProfileView; refetch: () => void }) {
function ProfileGroupChangeBody({
profile,
profileComponent,
refetch
}: {
profile: ProfileView
profileComponent: Profile
refetch: () => void
}) {

Check warning on line 40 in frontend/src/pages/profile/profile.groupChange.page.tsx

View check run for this annotation

SonarQubeCloud / [cmsch-frontend] SonarCloud Code Analysis

Mark the props of the component as read-only.

See more on https://sonarcloud.io/project/issues?id=kir-dev_cmsch-frontend&issues=AZ7AU9LZq26mY3X2r2Tx&open=AZ7AU9LZq26mY3X2r2Tx&pullRequest=1042
const availableGroups = profile.availableGroups
? Object.entries<string>(profile.availableGroups).toSorted((a, b) => a[1].localeCompare(b[1]))
: []
Expand All @@ -40,7 +55,7 @@
navigate(AbsolutePaths.PROFILE)
break
case GroupChangeStatus.INVALID_GROUP:
setError('Érvénytelen tankör!')
setError(`Érvénytelen ${profileComponent.groupTitle}!`)
break
case GroupChangeStatus.LEAVE_DENIED:
setError('Nem engedélyezett a módosítás!')
Expand All @@ -60,14 +75,16 @@

const onSubmit = () => {
if (value) mutate(value)
else setError('Válassz tankört!')
else setError(`Válassz ${profileComponent.groupTitle}-t!`)
}

return (
<CmschPage title="Tankör beállítása">
<h1 className="text-4xl font-bold tracking-tight">Tankör beállítása</h1>
<p className="mt-10 text-center">Állítsd be a tankörödet, hogy részt vehess a feladatokban!</p>
<p className="text-center text-muted-foreground">Csak helyesen beállított tankörrel fog érvényesülni a tanköri jelenlét!</p>
<CmschPage title={`${profileComponent.groupTitle} beállítása`}>
<h1 className="text-4xl font-bold tracking-tight">{`${profileComponent.groupTitle} beállítása`}</h1>
<p className="mt-10 text-center">Állíts be saját {profileComponent.groupTitle}-t, hogy részt vehess a feladatokban!</p>
{profileComponent.showMinimumTokenMessage && (
<p className="text-center text-muted-foreground">Csak helyesen beállított tankör esetén fog érvényesülni a tanköri jelenlét!</p>
)}
{availableGroups.length ? (
<form
onSubmit={(e) => {
Expand All @@ -77,10 +94,10 @@
>
<div className="mx-auto mt-10 flex max-w-80 flex-col gap-5">
<div className="flex flex-col gap-2">
<Label htmlFor="group">Melyik tankörbe tartozol?</Label>
<Label htmlFor="group">Melyik {profileComponent.groupTitle}-be tartozol?</Label>
<Select value={value} onValueChange={setValue}>
<SelectTrigger id="group">
<SelectValue placeholder="Válassz tankört!" />
<SelectValue placeholder={`Válassz ${profileComponent.groupTitle}-t!`} />
</SelectTrigger>
<SelectContent>
{availableGroups?.map((entry) => (
Expand Down
Loading