From b0ed3d26bda4ff696387f8d67a4830bb4b42c78b Mon Sep 17 00:00:00 2001 From: saml33 Date: Sun, 27 Nov 2022 20:21:38 +1100 Subject: [PATCH] add search form --- components/shared/Button.tsx | 3 ++ pages/search.tsx | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 pages/search.tsx diff --git a/components/shared/Button.tsx b/components/shared/Button.tsx index 4a9ff6d3..37d061ef 100644 --- a/components/shared/Button.tsx +++ b/components/shared/Button.tsx @@ -11,6 +11,7 @@ interface AllButtonProps { interface ButtonProps { size?: 'large' | 'medium' | 'small' + type?: 'button' | 'submit' | 'reset' } type ButtonCombinedProps = AllButtonProps & ButtonProps @@ -22,6 +23,7 @@ const Button: FunctionComponent = ({ className, secondary, size = 'medium', + type = 'button', ...props }) => { const { theme } = useTheme() @@ -44,6 +46,7 @@ const Button: FunctionComponent = ({ ? 'h-12 px-6' : 'h-8 px-3' } default-transition font-bold focus:outline-none disabled:cursor-not-allowed disabled:opacity-60 disabled:hover:brightness-100 ${className}`} + type={type} {...props} > {children} diff --git a/pages/search.tsx b/pages/search.tsx new file mode 100644 index 00000000..3ddd83a9 --- /dev/null +++ b/pages/search.tsx @@ -0,0 +1,72 @@ +import ButtonGroup from '@components/forms/ButtonGroup' +import Input from '@components/forms/Input' +import Button from '@components/shared/Button' +import { MagnifyingGlassIcon } from '@heroicons/react/20/solid' +import type { NextPage } from 'next' +import { useTranslation } from 'next-i18next' +import { serverSideTranslations } from 'next-i18next/serverSideTranslations' +import { ChangeEvent, FormEvent, useState } from 'react' +import { notify } from 'utils/notifications' + +export async function getStaticProps({ locale }: { locale: string }) { + return { + props: { + ...(await serverSideTranslations(locale, ['common'])), + }, + } +} + +const Search: NextPage = () => { + const { t } = useTranslation('common') + const [loading, setLoading] = useState(false) + const [searchString, setSearchString] = useState('') + // const [searchResults, setSearchResults] = useState([]) + const [searchType, setSearchType] = useState('mango-account') + + const handleSearch = async (e: FormEvent) => { + e.preventDefault() + try { + setLoading(true) + const response = await fetch( + `https://mango-transaction-log.herokuapp.com/v4/user-data/profile-search?search-string=${searchString}&search-method=${searchType}` + ) + const data = await response.json() + console.log(data) + } catch { + notify({ + title: t('search-failed'), + type: 'error', + }) + } finally { + setLoading(false) + } + } + + return ( +
+
handleSearch(e)}> + ) => + setSearchString(e.target.value) + } + prefix={} + /> + setSearchType(t)} + values={['mango-account', 'mango-account-name', 'profile-name']} + /> + + + {loading ? 'Loading...' : ''} +
+ ) +} + +export default Search