Skip to content
This repository was archived by the owner on Jan 1, 2025. It is now read-only.

Commit 1ef5ab5

Browse files
authored
Merge pull request #2 from knowankit/feat/add-fe-typescript
Typescript support
2 parents c11c2e9 + 106bf33 commit 1ef5ab5

File tree

21 files changed

+50
-14
lines changed

21 files changed

+50
-14
lines changed

apps/api/schema.gql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ input CreateTaskInput {
66
_id: ID!
77
description: String
88
endDate: DateTime
9-
startDate: DateTime = "2022-04-02T08:21:45.099Z"
9+
startDate: DateTime = "2022-04-03T08:34:13.996Z"
1010
status: String = "pending"
1111
title: String!
1212
}

apps/fe-e2e/cypress.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"fixturesFolder": "./src/fixtures",
44
"integrationFolder": "./src/integration",
55
"modifyObstructiveCode": false,
6-
"supportFile": "./src/support/index.js",
6+
"supportFile": "./src/support/index.ts",
77
"pluginsFile": false,
88
"video": true,
99
"videosFolder": "../../dist/cypress/apps/fe-e2e/videos",

apps/fe-e2e/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"executor": "@nrwl/linter:eslint",
2020
"outputs": ["{options.outputFile}"],
2121
"options": {
22-
"lintFilePatterns": ["apps/fe-e2e/**/*.js"]
22+
"lintFilePatterns": ["apps/fe-e2e/**/*.{js,ts}"]
2323
}
2424
}
2525
},

apps/fe-e2e/src/integration/app.spec.js renamed to apps/fe-e2e/src/integration/app.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { getGreeting } from '../support/app.po';
2+
23
describe('fe', () => {
34
beforeEach(() => cy.visit('/'));
5+
46
it('should display welcome message', () => {
57
// Custom command example, see `../support/commands.ts` file
68
cy.login('my-email@something.com', 'myPassword');
9+
710
// Function helper example, see `../support/app.po.ts` file
811
getGreeting().contains('Welcome fe');
912
});
File renamed without changes.

apps/fe-e2e/src/support/commands.js renamed to apps/fe-e2e/src/support/commands.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
// commands please read more here:
88
// https://on.cypress.io/custom-commands
99
// ***********************************************
10+
11+
// eslint-disable-next-line @typescript-eslint/no-namespace
12+
declare namespace Cypress {
13+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
14+
interface Chainable<Subject> {
15+
login(email: string, password: string): void;
16+
}
17+
}
1018
//
1119
// -- This is a parent command --
1220
Cypress.Commands.add('login', (email, password) => {

apps/fe-e2e/src/support/index.js renamed to apps/fe-e2e/src/support/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
// You can read more here:
1313
// https://on.cypress.io/configuration
1414
// ***********************************************************
15+
1516
// Import commands.js using ES2015 syntax:
1617
import './commands';

apps/fe/project.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"outputPath": "dist/apps/fe",
1313
"index": "apps/fe/src/index.html",
1414
"baseHref": "/",
15-
"main": "apps/fe/src/main.js",
16-
"polyfills": "apps/fe/src/polyfills.js",
15+
"main": "apps/fe/src/main.tsx",
16+
"polyfills": "apps/fe/src/polyfills.ts",
1717
"tsConfig": "apps/fe/tsconfig.app.json",
1818
"assets": ["apps/fe/src/favicon.ico", "apps/fe/src/assets"],
1919
"styles": ["apps/fe/src/styles.scss"],
@@ -24,8 +24,8 @@
2424
"production": {
2525
"fileReplacements": [
2626
{
27-
"replace": "apps/fe/src/environments/environment.js",
28-
"with": "apps/fe/src/environments/environment.prod.js"
27+
"replace": "apps/fe/src/environments/environment.ts",
28+
"with": "apps/fe/src/environments/environment.prod.ts"
2929
}
3030
],
3131
"optimization": true,
File renamed without changes.
File renamed without changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
import { render } from '@testing-library/react';
2+
23
import { BrowserRouter } from 'react-router-dom';
4+
35
import App from './app';
6+
47
describe('App', () => {
58
it('should render successfully', () => {
69
const { baseElement } = render(
710
<BrowserRouter>
811
<App />
912
</BrowserRouter>
1013
);
14+
1115
expect(baseElement).toBeTruthy();
1216
});
17+
1318
it('should have a greeting as the title', () => {
1419
const { getByText } = render(
1520
<BrowserRouter>
1621
<App />
1722
</BrowserRouter>
1823
);
24+
1925
expect(getByText(/Welcome fe/gi)).toBeTruthy();
2026
});
2127
});
File renamed without changes.

apps/fe/src/app/nx-welcome.js renamed to apps/fe/src/app/nx-welcome.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Delete this file and get started with your project!
66
* * * * * * * * * * * * * * * * * * * * * * * * * * * *
77
*/
8-
export function NxWelcome({ title }) {
8+
export function NxWelcome({ title }: { title: string }) {
99
return (
1010
<>
1111
<style
@@ -816,4 +816,5 @@ export function NxWelcome({ title }) {
816816
</>
817817
);
818818
}
819+
819820
export default NxWelcome;

apps/fe/src/components/add-task.js renamed to apps/fe/src/components/add-task.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { CREATE_TASK } from '../api/task/mutations';
44
import { GET_TASKS } from '../api/task/queries';
55
import { TextField, Button, Stack } from '@mui/material';
66

7+
interface FormValues {
8+
title?: string;
9+
description?: string;
10+
}
11+
712
const AddTask = () => {
813
const [createTask] = useMutation(CREATE_TASK);
914

@@ -12,7 +17,7 @@ const AddTask = () => {
1217
<Formik
1318
initialValues={{ title: '', description: '' }}
1419
validate={(values) => {
15-
const errors = {};
20+
const errors: FormValues = {};
1621
if (!values.title) {
1722
errors.title = 'Required';
1823
}

apps/fe/src/components/tasks.js renamed to apps/fe/src/components/tasks.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ import { GET_TASKS } from '../api/task/queries';
33
import { DELETE_TASK } from '../api/task/mutations';
44
import { Button } from '@mui/material';
55

6+
interface Task {
7+
_id: number;
8+
title: string;
9+
}
10+
11+
type TaskType = {
12+
getTasks: Task[];
13+
};
14+
615
const Tasks = () => {
7-
const { loading, data } = useQuery(GET_TASKS);
16+
const { loading, data } = useQuery<TaskType>(GET_TASKS);
817
const [deleteTask] = useMutation(DELETE_TASK);
918

10-
const handleDelete = async (taskId) => {
19+
const handleDelete = async (taskId: number) => {
1120
await deleteTask({
1221
variables: {
1322
id: taskId,
@@ -19,6 +28,7 @@ const Tasks = () => {
1928
return (
2029
<>
2130
{!loading &&
31+
data &&
2232
data['getTasks'].map((task, index) => (
2333
<div key={index}>
2434
{task.title}{' '}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This file can be replaced during build by using the `fileReplacements` array.
22
// When building for production, this file is replaced with `environment.prod.ts`.
3+
34
export const environment = {
45
production: false,
56
};

apps/fe/src/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<title>Complicated Todo</title>
5+
<title>Fe</title>
66
<base href="/" />
77

88
<meta name="viewport" content="width=device-width, initial-scale=1" />
9-
<!-- <link rel="icon" type="image/x-icon" href="favicon.ico" /> -->
9+
<link rel="icon" type="image/x-icon" href="favicon.ico" />
1010
<link
1111
rel="stylesheet"
1212
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"

apps/fe/src/main.js renamed to apps/fe/src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import App from './app/app';
77

88
const client = new ApolloClient({
99
cache: new InMemoryCache(),
10-
uri: 'http://localhost:5000/graphql'
10+
uri: 'http://localhost:5000/graphql',
1111
});
1212

1313
ReactDOM.render(
File renamed without changes.

apps/fe/src/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* You can add global styles to this file, and also import other style files */
12
body {
23
font-family: 'Roboto';
34
}

0 commit comments

Comments
 (0)