feat: add empty state to events grid when no events exist
Signed-off-by: Noa Virellia <noa@requiem.garden>
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import type { EventInfo } from './types';
|
||||
import { FileQuestionMark } from 'lucide-react';
|
||||
import PlaceholderImage from '@/assets/event-placeholder.png';
|
||||
import { useGetEvents } from '@/hooks/data/useGetEvents';
|
||||
import { Button } from '../ui/button';
|
||||
import { DialogTrigger } from '../ui/dialog';
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from '../ui/empty';
|
||||
import { EventGridView } from './event-grid.view';
|
||||
import { KycDialogContainer } from './kyc/kyc.dialog.container';
|
||||
|
||||
@@ -10,31 +12,48 @@ export function EventGridContainer() {
|
||||
const { data, isLoading } = useGetEvents();
|
||||
const allEvents: EventInfo[] = isLoading
|
||||
? []
|
||||
: data.pages.flatMap(page => page.data!).map(it => ({
|
||||
type: it.type! as EventInfo['type'],
|
||||
eventId: it.event_id!,
|
||||
isJoined: it.is_joined!,
|
||||
requireKyc: it.enable_kyc!,
|
||||
coverImage: it.thumbnail! || PlaceholderImage,
|
||||
eventName: it.name!,
|
||||
description: it.description!,
|
||||
startTime: new Date(it.start_time!),
|
||||
endTime: new Date(it.end_time!),
|
||||
} satisfies EventInfo));
|
||||
: data.pages.flatMap(page => page.data ?? []).map(it => ({
|
||||
type: it.type! as EventInfo['type'],
|
||||
eventId: it.event_id!,
|
||||
isJoined: it.is_joined!,
|
||||
requireKyc: it.enable_kyc!,
|
||||
coverImage: it.thumbnail! || PlaceholderImage,
|
||||
eventName: it.name!,
|
||||
description: it.description!,
|
||||
startTime: new Date(it.start_time!),
|
||||
endTime: new Date(it.end_time!),
|
||||
} satisfies EventInfo));
|
||||
|
||||
return (
|
||||
<EventGridView
|
||||
events={allEvents}
|
||||
assembleFooter={eventInfo => (eventInfo.isJoined
|
||||
? <Button className="w-full" disabled>已加入</Button>
|
||||
: (
|
||||
<KycDialogContainer eventIdToJoin={eventInfo.eventId}>
|
||||
<DialogTrigger asChild>
|
||||
<Button className="w-full">加入活动</Button>
|
||||
</DialogTrigger>
|
||||
</KycDialogContainer>
|
||||
)
|
||||
<>
|
||||
{allEvents.length > 0 && (
|
||||
<EventGridView
|
||||
events={allEvents}
|
||||
assembleFooter={eventInfo => (eventInfo.isJoined
|
||||
? <Button className="w-full" disabled>已加入</Button>
|
||||
: (
|
||||
<KycDialogContainer eventIdToJoin={eventInfo.eventId}>
|
||||
<DialogTrigger asChild>
|
||||
<Button className="w-full">加入活动</Button>
|
||||
</DialogTrigger>
|
||||
</KycDialogContainer>
|
||||
)
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
{
|
||||
allEvents.length === 0 && (
|
||||
<Empty className="h-full">
|
||||
<EmptyHeader>
|
||||
<EmptyMedia variant="icon">
|
||||
<FileQuestionMark />
|
||||
</EmptyMedia>
|
||||
<EmptyTitle>暂无活动</EmptyTitle>
|
||||
<EmptyDescription>前面的区域 以后再来探索吧</EmptyDescription>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
)
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
104
client/cms/src/components/ui/empty.tsx
Normal file
104
client/cms/src/components/ui/empty.tsx
Normal file
@@ -0,0 +1,104 @@
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Empty({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="empty"
|
||||
className={cn(
|
||||
"flex min-w-0 flex-1 flex-col items-center justify-center gap-6 rounded-lg border-dashed p-6 text-center text-balance md:p-12",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function EmptyHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="empty-header"
|
||||
className={cn(
|
||||
"flex max-w-sm flex-col items-center gap-2 text-center",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const emptyMediaVariants = cva(
|
||||
"flex shrink-0 items-center justify-center mb-2 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-transparent",
|
||||
icon: "bg-muted text-foreground flex size-10 shrink-0 items-center justify-center rounded-lg [&_svg:not([class*='size-'])]:size-6",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function EmptyMedia({
|
||||
className,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & VariantProps<typeof emptyMediaVariants>) {
|
||||
return (
|
||||
<div
|
||||
data-slot="empty-icon"
|
||||
data-variant={variant}
|
||||
className={cn(emptyMediaVariants({ variant, className }))}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function EmptyTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="empty-title"
|
||||
className={cn("text-lg font-medium tracking-tight", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function EmptyDescription({ className, ...props }: React.ComponentProps<"p">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="empty-description"
|
||||
className={cn(
|
||||
"text-muted-foreground [&>a:hover]:text-primary text-sm/relaxed [&>a]:underline [&>a]:underline-offset-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function EmptyContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="empty-content"
|
||||
className={cn(
|
||||
"flex w-full max-w-sm min-w-0 flex-col items-center gap-4 text-sm text-balance",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Empty,
|
||||
EmptyHeader,
|
||||
EmptyTitle,
|
||||
EmptyDescription,
|
||||
EmptyContent,
|
||||
EmptyMedia,
|
||||
}
|
||||
@@ -7,7 +7,7 @@ export const Route = createFileRoute('/_workbenchLayout/events')({
|
||||
|
||||
function RouteComponent() {
|
||||
return (
|
||||
<div className="py-4 px-6 md:gap-6 md:py-6">
|
||||
<div className="py-4 px-6 md:gap-6 md:py-6 h-full">
|
||||
<EventGridContainer />
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user