File tree Expand file tree Collapse file tree 3 files changed +34
-22
lines changed
common/Modals/PreferencesModal/PaymentInfo Expand file tree Collapse file tree 3 files changed +34
-22
lines changed Original file line number Diff line number Diff line change 11import React from 'react' ;
2+ import Helmet from 'react-helmet' ;
23import { StripeProvider , Elements } from 'react-stripe-elements' ;
34import { STRIPE_API_KEY } from '@codesandbox/common/lib/utils/config' ;
5+ import { useScript } from 'app/hooks' ;
46import { CheckoutForm } from './CheckoutForm' ;
57import { Container } from './elements' ;
68
@@ -14,6 +16,8 @@ interface ISubscribeFormProps {
1416 hasCoupon ?: boolean ;
1517}
1618
19+ const context = window as any ;
20+
1721export const SubscribeForm : React . FC < ISubscribeFormProps > = ( {
1822 name,
1923 subscribe,
@@ -22,20 +26,33 @@ export const SubscribeForm: React.FC<ISubscribeFormProps> = ({
2226 isLoading = false ,
2327 error,
2428 hasCoupon,
25- } ) => (
26- < Container >
27- < StripeProvider apiKey = { STRIPE_API_KEY } >
28- < Elements >
29- < CheckoutForm
30- buttonName = { buttonName }
31- loadingText = { loadingText }
32- subscribe = { subscribe }
33- name = { name }
34- isLoading = { isLoading }
35- error = { error }
36- hasCoupon = { hasCoupon }
37- />
38- </ Elements >
39- </ StripeProvider >
40- </ Container >
41- ) ;
29+ } ) => {
30+ const [ stripe , setStripe ] = React . useState ( null ) ;
31+ const [ loaded ] = useScript ( 'https://js.stripe.com/v3/' ) ;
32+
33+ React . useEffect ( ( ) => {
34+ if ( context . Stripe ) {
35+ setStripe ( context . Stripe ( STRIPE_API_KEY ) ) ;
36+ }
37+ } , [ loaded ] ) ;
38+
39+ return (
40+ < >
41+ < Container >
42+ < StripeProvider stripe = { stripe } >
43+ < Elements >
44+ < CheckoutForm
45+ buttonName = { buttonName }
46+ loadingText = { loadingText }
47+ subscribe = { subscribe }
48+ name = { name }
49+ isLoading = { isLoading }
50+ error = { error }
51+ hasCoupon = { hasCoupon }
52+ />
53+ </ Elements >
54+ </ StripeProvider >
55+ </ Container >
56+ </ >
57+ ) ;
58+ } ;
Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ class Patron extends React.Component {
1919 < MaxWidth >
2020 < Helmet >
2121 < title > Patron - CodeSandbox</ title >
22- < script async src = "https://js.stripe.com/v3/" />
2322 </ Helmet >
2423 < Margin vertical = { 1.5 } horizontal = { 1.5 } >
2524 < Navigation title = "Become a Patron" />
Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import Helmet from 'react-helmet' ;
32import { inject , observer } from 'app/componentConnectors' ;
43import { SubscribeForm } from 'app/components/SubscribeForm' ;
54import { Card } from './Card' ;
@@ -50,9 +49,6 @@ class PaymentInfoComponent extends React.Component<Props> {
5049 const { preferences } = this . props . store ;
5150 return (
5251 < Container >
53- < Helmet >
54- < script async src = "https://js.stripe.com/v3/" />
55- </ Helmet >
5652 < Title > Payment Info</ Title >
5753 { preferences . isLoadingPaymentDetails ? (
5854 < div > Loading payment details...</ div >
You can’t perform that action at this time.
0 commit comments