2023-04-02 21:24:50 +02:00
|
|
|
import useMessages from 'hooks/useMessages';
|
|
|
|
import useUser from 'hooks/useUser';
|
2023-03-09 21:42:12 +01:00
|
|
|
import Link from 'next/link';
|
2023-04-13 02:43:08 +02:00
|
|
|
import { Button, Icon, Icons, Text } from 'react-basics';
|
2023-04-02 21:24:50 +02:00
|
|
|
import TeamWebsiteRemoveButton from './TeamWebsiteRemoveButton';
|
2023-04-13 02:43:08 +02:00
|
|
|
import SettingsTable from 'components/common/SettingsTable';
|
|
|
|
import useConfig from 'hooks/useConfig';
|
2023-03-09 21:42:12 +01:00
|
|
|
|
2023-03-11 02:49:19 +01:00
|
|
|
export default function TeamWebsitesTable({ data = [], onSave }) {
|
2023-03-22 22:05:55 +01:00
|
|
|
const { formatMessage, labels } = useMessages();
|
2023-04-13 02:43:08 +02:00
|
|
|
const { openExternal } = useConfig();
|
2023-03-09 21:42:12 +01:00
|
|
|
const { user } = useUser();
|
|
|
|
const columns = [
|
2023-03-11 02:49:19 +01:00
|
|
|
{ name: 'name', label: formatMessage(labels.name) },
|
2023-03-09 21:42:12 +01:00
|
|
|
{ name: 'domain', label: formatMessage(labels.domain) },
|
|
|
|
{ name: 'action', label: ' ' },
|
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
2023-04-13 02:43:08 +02:00
|
|
|
<SettingsTable columns={columns} data={data}>
|
|
|
|
{row => {
|
|
|
|
const { teamId } = row;
|
|
|
|
const { id: websiteId, name, domain, userId } = row.website;
|
|
|
|
const { teamUser } = row.team;
|
|
|
|
const owner = teamUser[0];
|
|
|
|
const canRemove = user.id === userId || user.id === owner.userId;
|
2023-03-09 21:42:12 +01:00
|
|
|
|
2023-04-13 02:43:08 +02:00
|
|
|
row.name = name;
|
|
|
|
row.domain = domain;
|
2023-03-09 21:42:12 +01:00
|
|
|
|
2023-04-13 02:43:08 +02:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Link href={`/websites/${websiteId}`} target={openExternal ? '_blank' : null}>
|
|
|
|
<Button>
|
|
|
|
<Icon>
|
|
|
|
<Icons.External />
|
|
|
|
</Icon>
|
|
|
|
<Text>{formatMessage(labels.view)}</Text>
|
|
|
|
</Button>
|
|
|
|
</Link>
|
|
|
|
{canRemove && (
|
|
|
|
<TeamWebsiteRemoveButton
|
|
|
|
teamId={teamId}
|
|
|
|
websiteId={websiteId}
|
|
|
|
onSave={onSave}
|
|
|
|
></TeamWebsiteRemoveButton>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</SettingsTable>
|
2023-03-09 21:42:12 +01:00
|
|
|
);
|
|
|
|
}
|