From 31747420d1689179d2a39d2277bb9387dd7fb165 Mon Sep 17 00:00:00 2001 From: Mike Fix Date: Tue, 27 Aug 2019 14:39:27 -0700 Subject: [PATCH] snippets and account pages --- components/Billing.js | 277 +++++++++++++++++++ components/LoginButton.js | 33 ++- cypress/integration/background-color.spec.js | 2 +- lib/api.js | 16 ++ lib/client.js | 8 + next.config.js | 3 +- now.json | 15 +- package.json | 2 + pages/_document.js | 4 +- pages/about.js | 2 +- pages/account.js | 258 +++++++++++++++++ pages/snippets.js | 213 ++++++++++++++ static/{ => svg}/github.svg | 0 static/{ => svg}/open-source-companies.svg | 0 static/svg/person.svg | 1 + static/svg/snippets.svg | 1 + yarn.lock | 12 + 17 files changed, 833 insertions(+), 14 deletions(-) create mode 100644 components/Billing.js create mode 100644 pages/account.js create mode 100644 pages/snippets.js rename static/{ => svg}/github.svg (100%) rename static/{ => svg}/open-source-companies.svg (100%) create mode 100644 static/svg/person.svg create mode 100644 static/svg/snippets.svg 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 ( -