Merged in chore/cleanup-scandic-web (pull request #2831)
chore: Cleanup scandic-web * Remove unused files * Remove unused and add missing packages * Remove unused exports Approved-by: Linus Flood
This commit is contained in:
@@ -51,14 +51,3 @@ export function isValidSortOption(
|
||||
): value is HotelSortOption {
|
||||
return sortItems.map((item) => item.value).includes(value as HotelSortOption)
|
||||
}
|
||||
|
||||
export function getBasePathNameWithoutFilters(
|
||||
pathname: string,
|
||||
filterSlugs: string[]
|
||||
) {
|
||||
const pathSegments = pathname.split("/")
|
||||
const filteredSegments = pathSegments.filter(
|
||||
(segment) => !filterSlugs.includes(segment)
|
||||
)
|
||||
return filteredSegments.join("/")
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ import { produce } from "immer"
|
||||
import { useContext } from "react"
|
||||
import { create, useStore } from "zustand"
|
||||
|
||||
import { BreakfastPackageEnum } from "@scandic-hotels/trpc/enums/breakfast"
|
||||
|
||||
import { clearAncillarySessionData } from "@/components/HotelReservation/MyStay/utils/ancillaries"
|
||||
import { AddAncillaryContext } from "@/contexts/AddAncillary"
|
||||
|
||||
@@ -10,7 +12,6 @@ import type {
|
||||
Ancillary,
|
||||
SelectedAncillary,
|
||||
} from "@/types/components/myPages/myStay/ancillaries"
|
||||
import { BreakfastPackageEnum } from "@scandic-hotels/trpc/enums/breakfast"
|
||||
import type { Room } from "@/types/stores/my-stay"
|
||||
|
||||
export enum AncillaryStepEnum {
|
||||
@@ -40,7 +41,7 @@ export type BreakfastData = {
|
||||
currency: string
|
||||
}
|
||||
|
||||
export interface AddAncillaryState {
|
||||
interface AddAncillaryState {
|
||||
currentStep: number
|
||||
steps: Steps
|
||||
booking: Room
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
import { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
|
||||
|
||||
import type { AvailabilityError } from "@scandic-hotels/booking-flow/types/stores/rates"
|
||||
import type {
|
||||
Product,
|
||||
RoomConfiguration,
|
||||
RoomsAvailability,
|
||||
} from "@scandic-hotels/trpc/types/roomAvailability"
|
||||
|
||||
export function findProduct(
|
||||
rateCode: string,
|
||||
product: Product,
|
||||
counterRateCode = ""
|
||||
) {
|
||||
if ("corporateCheque" in product) {
|
||||
return product.corporateCheque.rateCode === rateCode
|
||||
}
|
||||
|
||||
if ("redemption" in product) {
|
||||
return product.redemption.rateCode === rateCode
|
||||
}
|
||||
|
||||
if ("voucher" in product) {
|
||||
return product.voucher.rateCode === rateCode
|
||||
}
|
||||
|
||||
const memberExists = "member" in product
|
||||
const publicExists = "public" in product
|
||||
const isRegularRate = memberExists && publicExists
|
||||
if (isRegularRate) {
|
||||
let isProduct = false
|
||||
if (product.member) {
|
||||
isProduct =
|
||||
product.member.rateCode === rateCode ||
|
||||
product.member.rateCode === counterRateCode
|
||||
}
|
||||
if (product.public) {
|
||||
isProduct =
|
||||
product.public.rateCode === rateCode ||
|
||||
product.public.rateCode === counterRateCode
|
||||
}
|
||||
return isProduct
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function findProductInRoom(
|
||||
rateCode: string | undefined | null,
|
||||
room: RoomConfiguration,
|
||||
counterRateCode: string | undefined | null
|
||||
) {
|
||||
if (!rateCode) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (room.campaign.length) {
|
||||
const campaignProduct = room.campaign.find((product) =>
|
||||
findProduct(rateCode, product, counterRateCode || "")
|
||||
)
|
||||
if (campaignProduct) {
|
||||
return campaignProduct
|
||||
}
|
||||
}
|
||||
if (room.code.length) {
|
||||
const codeProduct = room.code.find((product) =>
|
||||
findProduct(rateCode, product, counterRateCode || "")
|
||||
)
|
||||
if (codeProduct) {
|
||||
return codeProduct
|
||||
}
|
||||
}
|
||||
if (room.redemptions.length) {
|
||||
const redemptionProduct = room.redemptions.find((product) =>
|
||||
findProduct(rateCode, product)
|
||||
)
|
||||
if (redemptionProduct) {
|
||||
return redemptionProduct
|
||||
}
|
||||
}
|
||||
if (room.regular.length) {
|
||||
const regularProduct = room.regular.find((product) =>
|
||||
findProduct(rateCode, product, counterRateCode || "")
|
||||
)
|
||||
if (regularProduct) {
|
||||
return regularProduct
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function findSelectedRate(
|
||||
rateCode: string | undefined | null,
|
||||
counterRateCode: string | undefined | null,
|
||||
roomTypeCode: string | undefined | null,
|
||||
rooms: RoomConfiguration[] | AvailabilityError
|
||||
) {
|
||||
if (!Array.isArray(rooms)) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (!rateCode) {
|
||||
return null
|
||||
}
|
||||
|
||||
return rooms.find((room) => {
|
||||
if (room.roomTypeCode !== roomTypeCode) {
|
||||
return false
|
||||
}
|
||||
return findProductInRoom(rateCode, room, counterRateCode)
|
||||
})
|
||||
}
|
||||
|
||||
export function findDefaultCurrency(
|
||||
roomsAvailability: (RoomsAvailability | AvailabilityError)[] | undefined
|
||||
) {
|
||||
if (!roomsAvailability || !roomsAvailability.length) {
|
||||
return CurrencyEnum.Unknown
|
||||
}
|
||||
|
||||
const availability = roomsAvailability.filter(
|
||||
(room): room is RoomsAvailability => {
|
||||
if ("error" in room) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
)[0]
|
||||
|
||||
const pkg = availability?.packages.find((pkg) => pkg.localPrice.currency)
|
||||
if (!pkg) {
|
||||
return CurrencyEnum.Unknown
|
||||
}
|
||||
|
||||
const defaultCurrency = pkg.localPrice.currency
|
||||
return defaultCurrency
|
||||
}
|
||||
Reference in New Issue
Block a user