Skip to content

Commit 8ac12f8

Browse files
committed
Init commit
0 parents  commit 8ac12f8

26 files changed

+529
-0
lines changed

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.idea
8+
9+
# testing
10+
/coverage
11+
12+
# production
13+
/build
14+
15+
# misc
16+
.DS_Store
17+
.env.local
18+
.env.development.local
19+
.env.test.local
20+
.env.production.local
21+
22+
npm-debug.log*
23+
yarn-debug.log*
24+
yarn-error.log*

.prettierrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": true,
3+
"tabWidth": 2,
4+
"printWidth": 100,
5+
"singleQuote": true,
6+
"trailingComma": "none",
7+
"jsxBracketSameLine": true
8+
}

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# ReactJS / TypeScript / Apollo / GraphQL example
2+
3+
## Available Scripts
4+
5+
In the project directory, you can run:
6+
7+
### `npm start`
8+
9+
Runs the app in the development mode.\
10+
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11+
12+
The page will reload if you make edits.\
13+
You will also see any lint errors in the console.
14+
15+
### `npm test`
16+
17+
Launches the test runner in the interactive watch mode.\
18+
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19+
20+
### `npm run build`
21+
22+
Builds the app for production to the `build` folder.\
23+
It correctly bundles React in production mode and optimizes the build for the best performance.
24+
25+
The build is minified and the filenames include the hashes.\
26+
Your app is ready to be deployed!
27+
28+
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29+
30+
### `npm run eject`
31+
32+
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33+
34+
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35+
36+
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37+
38+
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

package.json

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "reactjs-typescript-apollo-graphql-example",
3+
"version": "0.1.0",
4+
"author": "OmiSoft.Net",
5+
"license": "MIT",
6+
"private": true,
7+
"dependencies": {
8+
"@apollo/client": "^3.5.10",
9+
"@testing-library/jest-dom": "^5.16.2",
10+
"@testing-library/react": "^12.1.4",
11+
"@testing-library/user-event": "^13.5.0",
12+
"@types/jest": "^27.4.1",
13+
"@types/node": "^16.11.26",
14+
"@types/react": "^17.0.40",
15+
"@types/react-dom": "^17.0.13",
16+
"antd": "^4.19.2",
17+
"apollo-boost": "^0.4.9",
18+
"apollo-upload-client": "^17.0.0",
19+
"graphql": "^16.3.0",
20+
"graphql-ws": "^5.6.3",
21+
"react": "^17.0.2",
22+
"react-apollo": "^3.1.5",
23+
"react-dom": "^17.0.2",
24+
"react-router-dom": "^6.2.2",
25+
"react-scripts": "5.0.0",
26+
"styled-components": "^5.3.3",
27+
"typescript": "^4.6.2",
28+
"web-vitals": "^2.1.4"
29+
},
30+
"scripts": {
31+
"start": "react-scripts start",
32+
"build": "react-scripts build",
33+
"test": "react-scripts test",
34+
"eject": "react-scripts eject"
35+
},
36+
"eslintConfig": {
37+
"extends": [
38+
"react-app",
39+
"react-app/jest"
40+
]
41+
},
42+
"browserslist": {
43+
"production": [
44+
">0.2%",
45+
"not dead",
46+
"not op_mini all"
47+
],
48+
"development": [
49+
"last 1 chrome version",
50+
"last 1 firefox version",
51+
"last 1 safari version"
52+
]
53+
},
54+
"devDependencies": {
55+
"@types/apollo-upload-client": "^17.0.0",
56+
"@types/styled-components": "^5.1.24",
57+
"eslint": "^8.11.0"
58+
}
59+
}

public/favicon.ico

3.78 KB
Binary file not shown.

public/index.html

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta
9+
name="description"
10+
content="Web site created using create-react-app"
11+
/>
12+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13+
<!--
14+
manifest.json provides metadata used when your web app is installed on a
15+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16+
-->
17+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18+
<!--
19+
Notice the use of %PUBLIC_URL% in the tags above.
20+
It will be replaced with the URL of the `public` folder during the build.
21+
Only files inside the `public` folder can be referenced from the HTML.
22+
23+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24+
work correctly both with client-side routing and a non-root public URL.
25+
Learn how to configure a non-root public URL by running `npm run build`.
26+
-->
27+
<title>React App</title>
28+
</head>
29+
<body>
30+
<noscript>You need to enable JavaScript to run this app.</noscript>
31+
<div id="root"></div>
32+
<!--
33+
This HTML file is a template.
34+
If you open it directly in the browser, you will see an empty page.
35+
36+
You can add webfonts, meta tags, or analytics to this file.
37+
The build step will place the bundled scripts into the <body> tag.
38+
39+
To begin the development, run `npm start` or `yarn start`.
40+
To create a production bundle, use `npm run build` or `yarn build`.
41+
-->
42+
</body>
43+
</html>

public/logo192.png

5.22 KB
Loading

public/logo512.png

9.44 KB
Loading

public/manifest.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
},
10+
{
11+
"src": "logo192.png",
12+
"type": "image/png",
13+
"sizes": "192x192"
14+
},
15+
{
16+
"src": "logo512.png",
17+
"type": "image/png",
18+
"sizes": "512x512"
19+
}
20+
],
21+
"start_url": ".",
22+
"display": "standalone",
23+
"theme_color": "#000000",
24+
"background_color": "#ffffff"
25+
}

public/robots.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:

src/App.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import { BrowserRouter } from 'react-router-dom';
3+
import { MainRouter } from './routes';
4+
5+
function App() {
6+
return (
7+
<BrowserRouter>
8+
<MainRouter />
9+
</BrowserRouter>
10+
);
11+
}
12+
13+
export default App;
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import React, { useState } from 'react';
2+
import { Upload, Space, Button, UploadProps } from 'antd';
3+
import { RcFile } from 'antd/lib/upload';
4+
import { UploadOutlined } from '@ant-design/icons';
5+
import { gql, useMutation } from '@apollo/client';
6+
7+
const UPLOAD_FILE = gql`
8+
mutation uploadFile($files: [Upload!]!) {
9+
uploadFile(files: $files)
10+
}
11+
`;
12+
13+
export const FileInput: React.FC = () => {
14+
const [uploadFile] = useMutation(UPLOAD_FILE, {
15+
onCompleted: () => {
16+
setUploading(false);
17+
},
18+
onError: () => {
19+
setUploading(false);
20+
}
21+
});
22+
const [uploading, setUploading] = useState(false);
23+
const [fileList, setFileList] = useState<RcFile[]>([]);
24+
25+
const handleUpload = () => {
26+
setUploading(true);
27+
uploadFile({ variables: { files: fileList } });
28+
};
29+
30+
const props: UploadProps<RcFile> = {
31+
multiple: true,
32+
onRemove: (file) => {
33+
const currentFile = file as RcFile;
34+
const index = fileList.indexOf(currentFile);
35+
const newFileList = fileList.slice();
36+
newFileList.splice(index, 1);
37+
setFileList([...newFileList]);
38+
return false;
39+
},
40+
beforeUpload: (file) => {
41+
setFileList((value) => {
42+
return [...value, file];
43+
});
44+
45+
return false;
46+
},
47+
fileList
48+
};
49+
return (
50+
<Space direction="vertical">
51+
<Upload {...props}>
52+
<Button icon={<UploadOutlined />}>Select Files</Button>
53+
</Upload>
54+
<Button
55+
type="primary"
56+
onClick={handleUpload}
57+
disabled={fileList.length === 0}
58+
loading={uploading}
59+
style={{ marginTop: 16 }}>
60+
{uploading ? 'Uploading' : 'Start Upload'}
61+
</Button>
62+
</Space>
63+
);
64+
};

src/components/fileInput/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { FileInput } from './fileInput';
2+
export default FileInput;
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import { gql } from '@apollo/client';
3+
import { message, Space } from 'antd';
4+
import { useSubscription } from '@apollo/client';
5+
import { useEffect } from 'react';
6+
7+
const RENDER_FILE_STATUS = gql`
8+
subscription {
9+
fileStatus
10+
}
11+
`;
12+
13+
enum UploadStatuses {
14+
SUCCESS = 'Fulfilled',
15+
ERROR = 'Rejected'
16+
}
17+
18+
export const FileStatus = () => {
19+
const { data } = useSubscription(RENDER_FILE_STATUS);
20+
21+
useEffect(() => {
22+
if (data && data.fileStatus === UploadStatuses.SUCCESS) {
23+
message.success(data.fileStatus);
24+
}
25+
26+
if (data && data.fileStatus === UploadStatuses.ERROR) {
27+
message.error(data.fileStatus);
28+
}
29+
}, [data]);
30+
31+
return <Space />;
32+
};

src/components/fileStatus/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { FileStatus } from './fileStatus';
2+
3+
export default FileStatus;

src/components/getUser/getUser.tsx

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import { gql, useLazyQuery } from '@apollo/client';
3+
import { Input, Space, Form, Button, Card } from 'antd';
4+
5+
const GET_USER_DATA = gql`
6+
query GetContactByEmail($email: String!) {
7+
getContactByEmail(email: $email) {
8+
vid
9+
}
10+
}
11+
`;
12+
13+
export const GetUser: React.FC = () => {
14+
const [getContact, { data }] = useLazyQuery(GET_USER_DATA);
15+
16+
const handleEmail = ({ email }: { email: string }) => {
17+
getContact({ variables: { email } });
18+
};
19+
20+
return (
21+
<Space align="center" direction="vertical">
22+
<Form
23+
name="basic"
24+
labelCol={{ span: 8 }}
25+
wrapperCol={{ span: 16 }}
26+
onFinish={handleEmail}
27+
autoComplete="off">
28+
<Form.Item label="Email" name="email" rules={[{ type: 'email' }]}>
29+
<Input placeholder="HubSpot contact email" />
30+
</Form.Item>
31+
<Form.Item wrapperCol={{ offset: 8, span: 16 }}>
32+
<Button type="primary" htmlType="submit">
33+
Get contacts vid
34+
</Button>
35+
</Form.Item>
36+
</Form>
37+
38+
{data && <Card title="Some contact data">{JSON.stringify(data)}</Card>}
39+
</Space>
40+
);
41+
};

src/components/getUser/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { GetUser } from './getUser';
2+
3+
export default GetUser;

src/index.css

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@import '~antd/dist/antd.css';
2+
3+
body {
4+
margin: 0;
5+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
6+
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
7+
sans-serif;
8+
-webkit-font-smoothing: antialiased;
9+
-moz-osx-font-smoothing: grayscale;
10+
}
11+
12+
code {
13+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
14+
monospace;
15+
}

0 commit comments

Comments
 (0)