-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 투표 페이지 퍼블리싱, 기능구현 #43
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
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f4e47eb
feat: post vote
bae080311 8b4e5fe
feat: get vote
bae080311 15502f2
feat: use get vote
bae080311 6bcfdda
feat: return type
bae080311 41f1153
feat: success image
bae080311 de2278e
feat: return
bae080311 9b4dc16
feat: vote page
bae080311 bd7b3e1
feat: order card
bae080311 0680d8f
fix: 비동기
bae080311 7efaf50
fix: 오탈자
bae080311 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import VoteView from "@/views/vote/ui/VoteView"; | ||
|
|
||
| export default function VotePage() { | ||
| return <VoteView />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| interface OrderCardProps { | ||
| teamName: string | undefined; | ||
| type: "prev" | "next"; | ||
| } | ||
|
|
||
| export default function OrderCard({ teamName, type }: OrderCardProps) { | ||
| return ( | ||
| <article className="flex flex-col sm:mt-[80px] mt-[40px] justify-center gap-16 items-center w-full bg-gray-50 rounded-lg py-16"> | ||
| <span className="text-caption1r text-gray-500"> | ||
| {type === "prev" ? "전 공연 팀" : "다음 공연 팀"} | ||
| </span> | ||
| <strong className="text-body3b">{teamName ?? "없음"}</strong> | ||
| </article> | ||
| ); | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import instance from "@/shared/lib/axios"; | ||
|
|
||
| export const postVote = (teamName: string, team_id: number) => { | ||
| try { | ||
| return instance.post("vote", { | ||
| select: true, | ||
| teamName, | ||
| team_id, | ||
| }); | ||
| } catch (error) { | ||
| throw error; | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<Response>({ | ||
| queryKey: ["vote"], | ||
| queryFn: getVote, | ||
| refetchInterval: 5000, | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 ?? "현재 투표를 불러오는데 실패했습니다"); | ||
|
bae080311 marked this conversation as resolved.
|
||
|
|
||
| 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 ( | ||
| <div className="flex justify-center"> | ||
| <div className="w-full max-w-[600px]"> | ||
| <MiniHeader label="투표" /> | ||
| <div className="sm:px-[106px] px-16 mt-[23px]"> | ||
| <div className="flex flex-col gap-16 items-center bg-gray-50 rounded-lg h-[282px] justify-center py-[40px]"> | ||
| <p className="text-body2r text-gray-600">현재 투표 중인 팀</p> | ||
| <h1 className="sm:text-title2b text-title4b">{data?.teamName ?? "팀 이름"}</h1> | ||
| {isSuccess && ( | ||
| <Image alt="성공" className="mt-[46px]" src={success} height={72} width={72} /> | ||
| )} | ||
| </div> | ||
| <Button onClick={handleVote} className="w-full sm:mt-[80px] mt-[40px]"> | ||
|
bae080311 marked this conversation as resolved.
bae080311 marked this conversation as resolved.
|
||
| 투표하기 | ||
| </Button> | ||
| <div className="flex gap-10 items-center justify-center mt-12"> | ||
| <Inform width={16} height={16} color="#BDBDBD" /> | ||
| <small className="text-gray-300 text-caption2r"> | ||
| 관리자가 투표를 시작할 때까지 기다려주세요 | ||
| </small> | ||
| </div> | ||
| <div className="flex gap-24"> | ||
| <OrderCard type="prev" teamName={data?.prev_team.teamName} /> | ||
| <OrderCard type="next" teamName={data?.next_team.teamName} /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.