From a7f9d3f13d674bb63e80fc1f4e6bc0d22581c20f Mon Sep 17 00:00:00 2001 From: soyun-git121 Date: Tue, 5 Aug 2025 09:31:21 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=ED=94=84=EB=A1=9C=ED=95=84=20api=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/profile/profile.api.ts | 14 ++++ src/api/user/userEdit.api.ts | 9 +++ src/hooks/queries/useUserProfileQuery.ts | 22 ++++++ src/pages/my/CinemaChoice.tsx | 13 +++- src/pages/my/ProfileEdit.tsx | 94 +++++++++++++++++------- src/pages/my/SelectGenre.tsx | 17 +++-- src/types/user.ts | 9 ++- src/types/userEdit.ts | 13 ++++ 8 files changed, 155 insertions(+), 36 deletions(-) create mode 100644 src/api/profile/profile.api.ts create mode 100644 src/api/user/userEdit.api.ts create mode 100644 src/hooks/queries/useUserProfileQuery.ts create mode 100644 src/types/userEdit.ts diff --git a/src/api/profile/profile.api.ts b/src/api/profile/profile.api.ts new file mode 100644 index 0000000..24bb4b5 --- /dev/null +++ b/src/api/profile/profile.api.ts @@ -0,0 +1,14 @@ +import api from '@/api/api'; +import type { UserProfile } from '@/types/user'; +import type { ApiError } from '@/types/api-response'; + +export const getUserProfile = async (): Promise => { + try { + const response = await api.get('/profile'); + return response.data; + } catch (err) { + const apiError = err as ApiError; + console.error('프로필 로딩 에러:', apiError); + throw apiError; + } +}; \ No newline at end of file diff --git a/src/api/user/userEdit.api.ts b/src/api/user/userEdit.api.ts new file mode 100644 index 0000000..0334765 --- /dev/null +++ b/src/api/user/userEdit.api.ts @@ -0,0 +1,9 @@ +import api from '@/api/api'; +import type { UpdateUserProfileRequest, UserProfileResponse } from '@/types/userEdit'; + +export const updateUserProfile = async ( + data: UpdateUserProfileRequest +): Promise => { + const res = await api.put('/api/v1/profile', data); + return res.data.data; +}; \ No newline at end of file diff --git a/src/hooks/queries/useUserProfileQuery.ts b/src/hooks/queries/useUserProfileQuery.ts new file mode 100644 index 0000000..930ed24 --- /dev/null +++ b/src/hooks/queries/useUserProfileQuery.ts @@ -0,0 +1,22 @@ +import { useQuery } from '@tanstack/react-query'; +import api from '@/api/api'; + +export interface UserProfile { + nickname: string; + imageUrl: string | null; + genres: string[]; + auditoriums: string[]; +} + +const fetchUserProfile = async (): Promise => { + const res = await api.get('/api/v1/user/profile'); + return res.data.data; +}; + +export const useUserProfileQuery = () => { + return useQuery({ + queryKey: ['userProfile'], + queryFn: fetchUserProfile, + staleTime: 1000 * 60 * 5, // 5분 캐시 + }); +}; \ No newline at end of file diff --git a/src/pages/my/CinemaChoice.tsx b/src/pages/my/CinemaChoice.tsx index cbb5f40..de56cf9 100644 --- a/src/pages/my/CinemaChoice.tsx +++ b/src/pages/my/CinemaChoice.tsx @@ -1,5 +1,5 @@ import { useState } from 'react'; -import { useNavigate } from 'react-router-dom'; +import { useNavigate, useLocation } from 'react-router-dom'; import { Button, Header, ToggleTab } from '@/components'; import type { CinemaFormat, CinemaType } from '@/types/onboarding'; @@ -15,6 +15,7 @@ const MAX_SELECTABLE_THEATERS = 2; export default function CinemaChoice() { const navigate = useNavigate(); + const location = useLocation(); const [selectedTheaters, setSelectedTheaters] = useState([]); const [activeFormat, setActiveFormat] = useState('Dolby'); @@ -32,8 +33,13 @@ export default function CinemaChoice() { }; const handleConfirmSelection = () => { - console.log('선택된 영화관:', selectedTheaters); - navigate(-1); + navigate('/my/profile-edit', { + state: { + auditoriums: selectedTheaters, + nickname: location.state?.nickname, + genres: location.state?.genres, + }, + }); }; const handleFormatSelect = (format: string) => { @@ -67,7 +73,6 @@ export default function CinemaChoice() { onSelect={(selectedValue) => handleFormatSelect(selectedValue)} /> - {/* 영화관 목록 */}
{currentTheaters.map((theater) => (
-
- - {/* 즐겨찾는 영화관 섹션 */} -
- {/* Footer */} -