11import { Button , VStack } from "@chakra-ui/react" ;
22import { useState } from "react" ;
33
4+ import { usePurchase } from "@/features/carts/application/use-purchase" ;
45import type { PaymentMethod } from "@/features/carts/models/payment-method" ;
5- import { usePurchase } from "@/features/carts/providers/use-purchase" ;
66import { Select } from "@/lib/components/Form/Select" ;
77import { TextInput } from "@/lib/components/Form/TextInput" ;
88import { useTranslations } from "@/lib/i18n/use-transations" ;
99
10- import { usePurchaseNotifications } from "./use-checkout-notifications" ;
11-
1210interface IProps {
1311 onSuccess ?: ( ) => void ;
1412}
@@ -19,8 +17,7 @@ const CheckoutForm = ({ onSuccess }: IProps) => {
1917 const [ address , setAddress ] = useState < string > ( ) ;
2018 const [ method , setMethod ] = useState < PaymentMethod > ( "blik" ) ;
2119
22- const [ purchase , isLoading ] = usePurchase ( ) ;
23- const [ notifySuccess , notifyFailure ] = usePurchaseNotifications ( ) ;
20+ const { purchase, isPending } = usePurchase ( ) ;
2421
2522 return (
2623 < VStack
@@ -29,13 +26,8 @@ const CheckoutForm = ({ onSuccess }: IProps) => {
2926 onSubmit = { async ( e ) => {
3027 e . preventDefault ( ) ;
3128
32- try {
33- await purchase ( ) ;
34- notifySuccess ( ) ;
35- onSuccess ?.( ) ;
36- } catch {
37- notifyFailure ( ) ;
38- }
29+ const success = await purchase ( ) ;
30+ if ( success ) onSuccess ?.( ) ;
3931 } }
4032 >
4133 < TextInput
@@ -64,7 +56,7 @@ const CheckoutForm = ({ onSuccess }: IProps) => {
6456 >
6557 { t ( "payment-method" ) }
6658 </ Select >
67- < Button type = "submit" colorPalette = "blue" w = "100%" loading = { isLoading } >
59+ < Button type = "submit" colorPalette = "blue" w = "100%" loading = { isPending } >
6860 { t ( "submit" ) }
6961 </ Button >
7062 </ VStack >
0 commit comments