-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
3 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
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,47 @@ | ||
import { get, post } from "@apis/index"; | ||
import { components } from "@typings/api/schema"; | ||
import { ApiResponseType } from "@typings/commonType"; | ||
import { AxiosResponse } from "axios"; | ||
|
||
export interface postGuestReq { | ||
scheduleId: number; | ||
purchaseTicketCount: number; | ||
scheduleNumber: string; | ||
bookerName: string; | ||
bookerPhoneNumber: string; | ||
birthDate: string; | ||
password: string; | ||
totalPaymentAmount: number; | ||
isPaymentCompleted: boolean; | ||
} | ||
|
||
type GuestBookingResponse = components["schemas"]["GuestBookingResponse"]; | ||
|
||
// 1. API 요청 함수 작성 및 타입 추가 | ||
export const postGuestBook = async ( | ||
formData: postGuestReq | ||
): Promise<GuestBookingResponse | null> => { | ||
try { | ||
const response: AxiosResponse<ApiResponseType<GuestBookingResponse>> = await post( | ||
"/bookings/guest", | ||
formData | ||
); | ||
|
||
return response.data.data; | ||
} catch (error) { | ||
console.error("error", error); | ||
|
||
return null; | ||
} | ||
}; | ||
|
||
export const getGuestBookingList = async () => { | ||
try { | ||
const response = await get("/bookings/guest/retrieve"); | ||
|
||
console.log(response.data); | ||
return response; | ||
} catch (error) { | ||
console.error("error", error); | ||
} | ||
}; |
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,28 @@ | ||
import { QueryClient, useMutation, useQuery } from "@tanstack/react-query"; | ||
import { getGuestBookingList, postGuestBook, postGuestReq } from "./api"; | ||
|
||
export const QUERY_KEY = { | ||
LIST: "list", | ||
}; | ||
|
||
// 2. 쿼리 작성 | ||
export const useGuestBook = () => { | ||
const queryClient = new QueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: (formData: postGuestReq) => postGuestBook(formData), // API 요청 함수 | ||
onSuccess: (res) => { | ||
// 성공 시, 호출 | ||
queryClient.invalidateQueries({ queryKey: [QUERY_KEY.LIST] }); | ||
}, | ||
}); | ||
}; | ||
|
||
export const useGetGuestBookingList = () => { | ||
return useQuery({ | ||
queryKey: [QUERY_KEY.LIST], | ||
queryFn: () => getGuestBookingList(), | ||
staleTime: 1000 * 60 * 60, | ||
gcTime: 1000 * 60 * 60 * 24, | ||
}); | ||
}; |
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