umami/components/pages/settings/teams/TeamMembersTable.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-04-02 21:24:50 +02:00
import useMessages from 'hooks/useMessages';
import useUser from 'hooks/useUser';
import { ROLES } from 'lib/constants';
import TeamMemberRemoveButton from './TeamMemberRemoveButton';
2023-04-13 02:43:08 +02:00
import SettingsTable from 'components/common/SettingsTable';
2023-01-10 08:59:26 +01:00
2023-04-21 17:00:42 +02:00
export function TeamMembersTable({ data = [], onSave, readOnly }) {
2023-03-22 22:05:55 +01:00
const { formatMessage, labels } = useMessages();
2023-01-31 06:44:07 +01:00
const { user } = useUser();
2023-01-25 16:42:46 +01:00
const columns = [
2023-04-13 02:43:08 +02:00
{ name: 'username', label: formatMessage(labels.username) },
{ name: 'role', label: formatMessage(labels.role) },
{ name: 'action', label: ' ' },
2023-01-25 16:42:46 +01:00
];
2023-04-13 02:43:08 +02:00
const cellRender = (row, data, key) => {
if (key === 'username') {
return row?.user?.username;
}
if (key === 'role') {
return formatMessage(
labels[Object.keys(ROLES).find(key => ROLES[key] === row.role) || labels.unknown],
);
}
return data[key];
};
2023-04-13 02:43:08 +02:00
return (
<SettingsTable data={data} columns={columns} cellRender={cellRender}>
{row => {
return (
!readOnly && (
<TeamMemberRemoveButton
teamId={row.teamId}
userId={row.userId}
disabled={user.id === row?.user?.id || row.role === ROLES.teamOwner}
onSave={onSave}
/>
)
);
}}
</SettingsTable>
);
}
2023-04-21 17:00:42 +02:00
export default TeamMembersTable;