display from_city and to_city on ui
This commit is contained in:
@@ -40,20 +40,10 @@ export default function AddressSelector() {
|
||||
.replace(/\s+/g, '-')
|
||||
}
|
||||
|
||||
const validateInputs = () => {
|
||||
if (!fromAddress.trim()) {
|
||||
throw new Error('Укажите город отправления')
|
||||
}
|
||||
if (!toAddress.trim()) {
|
||||
throw new Error('Укажите город назначения')
|
||||
}
|
||||
if (fromAddress.trim() === toAddress.trim()) {
|
||||
throw new Error('Города отправления и назначения должны различаться')
|
||||
}
|
||||
}
|
||||
|
||||
const getSearchUrl = async (category: 'mover' | 'customer') => {
|
||||
validateInputs()
|
||||
if (!fromAddress.trim() || !toAddress.trim()) {
|
||||
return `/search/${category}`
|
||||
}
|
||||
|
||||
const [fromCity, toCity] = await Promise.all([getCityName(fromAddress), getCityName(toAddress)])
|
||||
|
||||
@@ -65,6 +55,12 @@ export default function AddressSelector() {
|
||||
|
||||
const handleSearch = async (category: 'mover' | 'customer') => {
|
||||
setError(null)
|
||||
|
||||
if (!fromAddress.trim() || !toAddress.trim()) {
|
||||
router.push(`/search/${category}`)
|
||||
return
|
||||
}
|
||||
|
||||
setIsLoading(true)
|
||||
|
||||
try {
|
||||
@@ -82,8 +78,8 @@ export default function AddressSelector() {
|
||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-end sm:gap-3">
|
||||
<div className="w-full min-w-0 sm:flex-[3] sm:px-1">
|
||||
<TextInput
|
||||
placeholder="Минск, Беларусь"
|
||||
tooltip="Укажите пункт (Город/Страна), откуда необходимо забрать посылку."
|
||||
placeholder="Минск"
|
||||
tooltip="Укажите пункт (Город), откуда необходимо забрать посылку."
|
||||
label="Забрать посылку из"
|
||||
value={fromAddress}
|
||||
handleChange={e => {
|
||||
@@ -97,9 +93,9 @@ export default function AddressSelector() {
|
||||
</div>
|
||||
<div className="w-full min-w-0 sm:flex-[3] sm:px-1">
|
||||
<TextInput
|
||||
placeholder="Москва, Россия"
|
||||
placeholder="Москва"
|
||||
label="Доставить посылку в"
|
||||
tooltip="Укажите пункт (Город/Страна), куда необходимо доставить посылку."
|
||||
tooltip="Укажите пункт (Город), куда необходимо доставить посылку."
|
||||
value={toAddress}
|
||||
handleChange={e => {
|
||||
setError(null)
|
||||
|
||||
Reference in New Issue
Block a user