chore: remove locations type to opt for location in array instead, this highlights array objects

This commit is contained in:
Christian Andolf
2025-04-02 10:11:39 +02:00
parent 14f9b68365
commit 2a07fcf7be
4 changed files with 15 additions and 16 deletions

View File

@@ -4,7 +4,7 @@ import {
type InitState, type InitState,
type State, type State,
} from "@/types/components/form/bookingwidget" } from "@/types/components/form/bookingwidget"
import type { Locations } from "@/types/trpc/routers/hotel/locations" import type { Location } from "@/types/trpc/routers/hotel/locations"
export const localStorageKey = "searchHistory" export const localStorageKey = "searchHistory"
export const sessionStorageKey = "searchData" export const sessionStorageKey = "searchData"
@@ -61,7 +61,7 @@ export function reducer(state: State, action: Action) {
} }
}) })
const matches: Locations = [] const matches: Location[] = []
matchesMap.forEach((value) => { matchesMap.forEach((value) => {
matches.push(value) matches.push(value)
}) })

View File

@@ -1,14 +1,14 @@
import type { BookingWidgetType } from "@/types/components/bookingWidget" import type { BookingWidgetType } from "@/types/components/bookingWidget"
import type { Location, Locations } from "@/types/trpc/routers/hotel/locations" import type { Location } from "@/types/trpc/routers/hotel/locations"
export interface BookingWidgetFormProps { export interface BookingWidgetFormProps {
locations: Locations locations: Location[]
type?: BookingWidgetType type?: BookingWidgetType
onClose: () => void onClose: () => void
} }
export interface BookingWidgetFormContentProps { export interface BookingWidgetFormContentProps {
locations: Locations locations: Location[]
formId: string formId: string
onSubmit: () => void onSubmit: () => void
isSearching: boolean isSearching: boolean
@@ -40,7 +40,7 @@ interface SearchLocationsAction {
interface SetItemAction { interface SetItemAction {
payload: { payload: {
location: Location location: Location
searchHistory: Locations searchHistory: Location[]
} }
type: ActionType.SELECT_ITEM type: ActionType.SELECT_ITEM
} }
@@ -48,7 +48,7 @@ interface SetItemAction {
export interface SetStorageData { export interface SetStorageData {
payload: { payload: {
searchData?: Location searchData?: Location
searchHistory?: Locations searchHistory?: Location[]
} }
type: ActionType.SET_STORAGE_DATA type: ActionType.SET_STORAGE_DATA
} }
@@ -61,11 +61,11 @@ export type Action =
| SetStorageData | SetStorageData
export interface State { export interface State {
defaultLocations: Locations defaultLocations: Location[]
locations: Locations locations: Location[]
search: string search: string
searchData: Location | undefined searchData: Location | undefined
searchHistory: Locations | null searchHistory: Location[] | null
} }
export interface InitState extends Pick<State, "defaultLocations"> { export interface InitState extends Pick<State, "defaultLocations"> {

View File

@@ -2,10 +2,10 @@ import type { VariantProps } from "class-variance-authority"
import type { PropGetters } from "downshift" import type { PropGetters } from "downshift"
import type { dialogVariants } from "@/components/Forms/BookingWidget/FormContent/Search/SearchList/Dialog/variants" import type { dialogVariants } from "@/components/Forms/BookingWidget/FormContent/Search/SearchList/Dialog/variants"
import type { Location, Locations } from "../trpc/routers/hotel/locations" import type { Location } from "../trpc/routers/hotel/locations"
export interface SearchProps { export interface SearchProps {
locations: Locations locations: Location[]
handlePressEnter: () => void handlePressEnter: () => void
} }
@@ -22,9 +22,9 @@ export interface SearchListProps {
isOpen: boolean isOpen: boolean
handleClearSearchHistory: () => void handleClearSearchHistory: () => void
highlightedIndex: HighlightedIndex highlightedIndex: HighlightedIndex
locations: Locations locations: Location[]
search: string search: string
searchHistory: Locations | null searchHistory: Location[] | null
} }
export interface ListProps export interface ListProps

View File

@@ -8,8 +8,7 @@ import type {
export interface LocationSchema extends z.output<typeof locationsSchema> {} export interface LocationSchema extends z.output<typeof locationsSchema> {}
export type Locations = LocationSchema["data"] export type Location = LocationSchema["data"][number]
export type Location = Locations[number]
export type CityLocation = Location & { type: "cities" } export type CityLocation = Location & { type: "cities" }
export type HotelLocation = Location & { type: "hotels" } export type HotelLocation = Location & { type: "hotels" }