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/components/common/ProtectRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface ProtectRouteProps extends PropsWithChildren {
}

const ProtectRoute = ({ children, redirectUrl }: ProtectRouteProps) => {
const { isLoggedIn } = useAuthStore();
const isLoggedIn = useAuthStore((state) => state.isLoggedIn);

if (!isLoggedIn) {
alert('로그인이 필요한 서비스입니다.');
Expand Down
13 changes: 4 additions & 9 deletions src/components/common/avatar/Avatar.styled.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import styled from 'styled-components';
import { AvatarProps } from './Avatar';

interface AvatarContainerProps extends Omit<AvatarProps, 'image'> {
$isMainLogo?: boolean;
}

export const AvatarContainer = styled.div<AvatarContainerProps>`
export const AvatarContainer = styled.div<Omit<AvatarProps, 'image'>>`
width: ${({ size }) => size};
height: ${({ size }) => size};
border-radius: ${({ $isMainLogo }) => ($isMainLogo ? '0' : '50%')};
border: ${({ $isMainLogo, theme }) =>
$isMainLogo ? 'none' : `1px solid ${theme.color.border}`};
border-radius: 50%;
border: 1px solid ${({ theme }) => theme.color.border};

.avatar {
width: 100%;
height: 100%;
border-radius: ${({ $isMainLogo }) => ($isMainLogo ? '0' : '50%')};
border-radius: 50%;
}

@media screen and ${({ theme }) => theme.mediaQuery.tablet} {
Expand Down
4 changes: 1 addition & 3 deletions src/components/common/avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { ReactNode } from 'react';
import * as S from './Avatar.styled';
import defaultImg from '../../../assets/defaultImg.png';
import MainLogo from '../../../assets/mainlogo.svg';

export interface AvatarProps {
size: string;
image: string | ReactNode;
}

function Avatar({ size, image }: AvatarProps) {
const isMainLogo = image === MainLogo;
const releasedImg =
typeof image === 'string' && image.trim() ? image : defaultImg;
return (
<S.AvatarContainer size={size} $isMainLogo={isMainLogo}>
<S.AvatarContainer size={size}>
{typeof image === 'string' || !image ? (
<img className='avatar' src={releasedImg} alt='Avatar' />
) : (
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Modal from '../modal/Modal';
function Header() {
const { isOpen, message, handleModalOpen, handleModalClose } = useModal();
const { userLogout } = useAuth(handleModalOpen);
const { isLoggedIn } = useAuthStore((state) => state);
const isLoggedIn = useAuthStore((state) => state.isLoggedIn);
const { myData, isLoading } = useMyProfileInfo();

const profileImg = myData?.profileImg || DefaultImg;
Expand Down
11 changes: 11 additions & 0 deletions src/components/common/sidebar/Sidebar.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ export const Container = styled.div`
padding-bottom: 1rem;
`;

export const LogoContainer = styled.div`
width: 110px;
height: 110px;

img {
width: 100%;
height: 100%;
object-fit: contain;
}
`;

export const AvartarContainer = styled.div`
width: 100%;
display: flex;
Expand Down
33 changes: 12 additions & 21 deletions src/components/common/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { NavLink, useLocation } from 'react-router-dom';
import Avatar from '../avatar/Avatar';
import * as S from './Sidebar.styled';
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback } from 'react';
import EditMyProfileImg from './editMyProfileImg/EditMyProfileImg';
import useAuthStore from '../../../store/authStore';
import MainLogo from '../../../assets/mainlogo.svg';

interface MenuItem {
label: string;
Expand All @@ -18,7 +19,7 @@ interface SidebarProps {
}

const Sidebar = ({ menuItems, profileImage, nickname }: SidebarProps) => {
const { isLoggedIn } = useAuthStore((state) => state);
const isLoggedIn = useAuthStore((state) => state.isLoggedIn);
const location = useLocation();
const isUserPage = location.pathname.includes('/user');
const isManagePage = location.pathname.includes('/manage');
Expand All @@ -27,38 +28,28 @@ const Sidebar = ({ menuItems, profileImage, nickname }: SidebarProps) => {

const getActiveIndex = useCallback(() => {
const currentPath = location.pathname;
const matchedIndex = menuItems.findIndex(
(item) => currentPath === item.path
);
return matchedIndex !== -1 ? matchedIndex : 0;
return menuItems.findIndex((item) => currentPath === item.path) ?? 0;
}, [location.pathname, menuItems]);

const [activeIndex, setActiveIndex] = useState<number>(getActiveIndex);

useEffect(() => {
setActiveIndex(getActiveIndex());
}, [location.pathname, menuItems, getActiveIndex]);

const handleClick = (index: number) => {
setActiveIndex(index);
};

return (
<S.Container>
<S.AvartarContainer>
<S.AvartarWrapper>
<Avatar size='120px' image={profileImage} />
{profileImage === MainLogo ? (
<S.LogoContainer>
<img src={MainLogo} alt='main logo' />
</S.LogoContainer>
) : (
<Avatar size='120px' image={profileImage} />
)}
{isMyProfile && <EditMyProfileImg />}
</S.AvartarWrapper>
<span>{nickname ? nickname : ''}</span>
</S.AvartarContainer>
<S.MenuList>
{menuItems.map(({ label, path, icon }, index) => (
<NavLink key={path} to={path}>
<S.MenuItem
$isActive={activeIndex === index}
onClick={() => handleClick(index)}
>
<S.MenuItem $isActive={getActiveIndex() === index}>
{icon && <S.IconWrapper>{icon}</S.IconWrapper>}
{label}
</S.MenuItem>
Expand Down
2 changes: 1 addition & 1 deletion src/constants/modalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const MODAL_MESSAGE = {
myProfileSuccess: '프로필 수정이 완료되었습니다.',
myProfileFail: '프로필 수정에 실패했습니다.',
profileImgSuccess: '프로필 이미지가 업로드 되었습니다.',
profileImgFail: '이미지는 5MB 이하, .png.jpg.jpeg.svg 형식만 가능합니다.',
profileImgFail: '이미지는 5MB 이하, .png.jpg.jpeg 형식만 가능합니다.',
ModifyProjectSuccess: '공고 수정이 정상적으로 완료 되었습니다.',
ModifyProjectFail: '공고 수정을 실패 했습니다.',
createProjectSuccess: '공고 생성을 완료 했습니다.',
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useMyInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { MODAL_MESSAGE } from '../constants/modalMessage';

export const useMyProfileInfo = () => {
const { isLoggedIn } = useAuthStore();
const isLoggedIn = useAuthStore((state) => state.isLoggedIn);

const { data, isLoading } = useQuery<UserInfo>({
queryKey: myInfoKey.myProfile,
Expand Down Expand Up @@ -84,7 +84,7 @@ export const useUploadProfileImg = (
};

export const useMyJoinedProjectList = () => {
const { isLoggedIn } = useAuthStore();
const isLoggedIn = useAuthStore((state) => state.isLoggedIn);

const { data, isLoading } = useQuery<MyJoinedProjectList>({
queryKey: ProjectListKey.myJoinedList,
Expand All @@ -96,7 +96,7 @@ export const useMyJoinedProjectList = () => {
};

export const useMyAppliedStatusList = () => {
const { isLoggedIn } = useAuthStore();
const isLoggedIn = useAuthStore((state) => state.isLoggedIn);

const { data, isLoading } = useQuery<MyAppliedProjectStatusList>({
queryKey: ProjectListKey.myAppliedStatusList,
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useUserInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useAuthStore from '../store/authStore';
import { UserJoinedProjectList } from '../models/userProject';

export const useUserProfileInfo = (id: number) => {
const { isLoggedIn } = useAuthStore();
const isLoggedIn = useAuthStore((state) => state.isLoggedIn);

const { data, isLoading } = useQuery<UserInfo>({
queryKey: [userInfoKey.userProfile, id],
Expand All @@ -19,7 +19,7 @@ export const useUserProfileInfo = (id: number) => {
};

export const useUserJoinedProjectList = (id: number) => {
const { isLoggedIn } = useAuthStore();
const isLoggedIn = useAuthStore((state) => state.isLoggedIn);

const { data, isLoading } = useQuery<UserJoinedProjectList>({
queryKey: [userInfoKey.userJoinedList, id],
Expand Down
2 changes: 1 addition & 1 deletion src/routes/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const ModifyProject = lazy(
);

const AppRoutes = () => {
const { isLoggedIn } = useAuthStore();
const isLoggedIn = useAuthStore((state) => state.isLoggedIn);

const routeList = [
// {
Expand Down