forked from FC-FastCatch/FastCatch-FrontEnd
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: 예약하기 페이지 post 요청 react-query로 수정 (#60)
- Loading branch information
1 parent
4c6a959
commit 7bc21dd
Showing
4 changed files
with
65 additions
and
39 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
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,41 @@ | ||
import { postOrderApi } from "@/api/postOrderApi"; | ||
import { orderResultState } from "@/states/orderResultState"; | ||
import { useMutation } from "react-query"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useSetRecoilState } from "recoil"; | ||
|
||
export const usePostOrder = (orderData: OrderData) => { | ||
const setOrderResult = useSetRecoilState(orderResultState); | ||
const navigate = useNavigate(); | ||
const postOrderMutation = useMutation( | ||
() => postOrderApi("/api/reservations", orderData), | ||
{ | ||
onSuccess: () => { | ||
navigate("/order/result?=true"); | ||
setOrderResult(true); | ||
}, | ||
onError: () => { | ||
navigate("/order/result?=false"); | ||
setOrderResult(false); | ||
}, | ||
} | ||
); | ||
|
||
const isLoading = postOrderMutation.isLoading; | ||
|
||
return { | ||
...postOrderMutation, | ||
isLoading, | ||
}; | ||
}; | ||
|
||
interface OrderData { | ||
roomId: number; | ||
visitorName: string; | ||
visitorPhone: string; | ||
startDate: string; | ||
endDate: string; | ||
couponId?: number; | ||
totalPrice: number; | ||
payMethod: string; | ||
} |
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
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