Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/components/common/EmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ import { Button } from '@/components/ui/button';
import { RotateCcw } from 'lucide-react';
import { EMPTY_STATE_ILLUSTRATION_SIZES } from './emptyStateIllustration.config';

interface EmptyStateCta {
label: string;
onClick: () => void;
}

interface EmptyStateProps {
image: string;
title: string;
description: string;
className?: string;
/** @deprecated Use `cta` — kept for the existing search-reset callers. */
onReset?: () => void;
/** Generic optional call-to-action, e.g. linking a zero-result list back to discovery. */
cta?: EmptyStateCta;
}

const EmptyState: React.FC<EmptyStateProps> = ({
Expand All @@ -17,6 +25,7 @@ const EmptyState: React.FC<EmptyStateProps> = ({
description,
className,
onReset,
cta,
}: EmptyStateProps) => {
return (
<div
Expand Down Expand Up @@ -62,6 +71,16 @@ const EmptyState: React.FC<EmptyStateProps> = ({
Reset Search
</Button>
)}

{!onReset && cta && (
<Button
onClick={cta.onClick}
variant="outline"
className="rounded-xl border-white/10 bg-white/5 px-6 font-bold text-white transition-all hover:border-amber-500/30 hover:bg-amber-500/10"
>
{cta.label}
</Button>
)}
</div>
);
};
Expand Down
75 changes: 75 additions & 0 deletions src/components/common/__tests__/EmptyState.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import EmptyState from '../EmptyState';

describe('EmptyState', () => {
it('renders the title and description', () => {
render(
<EmptyState
image="/images/no-results.png"
title="No holdings yet"
description="You don't currently hold any creator keys."
/>
);

expect(screen.getByText('No holdings yet')).toBeInTheDocument();
expect(
screen.getByText("You don't currently hold any creator keys.")
).toBeInTheDocument();
});

it('renders no action button when neither onReset nor cta is supplied', () => {
render(
<EmptyState image="/images/no-results.png" title="Empty" description="Nothing here." />
);

expect(screen.queryByRole('button')).not.toBeInTheDocument();
});

it('renders the legacy reset button and calls onReset when clicked', () => {
const onReset = vi.fn();
render(
<EmptyState
image="/images/no-results.png"
title="No creators found"
description="Try a different search."
onReset={onReset}
/>
);

fireEvent.click(screen.getByRole('button', { name: /reset search results/i }));
expect(onReset).toHaveBeenCalledTimes(1);
});

it('renders a generic cta button and calls its onClick when clicked', () => {
const onClick = vi.fn();
render(
<EmptyState
image="/images/no-results.png"
title="No holdings yet"
description="Discover creators to get started."
cta={{ label: 'Discover creators', onClick }}
/>
);

fireEvent.click(screen.getByRole('button', { name: 'Discover creators' }));
expect(onClick).toHaveBeenCalledTimes(1);
});

it('prefers onReset over cta when both are somehow supplied', () => {
const onReset = vi.fn();
const onClick = vi.fn();
render(
<EmptyState
image="/images/no-results.png"
title="No creators found"
description="Try a different search."
onReset={onReset}
cta={{ label: 'Discover creators', onClick }}
/>
);

expect(screen.getByRole('button', { name: /reset search results/i })).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Discover creators' })).not.toBeInTheDocument();
});
});
17 changes: 17 additions & 0 deletions src/pages/LandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,23 @@ function LandingPage() {
</div>
{isLoading ? (
<CreatorHoldingsListSkeleton className="mt-6" />
) : heldKeyPositions.filter(
position => position.quantity && position.quantity > 0
).length === 0 ? (
<EmptyState
className="mt-6"
image="/images/no-results.png"
title="No holdings yet"
description="You don't currently hold any creator keys. Discover creators to get started."
cta={{
label: 'Discover creators',
onClick: () => {
document
.getElementById('main-creator-list')
?.scrollIntoView({ behavior: 'smooth', block: 'start' });
},
}}
/>
) : (
<div className="mt-6 grid gap-3 sm:grid-cols-2 lg:grid-cols-3">
{heldKeyPositions
Expand Down
Loading