Skip to content

Commit aec7c93

Browse files
authored
AYS-333 | Solving test errors (#67)
1 parent 571faca commit aec7c93

File tree

7 files changed

+318
-430
lines changed

7 files changed

+318
-430
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
'use client'
2+
3+
import { FormControl, FormField, FormItem, FormMessage } from '@/components/ui/form'
4+
import { Input } from '@/components/ui/input'
5+
import PhoneInput from '@/components/ui/PhoneInput'
6+
import { CountryData } from 'react-phone-input-2'
7+
import { Label } from '@/components/ui/label'
8+
import SelectLocation from '@/components/SelectLocation'
9+
import { Textarea } from '@/components/ui/textarea'
10+
11+
export default function EvacuationForm({ form }: { form: any }) {
12+
const countryCodeError = form.getFieldState('phoneNumber.countryCode', form.formState).error
13+
const lineNumberError = form.getFieldState('phoneNumber.lineNumber', form.formState).error
14+
15+
return (
16+
<>
17+
{/* name surname block*/}
18+
<div className="grid grid-cols-2 gap-2">
19+
<FormField name="firstName" render={({ field }) => (
20+
<FormItem>
21+
<FormControl>
22+
<Input placeholder="İsim" {...field} />
23+
</FormControl>
24+
<FormMessage />
25+
</FormItem>
26+
)} />
27+
28+
<FormField name="lastName" render={({ field }) => (
29+
<FormItem>
30+
<FormControl>
31+
<Input placeholder="Soyisim" {...field} />
32+
</FormControl>
33+
<FormMessage />
34+
</FormItem>
35+
)} />
36+
</div>
37+
38+
{/*Phone Number block*/}
39+
<FormField name="phoneNumber" render={({ field }) => (
40+
<FormItem>
41+
<FormControl>
42+
<PhoneInput
43+
value={field.value.countryCode + field.value.lineNumber}
44+
onChange={(value: string, country: CountryData) => {
45+
const countryCode: string = country.dialCode
46+
const lineNumber: string = value.slice(countryCode.length)
47+
field.onChange({ countryCode, lineNumber })
48+
}}
49+
/>
50+
</FormControl>
51+
<div className="text-red-500 font-thin text-sm flex gap-2">
52+
<span>{countryCodeError?.message}</span>
53+
<span>{lineNumberError?.message}</span>
54+
</div>
55+
</FormItem>
56+
)} />
57+
58+
{/*number of seats block*/}
59+
<FormField name="seatingCount" render={({ field }) => (
60+
<FormItem>
61+
<FormControl>
62+
<div className="flex items-center justify-between gap-5">
63+
<Label htmlFor="seatingCount" className="text-background text-nowrap font-semibold">Koltuk
64+
Sayısı:</Label>
65+
<Input
66+
id="seatingCount"
67+
placeholder="Koltuk Sayısı"
68+
type="number"
69+
min={1}
70+
max={999}
71+
{...field}
72+
onChange={(e) => {
73+
const value = e.target.value ? Number(e.target.value) : ''
74+
field.onChange(value)
75+
}}
76+
/>
77+
</div>
78+
</FormControl>
79+
<FormMessage />
80+
</FormItem>
81+
)} />
82+
83+
<hr />
84+
<span className="font-bold text-white block text-center">Başvurunun Yapıldığı Konum</span>
85+
{/*application location box*/}
86+
<div className="grid grid-cols-2 gap-2">
87+
<FormField name="sourceCity" render={({ field }) => (
88+
<FormItem>
89+
<FormControl>
90+
<SelectLocation
91+
type="city"
92+
value={field.value}
93+
onChange={field.onChange}
94+
/>
95+
</FormControl>
96+
<FormMessage />
97+
</FormItem>
98+
)} />
99+
100+
<FormField name="sourceDistrict" render={({ field }) => (
101+
<FormItem>
102+
<FormControl>
103+
<SelectLocation
104+
type="district"
105+
cityValue={form.watch('sourceCity')}
106+
value={field.value}
107+
onChange={field.onChange}
108+
/>
109+
</FormControl>
110+
<FormMessage />
111+
</FormItem>
112+
)} />
113+
</div>
114+
115+
<FormField name="address" render={({ field }) => (
116+
<FormItem>
117+
<FormControl>
118+
<Textarea {...field} placeholder="Açık adres" />
119+
</FormControl>
120+
<FormMessage />
121+
</FormItem>
122+
)} />
123+
124+
<hr />
125+
<span className="font-bold text-white block text-center">Tahliye Sağlanacak Konum</span>
126+
127+
{/*target location box*/}
128+
<div className="grid grid-cols-2 gap-2">
129+
<FormField name="targetCity" render={({ field }) => (
130+
<FormItem>
131+
<FormControl>
132+
<SelectLocation
133+
type="city"
134+
value={field.value}
135+
onChange={field.onChange}
136+
/>
137+
</FormControl>
138+
<FormMessage />
139+
</FormItem>
140+
)} />
141+
142+
<FormField name="targetDistrict" render={({ field }) => (
143+
<FormItem>
144+
<FormControl>
145+
<SelectLocation
146+
type="district"
147+
cityValue={form.watch('targetCity')}
148+
value={field.value}
149+
onChange={field.onChange}
150+
/>
151+
</FormControl>
152+
<FormMessage />
153+
</FormItem>
154+
)} />
155+
</div>
156+
</>
157+
)
158+
}

0 commit comments

Comments
 (0)