grafana/public/app/features/users/InviteesTable.tsx

65 lines
1.8 KiB
TypeScript
Raw Normal View History

2018-10-03 02:43:10 -05:00
import React, { createRef, PureComponent } from 'react';
import { Invitee } from 'app/types';
export interface Props {
invitees: Invitee[];
2018-10-03 03:54:15 -05:00
onRevokeInvite: (code: string) => void;
2018-10-03 02:43:10 -05:00
}
export default class InviteesTable extends PureComponent<Props> {
private copyUrlRef = createRef<HTMLTextAreaElement>();
copyToClipboard = () => {
const node = this.copyUrlRef.current;
if (node) {
node.select();
document.execCommand('copy');
}
};
render() {
2018-10-03 03:54:15 -05:00
const { invitees, onRevokeInvite } = this.props;
2018-10-03 02:43:10 -05:00
return (
<table className="filter-table form-inline">
<thead>
<tr>
<th>Email</th>
<th>Name</th>
<th />
<th style={{ width: '34px' }} />
</tr>
</thead>
<tbody>
{invitees.map((invitee, index) => {
return (
<tr key={`${invitee.id}-${index}`}>
<td>{invitee.email}</td>
<td>{invitee.name}</td>
<td className="text-right">
<button className="btn btn-inverse btn-mini" onClick={this.copyToClipboard}>
<textarea
readOnly={true}
value={invitee.url}
style={{ position: 'absolute', right: -1000 }}
ref={this.copyUrlRef}
/>
<i className="fa fa-clipboard" /> Copy Invite
</button>
&nbsp;
</td>
<td>
2018-10-03 03:54:15 -05:00
<button className="btn btn-danger btn-mini" onClick={() => onRevokeInvite(invitee.code)}>
2018-10-03 02:43:10 -05:00
<i className="fa fa-remove" />
</button>
</td>
</tr>
);
})}
</tbody>
</table>
);
}
}