diff --git a/src/app/vote/page.tsx b/src/app/vote/page.tsx new file mode 100644 index 00000000..6d123059 --- /dev/null +++ b/src/app/vote/page.tsx @@ -0,0 +1,5 @@ +import VoteView from "@/views/vote/ui/VoteView"; + +export default function VotePage() { + return ; +} diff --git a/src/entities/list/consts/status.ts b/src/entities/list/consts/status.ts index a35a176a..86b53fb7 100644 --- a/src/entities/list/consts/status.ts +++ b/src/entities/list/consts/status.ts @@ -1,5 +1,5 @@ export const STATUS = { - PENDING: "PENGDING", + PENDING: "PENDING", ONGOING: "ONGOING", FINISHED: "FINISHED", } as const; diff --git a/src/entities/vote/ui/OrderCard/index.tsx b/src/entities/vote/ui/OrderCard/index.tsx new file mode 100644 index 00000000..bba47522 --- /dev/null +++ b/src/entities/vote/ui/OrderCard/index.tsx @@ -0,0 +1,15 @@ +interface OrderCardProps { + teamName: string | undefined; + type: "prev" | "next"; +} + +export default function OrderCard({ teamName, type }: OrderCardProps) { + return ( + + + {type === "prev" ? "전 공연 팀" : "다음 공연 팀"} + + {teamName ?? "없음"} + + ); +} diff --git a/src/shared/asset/png/success.png b/src/shared/asset/png/success.png new file mode 100644 index 00000000..7dbe40e4 Binary files /dev/null and b/src/shared/asset/png/success.png differ diff --git a/src/views/vote/api/getVote.ts b/src/views/vote/api/getVote.ts new file mode 100644 index 00000000..0656510f --- /dev/null +++ b/src/views/vote/api/getVote.ts @@ -0,0 +1,10 @@ +import instance from "@/shared/lib/axios"; + +export const getVote = async () => { + try { + const res = await instance.get("/vote"); + return res.data; + } catch (error) { + throw error; + } +}; diff --git a/src/views/vote/api/postVote.ts b/src/views/vote/api/postVote.ts new file mode 100644 index 00000000..3e6f205c --- /dev/null +++ b/src/views/vote/api/postVote.ts @@ -0,0 +1,13 @@ +import instance from "@/shared/lib/axios"; + +export const postVote = async (teamName: string, team_id: number) => { + try { + return await instance.post("vote", { + select: true, + teamName, + team_id, + }); + } catch (error) { + throw error; + } +}; diff --git a/src/views/vote/model/useGetVote.ts b/src/views/vote/model/useGetVote.ts new file mode 100644 index 00000000..dc4c1e0c --- /dev/null +++ b/src/views/vote/model/useGetVote.ts @@ -0,0 +1,23 @@ +import { useQuery } from "@tanstack/react-query"; +import { getVote } from "../api/getVote"; + +interface Response { + team_id: number; + teamName: string; + prev_team: { + team_id: number; + teamName: string; + }; + next_team: { + team_id: number; + teamName: string; + }; +} + +export const useGetVote = () => { + return useQuery({ + queryKey: ["vote"], + queryFn: getVote, + refetchInterval: 5000, + }); +}; diff --git a/src/views/vote/ui/VoteView/index.tsx b/src/views/vote/ui/VoteView/index.tsx new file mode 100644 index 00000000..ce226f9b --- /dev/null +++ b/src/views/vote/ui/VoteView/index.tsx @@ -0,0 +1,59 @@ +"use client"; + +import Inform from "@/shared/asset/svg/Inform"; +import { Button } from "@/shared/ui"; +import MiniHeader from "@/shared/ui/MiniHeader"; +import { useGetVote } from "../../model/useGetVote"; +import { toast } from "sonner"; +import OrderCard from "@/entities/vote/ui/OrderCard"; +import { postVote } from "../../api/postVote"; +import { useState } from "react"; +import Image from "next/image"; +import success from "@/shared/asset/png/success.png"; + +export default function VoteView() { + const { data, isError, error } = useGetVote(); + const [isSuccess, setIsSuccess] = useState(false); + if (isError) toast.error(error.message ?? "현재 투표를 불러오는데 실패했습니다"); + + const handleVote = async () => { + if (data?.team_id && data.teamName) { + const res = await postVote(data?.teamName, data?.team_id); + if (res.status === 200) { + toast.success("투표되었습니다"); + setIsSuccess(true); + } else { + toast.error("투표되지 않았습니다 다시 시도해주세요"); + } + } + }; + return ( + + + + + + 현재 투표 중인 팀 + {data?.teamName ?? "팀 이름"} + {isSuccess && ( + + )} + + + 투표하기 + + + + + 관리자가 투표를 시작할 때까지 기다려주세요 + + + + + + + + + + ); +}
현재 투표 중인 팀