From 235fe67d770f83131c9ec10b99012319440db690 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sun, 15 May 2022 16:36:58 +0200 Subject: chore: add Search page --- src/components/organisms/forms/search-form.stories.tsx | 9 +-------- src/components/organisms/forms/search-form.test.tsx | 4 ++-- src/components/organisms/forms/search-form.tsx | 14 +++++++++++--- 3 files changed, 14 insertions(+), 13 deletions(-) (limited to 'src/components/organisms/forms') diff --git a/src/components/organisms/forms/search-form.stories.tsx b/src/components/organisms/forms/search-form.stories.tsx index 7f4c7c0..6ea6122 100644 --- a/src/components/organisms/forms/search-form.stories.tsx +++ b/src/components/organisms/forms/search-form.stories.tsx @@ -1,5 +1,4 @@ import { ComponentMeta, ComponentStory } from '@storybook/react'; -import { IntlProvider } from 'react-intl'; import SearchForm from './search-form'; /** @@ -10,6 +9,7 @@ export default { component: SearchForm, args: { hideLabel: false, + searchPage: '#', }, argTypes: { className: { @@ -40,13 +40,6 @@ export default { }, }, }, - decorators: [ - (Story) => ( - - - - ), - ], } as ComponentMeta; const Template: ComponentStory = (args) => ( diff --git a/src/components/organisms/forms/search-form.test.tsx b/src/components/organisms/forms/search-form.test.tsx index 4e3d285..59a2f68 100644 --- a/src/components/organisms/forms/search-form.test.tsx +++ b/src/components/organisms/forms/search-form.test.tsx @@ -3,14 +3,14 @@ import SearchForm from './search-form'; describe('SearchForm', () => { it('renders a search input', () => { - render(); + render(); expect( screen.getByRole('searchbox', { name: 'Search for:' }) ).toBeInTheDocument(); }); it('renders a submit button', () => { - render(); + render(); expect(screen.getByRole('button', { name: 'Search' })).toBeInTheDocument(); }); }); diff --git a/src/components/organisms/forms/search-form.tsx b/src/components/organisms/forms/search-form.tsx index 18b7c08..56d3895 100644 --- a/src/components/organisms/forms/search-form.tsx +++ b/src/components/organisms/forms/search-form.tsx @@ -4,18 +4,24 @@ import MagnifyingGlass from '@components/atoms/icons/magnifying-glass'; import LabelledField, { type LabelledFieldProps, } from '@components/molecules/forms/labelled-field'; +import { useRouter } from 'next/router'; import { FC, useState } from 'react'; import { useIntl } from 'react-intl'; import styles from './search-form.module.scss'; -export type SearchFormProps = Pick; +export type SearchFormProps = Pick & { + /** + * The search page url. + */ + searchPage: string; +}; /** * SearchForm component * * Render a search form. */ -const SearchForm: FC = ({ hideLabel }) => { +const SearchForm: FC = ({ hideLabel, searchPage }) => { const intl = useIntl(); const fieldLabel = intl.formatMessage({ defaultMessage: 'Search for:', @@ -28,10 +34,12 @@ const SearchForm: FC = ({ hideLabel }) => { id: 'WMqQrv', }); + const router = useRouter(); const [value, setValue] = useState(''); const submitHandler = () => { - return; + router.push({ pathname: searchPage, query: { s: value } }); + setValue(''); }; return ( -- cgit v1.2.3