-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 구매완료 티켓 조회 API 연동 #86
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
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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,14 @@ | ||
| import { axiosClient } from "../../../shared/types/api/http-client" | ||
| export const readMyTickets = { | ||
| get: async (page: number = 0, size: number = 10) => { | ||
| try { | ||
| const response = await axiosClient.get("/orders", { | ||
| params: { page, size }, | ||
| }); | ||
| return response.data; | ||
| } catch (error) { | ||
| console.error("티켓 조회 중 오류 발생:", 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 |
|---|---|---|
| @@ -1,50 +1,102 @@ | ||
| import TicketHostLayout from '../../../shared/ui/backgrounds/TicketHostLayout'; | ||
| import TicketLogo from '../../../../public/assets/menu/TicketLogo.svg'; | ||
| import { useState } from 'react'; | ||
| import { useEffect, useState } from 'react'; | ||
| import QrModal from '../../../../design-system/ui/modals/QrModal'; | ||
| import QRbackground from '../../../../design-system/icons/QRbackground.svg'; | ||
| import QRcode from '../../../../design-system/icons/QrCode.svg'; | ||
| import { trendingEvents } from '../../../shared/types/eventCardType'; | ||
| import EventCard from '../../../shared/ui/EventCard'; | ||
| import { readMyTickets } from '../../../features/ticket/api/order'; | ||
| import completedImg from '../../../../public/assets/menu/Completed.svg'; | ||
| import pendingImg from '../../../../public/assets/menu/Pending.svg'; | ||
| import ticketImg from '../../../../public/assets/menu/Ticket.svg'; | ||
|
|
||
| type Ticket = { | ||
| id: number; | ||
| eventId: number; | ||
| bannerImageUrl: string; | ||
| title: string; | ||
| hostChannelName: string; | ||
| address: string; | ||
| startDate: string; | ||
| ticketName: string; | ||
| orderStatus: "COMPLETED" | "PENDING" | "CANCELED"; | ||
| remainDays: "진행중" | "D-1" | "D-7" | "false"; | ||
| ticketPrice: number; | ||
| ticketQrCode: string; | ||
| checkIn: boolean; | ||
| hashtags: []; | ||
| }; | ||
|
|
||
| const MyTicketPage = () => { | ||
| const [isModalOpen, setIsModalOpen] = useState(false); | ||
| const [myTickets, setMyTickets] = useState<Ticket[]>([]); | ||
| const [selectedTicket, setSelectedTicket] = useState<Ticket | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| const fetchMyTickets = async () => { | ||
| try { | ||
| const response = await readMyTickets.get(0, 10); | ||
| setMyTickets(response.result || []); | ||
| } catch (error) { | ||
| console.error("티켓 목록 불러오기 실패:", error); | ||
| } | ||
| }; | ||
| fetchMyTickets(); | ||
| }, []); | ||
|
Comment on lines
+34
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 티켓 데이터 로딩 로직 개선 필요 useEffect를 사용한 데이터 로딩이 기본적으로 잘 구현되었습니다. 하지만 몇 가지 개선할 점이 있습니다:
다음과 같이 개선해 보세요: + const [isLoading, setIsLoading] = useState(false);
+ const [error, setError] = useState<string | null>(null);
useEffect(() => {
const fetchMyTickets = async () => {
+ setIsLoading(true);
+ setError(null);
try {
const response = await readMyTickets.get(0, 10);
setMyTickets(response.result || []);
} catch (error) {
console.error("티켓 목록 불러오기 실패:", error);
+ setError("티켓 정보를 불러오는 중 오류가 발생했습니다.");
} finally {
+ setIsLoading(false);
}
};
fetchMyTickets();
}, []); |
||
|
|
||
| return ( | ||
| <TicketHostLayout image={TicketLogo} centerContent="내 티켓" showText={true}> | ||
| {/* 이벤트 카드 목록 */} | ||
| <div className="grid grid-cols-2 gap-4 mx-6 mt-28 md:grid-cols-2 lg:grid-cols-2 pb-4"> | ||
| {trendingEvents.map((event, index) => ( | ||
| {myTickets.map((ticket, index) => ( | ||
| <EventCard | ||
| key={index} | ||
| img={event.img} | ||
| eventTitle={event.eventTitle} | ||
| dDay={event.dDay} | ||
| host={event.host} | ||
| eventDate={event.eventDate} | ||
| location={event.location} | ||
| hashtags={event.hashtags} | ||
| onClick={() => setIsModalOpen(true)} | ||
| /> | ||
| img={ticket.bannerImageUrl} | ||
| eventTitle={ticket.title} | ||
| dDay={ticket.remainDays} | ||
| host={ticket.hostChannelName} | ||
| eventDate={ticket.startDate} | ||
| location={ticket.address} | ||
| hashtags={ticket.hashtags} | ||
| onClick={() => { | ||
| setSelectedTicket(ticket); | ||
| setIsModalOpen(true); | ||
| }} | ||
| > | ||
| <div className="flex items-center text-xs text-gray-500"> | ||
| <img src={ticketImg} alt="날짜" className="w-3 h-3 mr-1" /> | ||
| {ticket.ticketName} | ||
| </div> | ||
| <div className="flex items-center text-xs text-gray-500"> | ||
| <img | ||
| src={ticket.orderStatus === 'COMPLETED' ? completedImg : pendingImg} | ||
| alt={ticket.orderStatus === 'COMPLETED' ? '승인됨' : '대기 중'} | ||
| className="w-3 h-3 mr-1" | ||
| /> | ||
| {ticket.orderStatus === 'COMPLETED' ? '승인됨' : '대기 중'} | ||
| </div> | ||
|
|
||
| </EventCard> | ||
| ))} | ||
| </div> | ||
|
|
||
| {isModalOpen && ( | ||
| {isModalOpen && selectedTicket &&( | ||
| <div className="fixed top-0 left-0 w-full h-full z-20"> | ||
| <div className="relative mx-auto w-full max-w-lg bg-black bg-opacity-30"> | ||
| <QrModal | ||
| isChecked={true} | ||
| iconPath1={<img src={QRbackground} alt="QRbackground" />} | ||
| iconPath2={<img src={QRcode} alt="QRcode" />} | ||
| title="이벤트명" | ||
| hostName="주최명" | ||
| date="2025-01-01" | ||
| location="이벤트 장소" | ||
| ticketName="티켓 이름" | ||
| price={50000} | ||
| isApproved={true} | ||
| isCheckIn={false} | ||
| title={selectedTicket.title} | ||
| hostName={selectedTicket.hostChannelName} | ||
| date={selectedTicket.startDate} | ||
| location={selectedTicket.address} | ||
| ticketName={selectedTicket.ticketName} | ||
| price={selectedTicket.ticketPrice} | ||
| orderStatus={selectedTicket.orderStatus} | ||
| isCheckIn={selectedTicket.checkIn} | ||
| isCountdownChecked={true} | ||
| remainDays={selectedTicket.remainDays} | ||
| onClick={() => setIsModalOpen(false)} | ||
| /> | ||
| </div> | ||
|
|
||
File renamed without changes.
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
API 에러 처리 개선 필요
현재 코드는 API 오류를 콘솔에만 기록하고 있습니다. 사용자 경험을 향상시키기 위해 오류 메시지를 표시하고 재시도 기능을 제공하는 것이 좋습니다.
API가 실패할 때 어떤 종류의 에러를 반환하는지 확인하고, 각 에러 유형에 맞는 사용자 친화적인 메시지를 표시하는 것이 좋습니다. 다음과 같은 쉘 스크립트로 API 응답을 확인해볼 수 있습니다:
🏁 Script executed:
Length of output: 546
API 에러 처리 개선 요청
현재
MyTicketPage.tsx의fetchMyTickets함수에서 API 호출 실패 시 단순히 콘솔에 에러만 기록하고 있습니다.이와 유사하게
src/features/ticket/api/order.ts에서도 에러를 콘솔에 기록한 후 에러를 재던지는 방식으로 처리되고 있음을 확인했습니다.다음 사항들을 개선해주시기 바랍니다:
이와 같이 에러 처리를 개선하여 사용자 경험을 높일 필요가 있습니다.