global css 적용, 권한설정 완료1
This commit is contained in:
@@ -3,12 +3,11 @@
|
||||
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import MainLogoSvg from './svgs/mainlogosvg';
|
||||
import ChevronDownSvg from './svgs/chevrondownsvg';
|
||||
|
||||
export default function Home() {
|
||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||
const [currentIndex, setCurrentIndex] = useState(0);
|
||||
const [isNameActive, setIsNameActive] = useState(false);
|
||||
const [userName, setUserName] = useState<string>('');
|
||||
|
||||
// 코스, 공지사항 더미 데이터
|
||||
const courseCards = useMemo(
|
||||
@@ -114,6 +113,57 @@ export default function Home() {
|
||||
[]
|
||||
);
|
||||
|
||||
// 사용자 정보 가져오기
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
|
||||
async function fetchUserInfo() {
|
||||
try {
|
||||
const localStorageToken = localStorage.getItem('token');
|
||||
const cookieToken = document.cookie
|
||||
.split('; ')
|
||||
.find(row => row.startsWith('token='))
|
||||
?.split('=')[1];
|
||||
|
||||
const token = localStorageToken || cookieToken;
|
||||
|
||||
if (!token) {
|
||||
return;
|
||||
}
|
||||
|
||||
const apiUrl = process.env.NEXT_PUBLIC_API_BASE_URL
|
||||
? `${process.env.NEXT_PUBLIC_API_BASE_URL}/auth/me`
|
||||
: 'https://hrdi.coconutmeet.net/auth/me';
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (isMounted && data.name) {
|
||||
setUserName(data.name);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('사용자 정보 조회 오류:', error);
|
||||
}
|
||||
}
|
||||
|
||||
fetchUserInfo();
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const containerEl = containerRef.current;
|
||||
if (!containerEl) return;
|
||||
@@ -141,10 +191,6 @@ export default function Home() {
|
||||
const handlePrev = () => scrollToIndex(currentIndex - 1);
|
||||
const handleNext = () => scrollToIndex(currentIndex + 1);
|
||||
|
||||
const handleNameClick = () => {
|
||||
setIsNameActive((prev) => !prev);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full min-h-screen flex flex-col bg-white">
|
||||
<main className="flex-1">
|
||||
@@ -223,19 +269,9 @@ export default function Home() {
|
||||
<div className="px-8 py-8">
|
||||
<div className="mb-6">
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleNameClick}
|
||||
aria-expanded={isNameActive}
|
||||
className="m-0 p-0 bg-transparent border-0 text-[18px] font-bold leading-normal text-[#333C47] cursor-pointer inline-flex items-center gap-1"
|
||||
>
|
||||
김하늘님
|
||||
<ChevronDownSvg
|
||||
width={20}
|
||||
height={20}
|
||||
className={'transition-transform duration-200 ' + (isNameActive ? 'rotate-180' : 'rotate-0')}
|
||||
/>
|
||||
</button>
|
||||
<span className="text-[18px] font-bold leading-normal text-[#333C47]">
|
||||
{userName ? `${userName}님` : '사용자님'}
|
||||
</span>
|
||||
<span className="text-[18px] font-bold leading-normal text-[#333C47]">환영합니다.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user