From 8f813eb9e7c6156470207ab1aa75642024c9d6a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matilda=20Landstr=C3=B6m?= Date: Thu, 4 Sep 2025 14:18:57 +0000 Subject: [PATCH] Merged in feat/SW-3163-remove-openinghours-name (pull request #2735) feat(SW-3163): update opening hours schema name/nameEnglish * feat(SW-3163): remove name * fix(SW-3163): update schemas Approved-by: Erik Tiekstra --- .../RestaurantBar/RestaurantBarItem/index.tsx | 2 +- .../HotelSubpage/Sidebar/RestaurantSidebar.tsx | 2 +- .../SidePeekAccordions/BreakfastAccordionItem.tsx | 5 +---- .../OpeningHours/AlternateOpeningHours/index.tsx | 4 ++-- .../lib/components/OpeningHours/index.tsx | 7 +++++-- .../components/OpeningHours/openingHours.test.ts | 8 -------- .../components/OpeningHours/openingHoursTypes.ts | 10 +++++++--- .../lib/components/OpeningHours/utils.ts | 4 ++-- .../hotels/schemas/hotel/include/restaurants.ts | 13 ++++++++----- 9 files changed, 27 insertions(+), 28 deletions(-) diff --git a/apps/scandic-web/components/ContentType/HotelPage/SidePeeks/RestaurantBar/RestaurantBarItem/index.tsx b/apps/scandic-web/components/ContentType/HotelPage/SidePeeks/RestaurantBar/RestaurantBarItem/index.tsx index 30abe7619..02ef27ead 100644 --- a/apps/scandic-web/components/ContentType/HotelPage/SidePeeks/RestaurantBar/RestaurantBarItem/index.tsx +++ b/apps/scandic-web/components/ContentType/HotelPage/SidePeeks/RestaurantBar/RestaurantBarItem/index.tsx @@ -60,7 +60,7 @@ export default async function RestaurantBarItem({ {openingDetails.map((details) => ( diff --git a/apps/scandic-web/components/ContentType/HotelSubpage/Sidebar/RestaurantSidebar.tsx b/apps/scandic-web/components/ContentType/HotelSubpage/Sidebar/RestaurantSidebar.tsx index e1093ebe5..9603e18f4 100644 --- a/apps/scandic-web/components/ContentType/HotelSubpage/Sidebar/RestaurantSidebar.tsx +++ b/apps/scandic-web/components/ContentType/HotelSubpage/Sidebar/RestaurantSidebar.tsx @@ -37,7 +37,7 @@ export default async function RestaurantSidebar({ {openingDetails.map((details) => ( diff --git a/packages/booking-flow/lib/components/SidePeekAccordions/BreakfastAccordionItem.tsx b/packages/booking-flow/lib/components/SidePeekAccordions/BreakfastAccordionItem.tsx index b54f89497..fb9dd5d3a 100644 --- a/packages/booking-flow/lib/components/SidePeekAccordions/BreakfastAccordionItem.tsx +++ b/packages/booking-flow/lib/components/SidePeekAccordions/BreakfastAccordionItem.tsx @@ -30,10 +30,7 @@ export default function BreakfastAccordionItem({ const openingHours = restaurants ?.map((restaurant) => { const breakfastDetail = restaurant.openingDetails.find( - (details) => - details.openingHours.name === "Breakfast" || - details.openingHours.name === - intl.formatMessage({ defaultMessage: "Breakfast" }) + (details) => details.openingHours.nameEnglish === "Breakfast" ) return breakfastDetail }) diff --git a/packages/design-system/lib/components/OpeningHours/AlternateOpeningHours/index.tsx b/packages/design-system/lib/components/OpeningHours/AlternateOpeningHours/index.tsx index d3eeca70a..8544314d8 100644 --- a/packages/design-system/lib/components/OpeningHours/AlternateOpeningHours/index.tsx +++ b/packages/design-system/lib/components/OpeningHours/AlternateOpeningHours/index.tsx @@ -8,10 +8,10 @@ import { Typography } from '../../Typography' import { getGroupedOpeningHours } from '../utils' import styles from '../openingHours.module.css' -import { OpeningHours } from '../openingHoursTypes' +import type { AlternateOpeningHours } from '../openingHoursTypes' interface AlternateOpeningHoursProps { - alternateOpeningHours: OpeningHours + alternateOpeningHours: AlternateOpeningHours } export default function AlternateOpeningHours({ diff --git a/packages/design-system/lib/components/OpeningHours/index.tsx b/packages/design-system/lib/components/OpeningHours/index.tsx index e1afc0851..55279a589 100644 --- a/packages/design-system/lib/components/OpeningHours/index.tsx +++ b/packages/design-system/lib/components/OpeningHours/index.tsx @@ -9,11 +9,14 @@ import AlternateOpeningHours from './AlternateOpeningHours' import { getGroupedOpeningHours, getTranslatedName } from './utils' import styles from './openingHours.module.css' -import type { OpeningHours } from './openingHoursTypes' +import type { + OpeningHours, + AlternateOpeningHours as AlternateOpeningHoursType, +} from './openingHoursTypes' interface OpeningHoursProps { openingHours: OpeningHours - alternateOpeningHours?: OpeningHours + alternateOpeningHours?: AlternateOpeningHoursType heading?: string } diff --git a/packages/design-system/lib/components/OpeningHours/openingHours.test.ts b/packages/design-system/lib/components/OpeningHours/openingHours.test.ts index 3162ee847..9dfe710d0 100644 --- a/packages/design-system/lib/components/OpeningHours/openingHours.test.ts +++ b/packages/design-system/lib/components/OpeningHours/openingHours.test.ts @@ -27,7 +27,6 @@ describe('getGroupedOpeningHours', () => { it('should group all days as closed', () => { const allDaysClosed: OpeningHours = { isActive: true, - name: 'Opening hours', nameEnglish: 'Opening hours', monday: { isClosed: true, @@ -86,7 +85,6 @@ describe('getGroupedOpeningHours', () => { it('should group all days with same opening hours', () => { const allDaysSameHours: OpeningHours = { isActive: true, - name: 'Opening hours', nameEnglish: 'Opening hours', monday: { openingTime: '09:00', @@ -145,7 +143,6 @@ describe('getGroupedOpeningHours', () => { it('should handle mixed opening hours', () => { const mixedOpeningHours: OpeningHours = { isActive: true, - name: 'Opening hours', nameEnglish: 'Opening hours', monday: { openingTime: '09:00', @@ -208,7 +205,6 @@ describe('getGroupedOpeningHours', () => { it('should handle always open days', () => { const someAlwaysOpen: OpeningHours = { isActive: true, - name: 'Opening hours', nameEnglish: 'Opening hours', monday: { alwaysOpen: true, @@ -271,7 +267,6 @@ describe('getGroupedOpeningHours', () => { it('should handle missing days', () => { const missingDays: OpeningHours = { isActive: true, - name: 'Opening hours', nameEnglish: 'Opening hours', monday: { openingTime: '09:00', @@ -306,7 +301,6 @@ describe('getGroupedOpeningHours', () => { it('should not group non-consecutive days with same hours', () => { const nonConsecutiveSameHours: OpeningHours = { isActive: true, - name: 'Opening hours', nameEnglish: 'Opening hours', monday: { openingTime: '09:00', @@ -341,7 +335,6 @@ describe('getGroupedOpeningHours', () => { it('should handle nullable opening/closing times', () => { const nullableHours: OpeningHours = { isActive: true, - name: 'Opening hours', nameEnglish: 'Opening hours', monday: { openingTime: '', @@ -376,7 +369,6 @@ describe('getGroupedOpeningHours', () => { it('should handle inactive restaurant hours', () => { const inactiveHours: OpeningHours = { isActive: false, - name: 'Opening hours', nameEnglish: 'Opening hours', monday: { openingTime: '09:00', diff --git a/packages/design-system/lib/components/OpeningHours/openingHoursTypes.ts b/packages/design-system/lib/components/OpeningHours/openingHoursTypes.ts index 1a611b8d3..8a10f1888 100644 --- a/packages/design-system/lib/components/OpeningHours/openingHoursTypes.ts +++ b/packages/design-system/lib/components/OpeningHours/openingHoursTypes.ts @@ -6,10 +6,8 @@ type OpeningHoursDetails = { sortOrder: number } -export type OpeningHours = { - name: string +interface OpeningHoursBase { isActive: boolean - nameEnglish: string monday?: OpeningHoursDetails tuesday?: OpeningHoursDetails wednesday?: OpeningHoursDetails @@ -18,3 +16,9 @@ export type OpeningHours = { saturday?: OpeningHoursDetails sunday?: OpeningHoursDetails } +export interface OpeningHours extends OpeningHoursBase { + nameEnglish: string +} +export interface AlternateOpeningHours extends OpeningHoursBase { + name: string +} diff --git a/packages/design-system/lib/components/OpeningHours/utils.ts b/packages/design-system/lib/components/OpeningHours/utils.ts index 97320d238..8b390a542 100644 --- a/packages/design-system/lib/components/OpeningHours/utils.ts +++ b/packages/design-system/lib/components/OpeningHours/utils.ts @@ -1,10 +1,10 @@ import { logger } from '@scandic-hotels/common/logger' import type { IntlShape } from 'react-intl' -import { OpeningHours } from './openingHoursTypes' +import type { OpeningHours, AlternateOpeningHours } from './openingHoursTypes' export function getGroupedOpeningHours( - openingHours: OpeningHours, + openingHours: OpeningHours | AlternateOpeningHours, intl: IntlShape ): string[] { const closedMsg = intl.formatMessage({ diff --git a/packages/trpc/lib/routers/hotels/schemas/hotel/include/restaurants.ts b/packages/trpc/lib/routers/hotels/schemas/hotel/include/restaurants.ts index bd595cf07..8a15c47e9 100644 --- a/packages/trpc/lib/routers/hotels/schemas/hotel/include/restaurants.ts +++ b/packages/trpc/lib/routers/hotels/schemas/hotel/include/restaurants.ts @@ -54,21 +54,24 @@ export const openingHoursDetailsSchema = z.object({ sortOrder: nullableIntValidator, }) -export const openingHoursSchema = z.object({ +const baseOpeningHoursSchema = z.object({ friday: openingHoursDetailsSchema.optional(), isActive: z.boolean().default(false), monday: openingHoursDetailsSchema.optional(), - name: nullableStringValidator, - nameEnglish: nullableStringValidator, saturday: openingHoursDetailsSchema.optional(), sunday: openingHoursDetailsSchema.optional(), thursday: openingHoursDetailsSchema.optional(), tuesday: openingHoursDetailsSchema.optional(), wednesday: openingHoursDetailsSchema.optional(), }) - +export const openingHoursSchema = baseOpeningHoursSchema.extend({ + nameEnglish: nullableStringValidator, +}) +export const alternateOpeningHoursSchema = baseOpeningHoursSchema.extend({ + name: nullableStringValidator, +}) const openingDetailsSchema = z.object({ - alternateOpeningHours: openingHoursSchema.optional(), + alternateOpeningHours: alternateOpeningHoursSchema.optional(), openingHours: openingHoursSchema, ordinary: openingHoursSchema.optional(), weekends: openingHoursSchema.optional(),