forked from CyberAgentHack/web-speed-hackathon-2024
/
index.tsx
121 lines (111 loc) · 3.82 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import {
Button,
Divider,
Flex,
Modal,
ModalCloseButton,
ModalContent,
ModalOverlay,
Stack,
Table,
TableContainer,
Tbody,
Td,
Text,
Th,
Thead,
Tr,
} from '@chakra-ui/react';
import { Link } from '@tanstack/react-router';
import { useToggle } from '@uidotdev/usehooks';
import type { GetBookResponse } from '@wsh-2024/schema/src/api/books/GetBookResponse';
import { useEpisodeList } from '../../../../features/episodes/hooks/useEpisodeList';
import { BookDetailContent } from './BookDetailContent';
import { BookEditContent } from './BookEditContent';
type Props = {
book: GetBookResponse;
isOpen: boolean;
onClose: () => void;
};
export const BookDetailModal: React.FC<Props> = ({ book, isOpen, onClose }) => {
const { data: episodeList } = useEpisodeList({ bookId: book.id });
// const { data: book } = useBook({ bookId });
const [isEdit, toggleIEdit] = useToggle(false);
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}>
{book != null && (
<>
{isEdit ? (
<BookEditContent book={book} onEditComplete={() => toggleIEdit()} />
) : (
<BookDetailContent book={book} onCloseDialog={onClose} onEdit={() => toggleIEdit()} />
)}
</>
)}
<Divider />
<Flex flexGrow={1} flexShrink={1} overflow="hidden">
{episodeList != null && (
<>
{episodeList.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 w={120}></Th>
<Th>エピソード名</Th>
</Tr>
</Thead>
<Tbody>
{episodeList.map((episode) => (
<Tr key={episode.id}>
<Td textAlign="center" verticalAlign="middle">
<Button
as={Link}
colorScheme="teal"
role="button"
to={`/admin/books/${book.id}/episodes/${episode.id}`}
variant="solid"
>
編集
</Button>
</Td>
<Td verticalAlign="middle">
<Text fontWeight="bold">{episode.name}</Text>
<Text color="gray.400" fontSize="small">
{episode.id}
</Text>
</Td>
</Tr>
))}
</Tbody>
</Table>
</TableContainer>
) : (
<Text align="center" flexGrow={1} flexShrink={1} pt={2}>
エピソードがありません
</Text>
)}
</>
)}
</Flex>
<Flex justifyContent="flex-end">
<Button
as={Link}
colorScheme="teal"
mt={4}
role="button"
to={`/admin/books/${book.id}/episodes/new`}
variant="solid"
>
エピソードを追加
</Button>
</Flex>
</Stack>
</ModalContent>
</Modal>
);
};