-
Notifications
You must be signed in to change notification settings - Fork 1
마이-메인페이지 구현 #219
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
마이-메인페이지 구현 #219
Changes from all commits
fab5b30
8f46d2d
fdc26c7
2a566bf
a9163f1
6794d08
cd00b99
461d9f9
8c5009a
6f900a5
694a400
c620d2e
1be2c37
02f9df5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { CalendarIcon, ListIcon, SettingIcon, UserIcon } from '@what-today/design-system'; | ||
| import { Link, useLocation } from 'react-router-dom'; | ||
| import { twMerge } from 'tailwind-merge'; | ||
|
|
||
| // interface MypageSidebarProps { | ||
| // /** | ||
| // * 사용자 프로필 이미지 URL | ||
| // * 전달되지 않을 경우 기본 아이콘(ProfileLogo)이 표시됩니다. | ||
| // */ | ||
| // profileImgUrl?: string; | ||
| // /** | ||
| // * 로그아웃 버튼 클릭 시 실행되는 콜백 함수(아마 모달을 띄우지 않을까 싶습니다.) | ||
| // */ | ||
| // onLogoutClick: () => void; | ||
| // /** | ||
| // * 클릭했을 때 sidebar 열림 여부 변경 | ||
| // */ | ||
| // onClick: () => void; | ||
| // /** | ||
| // * MypageSidebar의 열림 여부 | ||
| // */ | ||
| // isOpen: boolean; | ||
| // } | ||
|
|
||
| /** | ||
| * MypageSidebar 컴포넌트 | ||
| * | ||
| * 사용자의 프로필 이미지와 마이페이지 관련 메뉴를 표시합니다. | ||
| * 현재 URL 경로에 따라 해당 메뉴 항목을 하이라이트 처리합니다. | ||
| * 로그아웃 버튼을 포함하며, 클릭 시 지정된 콜백을 실행합니다. | ||
| * | ||
| * @component | ||
| * @example | ||
| * <MypageSidebar | ||
| * profileImgUrl="https://example.com/avatar.jpg" | ||
| * isOpen={isSidebarOpen} | ||
| * onClick={() => setSidebarOpen((prev) => !prev)} | ||
| * onLogoutClick={() => alert('hi')} | ||
| * /> | ||
| */ | ||
| export default function MypageMainSidebar() { | ||
| const location = useLocation(); | ||
|
|
||
| /** | ||
| * 사이드바에 표시할 고정 메뉴 항목 목록 | ||
| * 각 항목은 라벨, 아이콘 컴포넌트, 이동 경로로 구성됩니다. | ||
| */ | ||
| const items = [ | ||
| { icon: UserIcon, label: '내 정보', to: '/mypage/edit-profile' }, | ||
| { icon: ListIcon, label: '예약 내역', to: '/mypage/reservations-list' }, | ||
| { icon: SettingIcon, label: '내 체험 관리', to: '/mypage/manage-activities' }, | ||
| { icon: CalendarIcon, label: '예약 현황', to: '/mypage/reservations-status' }, | ||
| ]; | ||
|
|
||
| return ( | ||
| <nav | ||
| className={twMerge( | ||
| // 공통 스타일 | ||
| 'fixed z-50 max-w-200 min-w-200 rounded-2xl border border-gray-50 bg-white transition duration-300 md:static md:h-fit xl:w-280', | ||
| // 모바일에서 Drawer 위치 | ||
| // isOpen ? 'h-474 translate-x-0' : 'h-50 -translate-x-full bg-gray-200', | ||
| // 'md:translate-x-0', | ||
| // 'md:bg-white', | ||
| )} | ||
| > | ||
| {/* 콘텐츠: PC는 항상, 모바일은 isOpen일 때만 */} | ||
| <div | ||
| className={twMerge( | ||
| 'flex h-full flex-col items-center gap-24 px-14 py-12', | ||
| // isOpen ? 'flex' : 'hidden', | ||
| // 'md:flex', | ||
| )} | ||
| > | ||
| <ul className='flex w-full flex-col justify-center gap-4'> | ||
| {items.map(({ label, icon: Icon, to }) => { | ||
| const isSelected = location.pathname === to; | ||
| const itemClass = twMerge( | ||
| 'flex w-full cursor-pointer items-center gap-8 rounded-2xl px-20 py-14', | ||
| isSelected ? 'bg-primary-100 text-gray-950' : 'text-gray-600 hover:bg-gray-25', | ||
| ); | ||
| const iconColor = isSelected ? '#3d9ef2' : '#707177'; | ||
| return ( | ||
| <li key={label}> | ||
| <Link className={itemClass} to={to}> | ||
| <div className='flex size-24 items-center justify-center'> | ||
| <Icon color={`${iconColor}`} /> | ||
| </div> | ||
| <div className='body-text font-medium'>{label}</div> | ||
| </Link> | ||
| </li> | ||
| ); | ||
| })} | ||
| </ul> | ||
| </div> | ||
| </nav> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| import { useQueries, useQuery } from '@tanstack/react-query'; | ||
| import { | ||
| MypageProfileHeader, | ||
| MypageSummaryCard, | ||
| OngoingExperienceCard, | ||
| UpcomingSchedule, | ||
| useToast, | ||
| } from '@what-today/design-system'; | ||
| import dayjs from 'dayjs'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
|
|
||
| import { fetchReservationAvailableSchedule } from '@/apis/activityDetail'; | ||
| import { getMonthlySchedule } from '@/apis/myActivities'; | ||
| import { fetchMyReservations } from '@/apis/myReservations'; | ||
| import { useInfiniteMyActivitiesQuery } from '@/hooks/myActivity/useMyActivitiesQuery'; | ||
| import useAuth from '@/hooks/useAuth'; | ||
| import type { monthlyScheduleResponse } from '@/schemas/myActivities'; | ||
| import type { MyReservationsResponse } from '@/schemas/myReservations'; | ||
| import { useWhatTodayStore } from '@/stores'; | ||
|
|
||
| export default function MyPage() { | ||
| const navigate = useNavigate(); | ||
| const { logoutUser } = useAuth(); | ||
| const { user } = useWhatTodayStore(); | ||
| const { toast } = useToast(); | ||
|
|
||
| const MAX_PAGE_SIZE = 1000; | ||
| const year = dayjs().format('YYYY'); | ||
| const month = dayjs().format('MM'); | ||
|
|
||
| // 등록한 체험 갯수 | ||
| const { data: activityData } = useInfiniteMyActivitiesQuery(MAX_PAGE_SIZE); | ||
| const totalActivity = activityData?.pages[0]?.totalCount; | ||
|
|
||
| // 이번달 예약 승인 대기 갯수 | ||
| const activityIds = | ||
| activityData?.pages.flatMap((page: { activities: { id: number }[] }) => | ||
| page.activities.map((activity) => activity.id), | ||
| ) ?? []; | ||
|
|
||
| const monthlyReservationsResults = useQueries({ | ||
| queries: activityIds.map((id) => ({ | ||
| queryKey: ['monthlySchedule', id, year, month], | ||
| queryFn: () => getMonthlySchedule(id, { year, month }), | ||
| enabled: !!id, | ||
| })), | ||
| }); | ||
| const monthlyReservations = monthlyReservationsResults | ||
| .map((result) => result.data) | ||
| .filter(Boolean) as monthlyScheduleResponse[]; | ||
| const totalPending = monthlyReservations.flat().reduce((sum, item) => sum + item.reservations.pending || 0, 0); | ||
|
|
||
| // 완료한 체험 갯수 | ||
| const { data: completedData } = useQuery<MyReservationsResponse>({ | ||
| queryKey: ['reservations', 'completed'], | ||
| queryFn: () => | ||
| fetchMyReservations({ | ||
| cursorId: null, // 첫 페이지부터 가져옴 | ||
| size: MAX_PAGE_SIZE, // 충분히 큰 숫자로 설정 (전체 데이터 한 번에) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 페이지네이션이 걸려있는 목록에서 전체 데이터를 한 번에 받아올 때는, 혹시 cursorId만 제공되는 엔드포인트였을까요..?!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 안그래도 저렇게 1000을 넣는 것이 맞나 의문이 들긴 했어요... |
||
| status: 'completed', // 완료된 체험만 받아오기 | ||
| }), | ||
| staleTime: 1000 * 30, | ||
| }); | ||
|
|
||
| // 완료한 체험 중 리뷰 미작성 갯수 | ||
| const reviewRequired = completedData?.reservations.filter((res) => res.reviewSubmitted === false).length ?? 0; | ||
|
|
||
| // 다가오는 체험 데이터 | ||
| const { data: confirmedData } = useQuery<MyReservationsResponse>({ | ||
| queryKey: ['reservations', 'confirmed'], | ||
| queryFn: () => | ||
| fetchMyReservations({ | ||
| cursorId: null, // 첫 페이지부터 가져옴 | ||
| size: MAX_PAGE_SIZE, // 충분히 큰 숫자로 설정 (전체 데이터 한 번에) | ||
| status: 'confirmed', // 확정된 체험만 받아오기 | ||
| }), | ||
| staleTime: 1000 * 30, | ||
| }); | ||
|
|
||
| // 이번 달 모집 중인 체험 | ||
| const reservationAvailableResults = useQueries({ | ||
| queries: activityIds.map((id) => ({ | ||
| queryKey: ['availableSchedule', id, year, month], | ||
| queryFn: () => { | ||
| return fetchReservationAvailableSchedule(id, { year, month }); | ||
| }, | ||
| enabled: !!id, | ||
| })), | ||
| }); | ||
| const availableActivityIds = reservationAvailableResults | ||
| .map((result, index) => ({ data: result.data, activityId: activityIds[index] })) | ||
| .filter(({ data }) => Array.isArray(data) && data.length > 0) | ||
| .map(({ activityId }) => activityId); | ||
| // 1. useInfiniteMyActivitiesQuery에서 받은 모든 pages를 펼침 | ||
| const allActivities = activityData?.pages.flatMap((page) => page.activities) ?? []; | ||
| // 2. 예약 가능 activityId와 일치하는 항목만 필터링 | ||
| const availableActivities = allActivities.filter((activity) => availableActivityIds.includes(activity.id)); | ||
|
|
||
| const handleLogout = () => { | ||
| logoutUser(); | ||
| toast({ | ||
| title: '로그아웃 성공', | ||
| description: '다음에 또 만나요! 👋🏻', | ||
| type: 'success', | ||
| }); | ||
| navigate('/login'); | ||
| }; | ||
| return ( | ||
| <div className='flex gap-30'> | ||
| {/* <MypageMainSidebar /> */} | ||
| <div className='flex w-full flex-col gap-24'> | ||
| <MypageProfileHeader | ||
| name={user?.nickname} | ||
| profileImageUrl={user?.profileImageUrl ?? undefined} | ||
| onLogoutClick={handleLogout} | ||
| /> | ||
| <div className='flex gap-24'> | ||
| <MypageSummaryCard.Root> | ||
| <MypageSummaryCard.Item count={totalActivity || 0} label='등록한 체험' /> | ||
| <MypageSummaryCard.Item count={totalPending} label={`${dayjs().format('M')}월 승인 대기`} /> | ||
| </MypageSummaryCard.Root> | ||
| <MypageSummaryCard.Root className='bg-[#4D6071]'> | ||
| <MypageSummaryCard.Item | ||
| count={completedData?.totalCount || 0} | ||
| countClassName='text-white' | ||
| label='완료한 체험' | ||
| labelClassName='text-gray-200' | ||
| /> | ||
| <MypageSummaryCard.Item | ||
| count={reviewRequired} | ||
| countClassName='text-white' | ||
| label='리뷰 대기' | ||
| labelClassName='text-gray-200' | ||
| /> | ||
| </MypageSummaryCard.Root> | ||
| </div> | ||
| <div className='flex max-h-540 min-h-300 flex-col gap-16 rounded-3xl border border-gray-50 px-32 pt-24'> | ||
| <p className='body-text font-bold'>다가오는 일정</p> | ||
| <UpcomingSchedule | ||
| className='w-full overflow-y-scroll' | ||
| reservation={confirmedData?.reservations || []} | ||
| onClick={() => navigate('/')} | ||
| onClickReservation={(id) => navigate(`/activities/${id}`)} | ||
| /> | ||
| </div> | ||
| <div className='flex h-300 w-full flex-col gap-16 overflow-hidden rounded-3xl border border-gray-50 px-40 py-24'> | ||
| <p className='body-text font-bold'>{`${dayjs().format('M')}월 모집 중인 체험`}</p> | ||
| <OngoingExperienceCard | ||
| activities={availableActivities} | ||
| onClick={() => navigate('/experiences/create')} | ||
| onClickActivity={(id) => navigate(`/activities/${id}`)} | ||
| /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
kjhyun0830 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.