Skip to content
Merged
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
3 changes: 3 additions & 0 deletions apps/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ExplorePage from './features/explore/ExplorePage';
import CookbookPage from './features/cookbook/CookbookPage';
import RecipeCreatePage from './features/recipes/RecipeCreatePage';
import RecipeDetailPage from './features/recipe-detail/RecipeDetailPage';
import NotFoundPage from './features/not-found/NotFoundPage';

export function App() {
const restoreSession = useAppStore((state) => state.restoreSession);
Expand All @@ -32,6 +33,8 @@ export function App() {
<Route path="/recipes/:id" element={<RecipeDetailPage />} />
<Route path="/login" element={<LoginPage />} />
<Route path="/register" element={<RegisterPage />} />

<Route path="*" element={<NotFoundPage />} />
</Route>
</Routes>
);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 108 additions & 0 deletions apps/web/src/features/not-found/NotFoundPage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
@layer components {
.not-found-page {
display: grid;
place-items: center;

min-height: 72dvh;
padding: var(--space-10) var(--space-4) var(--space-16);
}

.not-found-page__card {
display: flex;
flex-direction: column;
align-items: center;

width: min(100%, 39rem);
padding: var(--space-10) var(--space-8) var(--space-8);

text-align: center;

background-color: var(--color-surface);
border: var(--border-width-thin) solid var(--color-border-default);
border-radius: var(--radius-xl);
box-shadow: var(--shadow-md);
}

.not-found-page__illustration {
width: clamp(5rem, 12vw, 7rem);
height: auto;

margin-block-end: var(--space-3);

object-fit: contain;
}

.not-found-page__content {
display: flex;
flex-direction: column;
align-items: center;
gap: var(--space-2);
}

.not-found-page__code {
margin: 0;

font-size: clamp(4rem, 9vw, 5.5rem);
font-weight: var(--font-weight-bold);
line-height: 0.95;
letter-spacing: -0.04em;
}

.not-found-page__title {
margin: 0;

font-size: var(--font-size-2xl);
font-weight: var(--font-weight-bold);
line-height: var(--line-height-tight);
}

.not-found-page__description {
margin: 0;

color: var(--color-text-secondary);

font-size: var(--font-size-lg);
line-height: var(--line-height-relaxed);
}

.not-found-page__actions {
display: flex;
justify-content: center;
gap: var(--space-3);

width: 100%;
margin-block-start: var(--space-6);
}

.not-found-page__actions > * {
min-width: 9.5rem;
}

.not-found-page__hint {
margin: var(--space-5) 0 0;

color: var(--color-text-secondary);

font-size: var(--font-size-sm);
line-height: var(--line-height-relaxed);
}

@media (max-width: 36rem) {
.not-found-page {
min-height: auto;
padding-block: var(--space-8) var(--space-12);
}

.not-found-page__card {
padding: var(--space-8) var(--space-5);
}

.not-found-page__actions {
flex-direction: column;
}

.not-found-page__actions > * {
width: 100%;
}
}
}
63 changes: 63 additions & 0 deletions apps/web/src/features/not-found/NotFoundPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { useNavigate } from 'react-router-dom';

import Button from '../../components/ui/Button/Button';
import LinkButton from '../../components/ui/LinkButton/LinkButton';
import chefHatIllustration from '../../assets/illustrations/not-found-chef-hat.png';

import './NotFoundPage.css';

function NotFoundPage() {
const navigate = useNavigate();

function handleGoBack() {
navigate(-1);
}

return (
<section className="not-found-page" aria-labelledby="not-found-title">
<div className="not-found-page__card">
<img
className="not-found-page__illustration"
src={chefHatIllustration}
alt=""
aria-hidden="true"
/>

<div className="not-found-page__content">
<p className="not-found-page__code" aria-hidden="true">
404
</p>

<h1 id="not-found-title" className="not-found-page__title">
Page not found
</h1>

<p className="not-found-page__description">
The recipe you’re looking for isn’t here.
</p>
</div>

<div className="not-found-page__actions">
<LinkButton to="/" size="lg">
Explore Recipes
</LinkButton>

<Button
type="button"
variant="secondary"
size="lg"
onClick={handleGoBack}
>
Go Back
</Button>
</div>

<p className="not-found-page__hint">
Try searching or return to Explore.
</p>
</div>
</section>
);
}

export default NotFoundPage;
50 changes: 50 additions & 0 deletions e2e/smoke.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,53 @@ test('collapses the header before navigation actions overflow', async ({
await page.evaluate(() => document.documentElement.clientWidth),
);
});

test('returns to Explore from the global not-found page', async ({ page }) => {
await page.goto('this-route-does-not-exist');

await page.getByRole('link', { name: 'Explore Recipes' }).click();

await expect(
page.getByRole('heading', { name: 'Explore Recipes' }),
).toBeVisible();

await expect(
page.getByRole('heading', { name: 'Page not found' }),
).not.toBeVisible();
});

test('Go Back returns to the previous page from the global not-found page', async ({
page,
}) => {
await page.goto('.');

await expect(
page.getByRole('heading', { name: 'Explore Recipes' }),
).toBeVisible();

await page.goto('this-route-does-not-exist');

await expect(
page.getByRole('heading', { name: 'Page not found' }),
).toBeVisible();

await page.getByRole('button', { name: 'Go Back' }).click();

await expect(
page.getByRole('heading', { name: 'Explore Recipes' }),
).toBeVisible();
});

test('keeps recipe-specific not-found handling separate from the global 404', async ({
page,
}) => {
await page.goto('recipes/does-not-exist');

await expect(
page.getByRole('heading', { name: 'Recipe not found' }),
).toBeVisible();

await expect(
page.getByRole('heading', { name: 'Page not found' }),
).not.toBeVisible();
});