Feature/select rate vertical data flow * add fix from SW-2666 * use translations for room packages * move types to it's own file * Merge branch 'master' of bitbucket.org:scandic-swap/web into feature/select-rate-vertical-data-flow * merge * feature/select-rate: double rate for campaing rates * revert NODE_ENV check in Cookiebot script * revert testing values * fix(SW-3171): fix all filter selected in price details * fix(SW-3166): multiroom anchoring when changing filter * fix(SW-3172): check hotelType, show correct breakfast message * Merge branch 'feature/select-rate-vertical-data-flow' of bitbucket.org:scandic-swap/web into feature/select-rate-vertical-data-flow * fix: show special needs icons for subsequent roomTypes SW-3167 * fix: Display strike through text when logged in SW-3168 * fix: Reinstate the scrollToView behaviour when selecting a rate SW-3169 * merge * . * PR fixes * fix: don't return notFound() * . * always include defaults for room packages * merge * merge * merge * Remove floating h1 for new select-rate Approved-by: Anton Gunnarsson
81 lines
2.0 KiB
TypeScript
81 lines
2.0 KiB
TypeScript
"use client"
|
|
|
|
import { TRPCClientError } from "@trpc/client"
|
|
import { useIntl } from "react-intl"
|
|
|
|
import { AlertTypeEnum } from "@scandic-hotels/trpc/types/alertType"
|
|
|
|
import Alert from "@/components/TempDesignSystem/Alert"
|
|
import { useSelectRateContext } from "@/contexts/SelectRate/SelectRateContext"
|
|
|
|
import { RateSummary } from "./RateSummary"
|
|
import Rooms from "./Rooms"
|
|
import { RoomsContainerSkeleton } from "./RoomsContainerSkeleton"
|
|
|
|
import styles from "./index.module.css"
|
|
|
|
import type { AppRouter } from "@scandic-hotels/trpc/routers/appRouter"
|
|
|
|
import type { RoomsContainerProps } from "@/types/components/hotelReservation/selectRate/roomsContainer"
|
|
|
|
export function RoomsContainer({}: RoomsContainerProps) {
|
|
const intl = useIntl()
|
|
|
|
const {
|
|
availability: { error, isFetching, isError },
|
|
input: { hasError: hasInputError },
|
|
} = useSelectRateContext()
|
|
|
|
if (isFetching) {
|
|
return <RoomsContainerSkeleton />
|
|
}
|
|
|
|
if (isError || hasInputError) {
|
|
const errorMessage = getErrorMessage(error, intl)
|
|
|
|
return (
|
|
<div className={styles.errorContainer}>
|
|
<Alert type={AlertTypeEnum.Alarm} heading={errorMessage} />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Rooms />
|
|
<RateSummary />
|
|
</>
|
|
)
|
|
}
|
|
|
|
function getErrorMessage(error: unknown, intl: ReturnType<typeof useIntl>) {
|
|
if (!isTRPCClientError(error)) {
|
|
return intl.formatMessage({
|
|
defaultMessage: "Something went wrong",
|
|
})
|
|
}
|
|
|
|
const firstError = error.data?.zodError?.formErrors?.at(0)
|
|
|
|
switch (firstError) {
|
|
case "FROMDATE_INVALID":
|
|
case "TODATE_INVALID":
|
|
case "TODATE_MUST_BE_AFTER_FROMDATE":
|
|
case "FROMDATE_CANNOT_BE_IN_THE_PAST": {
|
|
return intl.formatMessage({
|
|
defaultMessage: "Invalid dates",
|
|
})
|
|
}
|
|
default:
|
|
return intl.formatMessage({
|
|
defaultMessage: "Something went wrong",
|
|
})
|
|
}
|
|
}
|
|
|
|
function isTRPCClientError(
|
|
cause: unknown
|
|
): cause is TRPCClientError<AppRouter> {
|
|
return cause instanceof TRPCClientError
|
|
}
|