Skip to content

Commit 6140455

Browse files
committed
Add the main components
1 parent 27e8a78 commit 6140455

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

components/Providers.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use client'
2+
import { ReactNode } from 'react'
3+
import { ThemeProvider } from 'next-themes'
4+
const Providers = ({ children }: { children: ReactNode }) => {
5+
return (
6+
<ThemeProvider attribute='class' enableSystem storageKey='theme'>
7+
{children}
8+
</ThemeProvider>
9+
)
10+
}
11+
12+
export default Providers

components/Search.tsx

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
'use client'
2+
import {
3+
Select,
4+
SelectContent,
5+
SelectItem,
6+
SelectTrigger,
7+
SelectValue
8+
} from '@/components/ui/select'
9+
import { zodResolver } from '@hookform/resolvers/zod'
10+
import { useForm } from 'react-hook-form'
11+
import { z } from 'zod'
12+
import { Form, FormControl, FormField, FormItem } from '@/components/ui/form'
13+
import { Input } from '@/components/ui/input'
14+
15+
import Link from 'next/link'
16+
import { useQuery } from '@tanstack/react-query'
17+
import { fetchCountries } from '@/lib/action'
18+
19+
const formSchema = z.object({
20+
countryNames: z.string().min(2)
21+
})
22+
23+
const Search = ({}) => {
24+
const form = useForm<z.infer<typeof formSchema>>({
25+
resolver: zodResolver(formSchema)
26+
})
27+
28+
function onSubmit(values: z.infer<typeof formSchema>) {
29+
console.log(values)
30+
}
31+
const reg = [
32+
{ id: 1, name: 'All', unavailable: false },
33+
{ id: 2, name: 'Africa', unavailable: false },
34+
{ id: 3, name: 'Asia', unavailable: false },
35+
{ id: 4, name: 'America', unavailable: false },
36+
{ id: 5, name: 'Europe', unavailable: false },
37+
{ id: 6, name: 'Oceanian', unavailable: false }
38+
]
39+
const { data: CountriesData } = useQuery({
40+
queryKey: ['countries'],
41+
queryFn: () => fetchCountries
42+
})
43+
console.log(typeof CountriesData)
44+
return (
45+
<section className='mx-4 mt-12 flex flex-col gap-y-4 lg:flex-row lg:justify-between'>
46+
<Form {...form}>
47+
<form onSubmit={form.handleSubmit(onSubmit)} className='space-y-8'>
48+
<FormField
49+
control={form.control}
50+
name='countryNames'
51+
render={({ field }) => (
52+
<FormItem>
53+
<FormControl>
54+
<Input
55+
placeholder='Enter country name'
56+
className='w-full'
57+
{...field}
58+
/>
59+
</FormControl>
60+
</FormItem>
61+
)}
62+
/>
63+
</form>
64+
</Form>
65+
<div>
66+
<Select>
67+
<SelectTrigger className=' w-full'>
68+
<SelectValue placeholder='All' />
69+
</SelectTrigger>
70+
<SelectContent>
71+
{reg.map(item => (
72+
<SelectItem
73+
className='relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-slate-100 focus:text-slate-900 data-[disabled]:pointer-events-none data-[disabled]:opacity-50 dark:focus:bg-slate-800 dark:focus:text-slate-50'
74+
key={item.id}
75+
value='all'
76+
>
77+
{item.name}
78+
</SelectItem>
79+
))}
80+
</SelectContent>
81+
</Select>
82+
</div>
83+
<div></div>
84+
</section>
85+
)
86+
}
87+
88+
export default Search

0 commit comments

Comments
 (0)