Skip to content

Instantly share code, notes, and snippets.

@timbuckley
Created December 19, 2016 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timbuckley/8369188b6df9b9e49db145e1c29b8a1d to your computer and use it in GitHub Desktop.
Save timbuckley/8369188b6df9b9e49db145e1c29b8a1d to your computer and use it in GitHub Desktop.
Helping ppl on the internet
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