Skip to content
Open
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
8 changes: 7 additions & 1 deletion src/components/mypage/UserProfileLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ export default function UserProfileLayout() {

return (
<div className='absolute top-0 left-1/2 flex -translate-x-1/2 -translate-y-[40px] flex-col items-center justify-center gap-4 lg:-translate-y-[60px] lg:gap-6'>
<Avatar src={user.image} alt='유저이미지' className='size-20 cursor-pointer border-2 border-blue-300 lg:size-[120px]' onClick={handleAvatarClick} priority></Avatar>
<Avatar
src={user?.image ?? process.env.NEXT_PUBLIC_DEFAULT_IMAGE_URL}
alt='유저이미지'
className='size-20 cursor-pointer border-2 border-blue-300 lg:size-[120px]'
onClick={handleAvatarClick}
priority
></Avatar>
<input type='file' className='hidden' onChange={handleChangeImage} accept='image/*' ref={fileInputRef} />
<p className='text-black-950 text-lg font-medium lg:text-2xl'>{user.nickname}</p>
<LogoutButton className='h-9 w-[77px] px-3.5 py-1.5 text-[14px] font-normal whitespace-nowrap lg:h-12 lg:w-[100px] lg:px-4 lg:py-2 lg:text-xl lg:font-medium'></LogoutButton>
Expand Down
33 changes: 22 additions & 11 deletions src/context/MypageProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import { useGetUser } from '@/apis/user/queries';
import dayjs, { Dayjs } from 'dayjs';
import { useGetMonthlyEmotionLogs } from '@/apis/emotion-log/queries';

const defaultUser = {
image: process.env.NEXT_PUBLIC_DEFAULT_IMAGE_URL ?? '',
createdAt: '',
updatedAt: '',
teamId: '',
nickname: '사용자',
id: 0,
};

export const MypageContext = createContext<CreateContext>({
currentDate: dayjs(),
setCurrentDate: () => {},
userEmotion: [],
user: {
image: '',
createdAt: '',
updatedAt: '',
teamId: '',
nickname: '',
id: 0,
},
user: defaultUser,
});

export default function MypageProvider({ children }: PropsWithChildren) {
Expand All @@ -32,7 +34,16 @@ export default function MypageProvider({ children }: PropsWithChildren) {
enabled: !!user && !!currentDate,
});

if (!user || !userEmotion) return <div>로딩 중...</div>;

return <MypageContext.Provider value={{ currentDate, setCurrentDate, userEmotion, user }}>{children}</MypageContext.Provider>;
return (
<MypageContext.Provider
value={{
currentDate,
setCurrentDate,
userEmotion: userEmotion ?? [],
user: user ?? defaultUser,
}}
>
{children}
</MypageContext.Provider>
);
}