Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

561 redirect to results when cycle closes #562

Merged
merged 9 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions packages/berlin/src/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ function Header() {
)
);
})}
<NavButton to={`/events/${events?.[0].id}/cycles`} $color="secondary">
Agenda
</NavButton>
</>
)}
<NavButton to={`/events/${events?.[0].id}/register`} $color="secondary">
My proposals
</NavButton>
<NavButton to={`/events/${events?.[0].id}/cycles`} $color="secondary">
Agenda
</NavButton>
<NavButton to="/account" $color="secondary">
Account
</NavButton>
Expand Down
13 changes: 11 additions & 2 deletions packages/berlin/src/pages/Cycle.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// React and third-party libraries
import { useEffect, useMemo, useState } from 'react';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useParams } from 'react-router-dom';
import { useNavigate, useParams } from 'react-router-dom';
import toast from 'react-hot-toast';

// API
Expand Down Expand Up @@ -40,14 +40,16 @@

function Cycle() {
const queryClient = useQueryClient();

const navigate = useNavigate();
const { user } = useUser();
const { eventId, cycleId } = useParams();
const { data: cycle } = useQuery({
queryKey: ['cycles', cycleId],
queryFn: () => fetchCycle(cycleId || ''),
enabled: !!cycleId,
refetchInterval: 5000, // Poll every 5 seconds
});

const { data: userVotes } = useQuery({
queryKey: ['votes', cycleId],
queryFn: () => fetchUserVotes(cycleId || ''),
Expand All @@ -72,6 +74,13 @@
order: 'desc',
});

useEffect(() => {
if (cycle?.status === 'CLOSED') {
toast('Agenda has closed. Redirecting to results.');
navigate(`/events/${eventId}/cycles/${cycleId}/results`);
}
}, [cycle?.status]);

Check warning on line 82 in packages/berlin/src/pages/Cycle.tsx

View workflow job for this annotation

GitHub Actions / Check linting

React Hook useEffect has missing dependencies: 'cycleId', 'eventId', and 'navigate'. Either include them or remove the dependency array

useEffect(() => {
if (cycle && cycle.startAt && cycle.endAt) {
setStartAt(cycle.startAt);
Expand Down
4 changes: 2 additions & 2 deletions packages/berlin/src/pages/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { FINAL_QUESTION_TITLE } from '../utils/constants';
function Results() {
const [expandedIndex, setExpandedIndex] = useState<number | null>(null);

const { cycleId } = useParams();
const { eventId, cycleId } = useParams();

const { data: cycle } = useQuery({
queryKey: ['cycles', cycleId],
Expand Down Expand Up @@ -70,7 +70,7 @@ function Results() {

return (
<FlexColumn $gap="2rem">
<BackButton />
<BackButton fallbackRoute={`/events/${eventId}/cycles`} />
<Subtitle>Results for: {cycle?.forumQuestions?.[0].questionTitle}</Subtitle>
<FlexColumn $gap="0">
<ResultsColumns $showFunding={!!funding} />
Expand Down
Loading