mirror of
https://github.com/docmost/docmost.git
synced 2025-11-16 05:11:13 +10:00
73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import { Table, Group, Text, Avatar } from "@mantine/core";
|
|
import React, { useState } from "react";
|
|
import { useGetSpacesQuery } from "@/features/space/queries/space-query.ts";
|
|
import SpaceSettingsModal from "@/features/space/components/settings-modal.tsx";
|
|
import { useDisclosure } from "@mantine/hooks";
|
|
import { formatMemberCount } from "@/lib";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
export default function SpaceList() {
|
|
const { t } = useTranslation();
|
|
const { data, isLoading } = useGetSpacesQuery();
|
|
const [opened, { open, close }] = useDisclosure(false);
|
|
const [selectedSpaceId, setSelectedSpaceId] = useState<string>(null);
|
|
|
|
const handleClick = (spaceId: string) => {
|
|
setSelectedSpaceId(spaceId);
|
|
open();
|
|
};
|
|
|
|
return (
|
|
<>
|
|
{data && (
|
|
<Table highlightOnHover verticalSpacing="sm">
|
|
<Table.Thead>
|
|
<Table.Tr>
|
|
<Table.Th>{t("Space")}</Table.Th>
|
|
<Table.Th>{t("Members")}</Table.Th>
|
|
</Table.Tr>
|
|
</Table.Thead>
|
|
|
|
<Table.Tbody>
|
|
{data?.items.map((space, index) => (
|
|
<Table.Tr
|
|
key={index}
|
|
style={{ cursor: "pointer" }}
|
|
onClick={() => handleClick(space.id)}
|
|
>
|
|
<Table.Td>
|
|
<Group gap="sm">
|
|
<Avatar
|
|
color="initials"
|
|
variant="filled"
|
|
name={space.name}
|
|
/>
|
|
<div>
|
|
<Text fz="sm" fw={500}>
|
|
{space.name}
|
|
</Text>
|
|
<Text fz="xs" c="dimmed">
|
|
{space.description}
|
|
</Text>
|
|
</div>
|
|
</Group>
|
|
</Table.Td>
|
|
|
|
<Table.Td>{formatMemberCount(space.memberCount, t)}</Table.Td>
|
|
</Table.Tr>
|
|
))}
|
|
</Table.Tbody>
|
|
</Table>
|
|
)}
|
|
|
|
{selectedSpaceId && (
|
|
<SpaceSettingsModal
|
|
opened={opened}
|
|
onClose={close}
|
|
spaceId={selectedSpaceId}
|
|
/>
|
|
)}
|
|
</>
|
|
);
|
|
}
|