|
1 |
| -import { Box, Button, Collapse, Flex, Spinner, Text, useDisclosure } from '@chakra-ui/react'; |
| 1 | +import { Box, Button, Collapse, Flex, Spinner, useDisclosure } from '@chakra-ui/react'; |
2 | 2 | import { UserRole } from '@prisma/client';
|
3 | 3 | import { useSession } from 'next-auth/react';
|
4 | 4 | import { SessionUser } from '../../pages/api/auth/[...nextauth]';
|
5 |
| -import { trpc } from '../../utils/trpc'; |
| 5 | +import { TicketWithNames } from '../../server/trpc/router/ticket'; |
6 | 6 | import ActivityTable from './ActivityTable';
|
7 | 7 |
|
| 8 | +interface ActivityViewProps { |
| 9 | + helpedTickets: TicketWithNames[]; |
| 10 | + createdTickets: TicketWithNames[]; |
| 11 | +} |
| 12 | + |
8 | 13 | /**
|
9 | 14 | * Displays the activity log for the current user
|
10 | 15 | */
|
11 |
| -const ActivityView = () => { |
| 16 | +const ActivityView = (props: ActivityViewProps) => { |
| 17 | + const { helpedTickets, createdTickets } = props; |
12 | 18 | const { data: session } = useSession();
|
13 | 19 | const user = session?.user as SessionUser;
|
14 | 20 | const { isOpen: isHelpedTableOpen, onToggle: toggleHelpedTable } = useDisclosure();
|
15 | 21 | const { isOpen: isCreatedTableOpen, onToggle: toggleCreatedTable } = useDisclosure();
|
16 | 22 |
|
17 |
| - const { data: userTickets, isLoading: isTicketsLoading } = trpc.ticket.getTicketsWithUserId.useQuery( |
18 |
| - { userId: user.id, shouldSortByCreatedAt: true }, |
19 |
| - { refetchOnWindowFocus: false, enabled: !!user }, |
20 |
| - ); |
21 |
| - |
22 | 23 | return (
|
23 |
| - <> |
24 |
| - <Flex ml={4} mr={4} mt={4} mb={10} flexDirection='column'> |
25 |
| - <Text fontSize='3xl' fontWeight='semibold' mb={3}> |
26 |
| - Activity Log |
27 |
| - </Text> |
28 |
| - {isTicketsLoading ? ( |
29 |
| - <Spinner /> |
30 |
| - ) : ( |
31 |
| - <> |
32 |
| - <Flex> |
33 |
| - <Button mr={4} onClick={toggleHelpedTable} hidden={user.role === UserRole.STUDENT}> |
34 |
| - {isHelpedTableOpen ? 'Hide ' : 'Show '} helped tickets |
35 |
| - </Button> |
36 |
| - <Button onClick={toggleCreatedTable}>{isCreatedTableOpen ? 'Hide ' : 'Show '} created tickets</Button> |
37 |
| - </Flex> |
| 24 | + <Flex mr={4} flexDirection='column'> |
| 25 | + <Flex> |
| 26 | + <Button mr={4} onClick={toggleHelpedTable} hidden={user.role === UserRole.STUDENT}> |
| 27 | + {isHelpedTableOpen ? 'Hide ' : 'Show '} helped tickets |
| 28 | + </Button> |
| 29 | + <Button onClick={toggleCreatedTable}>{isCreatedTableOpen ? 'Hide ' : 'Show '} created tickets</Button> |
| 30 | + </Flex> |
38 | 31 |
|
39 |
| - <Box hidden={user.role === UserRole.STUDENT}> |
40 |
| - <Collapse in={isHelpedTableOpen} animateOpacity> |
41 |
| - <ActivityTable |
42 |
| - tickets={userTickets?.helpedTickets ?? []} |
43 |
| - title='Your helped tickets' |
44 |
| - shouldShowCreatedBy={true} |
45 |
| - /> |
46 |
| - </Collapse> |
47 |
| - </Box> |
| 32 | + <Box hidden={user.role === UserRole.STUDENT}> |
| 33 | + <Collapse in={isHelpedTableOpen} animateOpacity> |
| 34 | + <ActivityTable |
| 35 | + tickets={helpedTickets} |
| 36 | + title={`${helpedTickets.length} helped tickets`} |
| 37 | + shouldShowCreatedBy={true} |
| 38 | + /> |
| 39 | + </Collapse> |
| 40 | + </Box> |
48 | 41 |
|
49 |
| - <Box> |
50 |
| - <Collapse in={isCreatedTableOpen} animateOpacity> |
51 |
| - <ActivityTable |
52 |
| - tickets={userTickets?.createdTickets ?? []} |
53 |
| - title='Your created tickets' |
54 |
| - shouldShowCreatedBy={false} |
55 |
| - /> |
56 |
| - </Collapse> |
57 |
| - </Box> |
58 |
| - </> |
59 |
| - )} |
60 |
| - </Flex> |
61 |
| - </> |
| 42 | + <Box> |
| 43 | + <Collapse in={isCreatedTableOpen} animateOpacity> |
| 44 | + <ActivityTable |
| 45 | + tickets={createdTickets} |
| 46 | + title={`${createdTickets.length} created tickets`} |
| 47 | + shouldShowCreatedBy={false} |
| 48 | + /> |
| 49 | + </Collapse> |
| 50 | + </Box> |
| 51 | + </Flex> |
62 | 52 | );
|
63 | 53 | };
|
64 | 54 |
|
|
0 commit comments