Skip to content

Commit 19777bb

Browse files
author
Antonio Contreras LEMONCODE
committed
Create project and employee components and scenes
1 parent 054d5e2 commit 19777bb

10 files changed

Lines changed: 93 additions & 2 deletions

File tree

src/core/router/router.component.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
SubmoduleListScene,
88
ProjectListScene,
99
EmployeeListScene,
10+
ProjectScene,
11+
EmployeeScene,
1012
} from 'scenes';
1113

1214
export const RouterComponent: React.FunctionComponent = () => {
@@ -33,6 +35,16 @@ export const RouterComponent: React.FunctionComponent = () => {
3335
path={routes.employees}
3436
component={EmployeeListScene}
3537
/>
38+
<Route
39+
exact={true}
40+
path={routes.editProject()}
41+
component={ProjectScene}
42+
/>
43+
<Route
44+
exact={true}
45+
path={routes.editEmployee()}
46+
component={EmployeeScene}
47+
/>
3648
</Switch>
3749
</HashRouter>
3850
);

src/core/router/routes.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { generatePath } from 'react-router-dom';
2+
13
interface BaseRoutes {
24
root: string;
35
login: string;
@@ -18,8 +20,17 @@ const baseRoutes: BaseRoutes = {
1820
editEmployee: '/employees/:id',
1921
};
2022

21-
type Routes = Omit<BaseRoutes, 'editProject' | 'editEmployee'>;
23+
interface Routes extends Omit<BaseRoutes, 'editProject' | 'editEmployee'> {
24+
editProject: (id?: string) => string;
25+
editEmployee: (id?: string) => string;
26+
}
2227

2328
export const routes: Routes = {
2429
...baseRoutes,
30+
editProject: id =>
31+
id ? generatePath(baseRoutes.editProject, { id }) : baseRoutes.editProject,
32+
editEmployee: id =>
33+
id
34+
? generatePath(baseRoutes.editEmployee, { id })
35+
: baseRoutes.editEmployee,
2536
};
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
import React from 'react';
2+
import { useHistory } from 'react-router-dom';
3+
import { routes } from 'core/router';
24

35
export const EmployeeListComponent: React.FunctionComponent = () => {
4-
return <h1>Hello Employee list component</h1>;
6+
const history = useHistory();
7+
const goToEmployee = (
8+
event: React.MouseEvent<HTMLParagraphElement, MouseEvent>
9+
) => {
10+
event.preventDefault();
11+
history.push({
12+
pathname: routes.editEmployee('1'),
13+
});
14+
};
15+
return (
16+
<>
17+
<h1>Hello Employee list component</h1>
18+
<p onClick={goToEmployee}>Go to edit employee page</p>
19+
</>
20+
);
521
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
export const EmployeeComponent: React.FunctionComponent = () => {
4+
return <h1>Hello Edit employee component</h1>;
5+
};

src/pods/employee/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './employee.component';

src/pods/project/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './project.component';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import { useHistory } from 'react-router-dom';
3+
import { routes } from 'core/router';
4+
5+
export const ProjectComponent: React.FunctionComponent = () => {
6+
const history = useHistory();
7+
const goToProject = (
8+
event: React.MouseEvent<HTMLParagraphElement, MouseEvent>
9+
) => {
10+
event.preventDefault();
11+
history.push({
12+
pathname: routes.editProject('1'),
13+
});
14+
};
15+
return (
16+
<>
17+
<h1>Hello Edit project component</h1>
18+
<p onClick={goToProject}>Go to edit project component</p>
19+
</>
20+
);
21+
};

src/scenes/employee.scene.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import { AppLayout } from 'layouts';
3+
import { EmployeeComponent } from 'pods/employee';
4+
5+
export const EmployeeScene: React.FunctionComponent = () => {
6+
return (
7+
<AppLayout>
8+
<EmployeeComponent />
9+
</AppLayout>
10+
);
11+
};

src/scenes/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ export * from './login.scene';
22
export * from './submodule-list.scene';
33
export * from './project-list.scene';
44
export * from './employee-list.scene';
5+
export * from './project.scene';
6+
export * from './employee.scene';

src/scenes/project.scene.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
import { AppLayout } from 'layouts';
3+
import { ProjectComponent } from 'pods/project';
4+
5+
export const ProjectScene: React.FunctionComponent = () => {
6+
return (
7+
<AppLayout>
8+
<ProjectComponent />
9+
</AppLayout>
10+
);
11+
};

0 commit comments

Comments
 (0)