diff --git a/components/Billing.js b/components/Billing.js new file mode 100644 index 0000000..7b0ad67 --- /dev/null +++ b/components/Billing.js @@ -0,0 +1,277 @@ +import React from 'react' +import { Elements, StripeProvider, CardElement, injectStripe } from 'react-stripe-elements' +import { useAsyncCallback } from '@dawnlabs/tacklebox' + +import Button from './Button' +import Input from './Input' +import { useAuth } from './AuthContext' +import LoginButton from './LoginButton' + +import { COLORS } from '../lib/constants' + +const X = ( + + + + +) + +function Billing(props) { + const user = useAuth() + + const [submit, { error, loading, data: success }] = useAsyncCallback(async e => { + e.preventDefault() + + const name = e.target.name.value.trim() + + const res = await props.stripe.createToken({ name }) + + if (res.error) { + throw res.error.message + } + + return {} + }) + + if (!user) { + return ( +
+
+ +
+ +
+ ) + } + + return ( +
+ {success ? ( +
+

Thank you for supporting Carbon!

+

+ However, Carbon Diamond is not quite ready yet. +
+ Your card has not been charged or saved today. +
+ We greatly appreciate your support, and will contact you when these premium features + launch! +

+

+ — the Carbon Team{' '} + + 💛🖤 + +

+
+ ) : ( +
+

+ Upgrade to Diamond +
+ ($5.00 / month) +

+

Please enter a credit or debit card:

+
+
+ +
+ +
+ + (By clicking subscribe, you are accepting the{' '} + terms and conditions) + +
+ +
+ {X} + {error} +
+
+
+ )} + +
+ ) +} + +const BillingWithStripe = injectStripe(Billing) + +export default function() { + const [stripe, setStripe] = React.useState(null) + React.useEffect(() => { + setStripe(window.Stripe(process.env.STRIPE_PUBLIC_KEY)) + }, []) + return ( + + + + + + ) +} diff --git a/components/LoginButton.js b/components/LoginButton.js index 7b08784..42f2538 100644 --- a/components/LoginButton.js +++ b/components/LoginButton.js @@ -1,5 +1,5 @@ import React from 'react' -// import Link from 'next/link' +import Link from 'next/link' import firebase, { login, logout } from '../lib/client' import Button from './Button' @@ -8,14 +8,26 @@ import { useAuth } from './AuthContext' function Drawer(props) { return ( -