1- import { useState } from "react" ;
1+ import { useState , useEffect } from "react" ;
22import { useRouter } from "next/router" ;
33import Input from "../input/Input" ;
44import Image from "next/image" ;
@@ -8,11 +8,41 @@ import { apiRoutes } from "@/api/apiRoutes";
88const ChangeBebridge = ( ) => {
99 const router = useRouter ( ) ;
1010 const { dashboardId } = router . query ; // dashboardId 쿼리값 받기
11+ const [ dashboardDetail , setdashboardDetail ] = useState < { title ?: string } > (
12+ { }
13+ ) ;
1114 const [ title , setTitle ] = useState ( "" ) ;
1215 const [ selected , setSelected ] = useState < number | null > ( null ) ;
1316 const colors = [ "#7ac555" , "#760DDE" , "#FF9800" , "#76A5EA" , "#E876EA" ] ;
14- const token = process . env . NEXT_PUBLIC_API_TOKEN ;
1517
18+ /* 대시보드 이름 데이터 */
19+ useEffect ( ( ) => {
20+ const fetchDashboardTitle = async ( ) => {
21+ try {
22+ const dashboardIdNumber = Number ( dashboardId ) ;
23+ const res = await axiosInstance . get (
24+ apiRoutes . DashboardDetail ( dashboardIdNumber ) ,
25+ {
26+ params : {
27+ dashboardId,
28+ } ,
29+ }
30+ ) ;
31+ if ( res . data ) {
32+ const dashboardData = res . data ;
33+ setdashboardDetail ( dashboardData ) ;
34+ console . log ( "dashboardData" , dashboardData ) ;
35+ }
36+ } catch ( error ) {
37+ console . error ( "대시보드 상세내용 불러오는데 오류 발생:" , error ) ;
38+ }
39+ } ;
40+ if ( dashboardId ) {
41+ fetchDashboardTitle ( ) ;
42+ }
43+ } , [ dashboardId ] ) ;
44+
45+ /* 대시보드 이름 변경 버튼 */
1646 const handleUpdate = async ( ) => {
1747 const dashboardIdNumber = Number ( dashboardId ) ; // string dashboradId 값 number로 변경
1848 if ( ! dashboardId || ! title || selected === null ) return ;
@@ -25,13 +55,7 @@ const ChangeBebridge = () => {
2555 try {
2656 const response = await axiosInstance . put (
2757 apiRoutes . DashboardDetail ( dashboardIdNumber ) ,
28- payload ,
29- {
30- headers : {
31- Authorization : `Bearer ${ token } ` ,
32- "Content-Type" : "application/json" ,
33- } ,
34- }
58+ payload
3559 ) ;
3660 console . log ( "업데이트 성공:" , response . data ) ;
3761 alert ( "대시보드가 업데이트되었습니다!" ) ; // 추후에 toast로 변경
@@ -48,11 +72,12 @@ const ChangeBebridge = () => {
4872 < Input
4973 type = "text"
5074 onChange = { setTitle }
51- label = " 대시보드 이름"
75+ label = { ` 대시보드 이름 : ${ dashboardDetail ?. title || "" } ` }
5276 labelClassName = "text-lg sm:text-base text-black3 mt-6"
5377 placeholder = "뉴프로젝트"
5478 className = "max-w-[620px] mb-1"
5579 />
80+
5681 < div className = "flex mt-3" >
5782 { colors . map ( ( color , index ) => (
5883 < div key = { index } className = "relative" >
0 commit comments