-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
114 lines (110 loc) · 2.87 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { Button, Layout, Menu, Breadcrumb, Table, Tag, Space } from 'antd'
import Head from 'next/head'
import {useRouter} from 'next/router'
import Link from 'next/link'
import {deleteEmp} from '../../utils/fetch_fun'
const { Header, Footer, Content } = Layout;
export async function getServerSideProps() {
console.log('fetching..')
try {
const res = await fetch(`http://localhost:2020/Employee`, {method: 'GET'})
const data = await res.json()
if(!data)
return {
notFound: true,
}
return {
props:{
data,
},
}}catch(e) {
console.log(e)
}
}
export default function Employees(props) {
const router = useRouter()
const data = props.data
// NOTE: This are the colomn of the table
const columns = [
{
title: 'Id',
dataIndex: 'id',
key: 'id',
render: text => <a>{text}</a>,
},
{
title: 'First name',
dataIndex: 'first_name',
key: 'first_name',
},
{
title: 'Last name',
dataIndex: 'last_name',
key: 'last_name',
},
{
title: 'Activity',
dataIndex: 'is_active',
key: 'is_active',
render: text => <a>{text.toString()}</a>,
},
{
title: 'Date of birth',
dataIndex: 'date_of_birth',
key: 'date_of_birth',
},
{
title: 'Actions',
key: 'action',
render: (text, record) => (
<Space size="middle">
<Button size="small" type="primary" onClick={()=>router.push('/employees/' + text.id)}>
Edit
</Button>
<Button size="small" type="primary" onClick={()=>deleteEmp(text.id)}>
Delete
</Button>
</Space>
),
},
];
return (
<Layout className="layout">
<Head>
<title>Postem</title>
</Head>
<Header>
<div className="logo" />
<Menu theme="dark" mode="horizontal" defaultSelectedKeys={['2']}>
<Menu.Item key="1" >
<Link href="/">
<a> Postem </a>
</Link>
</Menu.Item>
<Menu.Item key="2">
<Link href="/employees">
<a> Employees </a>
</Link>
</Menu.Item>
<Menu.Item key="3" >
<Link href="/employees/hire">
<a> Hire </a>
</Link>
</Menu.Item>
</Menu>
</Header>
<Content style={{ padding: '0 50px' }}>
<Breadcrumb style={{ margin: '16px 0' }}/>
<div className="site-layout-content">
<Table columns={columns} dataSource={data} />
</div>
</Content>
<Footer style={{ textAlign: 'center' }}>
<Link href="/about">
<a>About me.. </a>
</Link>
Powered by PostBoy
</Footer>
</Layout>
)
}