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> </Typography>
{openingDetails.map((details) => ( {openingDetails.map((details) => (
<OpeningHours <OpeningHours
key={details.openingHours.name} key={details.openingHours.nameEnglish}
openingHours={details.openingHours} openingHours={details.openingHours}
alternateOpeningHours={details.alternateOpeningHours} alternateOpeningHours={details.alternateOpeningHours}
/> />

View File

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

View File

@@ -30,10 +30,7 @@ export default function BreakfastAccordionItem({
const openingHours = restaurants const openingHours = restaurants
?.map((restaurant) => { ?.map((restaurant) => {
const breakfastDetail = restaurant.openingDetails.find( const breakfastDetail = restaurant.openingDetails.find(
(details) => (details) => details.openingHours.nameEnglish === "Breakfast"
details.openingHours.name === "Breakfast" ||
details.openingHours.name ===
intl.formatMessage({ defaultMessage: "Breakfast" })
) )
return breakfastDetail return breakfastDetail
}) })

View File

@@ -8,10 +8,10 @@ import { Typography } from '../../Typography'
import { getGroupedOpeningHours } from '../utils' import { getGroupedOpeningHours } from '../utils'
import styles from '../openingHours.module.css' import styles from '../openingHours.module.css'
import { OpeningHours } from '../openingHoursTypes' import type { AlternateOpeningHours } from '../openingHoursTypes'
interface AlternateOpeningHoursProps { interface AlternateOpeningHoursProps {
alternateOpeningHours: OpeningHours alternateOpeningHours: AlternateOpeningHours
} }
export default function AlternateOpeningHours({ export default function AlternateOpeningHours({

View File

@@ -9,11 +9,14 @@ import AlternateOpeningHours from './AlternateOpeningHours'
import { getGroupedOpeningHours, getTranslatedName } from './utils' import { getGroupedOpeningHours, getTranslatedName } from './utils'
import styles from './openingHours.module.css' import styles from './openingHours.module.css'
import type { OpeningHours } from './openingHoursTypes' import type {
OpeningHours,
AlternateOpeningHours as AlternateOpeningHoursType,
} from './openingHoursTypes'
interface OpeningHoursProps { interface OpeningHoursProps {
openingHours: OpeningHours openingHours: OpeningHours
alternateOpeningHours?: OpeningHours alternateOpeningHours?: AlternateOpeningHoursType
heading?: string heading?: string
} }

View File

@@ -27,7 +27,6 @@ describe('getGroupedOpeningHours', () => {
it('should group all days as closed', () => { it('should group all days as closed', () => {
const allDaysClosed: OpeningHours = { const allDaysClosed: OpeningHours = {
isActive: true, isActive: true,
name: 'Opening hours',
nameEnglish: 'Opening hours', nameEnglish: 'Opening hours',
monday: { monday: {
isClosed: true, isClosed: true,
@@ -86,7 +85,6 @@ describe('getGroupedOpeningHours', () => {
it('should group all days with same opening hours', () => { it('should group all days with same opening hours', () => {
const allDaysSameHours: OpeningHours = { const allDaysSameHours: OpeningHours = {
isActive: true, isActive: true,
name: 'Opening hours',
nameEnglish: 'Opening hours', nameEnglish: 'Opening hours',
monday: { monday: {
openingTime: '09:00', openingTime: '09:00',
@@ -145,7 +143,6 @@ describe('getGroupedOpeningHours', () => {
it('should handle mixed opening hours', () => { it('should handle mixed opening hours', () => {
const mixedOpeningHours: OpeningHours = { const mixedOpeningHours: OpeningHours = {
isActive: true, isActive: true,
name: 'Opening hours',
nameEnglish: 'Opening hours', nameEnglish: 'Opening hours',
monday: { monday: {
openingTime: '09:00', openingTime: '09:00',
@@ -208,7 +205,6 @@ describe('getGroupedOpeningHours', () => {
it('should handle always open days', () => { it('should handle always open days', () => {
const someAlwaysOpen: OpeningHours = { const someAlwaysOpen: OpeningHours = {
isActive: true, isActive: true,
name: 'Opening hours',
nameEnglish: 'Opening hours', nameEnglish: 'Opening hours',
monday: { monday: {
alwaysOpen: true, alwaysOpen: true,
@@ -271,7 +267,6 @@ describe('getGroupedOpeningHours', () => {
it('should handle missing days', () => { it('should handle missing days', () => {
const missingDays: OpeningHours = { const missingDays: OpeningHours = {
isActive: true, isActive: true,
name: 'Opening hours',
nameEnglish: 'Opening hours', nameEnglish: 'Opening hours',
monday: { monday: {
openingTime: '09:00', openingTime: '09:00',
@@ -306,7 +301,6 @@ describe('getGroupedOpeningHours', () => {
it('should not group non-consecutive days with same hours', () => { it('should not group non-consecutive days with same hours', () => {
const nonConsecutiveSameHours: OpeningHours = { const nonConsecutiveSameHours: OpeningHours = {
isActive: true, isActive: true,
name: 'Opening hours',
nameEnglish: 'Opening hours', nameEnglish: 'Opening hours',
monday: { monday: {
openingTime: '09:00', openingTime: '09:00',
@@ -341,7 +335,6 @@ describe('getGroupedOpeningHours', () => {
it('should handle nullable opening/closing times', () => { it('should handle nullable opening/closing times', () => {
const nullableHours: OpeningHours = { const nullableHours: OpeningHours = {
isActive: true, isActive: true,
name: 'Opening hours',
nameEnglish: 'Opening hours', nameEnglish: 'Opening hours',
monday: { monday: {
openingTime: '', openingTime: '',
@@ -376,7 +369,6 @@ describe('getGroupedOpeningHours', () => {
it('should handle inactive restaurant hours', () => { it('should handle inactive restaurant hours', () => {
const inactiveHours: OpeningHours = { const inactiveHours: OpeningHours = {
isActive: false, isActive: false,
name: 'Opening hours',
nameEnglish: 'Opening hours', nameEnglish: 'Opening hours',
monday: { monday: {
openingTime: '09:00', openingTime: '09:00',

View File

@@ -6,10 +6,8 @@ type OpeningHoursDetails = {
sortOrder: number sortOrder: number
} }
export type OpeningHours = { interface OpeningHoursBase {
name: string
isActive: boolean isActive: boolean
nameEnglish: string
monday?: OpeningHoursDetails monday?: OpeningHoursDetails
tuesday?: OpeningHoursDetails tuesday?: OpeningHoursDetails
wednesday?: OpeningHoursDetails wednesday?: OpeningHoursDetails
@@ -18,3 +16,9 @@ export type OpeningHours = {
saturday?: OpeningHoursDetails saturday?: OpeningHoursDetails
sunday?: 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 { logger } from '@scandic-hotels/common/logger'
import type { IntlShape } from 'react-intl' import type { IntlShape } from 'react-intl'
import { OpeningHours } from './openingHoursTypes' import type { OpeningHours, AlternateOpeningHours } from './openingHoursTypes'
export function getGroupedOpeningHours( export function getGroupedOpeningHours(
openingHours: OpeningHours, openingHours: OpeningHours | AlternateOpeningHours,
intl: IntlShape intl: IntlShape
): string[] { ): string[] {
const closedMsg = intl.formatMessage({ const closedMsg = intl.formatMessage({

View File

@@ -54,21 +54,24 @@ export const openingHoursDetailsSchema = z.object({
sortOrder: nullableIntValidator, sortOrder: nullableIntValidator,
}) })
export const openingHoursSchema = z.object({ const baseOpeningHoursSchema = z.object({
friday: openingHoursDetailsSchema.optional(), friday: openingHoursDetailsSchema.optional(),
isActive: z.boolean().default(false), isActive: z.boolean().default(false),
monday: openingHoursDetailsSchema.optional(), monday: openingHoursDetailsSchema.optional(),
name: nullableStringValidator,
nameEnglish: nullableStringValidator,
saturday: openingHoursDetailsSchema.optional(), saturday: openingHoursDetailsSchema.optional(),
sunday: openingHoursDetailsSchema.optional(), sunday: openingHoursDetailsSchema.optional(),
thursday: openingHoursDetailsSchema.optional(), thursday: openingHoursDetailsSchema.optional(),
tuesday: openingHoursDetailsSchema.optional(), tuesday: openingHoursDetailsSchema.optional(),
wednesday: openingHoursDetailsSchema.optional(), wednesday: openingHoursDetailsSchema.optional(),
}) })
export const openingHoursSchema = baseOpeningHoursSchema.extend({
nameEnglish: nullableStringValidator,
})
export const alternateOpeningHoursSchema = baseOpeningHoursSchema.extend({
name: nullableStringValidator,
})
const openingDetailsSchema = z.object({ const openingDetailsSchema = z.object({
alternateOpeningHours: openingHoursSchema.optional(), alternateOpeningHours: alternateOpeningHoursSchema.optional(),
openingHours: openingHoursSchema, openingHours: openingHoursSchema,
ordinary: openingHoursSchema.optional(), ordinary: openingHoursSchema.optional(),
weekends: openingHoursSchema.optional(), weekends: openingHoursSchema.optional(),