Skip to content

Commit

Permalink
Merge pull request #141 from alkong-dalkong/feature/#140_queryKeys
Browse files Browse the repository at this point in the history
fix: queryKey 네이밍을 somethingQueryKeys로 변경
  • Loading branch information
G0MTENG authored Nov 3, 2024
2 parents 99e2530 + 05cb5e9 commit 4c02f3d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/features/clinic/query/queryKeys.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const queryKeys = {
export const clinicQueryKeys = {
all: ['clinic'] as const,
detail: (medicalId: number) => [...queryKeys.all, 'detail', medicalId] as const,
detail: (medicalId: number) => [...clinicQueryKeys.all, 'detail', medicalId] as const,
calendar: (userId: string, localDate: string) =>
[...queryKeys.all, 'calendar', userId, localDate] as const,
[...clinicQueryKeys.all, 'calendar', userId, localDate] as const,
}
8 changes: 4 additions & 4 deletions src/features/clinic/query/useClinicApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import {
clinicCalendar,
clinicInfo,
clinicQueryKeys,
createClinicInfo,
deleteClinicInfo,
editClinicInfo,
queryKeys,
} from '@/features'
import type { ClinicCalendarRequest } from '@/types'

export const useClinicInfo = (medicalId: number) =>
useQuery({
queryKey: queryKeys.detail(medicalId),
queryKey: clinicQueryKeys.detail(medicalId),
queryFn: () => clinicInfo(medicalId),
})

export const useClinicCalendar = ({ userId, localDate }: ClinicCalendarRequest) =>
useQuery({
queryKey: queryKeys.calendar(userId, localDate),
queryKey: clinicQueryKeys.calendar(userId, localDate),
queryFn: () => clinicCalendar({ userId, localDate }),
})

Expand All @@ -33,7 +33,7 @@ export const useEditClinicInfo = (medicalId: number) => {

return useMutation({
mutationFn: editClinicInfo,
onSuccess: () => queryClient.invalidateQueries({ queryKey: queryKeys.detail(medicalId) }),
onSuccess: () => queryClient.invalidateQueries({ queryKey: clinicQueryKeys.detail(medicalId) }),
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/features/health/query/queryKeys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const queryKeys = {
export const healthQueryKeys = {
all: ['health'] as const,
page: (userId: string, period: string) => [...queryKeys.all, userId, period],
page: (userId: string, period: string) => [...healthQueryKeys.all, userId, period],
}
8 changes: 4 additions & 4 deletions src/features/health/query/useHealth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { useParams } from 'next/navigation'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'

import { getHealth, postHealth, putHealth } from '@/features'
import { queryKeys } from '@/features'
import { clinicQueryKeys } from '@/features'
import { usePeriod } from '@/features/health/store/healthStore'
import type { PutPhysicalRequest } from '@/types'

export const useFetchHealth = () => {
const period = usePeriod()
const { userId } = useParams<{ userId: string }>()
return useQuery({
queryKey: queryKeys.page(userId, period),
queryKey: clinicQueryKeys.page(userId, period),
queryFn: () => getHealth({ userId, period }),
})
}
Expand All @@ -22,7 +22,7 @@ export const useCreateHealth = () => {
return useMutation({
mutationFn: postHealth,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: queryKeys.all })
queryClient.invalidateQueries({ queryKey: clinicQueryKeys.all })
},
})
}
Expand All @@ -33,7 +33,7 @@ export const useEditHealth = () => {
mutationFn: ({ weightId, request }: { weightId: number; request: PutPhysicalRequest }) =>
putHealth(weightId, request),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: queryKeys.all })
queryClient.invalidateQueries({ queryKey: clinicQueryKeys.all })
},
})
}

0 comments on commit 4c02f3d

Please sign in to comment.