-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 프로필 수정, 로그아웃, 회원 탈퇴 API 및 Mutation 연동 #109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+1,900
−66
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d75d422
feat: 마이페이지 탭 시스템 구축 및 활동 내역 리스트 구현
fryzke 176e1fd
fix: UserProfile 내 잘못된 프로퍼티 참조 수정 (icon -> image)
fryzke 5887045
fix: proxy 문자열 처리한 부분 되돌리기, 경험, 키워드 컴포넌트에 주석 추가(최대갯수)
fryzke 2ef2b26
Merge branch 'dev' of https://github.com/Inflearn-Prog/Prog-fe into f…
fryzke c3d3d41
feat: 프로필 수정, 로그아웃, 회원 탈퇴 API 및 Mutation 연동
fryzke dc81db5
fix: proxy 원상태로 복귀
fryzke 39fd286
fix: 피드백 반영 및 마이페이지용 Zustand store 분리
fryzke 86ad706
fix: 피드백 반영
fryzke 402a711
fix: 타입상수 수정 및 프로필 수정 업데이트 초기화 1회 제한으로 수정
fryzke 28412ac
fix: 상태에서 기타 선택시 입력한 값으로 저장되도록 수정
fryzke 7c25050
fix: 기타 입력란 빈칸 입력 방어 로직 추가
fryzke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| "use client"; | ||
|
|
||
| import { useRouter, useSearchParams } from "next/navigation"; | ||
|
|
||
| import { | ||
| LikedArticleCard, | ||
| MyArticleCard, | ||
| } from "@/components/mypage/articleCard"; | ||
| import { PaginationButton } from "@/components/pagination-button/pagination-button"; | ||
| import { toasts } from "@/components/shared/toast"; | ||
| import { useLikedPrompts, useUserPrompts } from "@/hooks/use-mypage"; | ||
| import { cn } from "@/lib/utils"; | ||
|
|
||
| export default function MypageActivitySection() { | ||
| const router = useRouter(); | ||
| const searchParams = useSearchParams(); | ||
|
|
||
| // 1. 현재 탭 및 페이지 상태 관리 | ||
| const rawSub = searchParams.get("sub"); | ||
| const activeSub: "liked" | "posted" = | ||
| rawSub === "posted" ? "posted" : "liked"; | ||
| const currentPage = Number(searchParams.get("page")) || 0; | ||
| const userId = 1; // 실제로는 인증 정보나 프로필 훅에서 가져온 ID 사용 | ||
|
|
||
| const { data: likedData, isLoading: isLikedLoading } = useLikedPrompts( | ||
| userId, | ||
| currentPage | ||
| ); | ||
| const { data: postedData, isLoading: isPostedLoading } = useUserPrompts({ | ||
| userId, | ||
| page: currentPage, | ||
| }); | ||
|
|
||
| const handleSubTabChange = (sub: "liked" | "posted") => { | ||
| const params = new URLSearchParams(searchParams.toString()); | ||
| params.set("sub", sub); | ||
| params.set("page", "0"); | ||
| router.push(`/mypage?${params.toString()}`, { scroll: false }); | ||
| }; | ||
|
|
||
| const handleCopy = async (e: React.MouseEvent, content: string) => { | ||
| e.stopPropagation(); | ||
| try { | ||
| await navigator.clipboard.writeText(content); | ||
| toasts.success("프롬프트가 클립보드에 복사되었습니다!"); | ||
| } catch { | ||
| alert("복사에 실패했습니다."); | ||
| } | ||
| }; | ||
| const handlePageChange = (page: number) => { | ||
| const params = new URLSearchParams(searchParams.toString()); | ||
| params.set("page", page.toString()); | ||
| router.push(`/mypage?${params.toString()}`, { scroll: false }); | ||
| }; | ||
|
|
||
| const handleCardClick = (id: number) => { | ||
| router.push(`/prompts/${id}`); | ||
| }; | ||
|
|
||
| // 현재 활성화된 데이터와 로딩 상태 결정 | ||
| const currentData = activeSub === "liked" ? likedData : postedData; | ||
| const isLoading = activeSub === "liked" ? isLikedLoading : isPostedLoading; | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-6 w-full"> | ||
| {/* 서브 탭 메뉴 */} | ||
| <div className="flex w-full bg-gray-0 border border-gray-100 rounded-[8px] overflow-hidden p-1 shadow-sm"> | ||
| <button | ||
| onClick={() => handleSubTabChange("liked")} | ||
| className={cn( | ||
| "flex-1 py-2.5 label-medium !font-bold transition-all rounded-[6px]", | ||
| activeSub === "liked" | ||
| ? "bg-blue-600 text-gray-0 shadow-sm" | ||
| : "text-gray-500 hover:bg-gray-50" | ||
| )} | ||
| > | ||
| 좋아요한 프롬프트 | ||
| </button> | ||
| <button | ||
| onClick={() => handleSubTabChange("posted")} | ||
| className={cn( | ||
| "flex-1 py-2.5 label-medium !font-bold transition-all rounded-[6px]", | ||
| activeSub === "posted" | ||
| ? "bg-blue-600 text-gray-0 shadow-sm" | ||
| : "text-gray-500 hover:bg-gray-50" | ||
| )} | ||
| > | ||
| 게시한 프롬프트 | ||
| </button> | ||
| </div> | ||
|
|
||
| {/* 리스트 영역 */} | ||
| <div className="flex flex-col gap-4"> | ||
| {isLoading ? ( | ||
| <div className="py-20 text-center text-gray-400">로딩 중...</div> | ||
| ) : currentData?.content.length === 0 ? ( | ||
| <div className="py-20 text-center text-gray-400"> | ||
| {activeSub === "liked" | ||
| ? "좋아요한 프롬프트가 없습니다." | ||
| : "게시한 프롬프트가 없습니다."} | ||
| </div> | ||
| ) : ( | ||
| currentData?.content.map((prompt) => | ||
| activeSub === "liked" ? ( | ||
| <LikedArticleCard | ||
| key={prompt.promptId} | ||
| title={prompt.title} | ||
| content={prompt.description} | ||
| onCopy={(e) => handleCopy(e, prompt.description)} | ||
| onClick={() => handleCardClick(prompt.promptId)} | ||
| /> | ||
| ) : ( | ||
| <MyArticleCard | ||
| key={prompt.promptId} | ||
| title={prompt.title} | ||
| content={prompt.description} | ||
| createdAt={prompt.createdAt} | ||
| onClick={() => handleCardClick(prompt.promptId)} | ||
| /> | ||
| ) | ||
| ) | ||
| )} | ||
| </div> | ||
|
|
||
| {/* 단순 페이지네이션 (필요 시 추가) */} | ||
| {!isLoading && (currentData?.pageInfo.totalPages ?? 0) > 1 && ( | ||
| <div className="flex justify-center gap-2 mt-4"> | ||
| <PaginationButton | ||
| currentPage={currentPage} | ||
| totalPages={currentData?.pageInfo.totalPages ?? 1} | ||
| onPageChange={handlePageChange} | ||
| /> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| "use client"; | ||
| import { useQueryClient } from "@tanstack/react-query"; | ||
| import Cookies from "js-cookie"; | ||
| import { useRouter } from "next/navigation"; | ||
|
|
||
| import UserProfile from "@/components/mypage/user-profile"; | ||
| import { BaseButton } from "@/components/shared/button"; | ||
| import { toasts } from "@/components/shared/toast"; | ||
| import { useUserProfile } from "@/hooks/use-mypage"; | ||
| import { deleteUserAccount, postLogout } from "@/queries/api/auth"; | ||
|
|
||
| export default function MypageLeftSection() { | ||
| const router = useRouter(); | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| const { data: userData, isLoading } = useUserProfile(); | ||
|
|
||
| const handleLogout = async () => { | ||
| if (confirm("로그아웃 하시겠습니까?")) { | ||
| try { | ||
| await postLogout(); | ||
|
|
||
| Cookies.remove("accessToken"); | ||
| Cookies.remove("refreshToken"); | ||
|
|
||
| queryClient.clear(); | ||
| toasts.success("로그아웃 되었습니다."); | ||
| router.push("/"); | ||
| router.refresh(); | ||
| } catch (error) { | ||
| Cookies.remove("accessToken"); | ||
| Cookies.remove("refreshToken"); | ||
| console.error("Logout failed:", error); | ||
| //TODO: error 컴포넌트가 생기면 사용자 피드백 주기 | ||
| //toasts.error("로그아웃 처리 중 오류가 발생했습니다."); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| const handleWithdraw = async () => { | ||
| const isConfirmed = confirm( | ||
| "정말로 탈퇴하시겠습니까?\n탈퇴 시 모든 데이터가 삭제되며 복구할 수 없습니다." | ||
| ); | ||
|
|
||
| if (!isConfirmed || !userData) return; | ||
|
|
||
| try { | ||
| await deleteUserAccount(userData.basicInfo.uid); | ||
|
|
||
| Cookies.remove("refreshToken"); | ||
| Cookies.remove("accessToken"); | ||
| queryClient.clear(); | ||
|
|
||
| toasts.success("회원 탈퇴가 완료되었습니다. 이용해 주셔서 감사합니다."); | ||
| router.push("/"); | ||
| router.refresh(); | ||
| } catch (error) { | ||
| console.error("Withdrawal failed:", error); | ||
| //toasts.error("탈퇴 처리 중 오류가 발생했습니다. 고객센터에 문의해주세요."); | ||
| } | ||
fryzke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| // 로딩 및 에러 처리 | ||
| if (isLoading) return <div className="p-10 text-center">로딩 중...</div>; | ||
| if (!userData) | ||
| return <div className="p-10 text-center">유저 정보가 없습니다.</div>; | ||
|
|
||
| const { basicInfo } = userData; | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-5"> | ||
| <UserProfile | ||
| nickname={basicInfo.nickname} | ||
| email={basicInfo.email} | ||
| profileImage={""} | ||
| provider={basicInfo.provider} | ||
| introduction={basicInfo.introduction ?? "반갑습니다!"} | ||
| /> | ||
|
|
||
| <BaseButton | ||
| onClick={handleLogout} | ||
| variant={"secondary"} | ||
| className="bg-gray-0" | ||
| > | ||
| 로그아웃 | ||
| </BaseButton> | ||
|
|
||
| <button | ||
| onClick={handleWithdraw} | ||
| className="text-error label-small opacity-60 hover:opacity-100 transition-opacity" | ||
| > | ||
| 계정 탈퇴 | ||
| </button> | ||
| </div> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.