@@ -15,6 +15,7 @@ import Link from "next/link";
1515import { useCookies } from "react-cookie" ;
1616import { jwtDecode } from "jwt-decode" ;
1717import { CourseQueryResult , HomePageQueryResult } from "@/sanity.types" ;
18+ import { Price3 } from "@/lib/stripe.types" ;
1819
1920export default function Buy ( {
2021 title,
@@ -25,10 +26,7 @@ export default function Buy({
2526} ) {
2627 const { currentUser } = useFirestoreUser ( ) ;
2728 const [ redirecting , setRedirecting ] = useState ( false ) ;
28- const [ price , setPrice ] = useState ( {
29- product : "" ,
30- unit_amount : 0 ,
31- } ) ;
29+ const [ price , setPrice ] = useState < Price3 | null > ( null ) ;
3230 const [ showBuy , setShowBuy ] = useState ( false ) ;
3331 const { toast } = useToast ( ) ;
3432 const [ cookies ] = useCookies ( [ "app.idt" ] ) ;
@@ -50,13 +48,15 @@ export default function Buy({
5048
5149 const getPrice = async ( ) => {
5250 const price = await getStripePrice ( { stripeProduct } ) ;
53- setPrice ( price . data ( ) as any ) ;
51+ const priceData = price . data ( ) as any ;
52+ console . log ( priceData ) ;
53+ setPrice ( priceData ) ;
5454 } ;
5555
5656 useEffect ( ( ) => {
57- if ( stripeProduct ) getPrice ( ) ;
57+ if ( stripeProduct && showBuy ) getPrice ( ) ;
5858 // eslint-disable-next-line react-hooks/exhaustive-deps
59- } , [ stripeProduct ] ) ;
59+ } , [ stripeProduct , showBuy ] ) ;
6060
6161 const onSubscribe = async ( ) => {
6262 setRedirecting ( true ) ;
@@ -81,8 +81,19 @@ export default function Buy({
8181 const subscribe = (
8282 < >
8383 < DialogHeader >
84- < DialogTitle > Purchase { title } </ DialogTitle >
84+ < DialogTitle className = "text-2xl font-bold" >
85+ Purchase: { title }
86+ </ DialogTitle >
8587 </ DialogHeader >
88+ { price && (
89+ < div className = "mt-4 flex gap-2 sm:gap-4 text-xl sm:text-2xl" >
90+ < div className = "flex items-center justify-between" > Price:</ div >
91+ < div className = "flex items-center justify-between gap-2" >
92+ < span className = "font-bold" > { price . unit_amount / 100 } </ span >
93+ < span className = "uppercase" > { price . currency } </ span >
94+ </ div >
95+ </ div >
96+ ) }
8697 < Button onClick = { onSubscribe } disabled = { redirecting } >
8798 { redirecting ? "Redirecting..." : "Continue to Stripe" }
8899 { ! redirecting && < ArrowRightIcon className = "ml-2" /> }
0 commit comments