display from_city and to_city on ui

This commit is contained in:
2025-05-27 13:07:23 +03:00
parent e0b705efa6
commit 7915221fc4
5 changed files with 72 additions and 63 deletions

View File

@@ -68,9 +68,11 @@ export default async function SearchPage(props: RouteSearchPageProps) {
return (
<div className="container mx-auto p-4">
<h1 className="mb-4 text-2xl font-bold">
{category === 'mover'
? `Поиск перевозчика по маршруту : ${fromCity}${toCity}`
: `Поиск посылки по маршруту : ${fromCity} ${toCity}`}
{results.length > 0
? category === 'mover'
? `Поиск перевозчика по маршруту ${results[0].from_city_russian_name} - ${results[0].to_city_russian_name}`
: `Поиск посылки по маршруту ${results[0].from_city_russian_name} - ${results[0].to_city_russian_name}`
: 'Результаты не найдены'}
</h1>
<Suspense fallback={<div>Загрузка результатов...</div>}>

View File

@@ -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)