-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
290 additions
and
55 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
101 changes: 101 additions & 0 deletions
101
src/app/[locale]/(console)/organisation/[organisation]/events/[id]/[subpage]/attendees.tsx
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,101 @@ | ||
'use client'; | ||
|
||
import { AttendsTable } from '@/components/data/attends/table'; | ||
import { LoaderOverlay } from '@/components/layout/LoaderOverlay'; | ||
import { NotFoundScreen } from '@/components/layout/NotFoundScreen'; | ||
import { Pagination, usePagination } from '@/components/logic/Pagination'; | ||
import { Button } from '@/components/ui/button'; | ||
import { useSurreal } from '@/lib/Surreal'; | ||
import { RichAttends } from '@/schema/relations/attends'; | ||
import { Event } from '@/schema/resources/event'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { RefreshCw } from 'lucide-react'; | ||
import { useTranslations } from 'next-intl'; | ||
import React from 'react'; | ||
import { z } from 'zod'; | ||
|
||
export default function EventAttendeesTab({ event }: { event: Event }) { | ||
const pagination = usePagination(); | ||
|
||
const t = useTranslations('pages.console.organisation.events'); | ||
const { isPending, data, refetch, error } = useData({ | ||
event: event.id, | ||
pagination, | ||
}); | ||
console.log(error); | ||
|
||
if (isPending) return <LoaderOverlay />; | ||
if (!data) return <NotFoundScreen text={t('not_found')} />; | ||
|
||
const { attendees, count } = data; | ||
|
||
return ( | ||
<div className="flex flex-grow flex-col gap-6 pt-6"> | ||
<div className="flex justify-start gap-4 pb-2"> | ||
<Button variant="outline" size="icon" onClick={() => refetch()}> | ||
<RefreshCw size={20} /> | ||
</Button> | ||
</div> | ||
<div className="rounded-md border"> | ||
<AttendsTable attendees={attendees ?? []} /> | ||
</div> | ||
<div className="flex items-center justify-end gap-10 pt-2"> | ||
<Pagination pagination={pagination} count={count} /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
function useData({ | ||
event, | ||
published, | ||
discoverable, | ||
pagination: { start, limit }, | ||
}: { | ||
event: Event['id']; | ||
published?: boolean; | ||
discoverable?: boolean; | ||
pagination: { | ||
start: number; | ||
limit: number; | ||
}; | ||
}) { | ||
const surreal = useSurreal(); | ||
return useQuery({ | ||
queryKey: ['organisation', 'event-attendees', event, { start, limit }], | ||
retry: false, | ||
queryFn: async () => { | ||
console.log(0); | ||
const result = await surreal.query< | ||
[null[], RichAttends[], { count: number }[]] | ||
>( | ||
/* surql */ ` | ||
LET $event = <record<event>> $event; | ||
SELECT * FROM $event<-attends | ||
START $start | ||
LIMIT $limit | ||
FETCH in, out, players.*; | ||
SELECT count() FROM $event<-attends | ||
GROUP ALL; | ||
`, | ||
{ | ||
event, | ||
published, | ||
discoverable, | ||
start, | ||
limit, | ||
} | ||
); | ||
|
||
console.log(1, result); | ||
if (!result?.[1] || !result?.[2]) return null; | ||
|
||
return { | ||
count: z.number().parse(result[2][0]?.count ?? 0), | ||
attendees: z.array(RichAttends).parse(result[1]), | ||
}; | ||
}, | ||
}); | ||
} |
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
7 changes: 0 additions & 7 deletions
7
...pp/[locale]/(console)/organisation/[organisation]/events/[id]/[subpage]/registrations.tsx
This file was deleted.
Oops, something went wrong.
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,170 @@ | ||
import { Avatar } from '@/components/cards/avatar'; | ||
import { Profile } from '@/components/cards/profile'; | ||
import { DateTooltip } from '@/components/miscellaneous/DateTooltip'; | ||
import { | ||
Table, | ||
TableBody, | ||
TableCaption, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
} from '@/components/ui/table'; | ||
import { RichAttends } from '@/schema/relations/attends'; | ||
import { Check, FileSearch, X } from 'lucide-react'; | ||
import React, { ReactNode } from 'react'; | ||
|
||
export type AttendsTableColumns = { | ||
in?: boolean; | ||
out?: boolean; | ||
players?: boolean; | ||
confirmed?: boolean; | ||
created?: boolean; | ||
updated?: boolean; | ||
actions?: boolean; | ||
}; | ||
|
||
export function AttendsTable({ | ||
attendees, | ||
columns, | ||
caption, | ||
}: { | ||
attendees: RichAttends[]; | ||
columns?: AttendsTableColumns; | ||
caption?: ReactNode; | ||
}) { | ||
const doRenderCol = (col: keyof AttendsTableColumns) => | ||
columns?.[col] ?? true; | ||
|
||
return ( | ||
<Table> | ||
<TableHeader> | ||
<TableRow> | ||
{doRenderCol('in') && <TableHead>Registrant</TableHead>} | ||
{doRenderCol('out') && <TableHead>Event</TableHead>} | ||
{doRenderCol('players') && <TableHead>Players</TableHead>} | ||
{doRenderCol('confirmed') && ( | ||
<TableHead>Confirmed</TableHead> | ||
)} | ||
{doRenderCol('created') && <TableHead>Created</TableHead>} | ||
{doRenderCol('updated') && <TableHead>Updated</TableHead>} | ||
{doRenderCol('actions') && <TableHead />} | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{attendees?.map((attends) => { | ||
return ( | ||
<TableRow key={attends.id}> | ||
{doRenderCol('in') && ( | ||
<TableCell> | ||
<Profile | ||
profile={attends.in} | ||
noSub | ||
clickable | ||
size="extra-tiny" | ||
/> | ||
</TableCell> | ||
)} | ||
{doRenderCol('out') && ( | ||
<TableCell> | ||
<Profile | ||
profile={attends.out} | ||
noSub | ||
clickable | ||
size="extra-tiny" | ||
renderBadge={false} | ||
/> | ||
</TableCell> | ||
)} | ||
{doRenderCol('players') && ( | ||
<TableCell className="flex -space-x-2"> | ||
{attends.players | ||
.slice(0, 5) | ||
.map((player) => ( | ||
<Avatar | ||
key={player.id} | ||
profile={player} | ||
size="extra-tiny" | ||
/> | ||
))} | ||
</TableCell> | ||
)} | ||
{doRenderCol('confirmed') && ( | ||
<TableCell> | ||
{attends.confirmed ? ( | ||
<Check size={20} /> | ||
) : ( | ||
<X size={20} /> | ||
)} | ||
</TableCell> | ||
)} | ||
{doRenderCol('created') && ( | ||
<TableCell> | ||
<DateTooltip date={attends.created} /> | ||
</TableCell> | ||
)} | ||
{doRenderCol('updated') && ( | ||
<TableCell> | ||
<DateTooltip date={attends.updated} /> | ||
</TableCell> | ||
)} | ||
{doRenderCol('actions') && ( | ||
<TableCell className="flex items-center justify-end gap-4"> | ||
{/* <Link | ||
href={url('overview')} | ||
className={buttonVariants({ | ||
size: 'sm', | ||
})} | ||
> | ||
{t('row.actions.manage')} | ||
<ArrowRight | ||
size={18} | ||
className="ml-2" | ||
/> | ||
</Link> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button size="icon" variant="ghost"> | ||
<MoreHorizontal size={20} /> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent className="w-44"> | ||
<DropdownMenuLabel> | ||
{t( | ||
'row.actions.more-options.label' | ||
)} | ||
</DropdownMenuLabel> | ||
<DropdownMenuSeparator /> | ||
<Link href={url('settings')}> | ||
<DropdownMenuItem className="hover:cursor-pointer"> | ||
<Wrench | ||
size={18} | ||
className="mr-2 h-4 w-4" | ||
/> | ||
{t( | ||
'row.actions.more-options.settings' | ||
)} | ||
</DropdownMenuItem> | ||
</Link> | ||
</DropdownMenuContent> | ||
</DropdownMenu> */} | ||
</TableCell> | ||
)} | ||
</TableRow> | ||
); | ||
})} | ||
</TableBody> | ||
{attendees?.length == 0 ? ( | ||
<TableCaption className="my-12"> | ||
<div className="flex items-center justify-center gap-1"> | ||
<FileSearch className="h-4 w-4" /> No attendees | ||
</div> | ||
</TableCaption> | ||
) : ( | ||
caption && ( | ||
<TableCaption className="mb-4">{caption}</TableCaption> | ||
) | ||
)} | ||
</Table> | ||
); | ||
} |
Oops, something went wrong.