Merged in feat/SW-599 (pull request #803)

feat: block all entries to enter details that miss the required params

Approved-by: Christel Westerberg
Approved-by: Tobias Johansson
This commit is contained in:
Simon.Emanuelsson
2024-11-01 06:57:06 +00:00
4 changed files with 169 additions and 46 deletions

View File

@@ -19,11 +19,6 @@ export default async function SummaryPage({
const { hotel, adults, children, roomTypeCode, rateCode, fromDate, toDate } =
getQueryParamsForEnterDetails(selectRoomParams)
if (!roomTypeCode || !rateCode) {
console.log("No roomTypeCode or rateCode")
return notFound()
}
const availability = await getSelectedRoomAvailability({
hotelId: parseInt(hotel),
adults,

View File

@@ -1,11 +1,10 @@
import { notFound, redirect } from "next/navigation"
import { notFound } from "next/navigation"
import {
getBreakfastPackages,
getCreditCardsSafely,
getHotelData,
getProfileSafely,
getRoomAvailability,
getSelectedRoomAvailability,
} from "@/lib/trpc/memoizedRequests"
import { HotelIncludeEnum } from "@/server/routers/hotels/input"
@@ -38,8 +37,6 @@ export default async function StepPage({
}: PageArgs<LangParams & { step: StepEnum }, SelectRateSearchParams>) {
const { lang } = params
void getBreakfastPackages(searchParams.hotel)
const intl = await getIntl()
const selectRoomParams = new URLSearchParams(searchParams)
const {
@@ -52,10 +49,7 @@ export default async function StepPage({
toDate,
} = getQueryParamsForEnterDetails(selectRoomParams)
if (!rateCode || !roomTypeCode) {
return notFound()
}
void getBreakfastPackages(searchParams.hotel)
void getSelectedRoomAvailability({
hotelId: parseInt(searchParams.hotel),
adults,

View File

@@ -72,38 +72,172 @@ const nextConfig = {
// https://nextjs.org/docs/app/api-reference/next-config-js/redirects#header-cookie-and-query-matching
redirects() {
// Param checks needs to be split as Next.js handles everything
// in the missing array as AND, therefore they need to be separate
// to handle when one or more are missing.
//
// Docs: all missing items must not match for the redirect to be applied.
return [
// {
// ----------------------------------------
// Uncomment when Team Explorer has deployed
// the select room submission
// ----------------------------------------
// source: "/:lang/hotelreservation/(select-bed|breakfast|details|payment)",
// destination: "/:lang/hotelreservation/select-rate",
// missing: [
// {
// key: "hotel",
// type: "query",
// value: undefined,
// },
// {
// key: "fromDate",
// type: "query",
// value: undefined,
// },
// {
// key: "toDate",
// type: "query",
// value: undefined,
// },
// {
// key: "room",
// type: "query",
// value: undefined,
// },
// ],
// permanent: false,
// },
{
// ----------------------------------------
// hotel (hotelId) param missing
// ----------------------------------------
source:
"/:lang/hotelreservation/(select-bed|breakfast|details|payment)",
destination: "/:lang/hotelreservation/select-rate",
missing: [
{
key: "hotel",
type: "query",
value: undefined,
},
],
permanent: false,
},
{
// ----------------------------------------
// hotel (hotelId) param has to be an integer
// ----------------------------------------
source:
"/:lang/hotelreservation/(select-bed|breakfast|details|payment)",
destination: "/:lang/hotelreservation/select-rate",
missing: [
{
key: "hotel",
type: "query",
value: "^[0-9]+$",
},
],
permanent: false,
},
{
// ----------------------------------------
// fromDate param missing
// ----------------------------------------
source:
"/:lang/hotelreservation/(select-bed|breakfast|details|payment)",
destination: "/:lang/hotelreservation/select-rate",
missing: [
{
key: "fromDate",
type: "query",
value: undefined,
},
],
permanent: false,
},
{
// ----------------------------------------
// fromDate param has to be a date
// ----------------------------------------
source:
"/:lang/hotelreservation/(select-bed|breakfast|details|payment)",
destination: "/:lang/hotelreservation/select-rate",
missing: [
{
key: "fromDate",
type: "query",
value: "^([12]\\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01]))$",
},
],
permanent: false,
},
{
// ----------------------------------------
// toDate param missing
// ----------------------------------------
source:
"/:lang/hotelreservation/(select-bed|breakfast|details|payment)",
destination: "/:lang/hotelreservation/select-rate",
missing: [
{
key: "toDate",
type: "query",
value: undefined,
},
],
permanent: false,
},
{
// ----------------------------------------
// toDate param has to be a date
// ----------------------------------------
source:
"/:lang/hotelreservation/(select-bed|breakfast|details|payment)",
destination: "/:lang/hotelreservation/select-rate",
missing: [
{
key: "toDate",
type: "query",
value: "^([12]\\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01]))$",
},
],
permanent: false,
},
{
// ----------------------------------------
// room[0].adults param missing
// ----------------------------------------
source:
"/:lang/hotelreservation/(select-bed|breakfast|details|payment)",
destination: "/:lang/hotelreservation/select-rate",
missing: [
{
key: "room[0].adults",
type: "query",
value: undefined,
},
],
permanent: false,
},
{
// ----------------------------------------
// room[0].adults param has to be an integer
// ----------------------------------------
source:
"/:lang/hotelreservation/(select-bed|breakfast|details|payment)",
destination: "/:lang/hotelreservation/select-rate",
missing: [
{
key: "room[0].adults",
type: "query",
value: "^[0-9]+$",
},
],
permanent: false,
},
{
// ----------------------------------------
// room[0].ratecode param missing
// ----------------------------------------
source:
"/:lang/hotelreservation/(select-bed|breakfast|details|payment)",
destination: "/:lang/hotelreservation/select-rate",
missing: [
{
key: "room[0].ratecode",
type: "query",
value: undefined,
},
],
permanent: false,
},
{
// ----------------------------------------
// room[0].roomtype param missing
// ----------------------------------------
source:
"/:lang/hotelreservation/(select-bed|breakfast|details|payment)",
destination: "/:lang/hotelreservation/select-rate",
missing: [
{
key: "room[0].roomtype",
type: "query",
value: undefined,
},
],
permanent: false,
},
]
},

View File

@@ -7,8 +7,8 @@ export interface Child {
interface Room {
adults: number
roomtype?: string
ratecode?: string
roomtype: string
ratecode: string
counterratecode?: string
child?: Child[]
}