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
This commit is contained in:
Matilda Landström
2025-09-04 14:18:57 +00:00
parent 711589ff5e
commit 8f813eb9e7
9 changed files with 27 additions and 28 deletions

View File

@@ -60,7 +60,7 @@ export default async function RestaurantBarItem({
</Typography>
{openingDetails.map((details) => (
<OpeningHours
key={details.openingHours.name}
key={details.openingHours.nameEnglish}
openingHours={details.openingHours}
alternateOpeningHours={details.alternateOpeningHours}
/>

View File

@@ -37,7 +37,7 @@ export default async function RestaurantSidebar({
</Typography>
{openingDetails.map((details) => (
<OpeningHours
key={details.openingHours.name}
key={details.openingHours.nameEnglish}
openingHours={details.openingHours}
alternateOpeningHours={details.alternateOpeningHours}
/>

View File

@@ -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
})

View File

@@ -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({

View File

@@ -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
}

View File

@@ -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',

View File

@@ -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
}

View File

@@ -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({

View File

@@ -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(),