Skip to content

Commit 909fbed

Browse files
authored
Clean up the code. (vercel#46)
1 parent b27f9fa commit 909fbed

32 files changed

+219
-1143
lines changed

.github/ISSUE_TEMPLATE/1.Bug_report.md

-36
This file was deleted.

.github/ISSUE_TEMPLATE/2.Feature_request.md

-22
This file was deleted.

.github/ISSUE_TEMPLATE/config.yml

-5
This file was deleted.

CHANGELOG.md

-3
This file was deleted.

CODE_OF_CONDUCT.md

-76
This file was deleted.

CONTRIBUTING.md

-38
This file was deleted.

LICENSE

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
MIT License
1+
The MIT License (MIT)
22

3-
Copyright (c) 2020 Stripe, Inc. (https://stripe.com)
3+
Copyright (c) 2021 Vercel, Inc.
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
116

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
148

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

components/Layout.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import Head from 'next/head';
22
import { useRouter } from 'next/router';
3-
import Navbar from './ui/Navbar';
4-
import Footer from './ui/Footer';
3+
4+
import Navbar from '@/components/ui/Navbar';
5+
import Footer from '@/components/ui/Footer';
56

67
export default function Layout({ children, meta: pageMeta }) {
78
const router = useRouter();
@@ -16,9 +17,6 @@ export default function Layout({ children, meta: pageMeta }) {
1617
<>
1718
<Head>
1819
<title>{meta.title}</title>
19-
<meta charSet="utf-8" />
20-
<meta content="IE=edge" httpEquiv="X-UA-Compatible" />
21-
<meta content="width=device-width, initial-scale=1" name="viewport" />
2220
<meta name="robots" content="follow, index" />
2321
<link href="/favicon.ico" rel="shortcut icon" />
2422
<meta content={meta.description} name="description" />
@@ -38,7 +36,7 @@ export default function Layout({ children, meta: pageMeta }) {
3836
<meta name="twitter:image" content={meta.cardImage} />
3937
</Head>
4038
<Navbar />
41-
<div id="skip">{children}</div>
39+
<main id="skip">{children}</main>
4240
<Footer />
4341
</>
4442
);

components/Pricing.js

+26-22
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
import cn from 'classnames';
22
import { useRouter } from 'next/router';
33
import { useState } from 'react';
4-
import { postData } from '../utils/helpers';
5-
import { getStripe } from '../utils/initStripejs';
6-
import { useUser } from '../components/UserContext';
7-
import Button from './ui/Button';
4+
5+
import Button from '@/components/ui/Button';
6+
import { postData } from '@/utils/helpers';
7+
import { getStripe } from '@/utils/stripe-client';
8+
import { useUser } from '@/utils/useUser';
89

910
export default function Pricing({ products }) {
10-
const [billingInterval, setBillingInterval] = useState('month');
11-
const [loading, setLoading] = useState(false);
1211
const router = useRouter();
12+
const [billingInterval, setBillingInterval] = useState('month');
13+
const [priceIdLoading, setPriceIdLoading] = useState();
1314
const { session, userLoaded, subscription } = useUser();
1415

1516
const handleCheckout = async (price) => {
16-
setLoading(true);
17+
setPriceIdLoading(price.id);
1718
if (!session) {
18-
router.push('/signin');
19-
return;
19+
return router.push('/signin');
2020
}
2121
if (subscription) {
22-
router.push('/account');
23-
return;
22+
return router.push('/account');
23+
}
24+
25+
try {
26+
const { sessionId } = await postData({
27+
url: '/api/create-checkout-session',
28+
data: { price },
29+
token: session.access_token
30+
});
31+
32+
const stripe = await getStripe();
33+
stripe.redirectToCheckout({ sessionId });
34+
} catch (error) {
35+
return alert(error.message);
36+
} finally {
37+
setPriceIdLoading(false);
2438
}
25-
const { sessionId, error: apiError } = await postData({
26-
url: '/api/createCheckoutSession',
27-
data: { price },
28-
token: session.access_token
29-
});
30-
if (apiError) return alert(apiError.message);
31-
const stripe = await getStripe();
32-
const { error: stripeError } = stripe.redirectToCheckout({ sessionId });
33-
if (stripeError) alert(error.message);
34-
setLoading(false);
3539
};
3640

3741
if (!products.length)
@@ -130,7 +134,7 @@ export default function Pricing({ products }) {
130134
variant="slim"
131135
type="button"
132136
disabled={session && !userLoaded}
133-
loading={loading}
137+
loading={priceIdLoading === price.id}
134138
onClick={() => handleCheckout(price.id)}
135139
className="mt-8 block w-full rounded-md py-2 text-sm font-semibold text-white text-center hover:bg-gray-900"
136140
>

components/ui/Button/Button.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,24 @@
11
import cn from 'classnames';
22
import React, { forwardRef, useRef } from 'react';
33
import mergeRefs from 'react-merge-refs';
4-
import { useButton } from 'react-aria';
54
import s from './Button.module.css';
6-
import LoadingDots from '../LoadingDots';
5+
6+
import LoadingDots from '@/components/ui/LoadingDots';
77

88
const Button = forwardRef((props, buttonRef) => {
99
const {
1010
className,
1111
variant = 'flat',
1212
children,
1313
active,
14-
onClick,
1514
width,
16-
Component = 'button',
1715
loading = false,
1816
disabled = false,
1917
style = {},
18+
Component = 'button',
2019
...rest
2120
} = props;
2221
const ref = useRef(null);
23-
const { buttonProps, isPressed } = useButton(
24-
{
25-
...rest,
26-
onPress: onClick,
27-
isDisabled: disabled,
28-
elementType: Component
29-
},
30-
ref
31-
);
32-
3322
const rootClassName = cn(
3423
s.root,
3524
{
@@ -45,14 +34,13 @@ const Button = forwardRef((props, buttonRef) => {
4534
aria-pressed={active}
4635
data-variant={variant}
4736
ref={mergeRefs([ref, buttonRef])}
48-
{...buttonProps}
49-
data-active={isPressed ? '' : undefined}
5037
className={rootClassName}
5138
disabled={disabled}
5239
style={{
5340
width,
5441
...style
5542
}}
43+
{...rest}
5644
>
5745
{children}
5846
{loading && (

components/ui/Footer/Footer.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import Link from 'next/link';
2-
import Logo from '../../icons/Logo';
3-
import GitHub from '../../icons/GitHub';
42
import s from './Footer.module.css';
53

4+
import Logo from '@/components/icons/Logo';
5+
import GitHub from '@/components/icons/GitHub';
6+
67
export default function Footer() {
78
return (
89
<footer className="mx-auto max-w-8xl px-6 bg-primary-2">

components/ui/Navbar/Navbar.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import Link from 'next/link';
22
import s from './Navbar.module.css';
3-
import Logo from '../../icons/Logo';
4-
import { useUser } from '../../UserContext';
3+
4+
import Logo from '@/components/icons/Logo';
5+
import { useUser } from '@/utils/useUser';
56

67
const Navbar = () => {
78
const { user, signOut } = useUser();

0 commit comments

Comments
 (0)