23 changed files with 3267 additions and 204 deletions
-
36src/components/shared/CountryDialSelect.tsx
-
12src/components/shared/FilterBar.tsx
-
9src/components/shared/FilterSelect.tsx
-
16src/components/shared/MultiFilterSelect.tsx
-
15src/components/shared/SortDropdown.tsx
-
17src/components/shared/ViewToggle.tsx
-
53src/features/billing/components/ReceiptLightboxDialog.tsx
-
40src/features/dashboard/DashboardHome.tsx
-
8src/features/services/ServicesPage.tsx
-
26src/features/services/components/BlogsServiceView.tsx
-
4src/features/services/components/StoreServiceView.tsx
-
12src/features/services/components/SupportServiceView.tsx
-
4src/features/settings/components/TestimonialsSettingsTab.tsx
-
334src/features/tours/components/CreateTourDialog.tsx
-
193src/features/tours/components/TourDetailDialog.tsx
-
65src/features/tours/components/TourDetailSheet.tsx
-
2src/features/tours/components/TourDetailShimmer.tsx
-
1347src/features/tours/components/TourHotelsAndTransportEditors.tsx
-
906src/features/tours/utils/tour-meta-builder.ts
-
6src/features/users/components/UserToursTab.tsx
-
130src/locales/ar.json
-
110src/locales/en.json
-
126src/locales/fa.json
1347
src/features/tours/components/TourHotelsAndTransportEditors.tsx
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,906 @@ |
|||
import type { |
|||
CustomTripDestinationItem, |
|||
CustomTripHotelItem, |
|||
CustomTripOriginItem, |
|||
} from '@/features/custom-trip/types' |
|||
import { OFFICIAL_PRESET_CITIES } from '@/features/custom-trip/components/CustomTripDestinationsTab' |
|||
import { doesHotelMatchDestination } from '@/stores/hotels-catalog' |
|||
import type { AccommodationItem, TourMeta, TransportInfo, TransportStepItem } from '../types' |
|||
|
|||
export type TourLanguageCode = 'ar' | 'fa' | 'en' | 'ru' | 'id' |
|||
|
|||
export const TOUR_ALL_LANGS: TourLanguageCode[] = ['ar', 'fa', 'en', 'ru', 'id'] |
|||
|
|||
export interface TourHotelSelectionRow { |
|||
id: string |
|||
cityKey: string |
|||
hotelId: string |
|||
nights: string |
|||
} |
|||
|
|||
export interface TourTransportStepRow { |
|||
id: string |
|||
fromCity: string |
|||
toCity: string |
|||
vehicleType: 'airplane' | 'train' | 'bus' |
|||
isReturn: boolean |
|||
departureTime?: string |
|||
carrierName?: string |
|||
baggageAllowance?: string |
|||
} |
|||
|
|||
export interface TourCityCatalogOption { |
|||
key: string |
|||
country: string |
|||
names: Record<TourLanguageCode, string> |
|||
hotels: CustomTripHotelItem[] |
|||
} |
|||
|
|||
export interface TransportCityPreset { |
|||
key: string |
|||
country: string |
|||
names: Record<TourLanguageCode, string> |
|||
} |
|||
|
|||
export const REGIONAL_CITY_DICTIONARY: TransportCityPreset[] = [ |
|||
{ |
|||
key: 'muscat', |
|||
country: 'عمان', |
|||
names: { ar: 'مسقط', fa: 'مسقط', en: 'Muscat', ru: 'Маскат', id: 'Muscat' }, |
|||
}, |
|||
{ |
|||
key: 'mashhad', |
|||
country: 'ایران', |
|||
names: { |
|||
ar: 'مشهد المقدسة', |
|||
fa: 'مشهد مقدس', |
|||
en: 'Holy Mashhad', |
|||
ru: 'Священный Мешхед', |
|||
id: 'Mashhad Suci', |
|||
}, |
|||
}, |
|||
{ |
|||
key: 'qom', |
|||
country: 'ایران', |
|||
names: { |
|||
ar: 'قم المقدسة', |
|||
fa: 'قم المقدسه', |
|||
en: 'Holy Qom', |
|||
ru: 'Священный Кум', |
|||
id: 'Qom Suci', |
|||
}, |
|||
}, |
|||
{ |
|||
key: 'karbala', |
|||
country: 'عراق', |
|||
names: { |
|||
ar: 'كربلاء المقدسة', |
|||
fa: 'کربلای معلی', |
|||
en: 'Holy Karbala', |
|||
ru: 'Священная Кербела', |
|||
id: 'Karbala Suci', |
|||
}, |
|||
}, |
|||
{ |
|||
key: 'najaf', |
|||
country: 'عراق', |
|||
names: { |
|||
ar: 'النجف الأشرف', |
|||
fa: 'نجف اشرف', |
|||
en: 'Holy Najaf', |
|||
ru: 'Священный Эн-Наджаф', |
|||
id: 'Najaf Suci', |
|||
}, |
|||
}, |
|||
{ |
|||
key: 'kadhimiya', |
|||
country: 'عراق', |
|||
names: { |
|||
ar: 'الكاظمية المقدسة', |
|||
fa: 'کاظمین', |
|||
en: 'Kadhimiya', |
|||
ru: 'Казимия', |
|||
id: 'Kadhimiya', |
|||
}, |
|||
}, |
|||
{ |
|||
key: 'samarra', |
|||
country: 'عراق', |
|||
names: { |
|||
ar: 'سامراء المقدسة', |
|||
fa: 'سامرا', |
|||
en: 'Samarra', |
|||
ru: 'Самарра', |
|||
id: 'Samarra', |
|||
}, |
|||
}, |
|||
{ |
|||
key: 'baghdad', |
|||
country: 'عراق', |
|||
names: { ar: 'بغداد', fa: 'بغداد', en: 'Baghdad', ru: 'Багдад', id: 'Baghdad' }, |
|||
}, |
|||
{ |
|||
key: 'makkah', |
|||
country: 'عربستان سعودی', |
|||
names: { |
|||
ar: 'مكة المكرمة', |
|||
fa: 'مکه مکرمه', |
|||
en: 'Holy Makkah', |
|||
ru: 'Священная Мекка', |
|||
id: 'Makkah Al-Mukarramah', |
|||
}, |
|||
}, |
|||
{ |
|||
key: 'madinah', |
|||
country: 'عربستان سعودی', |
|||
names: { |
|||
ar: 'المدينة المنورة', |
|||
fa: 'مدینه منوره', |
|||
en: 'Al-Madinah Al-Munawwarah', |
|||
ru: 'Лучезарная Медина', |
|||
id: 'Madinah Al-Munawwarah', |
|||
}, |
|||
}, |
|||
{ |
|||
key: 'tehran', |
|||
country: 'ایران', |
|||
names: { ar: 'طهران', fa: 'تهران', en: 'Tehran', ru: 'Тегеран', id: 'Teheran' }, |
|||
}, |
|||
{ |
|||
key: 'shiraz', |
|||
country: 'ایران', |
|||
names: { ar: 'شيراز', fa: 'شیراز', en: 'Shiraz', ru: 'Шираз', id: 'Shiraz' }, |
|||
}, |
|||
{ |
|||
key: 'isfahan', |
|||
country: 'ایران', |
|||
names: { ar: 'أصفهان', fa: 'اصفهان', en: 'Isfahan', ru: 'Исфахан', id: 'Isfahan' }, |
|||
}, |
|||
{ |
|||
key: 'ahvaz', |
|||
country: 'ایران', |
|||
names: { ar: 'الأهواز', fa: 'اهواز', en: 'Ahvaz', ru: 'Ахваз', id: 'Ahvaz' }, |
|||
}, |
|||
{ |
|||
key: 'tabriz', |
|||
country: 'ایران', |
|||
names: { ar: 'تبريز', fa: 'تبریز', en: 'Tabriz', ru: 'Тебриз', id: 'Tabriz' }, |
|||
}, |
|||
{ |
|||
key: 'manama', |
|||
country: 'بحرین', |
|||
names: { ar: 'المنامة', fa: 'منامه', en: 'Manama', ru: 'Манама', id: 'Manama' }, |
|||
}, |
|||
{ |
|||
key: 'kuwait', |
|||
country: 'کویت', |
|||
names: { ar: 'الكويت', fa: 'کویت', en: 'Kuwait City', ru: 'Эль-Кувейт', id: 'Kota Kuwait' }, |
|||
}, |
|||
{ |
|||
key: 'dubai', |
|||
country: 'امارات', |
|||
names: { ar: 'دبي', fa: 'دبی', en: 'Dubai', ru: 'Дубай', id: 'Dubai' }, |
|||
}, |
|||
{ |
|||
key: 'sharjah', |
|||
country: 'امارات', |
|||
names: { ar: 'الشارقة', fa: 'شارجه', en: 'Sharjah', ru: 'Шарджа', id: 'Sharjah' }, |
|||
}, |
|||
{ |
|||
key: 'doha', |
|||
country: 'قطر', |
|||
names: { ar: 'الدوحة', fa: 'دوحه', en: 'Doha', ru: 'Доха', id: 'Doha' }, |
|||
}, |
|||
{ |
|||
key: 'jeddah', |
|||
country: 'عربستان سعودی', |
|||
names: { ar: 'جدة', fa: 'جده', en: 'Jeddah', ru: 'Джидда', id: 'Jeddah' }, |
|||
}, |
|||
{ |
|||
key: 'dammam', |
|||
country: 'عربستان سعودی', |
|||
names: { ar: 'الدمام', fa: 'دمام', en: 'Dammam', ru: 'Даммам', id: 'Dammam' }, |
|||
}, |
|||
{ |
|||
key: 'riyadh', |
|||
country: 'عربستان سعودی', |
|||
names: { ar: 'الرياض', fa: 'ریاض', en: 'Riyadh', ru: 'Эр-Рияд', id: 'Riyadh' }, |
|||
}, |
|||
{ |
|||
key: 'beirut', |
|||
country: 'لبنان', |
|||
names: { ar: 'بيروت', fa: 'بیروت', en: 'Beirut', ru: 'Бейрут', id: 'Beirut' }, |
|||
}, |
|||
{ |
|||
key: 'damascus', |
|||
country: 'سوریه', |
|||
names: { ar: 'دمشق', fa: 'دمشق', en: 'Damascus', ru: 'Дамаск', id: 'Damaskus' }, |
|||
}, |
|||
] |
|||
|
|||
export const VEHICLE_LABELS_BY_LANG: Record< |
|||
'airplane' | 'train' | 'bus', |
|||
{ normal: Record<TourLanguageCode, string>; returnLeg: Record<TourLanguageCode, string> } |
|||
> = { |
|||
airplane: { |
|||
normal: { |
|||
ar: 'طيران (طائرة)', |
|||
fa: 'هواپیما (پرواز)', |
|||
en: 'Airplane (Flight)', |
|||
ru: 'Самолёт (Авиарейс)', |
|||
id: 'Pesawat (Penerbangan)', |
|||
}, |
|||
returnLeg: { |
|||
ar: 'رحلة العودة (طيران)', |
|||
fa: 'پرواز بازگشت به شهر مبدأ', |
|||
en: 'Return Flight to Origin', |
|||
ru: 'Обратный авиарейс', |
|||
id: 'Penerbangan Pulang ke Kota Asal', |
|||
}, |
|||
}, |
|||
train: { |
|||
normal: { |
|||
ar: 'قطار سريع', |
|||
fa: 'قطار (ریلی)', |
|||
en: 'High-Speed Train', |
|||
ru: 'Скоростной поезд', |
|||
id: 'Kereta Cepat', |
|||
}, |
|||
returnLeg: { |
|||
ar: 'رحلة العودة (قطار)', |
|||
fa: 'قطار بازگشت به شهر مبدأ', |
|||
en: 'Return Train to Origin', |
|||
ru: 'Обратный поезд', |
|||
id: 'Kereta Pulang ke Kota Asal', |
|||
}, |
|||
}, |
|||
bus: { |
|||
normal: { |
|||
ar: 'حافلة VIP (نقل بري)', |
|||
fa: 'اتوبوس VIP (زمینی)', |
|||
en: 'VIP Bus (Land Transit)', |
|||
ru: 'VIP-автобус (Наземный трансфер)', |
|||
id: 'Bus VIP (Jalur Darat)', |
|||
}, |
|||
returnLeg: { |
|||
ar: 'رحلة العودة البرية (حافلة)', |
|||
fa: 'بازگشت زمینی با اتوبوس به مبدأ', |
|||
en: 'Return Land Bus to Origin', |
|||
ru: 'Обратный автобус', |
|||
id: 'Bus Pulang ke Kota Asal', |
|||
}, |
|||
}, |
|||
} |
|||
|
|||
/** |
|||
* نرمالسازی رشته شهر برای مقایسه فازی بین زبانها |
|||
*/ |
|||
function normalizeCityToken(value: string | undefined | null): string { |
|||
return (value || '') |
|||
.trim() |
|||
.toLowerCase() |
|||
.replace(/ي/g, 'ی') |
|||
.replace(/ك/g, 'ک') |
|||
.replace(/ة/g, 'ه') |
|||
.replace(/أ|إ|آ/g, 'ا') |
|||
} |
|||
|
|||
/** |
|||
* استخراج فهرست شهرهای دارای هتل از کاتالوگ سیستم (Destinations + Hotels Catalog) |
|||
*/ |
|||
export function buildTourHotelCitiesCatalog( |
|||
hotels: CustomTripHotelItem[], |
|||
destinations: CustomTripDestinationItem[] |
|||
): TourCityCatalogOption[] { |
|||
const result: TourCityCatalogOption[] = [] |
|||
const matchedHotelIds = new Set<string>() |
|||
|
|||
// ۱. ابتدا از روی شهرهای مقصد رسمی و کاتالوگ مقاصد
|
|||
for (const preset of OFFICIAL_PRESET_CITIES) { |
|||
const matchingDest = destinations.find( |
|||
(d) => |
|||
String(d.id).toLowerCase() === preset.id.toLowerCase() || |
|||
normalizeCityToken(d.name) === normalizeCityToken(preset.names.fa) || |
|||
normalizeCityToken(d.name) === normalizeCityToken(preset.names.ar) || |
|||
normalizeCityToken(d.nameEn) === normalizeCityToken(preset.names.en) |
|||
) |
|||
|
|||
const cityHotels = hotels.filter((h) => { |
|||
if (matchingDest && doesHotelMatchDestination(h, matchingDest)) return true |
|||
const hCityNorm = normalizeCityToken(h.cityName) |
|||
if (!hCityNorm) return false |
|||
return ( |
|||
hCityNorm === normalizeCityToken(preset.id) || |
|||
Object.values(preset.names).some((n) => { |
|||
const nNorm = normalizeCityToken(n) |
|||
return nNorm && (hCityNorm === nNorm || hCityNorm.includes(nNorm) || nNorm.includes(hCityNorm)) |
|||
}) |
|||
) |
|||
}) |
|||
|
|||
cityHotels.forEach((h) => matchedHotelIds.add(String(h.id))) |
|||
|
|||
const names: Record<TourLanguageCode, string> = { |
|||
ar: matchingDest?.translations?.ar?.name || preset.names.ar, |
|||
fa: matchingDest?.translations?.fa?.name || preset.names.fa, |
|||
en: matchingDest?.translations?.en?.name || matchingDest?.nameEn || preset.names.en, |
|||
ru: matchingDest?.translations?.ru?.name || preset.names.ru, |
|||
id: matchingDest?.translations?.id?.name || preset.names.id, |
|||
} |
|||
|
|||
result.push({ |
|||
key: preset.id, |
|||
country: matchingDest?.country || preset.country, |
|||
names, |
|||
hotels: cityHotels, |
|||
}) |
|||
} |
|||
|
|||
// ۲. سایر شهرهایی که در destinations هستند ولی در OFFICIAL_PRESET_CITIES نبودند
|
|||
for (const dest of destinations) { |
|||
const alreadyExists = result.some( |
|||
(r) => |
|||
r.key.toLowerCase() === String(dest.id).toLowerCase() || |
|||
normalizeCityToken(r.names.fa) === normalizeCityToken(dest.name) || |
|||
normalizeCityToken(r.names.ar) === normalizeCityToken(dest.name) |
|||
) |
|||
if (alreadyExists) continue |
|||
|
|||
const cityHotels = hotels.filter((h) => doesHotelMatchDestination(h, dest)) |
|||
cityHotels.forEach((h) => matchedHotelIds.add(String(h.id))) |
|||
|
|||
const baseName = dest.name || dest.nameEn || String(dest.id) |
|||
result.push({ |
|||
key: String(dest.id || baseName), |
|||
country: dest.country || '', |
|||
names: { |
|||
ar: dest.translations?.ar?.name || baseName, |
|||
fa: dest.translations?.fa?.name || baseName, |
|||
en: dest.translations?.en?.name || dest.nameEn || baseName, |
|||
ru: dest.translations?.ru?.name || dest.nameEn || baseName, |
|||
id: dest.translations?.id?.name || dest.nameEn || baseName, |
|||
}, |
|||
hotels: cityHotels, |
|||
}) |
|||
} |
|||
|
|||
// ۳. هتلهایی که نام شهرشان در هیچیک از دستههای بالا نیامده است
|
|||
const unmatchedByCity = new Map<string, CustomTripHotelItem[]>() |
|||
for (const h of hotels) { |
|||
if (matchedHotelIds.has(String(h.id))) continue |
|||
const rawCity = (h.cityName || '').trim() |
|||
if (!rawCity) continue |
|||
const norm = normalizeCityToken(rawCity) |
|||
const existing = result.find((r) => |
|||
Object.values(r.names).some((n) => { |
|||
const nNorm = normalizeCityToken(n) |
|||
return nNorm && (nNorm === norm || nNorm.includes(norm) || norm.includes(nNorm)) |
|||
}) |
|||
) |
|||
if (existing) { |
|||
if (!existing.hotels.some((eh) => String(eh.id) === String(h.id))) { |
|||
existing.hotels.push(h) |
|||
} |
|||
continue |
|||
} |
|||
const list = unmatchedByCity.get(rawCity) || [] |
|||
list.push(h) |
|||
unmatchedByCity.set(rawCity, list) |
|||
} |
|||
|
|||
for (const [cityName, cityHotels] of unmatchedByCity.entries()) { |
|||
const localized = resolveLocalizedCityNames(cityName, destinations, []) |
|||
result.push({ |
|||
key: cityName, |
|||
country: '', |
|||
names: localized, |
|||
hotels: cityHotels, |
|||
}) |
|||
} |
|||
|
|||
// شهرهایی که هتل دارند بالاتر قرار بگیرند
|
|||
return result.sort((a, b) => b.hotels.length - a.hotels.length) |
|||
} |
|||
|
|||
/** |
|||
* استخراج تمام شهرهای قابل انتخاب برای مسیرهای حملونقل (شهرهای مبدأ + شهرهای مقصد + دیکشنری منطقهای) |
|||
*/ |
|||
export function buildTransportCitiesCatalog( |
|||
destinations: CustomTripDestinationItem[], |
|||
origins: CustomTripOriginItem[] |
|||
): TransportCityPreset[] { |
|||
const list: TransportCityPreset[] = [...REGIONAL_CITY_DICTIONARY] |
|||
|
|||
const addIfMissing = (preset: TransportCityPreset) => { |
|||
const exists = list.some( |
|||
(item) => |
|||
item.key.toLowerCase() === preset.key.toLowerCase() || |
|||
normalizeCityToken(item.names.fa) === normalizeCityToken(preset.names.fa) || |
|||
normalizeCityToken(item.names.ar) === normalizeCityToken(preset.names.ar) || |
|||
normalizeCityToken(item.names.en) === normalizeCityToken(preset.names.en) |
|||
) |
|||
if (!exists) { |
|||
list.push(preset) |
|||
} |
|||
} |
|||
|
|||
for (const origin of origins) { |
|||
const base = origin.name || origin.nameEn || String(origin.id) |
|||
if (!base) continue |
|||
addIfMissing({ |
|||
key: `origin_${origin.id}`, |
|||
country: origin.country || '', |
|||
names: { |
|||
ar: origin.translations?.ar?.name || base, |
|||
fa: origin.translations?.fa?.name || base, |
|||
en: origin.translations?.en?.name || origin.nameEn || base, |
|||
ru: origin.translations?.ru?.name || origin.nameEn || base, |
|||
id: origin.translations?.id?.name || origin.nameEn || base, |
|||
}, |
|||
}) |
|||
} |
|||
|
|||
for (const dest of destinations) { |
|||
const base = dest.name || dest.nameEn || String(dest.id) |
|||
if (!base) continue |
|||
addIfMissing({ |
|||
key: `dest_${dest.id}`, |
|||
country: dest.country || '', |
|||
names: { |
|||
ar: dest.translations?.ar?.name || base, |
|||
fa: dest.translations?.fa?.name || base, |
|||
en: dest.translations?.en?.name || dest.nameEn || base, |
|||
ru: dest.translations?.ru?.name || dest.nameEn || base, |
|||
id: dest.translations?.id?.name || dest.nameEn || base, |
|||
}, |
|||
}) |
|||
} |
|||
|
|||
return list |
|||
} |
|||
|
|||
/** |
|||
* ترجمه خودکار نام شهر در ۵ زبان بر اساس دیکشنری و کاتالوگ شهرهای مبدأ/مقصد |
|||
*/ |
|||
export function resolveLocalizedCityNames( |
|||
rawCityInput: string, |
|||
destinations: CustomTripDestinationItem[], |
|||
origins: CustomTripOriginItem[] |
|||
): Record<TourLanguageCode, string> { |
|||
const trimmed = (rawCityInput || '').trim() |
|||
if (!trimmed) { |
|||
return { ar: '', fa: '', en: '', ru: '', id: '' } |
|||
} |
|||
|
|||
const norm = normalizeCityToken(trimmed) |
|||
|
|||
// ۱. جستجو در دیکشنری شهرهای منطقهای و OFFICIAL_PRESET_CITIES
|
|||
for (const preset of OFFICIAL_PRESET_CITIES) { |
|||
const matched = |
|||
normalizeCityToken(preset.id) === norm || |
|||
Object.values(preset.names).some((n) => { |
|||
const nNorm = normalizeCityToken(n) |
|||
return nNorm === norm || (norm.length >= 3 && (nNorm.includes(norm) || norm.includes(nNorm))) |
|||
}) |
|||
if (matched) { |
|||
return { ...preset.names } |
|||
} |
|||
} |
|||
|
|||
for (const reg of REGIONAL_CITY_DICTIONARY) { |
|||
const matched = |
|||
normalizeCityToken(reg.key) === norm || |
|||
Object.values(reg.names).some((n) => { |
|||
const nNorm = normalizeCityToken(n) |
|||
return nNorm === norm || (norm.length >= 3 && (nNorm.includes(norm) || norm.includes(nNorm))) |
|||
}) |
|||
if (matched) { |
|||
return { ...reg.names } |
|||
} |
|||
} |
|||
|
|||
// ۲. جستجو در کاتالوگ مقاصد
|
|||
for (const dest of destinations) { |
|||
const candidates = [ |
|||
String(dest.id), |
|||
dest.name, |
|||
dest.nameEn, |
|||
dest.translations?.ar?.name, |
|||
dest.translations?.fa?.name, |
|||
dest.translations?.en?.name, |
|||
dest.translations?.ru?.name, |
|||
dest.translations?.id?.name, |
|||
].filter(Boolean) as string[] |
|||
|
|||
if (candidates.some((c) => normalizeCityToken(c) === norm)) { |
|||
return { |
|||
ar: dest.translations?.ar?.name || dest.name || trimmed, |
|||
fa: dest.translations?.fa?.name || dest.name || trimmed, |
|||
en: dest.translations?.en?.name || dest.nameEn || dest.name || trimmed, |
|||
ru: dest.translations?.ru?.name || dest.nameEn || dest.name || trimmed, |
|||
id: dest.translations?.id?.name || dest.nameEn || dest.name || trimmed, |
|||
} |
|||
} |
|||
} |
|||
|
|||
// ۳. جستجو در کاتالوگ شهرهای مبدأ
|
|||
for (const orig of origins) { |
|||
const candidates = [ |
|||
String(orig.id), |
|||
orig.name, |
|||
orig.translations?.ar?.name, |
|||
orig.translations?.fa?.name, |
|||
orig.translations?.en?.name, |
|||
orig.translations?.ru?.name, |
|||
orig.translations?.id?.name, |
|||
].filter(Boolean) as string[] |
|||
|
|||
if (candidates.some((c) => normalizeCityToken(c) === norm)) { |
|||
return { |
|||
ar: orig.translations?.ar?.name || orig.name || trimmed, |
|||
fa: orig.translations?.fa?.name || orig.name || trimmed, |
|||
en: orig.translations?.en?.name || orig.name || trimmed, |
|||
ru: orig.translations?.ru?.name || orig.name || trimmed, |
|||
id: orig.translations?.id?.name || orig.name || trimmed, |
|||
} |
|||
} |
|||
} |
|||
|
|||
return { |
|||
ar: trimmed, |
|||
fa: trimmed, |
|||
en: trimmed, |
|||
ru: trimmed, |
|||
id: trimmed, |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* ساخت آبجکت ۵ زبانه tour_meta از روی هتلهای انتخابشده و مراحل حملونقل |
|||
*/ |
|||
export function buildLocalizedTourMetaByLang(params: { |
|||
hotelRows: TourHotelSelectionRow[] |
|||
transportSteps: TourTransportStepRow[] |
|||
generalTransport?: { |
|||
carrierName?: string |
|||
departureTime?: string |
|||
baggageAllowance?: string |
|||
} |
|||
hotelsCatalog: CustomTripHotelItem[] |
|||
destinationsCatalog: CustomTripDestinationItem[] |
|||
originsCatalog: CustomTripOriginItem[] |
|||
existingMetaByLang?: Partial<Record<TourLanguageCode, TourMeta | undefined>> |
|||
fallbackAccommodationsByLang?: Partial<Record<TourLanguageCode, AccommodationItem[]>> |
|||
}): Record<TourLanguageCode, TourMeta> { |
|||
const { |
|||
hotelRows, |
|||
transportSteps, |
|||
generalTransport, |
|||
hotelsCatalog, |
|||
destinationsCatalog, |
|||
originsCatalog, |
|||
existingMetaByLang, |
|||
fallbackAccommodationsByLang, |
|||
} = params |
|||
|
|||
const validHotelRows = hotelRows.filter((r) => r.cityKey && r.hotelId) |
|||
const validTransportSteps = transportSteps.filter( |
|||
(s) => s.fromCity.trim() && s.toCity.trim() |
|||
) |
|||
|
|||
const cityCatalog = buildTourHotelCitiesCatalog(hotelsCatalog, destinationsCatalog) |
|||
|
|||
const result = {} as Record<TourLanguageCode, TourMeta> |
|||
|
|||
for (const lang of TOUR_ALL_LANGS) { |
|||
const prevMeta = existingMetaByLang?.[lang] || {} |
|||
|
|||
// ۱. ساخت لیست هتلها (accommodations) برای این زبان
|
|||
const accommodations: AccommodationItem[] = validHotelRows |
|||
.map((row) => { |
|||
const hotel = hotelsCatalog.find((h) => String(h.id) === String(row.hotelId)) |
|||
const cityOpt = cityCatalog.find((c) => c.key === row.cityKey) |
|||
const cityNames = cityOpt |
|||
? cityOpt.names |
|||
: resolveLocalizedCityNames( |
|||
hotel?.cityName || row.cityKey, |
|||
destinationsCatalog, |
|||
originsCatalog |
|||
) |
|||
|
|||
const localizedHotelName = |
|||
hotel?.translations?.[lang]?.name?.trim() || |
|||
hotel?.translations?.fa?.name?.trim() || |
|||
hotel?.translations?.ar?.name?.trim() || |
|||
hotel?.translations?.en?.name?.trim() || |
|||
hotel?.name || |
|||
'' |
|||
|
|||
const localizedDistance = |
|||
hotel?.translations?.[lang]?.distanceToShrine?.trim() || |
|||
hotel?.translations?.fa?.distanceToShrine?.trim() || |
|||
hotel?.translations?.ar?.distanceToShrine?.trim() || |
|||
hotel?.translations?.en?.distanceToShrine?.trim() || |
|||
hotel?.distanceToShrine || |
|||
'' |
|||
|
|||
const parsedNights = Number(row.nights) |
|||
|
|||
if (!localizedHotelName) return null |
|||
|
|||
const item: AccommodationItem = { |
|||
city: cityNames[lang] || cityNames.fa || row.cityKey, |
|||
hotel_name: localizedHotelName, |
|||
stars: hotel?.stars || 5, |
|||
distance_to_shrine: localizedDistance, |
|||
hotel_id: hotel?.id ?? row.hotelId, |
|||
city_key: row.cityKey, |
|||
} |
|||
if (Number.isFinite(parsedNights) && parsedNights > 0) { |
|||
item.nights = parsedNights |
|||
} |
|||
return item |
|||
}) |
|||
.filter((item): item is AccommodationItem => item !== null) |
|||
|
|||
// ۲. ساخت مراحل حملونقل (transport_steps) برای این زبان
|
|||
const stepsForLang: TransportStepItem[] = validTransportSteps.map((step, idx) => { |
|||
const fromNames = resolveLocalizedCityNames( |
|||
step.fromCity, |
|||
destinationsCatalog, |
|||
originsCatalog |
|||
) |
|||
const toNames = resolveLocalizedCityNames( |
|||
step.toCity, |
|||
destinationsCatalog, |
|||
originsCatalog |
|||
) |
|||
const vType = |
|||
step.vehicleType === 'train' || step.vehicleType === 'bus' |
|||
? step.vehicleType |
|||
: 'airplane' |
|||
const vLabels = VEHICLE_LABELS_BY_LANG[vType] |
|||
const vehicleLabel = step.isReturn ? vLabels.returnLeg[lang] : vLabels.normal[lang] |
|||
|
|||
return { |
|||
id: step.id || `step_${idx + 1}`, |
|||
order: idx + 1, |
|||
from_city: fromNames[lang] || step.fromCity, |
|||
to_city: toNames[lang] || step.toCity, |
|||
vehicle_type: vType, |
|||
vehicle_label: vehicleLabel, |
|||
is_return: Boolean(step.isReturn), |
|||
departure_time: step.departureTime?.trim() || generalTransport?.departureTime?.trim() || undefined, |
|||
carrier_name: step.carrierName?.trim() || generalTransport?.carrierName?.trim() || undefined, |
|||
baggage_allowance: |
|||
step.baggageAllowance?.trim() || generalTransport?.baggageAllowance?.trim() || undefined, |
|||
} |
|||
}) |
|||
|
|||
// ۳. ساخت خلاصه transport_info برای سازگاری کامل با کارتهای قبلی و فلاتر/فرانتاند
|
|||
let transportInfo: TransportInfo | undefined = prevMeta.transport_info |
|||
? { ...prevMeta.transport_info } |
|||
: undefined |
|||
|
|||
if (stepsForLang.length > 0) { |
|||
const firstStep = stepsForLang[0] |
|||
const nonReturnSteps = stepsForLang.filter((s) => !s.is_return) |
|||
const lastOutboundStep = |
|||
nonReturnSteps.length > 0 |
|||
? nonReturnSteps[nonReturnSteps.length - 1] |
|||
: stepsForLang[stepsForLang.length - 1] |
|||
|
|||
const uniqueVisitedCities: string[] = [] |
|||
for (const st of nonReturnSteps.length > 0 ? nonReturnSteps : stepsForLang) { |
|||
if (st.to_city && !uniqueVisitedCities.includes(st.to_city)) { |
|||
uniqueVisitedCities.push(st.to_city) |
|||
} |
|||
} |
|||
|
|||
const uniqueVehicles = Array.from(new Set(stepsForLang.map((s) => s.vehicle_label))) |
|||
|
|||
const defaultCarrierByLang: Record<TourLanguageCode, string> = { |
|||
ar: 'أسطول حملة نصرة العقيلة زينب عليها السلام السياحي', |
|||
fa: 'ناوگان اختصاصی تورهای کاروان نصرت عقیله زینب (س)', |
|||
en: 'Hamlat Nusrat Al Aqila Zainab s.a Executive Fleet', |
|||
ru: 'Специальный паломнический флот Хамлат Нусрат Аль-Акиلا Зайнаб с.а', |
|||
id: 'Armada Eksekutif Ziarah Hamlat Nusrat Al Aqila Zainab s.a', |
|||
} |
|||
const defaultBaggageByLang: Record<TourLanguageCode, string> = { |
|||
ar: '30 كجم بار + 7 كجم حقيبة يد داخل المقصورة', |
|||
fa: '۳۰ کیلوگرم بار مجاز + ۷ کیلوگرم بار دستی داخل کابین', |
|||
en: '30 kg checked baggage + 7 kg cabin carry-on', |
|||
ru: '30 кг багажа + 7 кг ручной клади', |
|||
id: '30 kg bagasi tercatat + 7 kg kabin', |
|||
} |
|||
const defaultDepTimeByLang: Record<TourLanguageCode, string> = { |
|||
ar: '07:00 صباحاً (انطلاق جماعي منظم)', |
|||
fa: '۰۷:۰۰ صبح (حرکت گروهی هماهنگ)', |
|||
en: '07:00 AM (Organized Group Departure)', |
|||
ru: '07:00 утра (Организованный групповой выезд)', |
|||
id: '07:00 Pagi (Keberangkatan Rombongan Terpadu)', |
|||
} |
|||
|
|||
transportInfo = { |
|||
...transportInfo, |
|||
vehicle_type: uniqueVehicles.join(' • ') || firstStep.vehicle_label, |
|||
carrier_name: |
|||
generalTransport?.carrierName?.trim() || |
|||
transportInfo?.carrier_name || |
|||
defaultCarrierByLang[lang], |
|||
departure_city: firstStep.from_city, |
|||
arrival_city: |
|||
uniqueVisitedCities.length > 0 |
|||
? uniqueVisitedCities.join(' / ') |
|||
: lastOutboundStep.to_city, |
|||
departure_time: |
|||
generalTransport?.departureTime?.trim() || |
|||
transportInfo?.departure_time || |
|||
defaultDepTimeByLang[lang], |
|||
baggage_allowance: |
|||
generalTransport?.baggageAllowance?.trim() || |
|||
transportInfo?.baggage_allowance || |
|||
defaultBaggageByLang[lang], |
|||
steps: stepsForLang, |
|||
} |
|||
} |
|||
|
|||
// نکته مهم: در بکاند TourDetailSerializer.get_tour_meta بررسی میکند که accommodations خالی نباشد.
|
|||
// اگر ادمین هتل انتخاب کرده باشد، accommodations پر است؛ در غیر این صورت از هتلهای قبلی یا هتلهای متناظر شهرهای مسیر استفاده میشود.
|
|||
let finalAccommodations = |
|||
accommodations.length > 0 |
|||
? accommodations |
|||
: prevMeta.accommodations && prevMeta.accommodations.length > 0 |
|||
? prevMeta.accommodations |
|||
: fallbackAccommodationsByLang?.[lang] || [] |
|||
|
|||
if (finalAccommodations.length === 0 && stepsForLang.length > 0) { |
|||
const autoAccommodations: AccommodationItem[] = [] |
|||
const seenCities = new Set<string>() |
|||
for (const rawStep of validTransportSteps) { |
|||
if (rawStep.isReturn) continue |
|||
const targetNorm = normalizeCityToken(rawStep.toCity) |
|||
if (!targetNorm || seenCities.has(targetNorm)) continue |
|||
const matchedCity = cityCatalog.find((c) => |
|||
Object.values(c.names).some((n) => { |
|||
const nNorm = normalizeCityToken(n) |
|||
return nNorm && (nNorm === targetNorm || nNorm.includes(targetNorm) || targetNorm.includes(nNorm)) |
|||
}) |
|||
) |
|||
if (matchedCity && matchedCity.hotels.length > 0) { |
|||
seenCities.add(targetNorm) |
|||
const firstHotel = matchedCity.hotels[0] |
|||
autoAccommodations.push({ |
|||
city: matchedCity.names[lang] || matchedCity.names.fa, |
|||
hotel_name: |
|||
firstHotel.translations?.[lang]?.name?.trim() || |
|||
firstHotel.translations?.fa?.name?.trim() || |
|||
firstHotel.name, |
|||
stars: firstHotel.stars || 5, |
|||
distance_to_shrine: |
|||
firstHotel.translations?.[lang]?.distanceToShrine?.trim() || |
|||
firstHotel.translations?.fa?.distanceToShrine?.trim() || |
|||
firstHotel.distanceToShrine || |
|||
'', |
|||
hotel_id: firstHotel.id, |
|||
city_key: matchedCity.key, |
|||
}) |
|||
} |
|||
} |
|||
if (autoAccommodations.length === 0 && cityCatalog.length > 0) { |
|||
const firstWithHotel = cityCatalog.find((c) => c.hotels.length > 0) |
|||
if (firstWithHotel) { |
|||
const h = firstWithHotel.hotels[0] |
|||
autoAccommodations.push({ |
|||
city: firstWithHotel.names[lang] || firstWithHotel.names.fa, |
|||
hotel_name: h.translations?.[lang]?.name?.trim() || h.name, |
|||
stars: h.stars || 5, |
|||
distance_to_shrine: h.translations?.[lang]?.distanceToShrine?.trim() || h.distanceToShrine || '', |
|||
hotel_id: h.id, |
|||
city_key: firstWithHotel.key, |
|||
}) |
|||
} |
|||
} |
|||
finalAccommodations = autoAccommodations |
|||
} |
|||
|
|||
result[lang] = { |
|||
...prevMeta, |
|||
...(finalAccommodations.length > 0 ? { accommodations: finalAccommodations } : {}), |
|||
...(transportInfo ? { transport_info: transportInfo } : {}), |
|||
...(stepsForLang.length > 0 ? { transport_steps: stepsForLang } : {}), |
|||
} |
|||
} |
|||
|
|||
return result |
|||
} |
|||
|
|||
/** |
|||
* بازیابی ردیفهای انتخاب هتل در فرم از روی tour_meta ذخیرهشده |
|||
*/ |
|||
export function extractHotelSelectionRowsFromTourMeta( |
|||
meta: TourMeta | undefined, |
|||
hotelsCatalog: CustomTripHotelItem[], |
|||
destinationsCatalog: CustomTripDestinationItem[] |
|||
): TourHotelSelectionRow[] { |
|||
const items = meta?.accommodations || [] |
|||
if (!items.length) return [] |
|||
|
|||
const cityCatalog = buildTourHotelCitiesCatalog(hotelsCatalog, destinationsCatalog) |
|||
|
|||
return items.map((acc, idx) => { |
|||
let matchedHotel = |
|||
acc.hotel_id !== undefined |
|||
? hotelsCatalog.find((h) => String(h.id) === String(acc.hotel_id)) |
|||
: undefined |
|||
|
|||
if (!matchedHotel && acc.hotel_name) { |
|||
const targetName = normalizeCityToken(acc.hotel_name) |
|||
matchedHotel = hotelsCatalog.find((h) => { |
|||
const candidates = [ |
|||
h.name, |
|||
h.translations?.fa?.name, |
|||
h.translations?.ar?.name, |
|||
h.translations?.en?.name, |
|||
h.translations?.ru?.name, |
|||
h.translations?.id?.name, |
|||
].filter(Boolean) as string[] |
|||
return candidates.some((c) => { |
|||
const cNorm = normalizeCityToken(c) |
|||
return cNorm === targetName || cNorm.includes(targetName) || targetName.includes(cNorm) |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
let cityKey = acc.city_key || '' |
|||
if (!cityKey && matchedHotel) { |
|||
const cityOpt = cityCatalog.find((c) => |
|||
c.hotels.some((ch) => String(ch.id) === String(matchedHotel!.id)) |
|||
) |
|||
if (cityOpt) cityKey = cityOpt.key |
|||
} |
|||
if (!cityKey && acc.city) { |
|||
const targetCity = normalizeCityToken(acc.city) |
|||
const cityOpt = cityCatalog.find((c) => |
|||
Object.values(c.names).some((n) => { |
|||
const nNorm = normalizeCityToken(n) |
|||
return nNorm && (nNorm === targetCity || nNorm.includes(targetCity) || targetCity.includes(nNorm)) |
|||
}) |
|||
) |
|||
if (cityOpt) cityKey = cityOpt.key |
|||
} |
|||
|
|||
return { |
|||
id: `hotel_row_${idx + 1}_${Date.now()}`, |
|||
cityKey: cityKey || acc.city || '', |
|||
hotelId: matchedHotel ? String(matchedHotel.id) : acc.hotel_id ? String(acc.hotel_id) : '', |
|||
nights: acc.nights ? String(acc.nights) : '', |
|||
} |
|||
}) |
|||
} |
|||
|
|||
/** |
|||
* بازیابی مراحل حملونقل در فرم از روی tour_meta ذخیرهشده |
|||
*/ |
|||
export function extractTransportStepsFromTourMeta( |
|||
meta: TourMeta | undefined |
|||
): TourTransportStepRow[] { |
|||
const rawSteps = meta?.transport_steps || meta?.transport_info?.steps || [] |
|||
if (rawSteps.length > 0) { |
|||
return rawSteps.map((st, idx) => ({ |
|||
id: st.id || `step_${idx + 1}_${Date.now()}`, |
|||
fromCity: st.from_city || '', |
|||
toCity: st.to_city || '', |
|||
vehicleType: |
|||
st.vehicle_type === 'train' || st.vehicle_type === 'bus' |
|||
? st.vehicle_type |
|||
: 'airplane', |
|||
isReturn: Boolean(st.is_return), |
|||
departureTime: st.departure_time || '', |
|||
carrierName: st.carrier_name || '', |
|||
baggageAllowance: st.baggage_allowance || '', |
|||
})) |
|||
} |
|||
|
|||
return [] |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue