Created
December 19, 2016 03:43
-
-
Save timbuckley/8369188b6df9b9e49db145e1c29b8a1d to your computer and use it in GitHub Desktop.
Helping ppl on the internet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class EmployeeList extends React.Component { | |
state = { | |
employees: [], | |
isLoading: true | |
} | |
componentDidMount() { | |
if (localStorage.token) { | |
this.loadEmployeesData() | |
} | |
} | |
render() { | |
return ( | |
<EmployeesTable | |
isLoading={this.state.isLoading} | |
employees={this.state.employees} | |
/> | |
) | |
} | |
loadEmployeesData = () => { | |
$.ajax({ | |
method: 'GET', | |
url: '/api/employeelist/', | |
datatype: 'json', | |
headers: { | |
'Authorization': 'Bearer ' + localStorage.token | |
}, | |
success: res => this.setState({ | |
employees: res, | |
isLoading: false | |
}) | |
}) | |
} | |
} | |
export function EmployeesTable(props) { | |
const { isLoading, employees } = props | |
if (isLoading) { | |
// return <Loading /> | |
} | |
const employeesRows = employees.map(e => ( | |
<tr> | |
<td>{e.first_name} {e.last_name}</td> | |
<td>12</td> | |
</tr> | |
)) | |
return ( | |
<div> | |
<h2>Employees</h2> | |
<table className="table table-responsive table-striped"> | |
<thead> | |
<tr> | |
<th>Name</th> | |
<th></th> | |
</tr> | |
</thead> | |
<tbody> | |
{employeesRows} | |
</tbody> | |
</table> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment