Skip to content

Commit ad1d47b

Browse files
committed
migrate to typescript
1 parent 871f83d commit ad1d47b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+217
-120
lines changed

next-env.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/types/global" />

next.config.js

+7-26
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
const withCss = require('@zeit/next-css');
2-
const withPurgeCss = require('next-purgecss');
3-
4-
class TailwindExtractor {
5-
static extract(content) {
6-
return content.match(/[A-Za-z0-9-_:\/]+/g) || [];
7-
}
8-
}
92

103
// next.config.js
11-
module.exports = withCss(
12-
withPurgeCss({
13-
purgeCssEnabled: ({ dev, isServer }) => !dev && !isServer, // Only enable PurgeCSS for client-side production builds
14-
purgeCss: {
15-
whitelist: ['html', 'body'],
16-
extractors: [
17-
{
18-
extractor: TailwindExtractor,
19-
extensions: ['html', 'js', 'css', 'tsx'],
20-
},
21-
],
22-
},
23-
target: 'serverless',
24-
env: {
25-
RZP_LIVE_KEY: process.env.RZP_LIVE_KEY,
26-
RZP_TEST_KEY: process.env.RZP_TEST_KEY,
27-
},
28-
})
29-
);
4+
module.exports = withCss({
5+
target: 'serverless',
6+
env: {
7+
RZP_LIVE_KEY: process.env.RZP_LIVE_KEY,
8+
RZP_TEST_KEY: process.env.RZP_TEST_KEY,
9+
},
10+
});

package.json

+9-8
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
1010
"url": "https://github.com/coderplex/donation-page/issues"
1111
},
1212
"homepage": "https://github.com/coderplex/donation-page#readme",
13-
"main": "pages/index.js",
13+
"main": "src/pages/index.ts",
1414
"engines": {
1515
"node": "v10.x"
1616
},
1717
"scripts": {
1818
"test": "echo \"Error: no test specified\" && exit 1",
1919
"dev": "now dev",
2020
"add-contributor": "all-contributors add",
21-
"format": "prettier --write './**/*.+(js|jsx|json|md)'"
21+
"format": "prettier --write './**/*.+(ts|tsx|css|json|js|jsx|json|md)'"
2222
},
2323
"keywords": [],
2424
"author": "",
2525
"license": "MIT",
2626
"dependencies": {
27+
"@types/airtable": "^0.5.6",
2728
"@zeit/next-css": "0.2.1-canary.4",
2829
"airtable": "^0.7.0",
2930
"clsx": "^1.0.4",
@@ -36,6 +37,9 @@
3637
"react-dom": "^16.8.6"
3738
},
3839
"devDependencies": {
40+
"@types/node": "^12.12.12",
41+
"@types/react": "^16.9.12",
42+
"@types/react-dom": "^16.9.4",
3943
"all-contributors-cli": "^6.8.1",
4044
"autoprefixer": "^9.6.1",
4145
"cssnano": "^4.1.10",
@@ -45,14 +49,11 @@
4549
"next-purgecss": "^3.1.1",
4650
"postcss-easy-import": "^3.0.0",
4751
"prettier": "^1.18.2",
48-
"tailwindcss": "^1.0.5"
52+
"tailwindcss": "^1.0.5",
53+
"typescript": "^3.7.2"
4954
},
5055
"lint-staged": {
51-
"*.js": [
52-
"prettier --write",
53-
"git add"
54-
],
55-
"*.json": [
56+
"*.{js,ts,tsx,jsx,json,css}": [
5657
"prettier --write",
5758
"git add"
5859
],

postcss.config.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
module.exports = {
2-
plugins: [require('postcss-easy-import'), require('tailwindcss'), require('autoprefixer')],
2+
plugins: [
3+
require('postcss-easy-import'),
4+
require('tailwindcss'),
5+
require('autoprefixer'),
6+
...(process.env.NODE_ENV === 'production'
7+
? [
8+
require('@fullhuman/postcss-purgecss')({
9+
content: ['./src/**/*.tsx'],
10+
defaultExtractor: content =>
11+
content
12+
.match(/[\w-/:%]+(?<!:)/g)
13+
.concat(content.match(/html|body|after|before|snackbar|snackbarks|tippy|next/g)) || [],
14+
whitelistPatterns: [/html/, /body/, /after/, /before/, /tippy/, /next/, /snackbar/, /snackbarks/],
15+
}),
16+
require('cssnano'),
17+
]
18+
: []),
19+
],
320
};
File renamed without changes.
File renamed without changes.

src/components/ContactUs.js renamed to src/components/ContactUs.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import { H2 } from './Typography';
44
import { EMAIL, PHONE } from '../constants';
55

6-
function ContactUs() {
6+
export function ContactUs() {
77
return (
88
<>
99
<H2>Contact Us:</H2>
@@ -22,5 +22,3 @@ function ContactUs() {
2222
</>
2323
);
2424
}
25-
26-
export default ContactUs;

src/components/Favicons.js renamed to src/components/Favicons.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
2-
32
import { CLOUDINARY_BASE, LOGO_PUBLIC_ID } from '../constants';
43

5-
export default function Favicons() {
4+
export function Favicons() {
65
const icons = getIcons();
76
return (
87
<>
@@ -13,7 +12,7 @@ export default function Favicons() {
1312
);
1413
}
1514

16-
export const getIconUrl = size => {
15+
export const getIconUrl = (size: number) => {
1716
return `${CLOUDINARY_BASE}/c_scale,w_${size}/${LOGO_PUBLIC_ID}`;
1817
};
1918

src/components/FindUs.js renamed to src/components/FindUs.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from 'react';
2-
2+
import { BASE_URL, CHAT_URL, CROWDFUND_URL, MEETUP_URL } from '../constants';
33
import { H2 } from './Typography';
4-
import { BASE_URL, MEETUP_URL, CHAT_URL, CROWDFUND_URL } from '../constants';
54

6-
function FindUs() {
5+
export function FindUs() {
76
return (
87
<>
98
<H2>Find us on the Internet</H2>
@@ -36,5 +35,3 @@ function FindUs() {
3635
</>
3736
);
3837
}
39-
40-
export default FindUs;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/components/Layout.js renamed to src/components/Layout.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { FunctionComponent } from 'react';
22
import clsx from 'clsx';
33

44
import { CODERPLEX_LOGO, DEFAULT_TITLE } from '../constants';
@@ -16,10 +16,14 @@ export function Header({ title = DEFAULT_TITLE }) {
1616
);
1717
}
1818

19-
export const Container = ({ className, ...props }) => (
19+
interface Props {
20+
className?: string;
21+
}
22+
23+
export const Container: FunctionComponent<Props> = ({ className, ...props }) => (
2024
<main className={clsx(['pb-12 md:flex max-w-5xl mx-auto', className])} {...props} />
2125
);
2226

23-
export const Section = ({ className, ...props }) => (
27+
export const Section: FunctionComponent<Props> = ({ className, ...props }) => (
2428
<section className={clsx(['border-gray-200', className])} {...props} />
2529
);
File renamed without changes.
File renamed without changes.

src/components/PaymentForm.js renamed to src/components/PaymentForm.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import IconBack from './Icons/Back';
99
import IconUPI from './Icons/UPI';
1010
import Loader from './Loader';
1111
import Modal from './Modal';
12-
import { getURL, getFinalAmount } from '../utils';
12+
import { getUPIUrl, getFinalAmount } from '../utils';
1313
import { openRzp } from '../services/rzp';
1414
import { saveUPIStatus } from '../services/upi';
1515

@@ -39,7 +39,8 @@ function PaymentForm({
3939
e.preventDefault();
4040
const { amount, email, phone } = form;
4141
saveUPIStatus(form);
42-
const url = getURL({ amount, email });
42+
const url = getUPIUrl({ amount, email });
43+
// @ts-ignore
4344
if (!isMobile()) {
4445
return setURL(`${window.origin}/api/upi?amount=${amount}&email=${email}`);
4546
}
@@ -64,6 +65,7 @@ function PaymentForm({
6465
...form,
6566
amount: finalAmount,
6667
category: actionName.toLowerCase,
68+
// @ts-ignore
6769
}).then(() => onSuccess({ ...form }));
6870
setIsSubmitting(false);
6971
setFormValue(initialState);

src/components/SEO.js renamed to src/components/SEO.tsx

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
import React, { useContext } from 'react';
1+
import React, { useContext, FunctionComponent } from 'react';
22
import Head from 'next/head';
33

44
import { DEFAULT_SEO_IMAGE, DEFAULT_TITLE, DEFAULT_DESCRIPTION, BASE_URL, THEME_COLOR } from '../constants';
5-
import Favicons from './Favicons';
5+
import { Favicons } from './Favicons';
66

7-
export default function SEO({
7+
interface Props {
8+
lang?: string;
9+
title?: string;
10+
description?: string;
11+
image?: string;
12+
url?: string;
13+
}
14+
15+
export const SEO: FunctionComponent<Props> = ({
816
lang = 'en',
917
title = DEFAULT_TITLE,
1018
description = DEFAULT_DESCRIPTION,
1119
image = DEFAULT_SEO_IMAGE,
1220
url = `${BASE_URL}/donate`,
13-
}) {
21+
}) => {
1422
const meta = [
1523
{
1624
name: 'viewport',
@@ -68,4 +76,4 @@ export default function SEO({
6876
))}
6977
</Head>
7078
);
71-
}
79+
};

src/components/Typography.js

-14
This file was deleted.

src/components/Typography.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React, { FunctionComponent } from 'react';
2+
import clsx from 'clsx';
3+
4+
interface Props {
5+
className?: string;
6+
}
7+
8+
export const H1: FunctionComponent<Props> = ({ className, ...props }) => (
9+
<h1 className={clsx(['text-2xl text-pink-400 px-4 py-1', className])} {...props} />
10+
);
11+
12+
export const H2: FunctionComponent<Props> = ({ className, ...props }) => (
13+
<h2 className={clsx(['text-xl text-pink-400 px-4 py-1 mt-3', className])} {...props} />
14+
);
15+
16+
export const Paragraph: FunctionComponent<Props> = ({ className, ...props }) => (
17+
<p className={clsx(['px-4 py-2 text-sm text-gray-700 leading-normal', className])} {...props} />
18+
);
File renamed without changes.
File renamed without changes.

src/pages/_app.js

-16
This file was deleted.

src/pages/_app.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import '../styles/index.css';
2+
3+
import React, { FunctionComponent } from 'react';
4+
import { AppProps } from 'next/app';
5+
6+
const App: FunctionComponent<AppProps> = ({ Component, pageProps }) => {
7+
return <Component {...pageProps} />;
8+
};
9+
10+
export default App;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/pages/api/upi.js renamed to src/pages/api/upi.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { getURL } from '../../utils';
1+
import { getUPIUrl } from '../../utils';
22

33
export default (req, res) => {
44
try {
5-
const url = getURL(req.query);
5+
const url = getUPIUrl(req.query);
66
res.writeHead(302, {
77
Location: url,
88
});

src/pages/crowdfund/[slug].js renamed to src/pages/crowdfund/[slug].tsx

+18-21
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import FindUs from '../../components/FindUs';
2-
import ContactUs from '../../components/ContactUs';
3-
import PaymentForm from '../../components/PaymentForm';
4-
import MobileFooter from '../../components/Footer';
5-
import SEO from '../../components/SEO';
6-
import { Header, Section, Container } from '../../components/Layout';
1+
import React from 'react';
72
import CampaignDetails from '../../components/CampaignDetails';
8-
import { fetchRecords, insertRecord } from '../../services/crowdfund';
9-
import { CAMPAIGNS_ROUTE, FUNDINGS_ROUTE } from '../../constants';
3+
import { ErrorComponent, Loading } from '../../components/common';
4+
import { ContactUs } from '../../components/ContactUs';
5+
import { FindUs } from '../../components/FindUs';
6+
import MobileFooter from '../../components/Footer';
107
import FundingsList from '../../components/FundingsList';
11-
import { Loading, ErrorComponent } from '../../components/common';
8+
import { Container, Header, Section } from '../../components/Layout';
9+
import { SEO } from '../../components/SEO';
10+
import { CAMPAIGNS_ROUTE, FUNDINGS_ROUTE } from '../../constants';
11+
import { fetchRecords, insertRecord } from '../../services/crowdfund';
1212

1313
export default class CrowdfundDetail extends React.Component {
1414
state = {
@@ -39,15 +39,20 @@ export default class CrowdfundDetail extends React.Component {
3939
}
4040

4141
render() {
42+
// @ts-ignore
4243
const { campaign, raised, loading, error, fundings } = this.state;
4344
const paymentFormProps = {
45+
// @ts-ignore
4446
maxAmount: campaign.req_amount - raised,
45-
actionName: "Contribute",
47+
actionName: 'Contribute',
4648
collectName: true,
47-
onSuccess: async data => insertRecord(FUNDINGS_ROUTE, this.props.slug, data)
48-
}
49+
// @ts-ignore
50+
onSuccess: async data => insertRecord(FUNDINGS_ROUTE, this.props.slug, data),
51+
};
4952
return (
5053
<>
54+
{/*
55+
// @ts-ignore */}
5156
<SEO title={`Contribute to ${campaign.title} by Coderplex`} />
5257
<Header title="Coderplex Crowdfunding" />
5358
<Container className="max-w-6xl">
@@ -58,15 +63,7 @@ export default class CrowdfundDetail extends React.Component {
5863
</Container>
5964
<Container className="flex-col md:w-1/3">
6065
<Section className="md:flex-1 md:block">
61-
<div className="shadow md:flex-1 hidden md:block bg-white p-4 m-4 mt-6 rounded-lg">
62-
{loading ? (
63-
<Loading />
64-
) : campaign.req_amount ? (
65-
<PaymentForm {...paymentFormProps} />
66-
) : (
67-
error && <ErrorComponent />
68-
)}
69-
</div>
66+
<div className="shadow md:flex-1 hidden md:block bg-white p-4 m-4 mt-6 rounded-lg">{/* Todo */}</div>
7067
<div className="shadow bg-white p-4 m-4 mt-6 rounded-lg">
7168
{loading ? <Loading /> : !error ? <FundingsList fundings={fundings} /> : <ErrorComponent />}
7269
</div>

src/pages/crowdfund/index.js renamed to src/pages/crowdfund/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import FindUs from '../../components/FindUs';
2-
import ContactUs from '../../components/ContactUs';
3-
import SEO from '../../components/SEO';
1+
import { FindUs } from '../../components/FindUs';
2+
import { ContactUs } from '../../components/ContactUs';
3+
import { SEO } from '../../components/SEO';
44
import { Header, Section, Container } from '../../components/Layout';
55
import { H1 } from '../../components/Typography';
66
import CampaignList from '../../components/CampaignList';

0 commit comments

Comments
 (0)