Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/auth/googleLogin/authConstants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const GOOGLE_CLIENT_ID = import.meta.env.VITE_GOOGLE_CLIENT_ID;
export const GOOGLE_REDIRECT_URI = import.meta.env.VITE_GOOGLE_REDIRECT_URI;
export const GOOGLE_REDIRECT_URI = import.meta.env.VITE_GOOGLE_REDIRECT_URI_LOCAL;
export const GOOGLE_AUTH_BASE_URL = 'https://accounts.google.com/o/oauth2/v2/auth';
export const GOOGLE_SCOPE = 'openid email profile';
export const GOOGLE_RESPONSE_TYPE = 'code';
6 changes: 3 additions & 3 deletions src/api/auth/googleLogin/util/getAccessToken.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { GOOGLE_REDIRECT_URI } from '@/api/auth/googleLogin/authConstants';
import axiosInstance from '@/api/axiosInstance';

const getAccessToken = async (code: string) => {
const redirectUri = import.meta.env.VITE_GOOGLE_REDIRECT_URI;

const response = await axiosInstance.post(
`/auth/oauth2/google/callback?redirect_uri=${redirectUri}`,
`/auth/oauth2/google/callback?redirect_uri=${GOOGLE_REDIRECT_URI}`,
{ code },
);

return response.data.data;
};

Expand Down
3 changes: 3 additions & 0 deletions src/api/domain/signup/hook/useGetUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { getUser } from '@/api/domain/signup';
import { QUERY_KEY } from '@/api/constant/queryKey';

export const useGetUser = () => {
const token = localStorage.getItem('accessToken');

return useQuery({
queryKey: QUERY_KEY.USER_INFO,
queryFn: getUser,
enabled: !!token,
});
};
2 changes: 1 addition & 1 deletion src/common/component/UserModal/UserModal.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const profileContainer = style({
export const profileImage = style({
width: '5rem',
height: '5rem',
borderRadius: '25%',
borderRadius: '50%',
objectFit: 'cover',
});

Expand Down
13 changes: 7 additions & 6 deletions src/page/home/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useNavigate } from 'react-router-dom';

import { HomeContainer } from '@/page/home/Home.css';
import { INTRO_MESSAGE } from '@/page/home/constant/scrollSection';
import { useFadeInOnView } from '@/page/home/hook/useFadeInOnView';
Expand All @@ -10,19 +8,21 @@ import { fadeSlide } from '@/page/home/style/fadeTransition.css';
import { useMultipleFadeInOnView } from '@/page/home/hook/useMultipleFadeInOnView';
import mandalAnimation from '@/assets/lottie/mandalart.json';
import aiAnimation from '@/assets/lottie/ai.json';
import { PATH } from '@/route';
import todoAnimation from '@/assets/lottie/todo.json';
import { useModal } from '@/common/hook/useModal';
import LoginModal from '@/common/component/LoginModal/LoginModal';

const animationDataArray = [mandalAnimation, aiAnimation, todoAnimation];
const sectionKeys = ['mandalart', 'ai', 'todo'] as const;

const Home = () => {
const navigate = useNavigate();
const scrolls = useMultipleFadeInOnView();
const end = useFadeInOnView<HTMLDivElement>();

const { openModal, closeModal, ModalWrapper } = useModal();

const handleOpenLogin = () => {
// openModal(<LoginModal onClose={closeModal} />);
navigate(PATH.TODO);
openModal(<LoginModal onClose={closeModal} />);
};

return (
Expand All @@ -44,6 +44,7 @@ const Home = () => {
})}

<EndSection fadeInRef={end.ref} visible={end.visible} onClick={handleOpenLogin} />
{ModalWrapper}
</div>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/shared/component/Layout/layoutHeader/Header.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const profilePlaceholder = style({
borderRadius: '50%',
backgroundColor: colors.grey6,
flexShrink: 0,
cursor: 'pointer',
});

export const loginButton = style({
Expand Down
39 changes: 37 additions & 2 deletions src/shared/component/Layout/layoutHeader/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import * as styles from './Header.css';

import { PATH } from '@/route/path';
import IcLogo from '@/assets/svg/IcLogo';
import LoginModal from '@/common/component/LoginModal/LoginModal';
import { useModal } from '@/common/hook/useModal';
import { useGetUser } from '@/api/domain/signup/hook/useGetUser';
import UserModal from '@/common/component/UserModal/UserModal';

const MENUS = [
{ label: '나의 할 일', path: PATH.TODO },
Expand All @@ -16,19 +20,32 @@ const Header = () => {
const navigate = useNavigate();
const location = useLocation();

const { data: user, isLoading } = useGetUser();

const findActiveMenu = MENUS.find((menu) => location.pathname.startsWith(menu.path));
const initialMenu = findActiveMenu ? findActiveMenu.label : '';

const [activeMenu, setActiveMenu] = useState<string>(initialMenu);
const [openProfile, setOpenProfile] = useState<boolean>(false);

const { openModal, closeModal, ModalWrapper } = useModal();

const handleLogin = () => {
openModal(<LoginModal onClose={closeModal} />);
};

const handleMenuClick = (menuLabel: string, path: string) => {
setActiveMenu(menuLabel);
navigate(path);
};

const handleProfile = () => {
setOpenProfile((prev) => !prev);
};

const renderNavMenu = () => (
<>
<nav className={styles.navWrapper}>
<nav className={styles.navWrapper} aria-label="주요 메뉴">
{MENUS.map((menu) => {
const isActive = activeMenu === menu.label;
const buttonClass = `${styles.navItem} ${isActive ? styles.navItemActive : ''}`;
Expand All @@ -45,6 +62,17 @@ const Header = () => {
);
})}
</nav>
{!isLoading && user && (
<>
<img
src={user.profileImageUrl}
alt="유저 프로필 이미지"
className={styles.profilePlaceholder}
onClick={handleProfile}
/>
{openProfile && <UserModal onClose={handleProfile} />}
</>
)}
</>
);

Expand All @@ -55,8 +83,15 @@ const Header = () => {
<IcLogo className={styles.logoImage} />
</Link>

{renderNavMenu()}
{!isLoading && user ? (
renderNavMenu()
) : (
<button className={styles.loginButton} onClick={handleLogin} type="button">
로그인
</button>
)}
</div>
{ModalWrapper}
</header>
);
};
Expand Down
Loading