Skip to content

Commit

Permalink
fix: ballot page refresh redirect to homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
kittybest committed Dec 11, 2024
1 parent 52a14bf commit e707fb6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
6 changes: 5 additions & 1 deletion packages/interface/src/layouts/BaseLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Head from "next/head";
import { useRouter } from "next/router";
import { useTheme } from "next-themes";
import { type PropsWithChildren, createContext, useContext, useEffect, useCallback, useMemo } from "react";
import { toast } from "sonner";
import { tv } from "tailwind-variants";
import { useAccount } from "wagmi";

Expand Down Expand Up @@ -62,9 +63,12 @@ export const BaseLayout = ({
const { isRegistered } = useMaci();

const manageDisplay = useCallback(() => {
if ((requireAuth && !address && !isConnecting) || (requireRegistration && !isRegistered)) {
if (requireAuth && !address && !isConnecting) {
router.push("/");
}
if (requireRegistration && !isRegistered) {
toast.error("You must sign up to access the full information on this page.");
}
}, [requireAuth, address, isConnecting, requireRegistration, isRegistered, router]);

useEffect(() => {
Expand Down
12 changes: 1 addition & 11 deletions packages/interface/src/pages/rounds/[pollId]/ballot/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import clsx from "clsx";
import Link from "next/link";
import { useRouter } from "next/router";
import { useEffect, useState, useMemo, useCallback } from "react";
import { useCallback, useState, useMemo } from "react";
import { useFormContext } from "react-hook-form";
import { useAccount } from "wagmi";

import { Button } from "~/components/ui/Button";
import { Dialog } from "~/components/ui/Dialog";
Expand Down Expand Up @@ -154,21 +152,13 @@ interface IBallotPageProps {
}

const BallotPage = ({ pollId }: IBallotPageProps): JSX.Element => {
const { address, isConnecting } = useAccount();
const { getBallot, sumBallot } = useBallot();
const { getRoundByPollId } = useRound();
const router = useRouter();
const roundState = useRoundState({ pollId });

const round = useMemo(() => getRoundByPollId(pollId), [pollId, getRoundByPollId]);
const ballot = useMemo(() => getBallot(pollId), [round?.pollId, getBallot]);

useEffect(() => {
if (!address && !isConnecting) {
router.push("/");
}
}, [address, isConnecting, router]);

const handleSubmit = useCallback(() => {
sumBallot();
}, [sumBallot]);
Expand Down

0 comments on commit e707fb6

Please sign in to comment.