route changes

This commit is contained in:
Ilgeldi 2025-03-28 17:11:31 +05:00
parent 3cbbdf21c4
commit ce90ebeb50
1 changed files with 16 additions and 4 deletions

View File

@ -15,6 +15,10 @@ import Link from "next/link";
import Confetti from "../common/Confetti"; import Confetti from "../common/Confetti";
import { useRouter, useSearchParams } from "next/navigation"; import { useRouter, useSearchParams } from "next/navigation";
interface IParams {
vote_id?: string;
}
interface ISocketMessage { interface ISocketMessage {
voting_id: number; voting_id: number;
voting_item_id: number; voting_item_id: number;
@ -23,7 +27,7 @@ interface ISocketMessage {
date: string; date: string;
} }
const ParticipantsList = () => { const ParticipantsList = ({ vote_id }: IParams) => {
const searchParams = useSearchParams(); const searchParams = useSearchParams();
const router = useRouter(); const router = useRouter();
const [data, setData] = useState<IAllVotes>(); const [data, setData] = useState<IAllVotes>();
@ -44,9 +48,17 @@ const ParticipantsList = () => {
const { setVoteDescription } = useContext(VoteContext).voteDescriptionContext; const { setVoteDescription } = useContext(VoteContext).voteDescriptionContext;
useEffect(() => { useEffect(() => {
const id = searchParams.get("d") const id = searchParams.get("d");
if (id) { if (id) {
Queries.getVote(id).then((res) => { Queries.getVoteByUUID(id).then((res) => {
setData(res);
setParticipantsData(res.data.voting_items);
setVoteDescription(res.data.description);
setVoteStatus(res.data.status);
setSmsNumber(res.data.sms_number);
});
} else if (vote_id) {
Queries.getVote(vote_id).then((res) => {
setData(res); setData(res);
setParticipantsData(res.data.voting_items); setParticipantsData(res.data.voting_items);
setVoteDescription(res.data.description); setVoteDescription(res.data.description);
@ -54,7 +66,7 @@ const ParticipantsList = () => {
setSmsNumber(res.data.sms_number); setSmsNumber(res.data.sms_number);
}); });
} else { } else {
router.push('/vote/active') router.push("/vote/active");
} }
if (participantsData) { if (participantsData) {