11import React from "react" ;
2+ import { useRouter } from "next/router" ;
23import clsx from "clsx" ;
34import Image from "next/image" ;
45
@@ -8,6 +9,11 @@ interface CardButtonProps
89 title ?: string ;
910 showCrown ?: boolean ;
1011 color ?: string ;
12+ isEditMode ?: boolean ;
13+ dashboardId : number ;
14+ createdByMe ?: boolean ;
15+ onDeleteClick ?: ( id : number ) => void ;
16+ onLeaveClick ?: ( id : number ) => void ;
1117}
1218
1319const CardButton : React . FC < CardButtonProps > = ( {
@@ -16,21 +22,59 @@ const CardButton: React.FC<CardButtonProps> = ({
1622 title = "비브리지" ,
1723 showCrown = true ,
1824 color = "#7ac555" , // 기본 색상
25+ isEditMode = false ,
26+ dashboardId,
27+ createdByMe,
28+ onDeleteClick,
29+ onLeaveClick,
1930 ...props
2031} ) => {
32+ const router = useRouter ( ) ;
33+
34+ const handleCardClick = ( e : React . MouseEvent < HTMLButtonElement > ) => {
35+ // 관리 상태에서 카드 클릭 이벤트 차단
36+ if ( isEditMode ) {
37+ e . preventDefault ( ) ;
38+ return ;
39+ }
40+ // 카드 클릭 시 해당 대시보드로 이동
41+ router . push ( `/dashboard/${ dashboardId } ` ) ;
42+ } ;
43+
44+ const handleEdit = ( e : React . MouseEvent ) => {
45+ e . stopPropagation ( ) ;
46+ router . push ( `/dashboard/${ dashboardId } /edit` ) ;
47+ } ;
48+
49+ const handleDelete = ( e : React . MouseEvent ) => {
50+ e . stopPropagation ( ) ;
51+ if ( createdByMe ) {
52+ // 실제 삭제 API 요청
53+ if ( onDeleteClick ) onDeleteClick ( dashboardId ) ;
54+ } else {
55+ // 나만 탈퇴
56+ if ( onLeaveClick ) onLeaveClick ( dashboardId ) ;
57+ }
58+ } ;
59+
2160 return (
2261 < button
62+ { ...props }
63+ onClick = { handleCardClick }
2364 className = { clsx (
2465 "flex justify-between items-center bg-white transition-all" ,
25- "rounded-lg px-4 py-3 font-semibold " ,
26- "border border-gray-300 hover:border-purple-500 " ,
66+ "rounded-lg px-4 py-3 font-16sb " ,
67+ "border border-gray-300" ,
2768 fullWidth ? "w-full" : "w-[260px] md:w-[247px] lg:w-[332px]" ,
2869 "h-[58px] md:h-[68px] lg:h-[70px]" ,
2970 "mt-[10px] md:mt-[16px] lg:mt-[20px]" ,
3071 "text-lg md:text-2lg lg:text-2lg" ,
72+ "transition-all" ,
73+ isEditMode
74+ ? "cursor-default hover:border-gray-300"
75+ : "cursor-pointer hover:border-purple-500" ,
3176 className
3277 ) }
33- { ...props }
3478 >
3579 { /* 왼쪽: 색상 도트 + 제목 + 왕관 */ }
3680 < div className = "flex items-center gap-[10px] overflow-hidden" >
@@ -40,7 +84,7 @@ const CardButton: React.FC<CardButtonProps> = ({
4084 </ svg >
4185
4286 { /* 제목 */ }
43- < span className = "font-semibold truncate" > { title } </ span >
87+ < span className = "font-16sb truncate" > { title } </ span >
4488
4589 { /* 왕관 */ }
4690 { showCrown && (
@@ -54,14 +98,33 @@ const CardButton: React.FC<CardButtonProps> = ({
5498 ) }
5599 </ div >
56100
57- { /* 오른쪽: 화살표 아이콘 */ }
58- < Image
59- src = "/svgs/arrow-forward-black.svg"
60- alt = "arrow icon"
61- width = { 16 }
62- height = { 16 }
63- className = "ml-2"
64- />
101+ { /* 오른쪽: 화살표 아이콘 or 수정/삭제 버튼 */ }
102+ { isEditMode ? (
103+ < div className = "flex flex-col gap-2" >
104+ { createdByMe && (
105+ < button
106+ onClick = { handleEdit }
107+ className = "font-12m text-gray1 border border-[var(--color-gray3)] px-2 rounded hover:bg-gray-100 cursor-pointer"
108+ >
109+ 수정
110+ </ button >
111+ ) }
112+ < button
113+ onClick = { handleDelete }
114+ className = "font-12m text-red-400 border border-red-400 px-2 rounded hover:bg-red-100 cursor-pointer"
115+ >
116+ 삭제
117+ </ button >
118+ </ div >
119+ ) : (
120+ < Image
121+ src = "/svgs/arrow-forward-black.svg"
122+ alt = "arrow icon"
123+ width = { 16 }
124+ height = { 16 }
125+ className = "ml-2"
126+ />
127+ ) }
65128 </ button >
66129 ) ;
67130} ;
0 commit comments