-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from Cassianky/events
Event Page (Attendance)
- Loading branch information
Showing
11 changed files
with
385 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
import * as React from 'react' | ||
import { | ||
Table, | ||
Thead, | ||
Tbody, | ||
Tr, | ||
Th, | ||
Td, | ||
chakra, | ||
Box, | ||
Icon, | ||
} from '@chakra-ui/react' | ||
import { BsArrowDownUp, BsChevronDown, BsChevronUp } from 'react-icons/bs' | ||
import { | ||
useReactTable, | ||
flexRender, | ||
getCoreRowModel, | ||
ColumnDef, | ||
SortingState, | ||
getSortedRowModel, | ||
} from '@tanstack/react-table' | ||
|
||
export type DataTableProps<Data extends object> = { | ||
data: Data[] | ||
columns: ColumnDef<Data, any>[] | ||
} | ||
|
||
export function DataTable<Data extends object>({ | ||
data, | ||
columns, | ||
}: DataTableProps<Data>) { | ||
const [sorting, setSorting] = React.useState<SortingState>([]) | ||
const table = useReactTable({ | ||
columns, | ||
data, | ||
getCoreRowModel: getCoreRowModel(), | ||
onSortingChange: setSorting, | ||
getSortedRowModel: getSortedRowModel(), | ||
state: { | ||
sorting, | ||
}, | ||
}) | ||
|
||
return ( | ||
<Box | ||
overflowY="auto" | ||
maxHeight="60vh" | ||
borderTop="3px solid #002D70" | ||
borderBottom="3px solid #002D70" | ||
sx={{ | ||
'&::-webkit-scrollbar': { | ||
width: '15px', | ||
outline: '3px solid #002D70', | ||
}, | ||
'&::-webkit-scrollbar-thumb': { | ||
backgroundColor: `#004B90`, | ||
borderRadius: '20px', | ||
border: '5px solid transparent', | ||
backgroundClip: 'content-box', | ||
}, | ||
}} | ||
> | ||
<Table> | ||
<Thead> | ||
{table.getHeaderGroups().map((headerGroup) => ( | ||
<Tr key={headerGroup.id}> | ||
<Th | ||
color="white" | ||
bgColor="#01003D" | ||
fontSize={{ base: '10px', md: '16px', lg: '20px' }} | ||
py={5} | ||
px={{ base: '2px', md: '6px', lg: '10px' }} | ||
textTransform="capitalize" | ||
textAlign="center" | ||
borderX="3px solid #002D70" | ||
borderY="none" | ||
fontWeight={600} | ||
position="sticky" | ||
zIndex={1} | ||
top={0} | ||
> | ||
Number | ||
</Th> | ||
{headerGroup.headers.map((header) => { | ||
// see https://tanstack.com/table/v8/docs/api/core/column-def#meta to type this correctly | ||
const meta: any = header.column.columnDef.meta | ||
return ( | ||
<Th | ||
color="white" | ||
bgColor="#01003D" | ||
fontSize={{ base: '10px', md: '16px', lg: '20px' }} | ||
py={5} | ||
px={{ base: '2px', md: '6px', lg: '10px' }} | ||
textTransform="capitalize" | ||
textAlign="center" | ||
borderX="3px solid #002D70" | ||
borderY="none" | ||
position="sticky" | ||
zIndex={1} | ||
top={0} | ||
key={header.id} | ||
onClick={header.column.getToggleSortingHandler()} | ||
isNumeric={meta?.isNumeric} | ||
> | ||
{flexRender( | ||
header.column.columnDef.header, | ||
header.getContext() | ||
)} | ||
|
||
<chakra.span pl="4"> | ||
{header.column.getIsSorted() ? ( | ||
header.column.getIsSorted() === 'desc' ? ( | ||
<Icon | ||
className="hover:cursor-pointer" | ||
aria-label="sorted descending" | ||
color="#F9813E" | ||
style={{ strokeWidth: '1.5' }} | ||
as={BsChevronDown} | ||
/> | ||
) : ( | ||
<Icon | ||
className="hover:cursor-pointer" | ||
aria-label="sorted descending" | ||
color="#F9813E" | ||
style={{ strokeWidth: '1.5' }} | ||
as={BsChevronUp} | ||
/> | ||
) | ||
) : ( | ||
<Icon | ||
className="hover:cursor-pointer" | ||
color="#F9813E" | ||
style={{ strokeWidth: '1.5' }} | ||
as={BsArrowDownUp} | ||
/> | ||
)} | ||
</chakra.span> | ||
</Th> | ||
) | ||
})} | ||
</Tr> | ||
))} | ||
</Thead> | ||
<Tbody> | ||
{table.getRowModel().rows.map((row) => ( | ||
<Tr key={row.id}> | ||
<Td | ||
py={5} | ||
px={{ base: '2px', md: '6px', lg: '10px' }} | ||
fontSize={{ base: '10px', md: '16px', lg: '20px' }} | ||
textAlign="center" | ||
borderX="3px solid #002D70" | ||
borderY="none" | ||
fontWeight={600} | ||
> | ||
{parseInt(row.id, 10) + 1} | ||
</Td> | ||
{row.getVisibleCells().map((cell) => { | ||
const meta: any = cell.column.columnDef.meta | ||
return ( | ||
<Td | ||
py={5} | ||
px={{ base: '2px', md: '6px', lg: '10px' }} | ||
fontSize={{ base: '10px', md: '16px', lg: '20px' }} | ||
textAlign="center" | ||
borderX="3px solid #002D70" | ||
borderY="none" | ||
fontWeight={600} | ||
key={cell.id} | ||
isNumeric={meta?.isNumeric} | ||
> | ||
{flexRender(cell.column.columnDef.cell, cell.getContext())} | ||
</Td> | ||
) | ||
})} | ||
</Tr> | ||
))} | ||
</Tbody> | ||
</Table> | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { VStack, Button, Progress, useBreakpointValue } from '@chakra-ui/react' | ||
import { DataTable } from '~/components/attendance/DataTable' | ||
import { trpc } from '~/utils/trpc' | ||
import React from 'react' | ||
import Head from 'next/head' | ||
import { useRouter } from 'next/router' | ||
import { createColumnHelper } from '@tanstack/react-table' | ||
import { AddIcon } from '@chakra-ui/icons' | ||
import { useState } from 'react' | ||
import TopNavbar from '~/components/common/TopNavbar' | ||
|
||
const AttendancePage = () => { | ||
const router = useRouter() | ||
const isSmallScreen = useBreakpointValue({ base: true, md: false }) | ||
const [eventInfoData, setEventInfoData] = useState<eventInfos[]>([]) | ||
|
||
trpc.attendance.getAllAttendance.useQuery(undefined, { | ||
onSuccess: (data: eventInfos[]) => setEventInfoData(data), | ||
}) | ||
|
||
type eventInfos = { | ||
number: string | ||
name: string | ||
total_users: string | ||
total_attendees: string | ||
startDate: string | ||
endDate: string | ||
} | ||
|
||
const columnHelper = createColumnHelper<eventInfos>() | ||
|
||
const columns = [ | ||
columnHelper.accessor('name', { | ||
cell: (info) => info.getValue(), | ||
header: 'Name', | ||
}), | ||
columnHelper.accessor('startDate', { | ||
cell: (info) => { | ||
const date = new Date(info.getValue().toString()) | ||
const formattedDate = date.toLocaleDateString('en-GB') | ||
return formattedDate | ||
}, | ||
header: 'Start Date', | ||
}), | ||
columnHelper.accessor('endDate', { | ||
cell: (info) => { | ||
const date = new Date(info.getValue().toString()) | ||
const formattedDate = date.toLocaleDateString('en-GB') | ||
return formattedDate | ||
}, | ||
header: 'End Date', | ||
}), | ||
columnHelper.accessor( | ||
(row) => ({ | ||
total_attendees: row.total_attendees, | ||
total_users: row.total_users, | ||
}), | ||
{ | ||
cell: (info) => { | ||
return ( | ||
<div> | ||
<p className="mb-2"> | ||
{info.getValue().total_attendees.toString()}/ | ||
{info.getValue().total_users.toString()} | ||
</p> | ||
<Progress | ||
rounded="md" | ||
background="#4365DD" | ||
colorScheme="progress" | ||
value={ | ||
(Number(info.getValue().total_attendees.toString()) / | ||
Number(info.getValue().total_users.toString())) * | ||
100 | ||
} | ||
></Progress> | ||
</div> | ||
) | ||
}, | ||
header: 'Attendance', | ||
} | ||
), | ||
] | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>Attendance</title> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<meta name="description" content="The attendance page for Atlas" /> | ||
</Head> | ||
<TopNavbar /> | ||
<div className="px-2 sm:px-6 sm:pt-5 md:px-20 md:pt-5 lg:px-28 lg:pt-5"> | ||
<h1 className="mb-10 text-center text-2xl font-bold">Attendance</h1> | ||
<VStack align="left" className="mb-10"> | ||
{isSmallScreen ? ( | ||
<Button | ||
bgColor="#97AEFF" | ||
width={45} | ||
className="mb-10 text-black" | ||
borderRadius="full" | ||
fontSize={15} | ||
onClick={() => router.push('/events/create')} | ||
> | ||
<AddIcon /> | ||
</Button> | ||
) : ( | ||
<Button | ||
bgColor="#97AEFF" | ||
width={215} | ||
className="mb-10 text-black" | ||
onClick={() => router.push('/events/create')} | ||
> | ||
Create Event | ||
</Button> | ||
)} | ||
<DataTable columns={columns} data={eventInfoData} /> | ||
</VStack> | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default AttendancePage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.