Merged in feat/sw-2863-move-contentstack-router-to-trpc-package (pull request #2389)

feat(SW-2863): Move contentstack router to trpc package

* Add exports to packages and lint rule to prevent relative imports

* Add env to trpc package

* Add eslint to trpc package

* Apply lint rules

* Use direct imports from trpc package

* Add lint-staged config to trpc

* Move lang enum to common

* Restructure trpc package folder structure

* WIP first step

* update internal imports in trpc

* Fix most errors in scandic-web

Just 100 left...

* Move Props type out of trpc

* Fix CategorizedFilters types

* Move more schemas in hotel router

* Fix deps

* fix getNonContentstackUrls

* Fix import error

* Fix entry error handling

* Fix generateMetadata metrics

* Fix alertType enum

* Fix duplicated types

* lint:fix

* Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package

* Fix broken imports

* Merge branch 'master' into feat/sw-2863-move-contentstack-router-to-trpc-package


Approved-by: Linus Flood
This commit is contained in:
Anton Gunnarsson
2025-06-26 07:53:01 +00:00
parent 0263ab8c87
commit 002d093af4
921 changed files with 3112 additions and 3008 deletions

View File

@@ -1,11 +1,9 @@
import type {
CategorizedFilters,
Filter,
SortItem,
} from "@/types/components/destinationFilterAndSort"
import { SortOption } from "@/types/enums/destinationFilterAndSort"
import type { DestinationPagesHotelData } from "@/types/hotel"
import type { DestinationCityListItem } from "@/types/trpc/routers/contentstack/destinationCityPage"
import { SortOption } from "@scandic-hotels/trpc/enums/destinationFilterAndSort"
import type { DestinationCityListItem } from "@scandic-hotels/trpc/types/destinationCityPage"
import type { DestinationPagesHotelData } from "@scandic-hotels/trpc/types/hotel"
import type { SortItem } from "@/types/components/destinationFilterAndSort"
const HOTEL_SORTING_STRATEGIES: Partial<
Record<
@@ -24,38 +22,6 @@ const HOTEL_SORTING_STRATEGIES: Partial<
},
}
const CITY_SORTING_STRATEGIES: Partial<
Record<
SortOption,
(a: DestinationCityListItem, b: DestinationCityListItem) => number
>
> = {
[SortOption.Name]: function (a, b) {
return a.cityName.localeCompare(b.cityName)
},
[SortOption.Recommended]: function (a, b) {
if (a.sort_order === null && b.sort_order === null) {
return a.cityName.localeCompare(b.cityName)
}
if (a.sort_order === null) {
return 1
}
if (b.sort_order === null) {
return -1
}
return b.sort_order - a.sort_order
},
}
function sortFilters(filters: Filter[]): Filter[] {
return [...filters].sort((a, b) => {
// First sort by sortOrder
const orderDiff = a.sortOrder - b.sortOrder
// If sortOrder is the same, sort by name as secondary criterion
return orderDiff === 0 ? a.name.localeCompare(b.name) : orderDiff
})
}
export function getFilteredHotels(
hotels: DestinationPagesHotelData[],
filters: string[]
@@ -85,14 +51,6 @@ export function getFilteredCities(
)
}
export function getSortedCities(
cities: DestinationCityListItem[],
sortOption: SortOption
) {
const sortFn = CITY_SORTING_STRATEGIES[sortOption]
return sortFn ? cities.sort(sortFn) : cities
}
export function getSortedHotels(
hotels: DestinationPagesHotelData[],
sortOption: SortOption
@@ -108,59 +66,6 @@ export function isValidSortOption(
return sortItems.map((item) => item.value).includes(value as SortOption)
}
const HOTEL_SURROUNDINGS_FILTER_TYPE_NAMES = [
"Hotel surroundings",
"Hotel omgivelser",
"Hotelumgebung",
"Hotellia lähellä",
"Hotellomgivelser",
"Omgivningar",
]
const HOTEL_FACILITIES_FILTER_TYPE_NAMES = [
"Hotel facilities",
"Hotellfaciliteter",
"Hotelfaciliteter",
"Hotel faciliteter",
"Hotel-Infos",
"Hotellin palvelut",
]
export function getFiltersFromHotels(
hotels: DestinationPagesHotelData[]
): CategorizedFilters {
if (hotels.length === 0) {
return { facilityFilters: [], surroundingsFilters: [] }
}
const filters = hotels.flatMap(({ hotel }) => hotel.detailedFacilities)
const uniqueFilterNames = [...new Set(filters.map((filter) => filter.name))]
const filterList = uniqueFilterNames
.map((filterName) => {
const filter = filters.find((filter) => filter.name === filterName)
return filter
? {
name: filter.name,
slug: filter.slug,
filterType: filter.filter,
sortOrder: filter.sortOrder,
}
: null
})
.filter((filter): filter is Filter => !!filter)
const facilityFilters = filterList.filter((filter) =>
HOTEL_FACILITIES_FILTER_TYPE_NAMES.includes(filter.filterType)
)
const surroundingsFilters = filterList.filter((filter) =>
HOTEL_SURROUNDINGS_FILTER_TYPE_NAMES.includes(filter.filterType)
)
return {
facilityFilters: sortFilters(facilityFilters),
surroundingsFilters: sortFilters(surroundingsFilters),
}
}
export function getBasePathNameWithoutFilters(
pathname: string,
filterSlugs: string[]

View File

@@ -2,6 +2,8 @@ import { produce } from "immer"
import { useContext } from "react"
import { create, useStore } from "zustand"
import { getSortedCities } from "@scandic-hotels/trpc/utils/getSortedCities"
import { DestinationDataContext } from "@/contexts/DestinationData"
import {
trackFilterChangeEvent,
@@ -12,12 +14,12 @@ import {
getBasePathNameWithoutFilters,
getFilteredCities,
getFilteredHotels,
getSortedCities,
getSortedHotels,
isValidSortOption,
} from "./helper"
import type { Filter } from "@/types/components/destinationFilterAndSort"
import type { Filter } from "@scandic-hotels/trpc/types/destinationFilterAndSort"
import type {
DestinationDataState,
InitialState,

View File

@@ -1,6 +1,9 @@
import isEqual from "fast-deep-equal"
import { parsePhoneNumberFromString } from "libphonenumber-js"
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import { RateTypeEnum } from "@scandic-hotels/trpc/enums/rateType"
import {
sumPackages,
sumPackagesRequestedPrice,
@@ -8,20 +11,19 @@ import {
import { detailsStorageName } from "."
import type { BreakfastPackage } from "@/types/components/hotelReservation/breakfast"
import { type RoomRate } from "@/types/components/hotelReservation/enterDetails/details"
import type { Price } from "@/types/components/hotelReservation/price"
import type { SelectRateBooking } from "@/types/components/hotelReservation/selectRate/selectRate"
import { CurrencyEnum } from "@/types/enums/currency"
import { RateTypeEnum } from "@/types/enums/rateType"
import type { Packages } from "@/types/requests/packages"
import type { PersistedState, RoomState } from "@/types/stores/enter-details"
import type {
CorporateChequeProduct,
PriceProduct,
RedemptionProduct,
VoucherProduct,
} from "@/types/trpc/routers/hotel/roomAvailability"
} from "@scandic-hotels/trpc/types/roomAvailability"
import type { BreakfastPackage } from "@/types/components/hotelReservation/breakfast"
import { type RoomRate } from "@/types/components/hotelReservation/enterDetails/details"
import type { Price } from "@/types/components/hotelReservation/price"
import type { SelectRateBooking } from "@/types/components/hotelReservation/selectRate/selectRate"
import type { Packages } from "@/types/requests/packages"
import type { PersistedState, RoomState } from "@/types/stores/enter-details"
import type { SafeUser } from "@/types/user"
export function extractGuestFromUser(user: NonNullable<SafeUser>) {

View File

@@ -4,7 +4,7 @@ import { useContext } from "react"
import { create, useStore } from "zustand"
import { getDefaultCountryFromLang } from "@/constants/languages"
import { dt } from "@/lib/dt"
import { dt } from "@scandic-hotels/common/dt"
import { DetailsContext } from "@/contexts/Details"

View File

@@ -10,7 +10,7 @@ import type {
Ancillary,
SelectedAncillary,
} from "@/types/components/myPages/myStay/ancillaries"
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
import { BreakfastPackageEnum } from "@scandic-hotels/trpc/enums/breakfast"
import type { Room } from "@/types/stores/my-stay"
export enum AncillaryStepEnum {

View File

@@ -1,8 +1,9 @@
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import { formatPrice } from "@/utils/numberFormatting"
import type { IntlShape } from "react-intl"
import { CurrencyEnum } from "@/types/enums/currency"
import type { Room } from "@/types/stores/my-stay"
export function calculateTotalPrice(

View File

@@ -1,10 +1,10 @@
import { CurrencyEnum } from "@/types/enums/currency"
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
import type { AvailabilityError } from "@/types/stores/rates"
import type {
Product,
RoomConfiguration,
RoomsAvailability,
} from "@/types/trpc/routers/hotel/roomAvailability"
} from "@scandic-hotels/trpc/types/roomAvailability"
export function findProduct(
rateCode: string,

View File

@@ -2,6 +2,9 @@ import { produce } from "immer"
import { useContext } from "react"
import { create, useStore } from "zustand"
import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
import { AvailabilityEnum } from "@scandic-hotels/trpc/enums/selectHotel"
import { REDEMPTION } from "@/constants/booking"
import { RatesContext } from "@/contexts/Rates"
@@ -13,12 +16,11 @@ import {
findSelectedRate,
} from "./helpers"
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
import type { PriceProduct } from "@scandic-hotels/trpc/types/roomAvailability"
import { BookingCodeFilterEnum } from "@/types/enums/bookingCodeFilter"
import type { Package, Packages } from "@/types/requests/packages"
import type { InitialState, RatesState } from "@/types/stores/rates"
import type { PriceProduct } from "@/types/trpc/routers/hotel/roomAvailability"
export function createRatesStore({
booking,