Skip to content

Commit

Permalink
fix weight page redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Tschonti committed Dec 29, 2024
1 parent 434a5de commit c668c6c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/client/src/pages/seasons/WeightAdjustment.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ import { Alert, AlertDescription, AlertIcon, Button, Heading, HStack, SimpleGrid
import { useMemo } from 'react'
import { FaEdit, FaMedal, FaRedoAlt } from 'react-icons/fa'
import { useNavigate, useParams } from 'react-router-dom'
import { useAuthContext } from 'src/api/contexts/useAuthContext'
import { useFetchSeasonWeights } from 'src/api/hooks/seasonHooks'
import { LoadingSpinner } from 'src/components/commons/LoadingSpinner'
import { LoginNavigate } from 'src/components/commons/LoginNavigate'
import { NavigateWithError } from 'src/components/commons/NavigateWithError'
import { criterionWeightReducer } from 'src/util/criterionWeightHelper'
import { PATHS } from 'src/util/paths'
import { CategoryWeights } from './components/CategoryWeights'
import { SourceSeasonSelectorModal } from './components/SourceSeasonSelectorModal'

export const WeightAdjustmentPage = () => {
const { seasonId } = useParams()
const { isLoading, data } = useFetchSeasonWeights(seasonId)
const { isLoading, data, error } = useFetchSeasonWeights(seasonId)
const nav = useNavigate()
const { isLoggedIn } = useAuthContext()

const totalWeightSum = useMemo(() => {
if (!data) return 0
Expand All @@ -28,6 +32,13 @@ export const WeightAdjustmentPage = () => {
}, 0)
}, [data])

if (!isLoggedIn) {
return <LoginNavigate />
}
if (error) {
return <NavigateWithError error={error} to={PATHS.INDEX} />
}

if (isLoading || !data) return <LoadingSpinner />
return (
<VStack alignItems="flex-start">
Expand Down

0 comments on commit c668c6c

Please sign in to comment.