From 7ae93775f3b3c2a3bdae07da8d19ec5cef4ee3d7 Mon Sep 17 00:00:00 2001 From: "ion.dormenco" Date: Tue, 20 Jan 2026 10:35:05 +0200 Subject: [PATCH] fix view of election round as platform admin --- .../ElectionEventDescription.tsx | 8 ++++---- .../election-event/hooks/election-event-hooks.ts | 13 +++++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/web/src/components/ElectionEventDescription/ElectionEventDescription.tsx b/web/src/components/ElectionEventDescription/ElectionEventDescription.tsx index 91419b22a..76c8a7f00 100644 --- a/web/src/components/ElectionEventDescription/ElectionEventDescription.tsx +++ b/web/src/components/ElectionEventDescription/ElectionEventDescription.tsx @@ -15,30 +15,30 @@ import { Link, useRouter } from '@tanstack/react-router'; import { ArchiveIcon, FileEdit, PlayIcon } from 'lucide-react'; import { useCallback, useContext } from 'react'; import { useTranslation } from 'react-i18next'; -import { useElectionRoundDetails } from '../../features/election-event/hooks/election-event-hooks'; +import { electionRoundDetailsQueryOptions } from '../../features/election-event/hooks/election-event-hooks'; import CoalitionDescription from '../CoalitionDescription/CoalitionDescription'; import ElectionRoundStatusBadge from '../ElectionRoundStatusBadge/ElectionRoundStatusBadge'; import { useConfirm } from '../ui/alert-dialog-provider'; import { Button } from '../ui/button'; import { useToast } from '../ui/use-toast'; +import { useSuspenseQuery } from '@tanstack/react-query'; export default function ElectionEventDescription() { const { t } = useTranslation(); const currentElectionRoundId = useCurrentElectionRoundStore((s) => s.currentElectionRoundId); - const { data: electionEvent } = useElectionRoundDetails(currentElectionRoundId); + const { data: electionEvent } = useSuspenseQuery(electionRoundDetailsQueryOptions(currentElectionRoundId)); const { userRole } = useContext(AuthContext); const { toast } = useToast(); const confirm = useConfirm(); - const router = useRouter(); + const router = useRouter(); const { mutate: unstartElectionRound } = useUnstartElectionRound(); const { mutate: startElectionRound } = useStartElectionRound(); const { mutate: archiveElectionRound } = useArchiveElectionRound(); const { mutate: unarchiveElectionRound } = useUnarchiveElectionRound(); - if (!electionEvent) return <>Loading...; const handleArchiveElectionRound = useCallback(async () => { if ( diff --git a/web/src/features/election-event/hooks/election-event-hooks.ts b/web/src/features/election-event/hooks/election-event-hooks.ts index 3bf0aaff5..92c600aba 100644 --- a/web/src/features/election-event/hooks/election-event-hooks.ts +++ b/web/src/features/election-event/hooks/election-event-hooks.ts @@ -1,5 +1,5 @@ import { authApi } from '@/common/auth-api'; -import { useQuery, UseQueryResult } from '@tanstack/react-query'; +import { queryOptions, useQuery, UseQueryResult } from '@tanstack/react-query'; import { electionRoundKeys } from '@/features/election-rounds/queries'; import { ElectionEvent } from '../models/election-event'; @@ -7,8 +7,9 @@ import { ElectionEvent } from '../models/election-event'; const STALE_TIME = 1000 * 60 * 5; // five minutes type ElectionEventResult = UseQueryResult; -export function useElectionRoundDetails(electionRoundId: string): ElectionEventResult { - return useQuery({ + +export const electionRoundDetailsQueryOptions = (electionRoundId: string) => { + return queryOptions({ queryKey: electionRoundKeys.detail(electionRoundId!), queryFn: async () => { const response = await authApi.get(`/election-rounds/${electionRoundId}`); @@ -18,6 +19,10 @@ export function useElectionRoundDetails(electionRoundId: string): ElectionEventR }; }, staleTime: STALE_TIME, - enabled: !!electionRoundId + enabled: !!electionRoundId, }); +}; + +export function useElectionRoundDetails(electionRoundId: string): ElectionEventResult { + return useQuery(electionRoundDetailsQueryOptions(electionRoundId)); }