forked from CyberAgentHack/web-speed-hackathon-2024
/
index.tsx
92 lines (84 loc) · 2.73 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {
Divider,
Flex,
Modal,
ModalCloseButton,
ModalContent,
ModalOverlay,
Stack,
Table,
TableContainer,
Tbody,
Td,
Text,
Th,
Thead,
Tr,
} from '@chakra-ui/react';
import { useToggle } from '@uidotdev/usehooks';
import { useAuthor } from '../../../../features/authors/hooks/useAuthor';
import { AuthorDetailContent } from './AuthorDetailContent';
import { AuthorEditContent } from './AuthorEditContent';
export type Props = {
authorId: string;
isOpen: boolean;
onClose: () => void;
};
export const AuthorDetailModal: React.FC<Props> = ({ authorId, isOpen, onClose }) => {
const { data: author } = useAuthor({ authorId });
const [isEdit, toggleIsEdit] = useToggle(false);
const bookList = author?.books;
return (
<Modal isOpen={isOpen} onClose={onClose} size="4xl">
<ModalOverlay />
<ModalContent containerProps={{ p: 8 }} height="100%" m={0} overflowY="auto">
<ModalCloseButton />
<Stack height="100%" p={4}>
{author != null && (
<>
{isEdit ? (
<AuthorEditContent author={author} onEditComplete={() => toggleIsEdit()} />
) : (
<AuthorDetailContent author={author} onCloseDialog={onClose} onEdit={() => toggleIsEdit()} />
)}
</>
)}
<Divider />
<Flex flexGrow={1} flexShrink={1} overflow="hidden">
{bookList != null && (
<>
{bookList.length !== 0 ? (
<TableContainer flexGrow={1} flexShrink={1} overflowY="auto">
<Table aria-label="作品一覧" variant="striped">
<Thead backgroundColor="white" position="sticky" top={0} zIndex={1}>
<Tr>
<Th>作品名</Th>
</Tr>
</Thead>
<Tbody>
{bookList.map((book) => (
<Tr key={book.id}>
<Td verticalAlign="middle">
<Text fontWeight="bold">{book.name}</Text>
<Text color="gray.400" fontSize="small">
{book.id}
</Text>
</Td>
</Tr>
))}
</Tbody>
</Table>
</TableContainer>
) : (
<Text align="center" flexGrow={1} flexShrink={1} pt={2}>
作品はまだありません
</Text>
)}
</>
)}
</Flex>
</Stack>
</ModalContent>
</Modal>
);
};