|
1 | 1 | import AvailableTicket from '../../../../public/assets/dashboard/ticket/Ticket(gray).svg'; |
2 | 2 | import PersonIcon from '../../../../public/assets/dashboard/ticket/PersonIcon.svg'; |
3 | 3 | import { ReadTicket } from '../../../pages/dashboard/ui/ticket/TicketListPage'; |
| 4 | +import { motion } from "framer-motion"; |
| 5 | +import { useState } from 'react'; |
| 6 | +import { deleteTicket } from '../../../features/ticket/api/ticket'; |
4 | 7 |
|
5 | 8 | const TicketItem = ({ ticket }: { ticket: ReadTicket }) => { |
| 9 | + const [isDragging, setIsDragging] = useState(false); |
| 10 | + const handleDelete = async () => { |
| 11 | + const isConfirmed = window.confirm("티켓을 삭제하시겠습니까?"); |
| 12 | + if (!isConfirmed) return; |
| 13 | + try { |
| 14 | + await deleteTicket.remove(ticket.ticketId); |
| 15 | + alert("티켓이 삭제되었습니다."); |
| 16 | + window.location.reload(); |
| 17 | + } catch (error) { |
| 18 | + console.error("티켓 삭제 중 오류 발생:", error); |
| 19 | + } |
| 20 | + }; |
6 | 21 | return ( |
7 | | - <div className="w-full h-14 bg-gray2 my-2 rounded-lg flex items-center justify-between p-5"> |
8 | | - <div className="flex gap-5"> |
9 | | - <p className="font-bold">{ticket.ticketPrice > 0 ? '일반' : '무료'}</p> |
10 | | - <p>{ticket.ticketName}</p> |
11 | | - </div> |
12 | | - <div className="flex flex-col gap-1 text-gray-400 text-xs"> |
13 | | - <div className="flex gap-1 items-center justify-end"> |
14 | | - <img src={AvailableTicket} /> {ticket.availableQuantity}개 남음 |
| 22 | + <div className="relative overflow-hidden w-full"> |
| 23 | + <motion.div |
| 24 | + className="flex items-center bg-white p-4" |
| 25 | + drag="x" |
| 26 | + dragConstraints={{ left: -100, right: 0 }} |
| 27 | + onDragStart={() => setIsDragging(true)} |
| 28 | + onDragEnd={(event, info) => { |
| 29 | + if (info.offset.x < -50) { |
| 30 | + setIsDragging(true); |
| 31 | + } else { |
| 32 | + setIsDragging(false); |
| 33 | + } |
| 34 | + }} |
| 35 | + > |
| 36 | + <div className="flex gap-5"> |
| 37 | + <p className="font-bold">{ticket.ticketPrice > 0 ? "일반" : "무료"}</p> |
| 38 | + <p>{ticket.ticketName}</p> |
15 | 39 | </div> |
16 | | - <div className="flex gap-1 items-center justify-end"> |
17 | | - <img src={PersonIcon} /> 1인당 최대 2장 |
| 40 | + <div className="flex-grow" /> |
| 41 | + <div className="flex flex-col gap-1 text-gray-400 text-xs"> |
| 42 | + <div className="flex gap-1 items-center justify-end"> |
| 43 | + <img src={AvailableTicket} alt="남은 티켓" /> {ticket.availableQuantity}개 남음 |
| 44 | + </div> |
| 45 | + <div className="flex gap-1 items-center justify-end"> |
| 46 | + <img src={PersonIcon} alt="1인당 최대 구매량" /> 1인당 최대 2장 |
| 47 | + </div> |
18 | 48 | </div> |
19 | | - </div> |
| 49 | + </motion.div> |
| 50 | + |
| 51 | + {/* 삭제 버튼 */} |
| 52 | + <motion.button |
| 53 | + className="absolute right-0 top-0 bottom-0 bg-red-500 text-white px-4 flex items-center justify-center transition-transform" |
| 54 | + initial={{ x: '100%' }} |
| 55 | + animate={{ x: isDragging ? 0 : 'calc(100% + 1px)' }} |
| 56 | + transition={{ duration: 0 }} |
| 57 | + onClick={handleDelete} |
| 58 | + > |
| 59 | + 삭제 |
| 60 | + </motion.button> |
| 61 | + |
20 | 62 | </div> |
21 | 63 | ); |
22 | 64 | }; |
|
0 commit comments