New admin section.
This commit is contained in:
19
src/app/(main)/admin/teams/AdminTeamsDataTable.tsx
Normal file
19
src/app/(main)/admin/teams/AdminTeamsDataTable.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { DataGrid } from '@/components/common/DataGrid';
|
||||
import { useTeamsQuery } from '@/components/hooks';
|
||||
import { AdminTeamsTable } from './AdminTeamsTable';
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
export function AdminTeamsDataTable({
|
||||
showActions,
|
||||
}: {
|
||||
showActions?: boolean;
|
||||
children?: ReactNode;
|
||||
}) {
|
||||
const queryResult = useTeamsQuery();
|
||||
|
||||
return (
|
||||
<DataGrid query={queryResult} allowSearch={true}>
|
||||
{({ data }) => <AdminTeamsTable data={data} showActions={showActions} />}
|
||||
</DataGrid>
|
||||
);
|
||||
}
|
||||
16
src/app/(main)/admin/teams/AdminTeamsPage.tsx
Normal file
16
src/app/(main)/admin/teams/AdminTeamsPage.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
'use client';
|
||||
import { AdminTeamsDataTable } from './AdminTeamsDataTable';
|
||||
import { Column } from '@umami/react-zen';
|
||||
import { SectionHeader } from '@/components/common/SectionHeader';
|
||||
import { useMessages } from '@/components/hooks';
|
||||
|
||||
export function AdminTeamsPage() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
|
||||
return (
|
||||
<Column gap>
|
||||
<SectionHeader title={formatMessage(labels.teams)} />
|
||||
<AdminTeamsDataTable />
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
78
src/app/(main)/admin/teams/AdminTeamsTable.tsx
Normal file
78
src/app/(main)/admin/teams/AdminTeamsTable.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
import { useState } from 'react';
|
||||
import { Row, Text, Icon, DataTable, DataColumn, MenuItem, Modal } from '@umami/react-zen';
|
||||
import Link from 'next/link';
|
||||
import { Trash } from '@/components/icons';
|
||||
import { useMessages } from '@/components/hooks';
|
||||
import { Edit } from '@/components/icons';
|
||||
import { MenuButton } from '@/components/input/MenuButton';
|
||||
import { DateDistance } from '@/components/common/DateDistance';
|
||||
|
||||
export function AdminTeamsTable({
|
||||
data = [],
|
||||
showActions = true,
|
||||
}: {
|
||||
data: any[];
|
||||
showActions?: boolean;
|
||||
}) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const [deleteUser, setDeleteUser] = useState(null);
|
||||
|
||||
return (
|
||||
<>
|
||||
<DataTable data={data}>
|
||||
<DataColumn id="name" label={formatMessage(labels.name)} width="2fr">
|
||||
{(row: any) => <Link href={`/admin/teams/${row.id}`}>{row.name}</Link>}
|
||||
</DataColumn>
|
||||
<DataColumn id="websites" label={formatMessage(labels.members)}>
|
||||
{(row: any) => row?._count?.teamUser}
|
||||
</DataColumn>
|
||||
<DataColumn id="members" label={formatMessage(labels.websites)}>
|
||||
{(row: any) => row?._count?.website}
|
||||
</DataColumn>
|
||||
<DataColumn id="owner" label={formatMessage(labels.owner)} width="200px">
|
||||
{(row: any) => (
|
||||
<Text title={row?.teamUser?.[0]?.user?.username} truncate>
|
||||
{row?.teamUser?.[0]?.user?.username}
|
||||
</Text>
|
||||
)}
|
||||
</DataColumn>
|
||||
<DataColumn id="created" label={formatMessage(labels.created)} width="160px">
|
||||
{(row: any) => <DateDistance date={new Date(row.createdAt)} />}
|
||||
</DataColumn>
|
||||
{showActions && (
|
||||
<DataColumn id="action" align="end" width="50px">
|
||||
{(row: any) => {
|
||||
const { id } = row;
|
||||
|
||||
return (
|
||||
<MenuButton>
|
||||
<MenuItem href={`/admin/users/${id}`} data-test="link-button-edit">
|
||||
<Row alignItems="center" gap>
|
||||
<Icon>
|
||||
<Edit />
|
||||
</Icon>
|
||||
<Text>{formatMessage(labels.edit)}</Text>
|
||||
</Row>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
id="delete"
|
||||
onAction={() => setDeleteUser(row)}
|
||||
data-test="link-button-delete"
|
||||
>
|
||||
<Row alignItems="center" gap>
|
||||
<Icon>
|
||||
<Trash />
|
||||
</Icon>
|
||||
<Text>{formatMessage(labels.delete)}</Text>
|
||||
</Row>
|
||||
</MenuItem>
|
||||
</MenuButton>
|
||||
);
|
||||
}}
|
||||
</DataColumn>
|
||||
)}
|
||||
</DataTable>
|
||||
<Modal isOpen={!!deleteUser}></Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
10
src/app/(main)/admin/teams/[teamId]/AdminTeamPage.tsx
Normal file
10
src/app/(main)/admin/teams/[teamId]/AdminTeamPage.tsx
Normal file
@@ -0,0 +1,10 @@
|
||||
'use client';
|
||||
import { TeamDetails } from '@/app/(main)/teams/[teamId]/settings/team/TeamDetails';
|
||||
|
||||
export function AdminTeamPage({ teamId }: { teamId: string }) {
|
||||
return (
|
||||
<>
|
||||
<TeamDetails teamId={teamId} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
17
src/app/(main)/admin/teams/[teamId]/page.tsx
Normal file
17
src/app/(main)/admin/teams/[teamId]/page.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { AdminTeamPage } from './AdminTeamPage';
|
||||
import { TeamProvider } from '@/app/(main)/teams/[teamId]/TeamProvider';
|
||||
import { Metadata } from 'next';
|
||||
|
||||
export default async function ({ params }: { params: Promise<{ teamId: string }> }) {
|
||||
const { teamId } = await params;
|
||||
|
||||
return (
|
||||
<TeamProvider teamId={teamId}>
|
||||
<AdminTeamPage teamId={teamId} />
|
||||
</TeamProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Team',
|
||||
};
|
||||
9
src/app/(main)/admin/teams/page.tsx
Normal file
9
src/app/(main)/admin/teams/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Metadata } from 'next';
|
||||
import { AdminTeamsPage } from './AdminTeamsPage';
|
||||
|
||||
export default function () {
|
||||
return <AdminTeamsPage />;
|
||||
}
|
||||
export const metadata: Metadata = {
|
||||
title: 'Teams',
|
||||
};
|
||||
Reference in New Issue
Block a user