add list of cities for car pick drop off locations
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import citiesDataset from '@/data/morocco-cities-rgph-2024.json'
|
||||
|
||||
export type SupportedCityLocale = 'en' | 'fr' | 'ar'
|
||||
|
||||
interface LocalizedName {
|
||||
en: string
|
||||
fr: string
|
||||
ar: string
|
||||
}
|
||||
|
||||
interface MoroccanCity {
|
||||
id: string
|
||||
name: LocalizedName
|
||||
province: LocalizedName
|
||||
}
|
||||
|
||||
interface MoroccanCitiesDataset {
|
||||
cities: MoroccanCity[]
|
||||
}
|
||||
|
||||
export function getMoroccanCityOptions(locale: string) {
|
||||
const resolvedLocale: SupportedCityLocale = locale === 'fr' || locale === 'ar' ? locale : 'en'
|
||||
const cityNames = (citiesDataset as MoroccanCitiesDataset).cities.map((city) => city.name[resolvedLocale])
|
||||
|
||||
return Array.from(new Set(cityNames)).sort((a, b) => a.localeCompare(b, resolvedLocale))
|
||||
}
|
||||
|
||||
export function mergeLocationOptions(options: string[], selectedLocations: string[]) {
|
||||
const selected = selectedLocations.map((location) => location.trim()).filter(Boolean)
|
||||
return Array.from(new Set([...selected, ...options]))
|
||||
}
|
||||
Reference in New Issue
Block a user