From 3dd5636099872c39ef01063831adaaa2f6c77562 Mon Sep 17 00:00:00 2001 From: KIM_DEAHO <102588838+DHowor1d@users.noreply.github.com> Date: Mon, 15 Sep 2025 20:33:09 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=B0=ED=8F=AC=20api=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/client.js | 47 ++++++++++++++++++++++++++++++++++++++++- src/pages/Dashboard.jsx | 33 +++++++++++++++++------------ 2 files changed, 65 insertions(+), 15 deletions(-) diff --git a/src/api/client.js b/src/api/client.js index b8fbe92..d0fb179 100644 --- a/src/api/client.js +++ b/src/api/client.js @@ -1,8 +1,53 @@ +// import axios from 'axios'; + +// // axios 인스턴스 생성 +// const api = axios.create({ +// baseURL: '/api', +// headers: { +// 'Content-Type': 'application/json', +// 'Accept': 'application/json', +// }, +// withCredentials: false, // CORS 설정 +// }); + +// // 요청 인터셉터 +// api.interceptors.request.use( +// (config) => { +// // 토큰 +// const token = localStorage.getItem('token'); +// if (token) { +// config.headers.Authorization = `Bearer ${token}`; +// } +// return config; +// }, +// (error) => { +// return Promise.reject(error); +// } +// ); + +// // 응답 인터셉터 +// api.interceptors.response.use( +// (response) => { +// return response; +// }, +// (error) => { +// console.error('API Error:', error); +// return Promise.reject(error); +// } +// ); + +// export default api; + + import axios from 'axios'; +const BASE_URL = window.location.hostname === "localhost" + ? "http://localhost:8081/api" // 로컬 백엔드 URL + : "https://api.sysonetaskmanager.store/api"; // 프로덕션 백엔드 URL + // axios 인스턴스 생성 const api = axios.create({ - baseURL: '/api', + baseURL: BASE_URL, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', diff --git a/src/pages/Dashboard.jsx b/src/pages/Dashboard.jsx index b103ad5..5921d6b 100644 --- a/src/pages/Dashboard.jsx +++ b/src/pages/Dashboard.jsx @@ -16,7 +16,7 @@ function Dashboard() { const navigate = useNavigate(); const { selectedProjectId } = useProjectStore(); - // fetchDashboardProjects API에서 데이터 가져오기 + // fetchDashboardProjects API에서 전체 데이터 가져오기 const { data: dashboardData } = useQuery({ queryKey: ['dashboardProjects'], queryFn: fetchDashboardProjects, @@ -33,10 +33,12 @@ function Dashboard() { const projectCount = dashboardData?.data?.projectCount || 0; const issueCount = dashboardData?.data?.issueCount || 0; - // 사용자 역할 확인 + // 사용자 역할 확인 - 대소문자 구분 없이 체크 const userRole = projectDashboardData?.data?.role || 'User'; - const isPM = userRole === 'PM'; - const isUser = userRole === 'User'; + const isPM = userRole?.toUpperCase() === 'PM'; + const isMaster = userRole?.toUpperCase() === 'MASTER'; + const isUser = userRole?.toUpperCase() === 'USER'; + const isAdmin = isPM || isMaster; // PM 또는 MASTER 권한 // 디버깅용 로그 useEffect(() => { @@ -44,26 +46,29 @@ function Dashboard() { console.log('프로젝트 대시보드 데이터:', projectDashboardData); console.log('사용자 역할:', userRole); console.log('PM 여부:', isPM); + console.log('MASTER 여부:', isMaster); + console.log('Admin 권한 여부:', isAdmin); console.log('User 여부:', isUser); } - }, [projectDashboardData, userRole, isPM, isUser]); + }, [projectDashboardData, userRole, isPM, isMaster, isAdmin, isUser]); const kpiData = [ { title: "진행 중인 프로젝트", value: projectCount.toString(), - icon: , + icon: , trend: "up", - path: "/projects", - trendValue: "+2 from last month", + trendValue: "+12%", + path: "/projects" }, { - title: "이번 주 마감 작업", + title: "진행 중인 이슈", value: issueCount.toString(), - icon: , + icon: , trend: "down", - trendValue: "-3 from last week", - }, + trendValue: "-5%", + path: "/issues" + } ]; return ( @@ -74,8 +79,8 @@ function Dashboard() {
- {/* 에러 발생 창 - PM일 경우에만 표시 */} - {isPM && ( + {/* 에러 발생 창 - PM 또는 MASTER일 경우에만 표시 */} + {isAdmin && ( )}