import React from 'react';
import { FormattedMessage as T, useIntl } from 'react-intl';
import {
Intent,
Button,
Popover,
Menu,
MenuDivider,
Tag,
MenuItem,
Position,
} from '@blueprintjs/core';
import { safeCallback, firstLettersArgs } from 'utils';
import { Icon, If } from 'components';
/**
* Avatar cell.
*/
function AvatarCell(row) {
return {firstLettersArgs(row.email)};
}
/**
* Users table actions menu.
*/
export function ActionsMenu({
row: { original },
payload: { onEdit, onInactivate, onActivate, onDelete, onResendInvitation },
}) {
const { formatMessage } = useIntl();
return (
);
}
/**
* Status accessor.
*/
function StatusAccessor(user) {
return !user.is_invite_accepted ? (
) : user.active ? (
) : (
);
}
/**
* Actions cell.
*/
function ActionsCell(props) {
return (
}
position={Position.RIGHT_BOTTOM}
>
} />
);
}
function FullNameAccessor(user) {
return user.is_invite_accepted ? user.full_name : user.email;
}
export const useUsersListColumns = () => {
const { formatMessage } = useIntl();
return React.useMemo(
() => [
{
id: 'avatar',
Header: '',
accessor: AvatarCell,
width: 40,
},
{
id: 'full_name',
Header: formatMessage({ id: 'full_name' }),
accessor: FullNameAccessor,
width: 150,
},
{
id: 'email',
Header: formatMessage({ id: 'email' }),
accessor: 'email',
width: 150,
},
{
id: 'phone_number',
Header: formatMessage({ id: 'phone_number' }),
accessor: 'phone_number',
width: 120,
},
{
id: 'status',
Header: 'Status',
accessor: StatusAccessor,
width: 80,
className: 'status',
},
{
id: 'actions',
Header: '',
Cell: ActionsCell,
className: 'actions',
width: 50,
disableResizing: true,
},
],
[formatMessage],
);
};