-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
284f557
commit 3bc9085
Showing
4 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
7 changes: 6 additions & 1 deletion
7
packages/web-domains/src/about-me/common/apis/mutates/useCreateHandWavings.ts
This file contains 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 |
---|---|---|
@@ -1,15 +1,20 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { Http } from '@/common/apis/base.api'; | ||
|
||
import { HAND_WAVINGS_STATUS_QUERY_KEY } from '../queries/useGetHandWavingsStatus'; | ||
|
||
interface Request { | ||
meetingId: number; | ||
receiverMemberId: number; | ||
} | ||
|
||
export const useCreateHandWavings = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: ({ meetingId, receiverMemberId }: Request) => | ||
Http.POST(`/v1/meetings/${meetingId}/hand-wavings`, { receiverMemberId }), | ||
onSuccess: (_, variable) => queryClient.invalidateQueries({ queryKey: [HAND_WAVINGS_STATUS_QUERY_KEY, variable] }), | ||
}); | ||
}; |
46 changes: 46 additions & 0 deletions
46
packages/web-domains/src/about-me/common/apis/queries/useGetHandWavingsStatus.ts
This file contains 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,46 @@ | ||
import { QueryClient, useQuery, UseQueryOptions } from '@tanstack/react-query'; | ||
|
||
import { Http } from '@/common/apis/base.api'; | ||
|
||
import { HandWavingStatusResponse } from '../schema/HandWavingStatusResponse'; | ||
|
||
interface Params { | ||
meetingId: number; | ||
receiverMemberId: number; | ||
} | ||
|
||
interface QueryProps extends Params { | ||
options?: UseQueryOptions<HandWavingStatusResponse>; | ||
} | ||
|
||
const queryFn = ({ meetingId, receiverMemberId }: Params) => | ||
Http.GET<HandWavingStatusResponse>(`/v1/meetings/${meetingId}/hand-wavings/receiver/${receiverMemberId}/status`); | ||
|
||
export const HAND_WAVINGS_STATUS_QUERY_KEY = 'HAND_WAVINGS_STATUS_QUERY_KEY '; | ||
|
||
export const useGetHandWavingsStatus = (props: QueryProps) => { | ||
const { options, ...params } = props; | ||
|
||
return useQuery({ | ||
queryKey: [HAND_WAVINGS_STATUS_QUERY_KEY, params], | ||
queryFn: () => queryFn(params), | ||
enabled: params.meetingId > 0, | ||
staleTime: 1000 * 60 * 10, // 10분 | ||
...options, | ||
}); | ||
}; | ||
|
||
interface PrefetchProps extends Params { | ||
queryClient: QueryClient; | ||
} | ||
|
||
export const getHandWavingsStatusPrefetch = (props: PrefetchProps) => { | ||
const { queryClient, ...params } = props; | ||
|
||
const prefetch = queryClient.prefetchQuery({ | ||
queryKey: [HAND_WAVINGS_STATUS_QUERY_KEY, params], | ||
queryFn: () => queryFn(params), | ||
}); | ||
|
||
return prefetch; | ||
}; |
4 changes: 4 additions & 0 deletions
4
packages/web-domains/src/about-me/common/apis/schema/HandWavingStatusResponse.ts
This file contains 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,4 @@ | ||
export interface HandWavingStatusResponse { | ||
HandWavingId: number; | ||
status: 'REQUESTED' | 'ACCEPTED' | 'REJECTED'; | ||
} |
This file contains 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