Skip to content

Commit

Permalink
Merge pull request #1 from anastasiiavorobiova/feat/utility-pages
Browse files Browse the repository at this point in the history
Feat/utility pages
  • Loading branch information
anastasiiavorobiova authored Sep 17, 2024
2 parents 8b9c148 + 8f1d758 commit dbbb9bf
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 17 deletions.
2 changes: 0 additions & 2 deletions .husky/pre-commit

This file was deleted.

15 changes: 9 additions & 6 deletions public/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@
"method": "Method",
"url": "URL"
},
"Error": {
"404": {
"title": "Looks like you're lost.",
"heading": "This page not found. Perhaps you were looking for something else?",
"back": "Back"
}
"NotFound": {
"title": "Looks like you're lost.",
"text": "This page not found. Perhaps you were looking for something else?",
"back": "Back"
},
"ErrorPage": {
"title": "Something bad just happened...",
"text": "Our servers could not handle your request. Don't worry, try refreshing the page.",
"button": "Refresh the page"
}
}
15 changes: 9 additions & 6 deletions public/messages/ua.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@
"method": "Метод",
"url": "Посилання"
},
"Error": {
"404": {
"title": "Схоже, Ви заблукали.",
"heading": "Веб сторінку не знайдено. Можливо, ви шукали щось інше?",
"back": "Повернутись"
}
"NotFound": {
"title": "Схоже, Ви заблукали.",
"text": "Веб сторінку не знайдено. Можливо, ви шукали щось інше?",
"back": "Повернутись"
},
"ErrorPage": {
"title": "Щось пішло не так...",
"text": "Наш сервер не зміг обробити запит. Не хвилюйтесь, спробуйте перезавантажити сторінку.",
"button": "Перезавантажити сторінку"
}
}
7 changes: 7 additions & 0 deletions src/app/[locale]/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use client';

import ErrorPage from '@/widgets/ErrorPage';

export default function ErrorBoundary({ reset }: { reset: () => void }) {
return <ErrorPage reset={reset} />;
}
1 change: 0 additions & 1 deletion src/app/[locale]/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ main {
}

header,
footer,
main {
padding: 20px;
}
Expand Down
9 changes: 9 additions & 0 deletions src/app/[locale]/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Center, Loader } from '@/shared/ui';

export default function Loading() {
return (
<Center h={100} w="100%">
<Loader color="teal" mx="auto" />
</Center>
);
}
4 changes: 2 additions & 2 deletions src/app/[locale]/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Container, Title, Text, Button, Group, NotFoundIcon } from '@/shared/ui
import styles from './NotFound.module.css';

export default function NotFoundPage({ reset }: { reset: () => void }) {
const t = useTranslations('Error.404');
const t = useTranslations('NotFound');

return (
<Container className={styles.root}>
Expand All @@ -15,7 +15,7 @@ export default function NotFoundPage({ reset }: { reset: () => void }) {
{t('title')}
</Title>
<Text c="dimmed" size="lg" ta="center" className={styles.description} data-testid="NotFoundTitle">
{t('heading')}
{t('text')}
</Text>
<Link href="/">
<Group justify="center">
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/ErrorPage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ErrorPage } from './ui/ErrorPage';

export default ErrorPage;
37 changes: 37 additions & 0 deletions src/widgets/ErrorPage/ui/ErrorPage.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.root {
padding-top: rem(80px);
padding-bottom: rem(80px);
}

.label {
text-align: center;
font-weight: 900;
font-size: rem(38px);
line-height: 1;
margin-bottom: calc(1.5 * var(--mantine-spacing-xl));
color: var(--mantine-color-gray-2);

@media (max-width: $mantine-breakpoint-sm) {
font-size: rem(32px);
}
}

.description {
max-width: rem(500px);
margin: auto;
margin-top: var(--mantine-spacing-xl);
margin-bottom: calc(1.5 * var(--mantine-spacing-xl));
}

.title {
font-family:
Greycliff CF,
var(--mantine-font-family);
text-align: center;
font-weight: 900;
font-size: rem(38px);

@media (max-width: $mantine-breakpoint-sm) {
font-size: rem(32px);
}
}
12 changes: 12 additions & 0 deletions src/widgets/ErrorPage/ui/ErrorPage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, expect, test, vi } from 'vitest';
import { screen } from '@testing-library/react';
import { renderWithWrappers } from '@/shared/lib/tests/withWrappers';
import { ErrorPage } from './ErrorPage';

describe('Error Page component', () => {
test('Renders', async () => {
await renderWithWrappers(<ErrorPage reset={vi.fn()} />);

expect(screen.getByText('Something bad just happened...')).toBeInTheDocument();
});
});
24 changes: 24 additions & 0 deletions src/widgets/ErrorPage/ui/ErrorPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use client';

import { Button, Container, Group, Title, Text } from '@/shared/ui';
import { useTranslations } from 'next-intl';
import styles from './ErrorPage.module.css';

export function ErrorPage({ reset }: { reset: () => void }) {
const t = useTranslations('ErrorPage');

return (
<Container className={styles.root}>
<div className={styles.label}>500</div>
<Title className={styles.title}>{t('title')}</Title>
<Text c="dimmed" size="lg" ta="center" className={styles.description}>
{t('text')}
</Text>
<Group justify="center">
<Button variant="subtle" size="md" onClick={reset}>
{t('button')}
</Button>
</Group>
</Container>
);
}

0 comments on commit dbbb9bf

Please sign in to comment.