Merged in feature/SW-3327-move-hotel-info-card-to-design-system (pull request #2730)

Feature/SW-3327 move hotel info card to design system

* wip

* wip

* wip

* wip moving hotelinfocard

* add controls for HotelInfoCard in storybook

* merge


Approved-by: Anton Gunnarsson
This commit is contained in:
Joakim Jäderberg
2025-08-29 10:09:48 +00:00
parent a0580de52f
commit 2a9313362f
14 changed files with 388 additions and 211 deletions

View File

@@ -3,7 +3,7 @@ import { describe, expect, it } from "vitest"
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
import { dt } from "@scandic-hotels/common/dt"
import { getHotelAlertsForBookingDates } from "./index"
import { filterOverlappingDates } from "./index"
import type { specialAlertsSchema } from "@scandic-hotels/trpc/routers/hotels/schemas/hotel/specialAlerts"
import type { z } from "zod"
@@ -23,11 +23,11 @@ function makeAlert(start: string, end: string): Alert {
}
}
describe("getHotelAlertsForBookingDates", () => {
describe("filterOverlappingDates", () => {
const alert = makeAlert("2025-09-01", "2025-09-10")
it("shows alert if booking starts inside alert", () => {
const result = getHotelAlertsForBookingDates(
const result = filterOverlappingDates(
[alert],
dt("2025-09-05"),
dt("2025-09-12")
@@ -36,7 +36,7 @@ describe("getHotelAlertsForBookingDates", () => {
})
it("shows alert if booking ends inside alert", () => {
const result = getHotelAlertsForBookingDates(
const result = filterOverlappingDates(
[alert],
dt("2025-08-28"),
dt("2025-09-05")
@@ -45,7 +45,7 @@ describe("getHotelAlertsForBookingDates", () => {
})
it("shows alert if booking fully contains alert", () => {
const result = getHotelAlertsForBookingDates(
const result = filterOverlappingDates(
[alert],
dt("2025-08-28"),
dt("2025-09-15")
@@ -54,7 +54,7 @@ describe("getHotelAlertsForBookingDates", () => {
})
it("shows alert if alert fully contains booking", () => {
const result = getHotelAlertsForBookingDates(
const result = filterOverlappingDates(
[alert],
dt("2025-09-03"),
dt("2025-09-05")
@@ -63,7 +63,7 @@ describe("getHotelAlertsForBookingDates", () => {
})
it("does not show alert if no overlap", () => {
const result = getHotelAlertsForBookingDates(
const result = filterOverlappingDates(
[alert],
dt("2025-08-01"),
dt("2025-08-05")

View File

@@ -7,7 +7,6 @@ import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum"
import { ChildBedTypeEnum } from "@scandic-hotels/trpc/enums/childBedTypeEnum"
import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
import type { specialAlertsSchema } from "@scandic-hotels/trpc/routers/hotels/schemas/hotel/specialAlerts"
import type { Package, Packages } from "@scandic-hotels/trpc/types/packages"
import type { JSX } from "react"
@@ -88,41 +87,57 @@ export function calculateVat(priceInclVat: number, vat: number) {
}
}
export function getHotelAlertsForBookingDates(
specialAlerts: Zod.infer<typeof specialAlertsSchema>,
export function filterOverlappingDates<
T extends {
startDate: Date | Dayjs | string | undefined | null
endDate: Date | Dayjs | string | undefined | null
},
>(dateRangeItems: T[], fromDate: Date | Dayjs, toDate: Date | Dayjs) {
const startDate = dt(fromDate)
const endDate = dt(toDate)
return dateRangeItems.filter((item) =>
hasOverlappingDates(item, startDate, endDate)
)
}
export function hasOverlappingDates(
dateRangeItem: {
startDate: Date | Dayjs | string | undefined | null
endDate: Date | Dayjs | string | undefined | null
},
fromDate: Date | Dayjs,
toDate: Date | Dayjs
) {
return specialAlerts.filter((alert) => {
if (alert.endDate && alert.startDate) {
const alertStartDate = dt(alert.startDate)
const alertEndDate = dt(alert.endDate)
const bookingStart = dt(fromDate)
const bookingEnd = dt(toDate)
const startDate = dt(fromDate)
const endDate = dt(toDate)
const fromDateIsBetweenAlertDates = bookingStart.isBetween(
alertStartDate,
alertEndDate,
"date",
"[]"
)
const toDateIsBetweenAlertDates = bookingEnd.isBetween(
alertStartDate,
alertEndDate,
"date",
"[]"
)
if (dateRangeItem.endDate && dateRangeItem.startDate) {
const itemStartDate = dt(dateRangeItem.startDate)
const itemEndDate = dt(dateRangeItem.endDate)
const bookingFullyContainsAlert =
bookingStart.isSameOrBefore(alertStartDate, "date") &&
bookingEnd.isSameOrAfter(alertEndDate, "date")
const fromDateIsBetweenItemDates = startDate.isBetween(
itemStartDate,
itemEndDate,
"date",
"[]"
)
const toDateIsBetweenItemDates = endDate.isBetween(
itemStartDate,
itemEndDate,
"date",
"[]"
)
return (
fromDateIsBetweenAlertDates ||
toDateIsBetweenAlertDates ||
bookingFullyContainsAlert
)
}
return true
})
const itemFullyContained =
startDate.isSameOrBefore(itemStartDate, "date") &&
endDate.isSameOrAfter(itemEndDate, "date")
return (
fromDateIsBetweenItemDates ||
toDateIsBetweenItemDates ||
itemFullyContained
)
}
return true
}