From 6e2f458ea947de929c902b444854cf3050343c7f Mon Sep 17 00:00:00 2001 From: Dongseok Lee Date: Fri, 21 Mar 2025 03:09:57 +0900 Subject: [PATCH] =?UTF-8?q?refactor(DEVING-78):=20=ED=97=A4=EB=8D=94=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A6=89=EC=8B=9C=20=EB=B0=98=EC=98=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84,=20=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EA=B8=B0=EB=B3=B8=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mypage/_features/ProfileImage.tsx | 60 +++++++++++++- src/components/common/Header.tsx | 17 +++- src/constants/mypage/mypageConstant.tsx | 4 + src/hooks/mutations/useMyPageMutation.tsx | 81 ++++++++++++++++--- src/hooks/mutations/useUserMutation.ts | 18 +++++ 5 files changed, 165 insertions(+), 15 deletions(-) diff --git a/src/app/(user-page)/mypage/_features/ProfileImage.tsx b/src/app/(user-page)/mypage/_features/ProfileImage.tsx index cff5d928..202b58f7 100644 --- a/src/app/(user-page)/mypage/_features/ProfileImage.tsx +++ b/src/app/(user-page)/mypage/_features/ProfileImage.tsx @@ -5,11 +5,16 @@ import { Button } from '@/components/ui/Button'; import Modal from '@/components/ui/modal/Modal'; import { useUpdateProfileImageMutation } from '@/hooks/mutations/useMyPageMutation'; import { useProfileQuery } from '@/hooks/queries/useMyPageQueries'; +import { QUERY_KEYS } from '@/hooks/queries/useMyPageQueries'; +import { useQueryClient } from '@tanstack/react-query'; import { Pencil } from 'lucide-react'; import Image from 'next/image'; import { useEffect, useRef, useState } from 'react'; -import { MAX_FILE_SIZE } from '../../../../constants/mypage/mypageConstant'; +import { + DEFAULT_PROFILE_IMAGE, + MAX_FILE_SIZE, +} from '../../../../constants/mypage/mypageConstant'; import SkeletonProfileImage from './skeletons/SkeletonProfileImage'; const ProfileImage = () => { @@ -19,6 +24,7 @@ const ProfileImage = () => { const [fileSizeError, setFileSizeError] = useState(null); const [isMobile, setIsMobile] = useState(false); const fileInputRef = useRef(null); + const queryClient = useQueryClient(); // 프로필 데이터 조회 const { data: profileData, isLoading: isProfileLoading } = useProfileQuery(); @@ -29,6 +35,7 @@ const ProfileImage = () => { // 프로필 이미지 URL const profileImageUrl = profileData?.data?.profilePic || null; + const isDefaultImage = profileImageUrl?.includes('default-profile.png'); // 반응형 화면 크기 감지 useEffect(() => { @@ -85,10 +92,41 @@ const ProfileImage = () => { resetImageState(); // 모달 닫기 setIsModalOpen(false); + // 배너 쿼리 무효화 (중요! - 헤더의 프로필 이미지도 업데이트되도록) + queryClient.invalidateQueries({ queryKey: QUERY_KEYS.banner() }); }, }); }; + // 기본 이미지로 변경하는 핸들러 + const handleResetToDefault = async () => { + try { + // 기본 이미지 URL을 Blob으로 변환 + const response = await fetch(DEFAULT_PROFILE_IMAGE); + const blob = await response.blob(); + + // 이전 미리보기 URL 해제 + if (previewUrl) URL.revokeObjectURL(previewUrl); + + // 새 미리보기 URL 생성 + const objectUrl = URL.createObjectURL(blob); + setPreviewUrl(objectUrl); + + // 선택된 파일 설정 (이것이 handleConfirm에서 사용됨) + const defaultImageFile = new File([blob], 'default-profile.png', { + type: blob.type, + }); + setSelectedFile(defaultImageFile); + + // 파일 크기 에러 초기화 + setFileSizeError(null); + + // 여기서 updateImage 호출 제거 - 변경 버튼 클릭할 때만 적용되도록 + } catch (error) { + console.error('기본 이미지 변경 중 오류 발생:', error); + } + }; + // 상태 초기화 함수 (중복 코드 제거) const resetImageState = () => { setSelectedFile(null); @@ -201,7 +239,25 @@ const ProfileImage = () => { disableConfirm={!!fileSizeError || !selectedFile} >
-
프로필 이미지
+
+
프로필 이미지
+ +