Skip to content

Commit

Permalink
Merge pull request #144 from alkong-dalkong/feature/#142_HomePage
Browse files Browse the repository at this point in the history
refactor: Home 페이지 컨벤션에 맞게 리펙토링
  • Loading branch information
G0MTENG authored Nov 3, 2024
2 parents 4c02f3d + f811331 commit 7e59bdc
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 26 deletions.
1 change: 0 additions & 1 deletion src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ export const api = new HttpClient({
})

export * from './auth'
export * from './home'
10 changes: 3 additions & 7 deletions src/app/home/[userId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { HomePage } from '@/features'
import { HomeClientPage } from '@/features'

export type HomeRouteParams = {
params: { userId: string }
}

const Home = ({ params: { userId } }: HomeRouteParams) => {
return <HomePage userId={userId} />
const Home = () => {
return <HomeClientPage />
}

export default Home
3 changes: 1 addition & 2 deletions src/apis/home.ts → src/features/home/query/home.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import dayjs from 'dayjs'

import { api } from '@/apis'
import type { HomeResponseType } from '@/types'

import { api } from '.'

export const getHomePageData = async (userId: string) => {
const currentTime = dayjs().format('YYYY-MM-DD HH:mm:ss')

Expand Down
4 changes: 4 additions & 0 deletions src/features/home/query/queryKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const homeQueryKeys = {
all: ['home'] as const,
user: (userId: string) => [...homeQueryKeys.all, userId],
}
16 changes: 16 additions & 0 deletions src/features/home/query/useHome.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use client'

import { useParams } from 'next/navigation'
import { useQuery } from '@tanstack/react-query'

import { getHomePageData, homeQueryKeys } from '@/features'
import type { HomeResponseType } from '@/types'

export const useFetchHome = () => {
const { userId } = useParams<{ userId: string }>()

return useQuery<HomeResponseType>({
queryKey: homeQueryKeys.user(userId),
queryFn: () => getHomePageData(userId),
})
}
8 changes: 4 additions & 4 deletions src/features/home/ui/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import { DashBoardTemplate, HelperBox } from '@/features'
import { ClinicSection, HealthSection, MedicineSection } from '@/features'
import { HealthInfo, MedicineInfo, RecentMedicalInfo, UpcomingMedicalInfo } from '@/features'
import { useHome } from '@/hooks/apis/useHome'
import { useFetchHome } from '@/features'

export const HomePage = ({ userId }: { userId: string }) => {
const { data: homePageData } = useHome(userId)
export const HomeClientPage = () => {
const { data: homePageData } = useFetchHome()

if (!homePageData) {
return (
Expand All @@ -22,7 +22,7 @@ export const HomePage = ({ userId }: { userId: string }) => {
return (
<DashBoardTemplate route="home">
<ClinicSection>
{!upcomingMedicalInfo && !recentMedicalInfo && (
{!(upcomingMedicalInfo || recentMedicalInfo) && (
<HelperBox title="진료에서 내원 일정을 추가해 보세요!" />
)}
{upcomingMedicalInfo && <UpcomingMedicalInfo {...upcomingMedicalInfo} />}
Expand Down
2 changes: 1 addition & 1 deletion src/features/home/utils/dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dayjs from 'dayjs'

import 'dayjs/locale/ko'

const weekEn2Ko: { [key: string]: string } = {
const weekEn2Ko: Record<string, string> = {
MONDAY: '월',
TUESDAY: '화',
WEDNESDAY: '수',
Expand Down
3 changes: 3 additions & 0 deletions src/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export * from './health/store/healthStore'
export * from './health/ui/HealthClientPage'

// home
export * from './home/query/home'
export * from './home/query/queryKeys'
export * from './home/query/useHome'
export * from './home/ui/HelperBox'
export * from './home/ui/HomePage'
export * from './home/ui/InfoBox'
Expand Down
11 changes: 0 additions & 11 deletions src/hooks/apis/useHome.ts

This file was deleted.

0 comments on commit 7e59bdc

Please sign in to comment.