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 } = const { hotel, adults, children, roomTypeCode, rateCode, fromDate, toDate } =
getQueryParamsForEnterDetails(selectRoomParams) getQueryParamsForEnterDetails(selectRoomParams)
if (!roomTypeCode || !rateCode) {
console.log("No roomTypeCode or rateCode")
return notFound()
}
const availability = await getSelectedRoomAvailability({ const availability = await getSelectedRoomAvailability({
hotelId: parseInt(hotel), hotelId: parseInt(hotel),
adults, adults,

View File

@@ -1,11 +1,10 @@
import { notFound, redirect } from "next/navigation" import { notFound } from "next/navigation"
import { import {
getBreakfastPackages, getBreakfastPackages,
getCreditCardsSafely, getCreditCardsSafely,
getHotelData, getHotelData,
getProfileSafely, getProfileSafely,
getRoomAvailability,
getSelectedRoomAvailability, getSelectedRoomAvailability,
} from "@/lib/trpc/memoizedRequests" } from "@/lib/trpc/memoizedRequests"
import { HotelIncludeEnum } from "@/server/routers/hotels/input" import { HotelIncludeEnum } from "@/server/routers/hotels/input"
@@ -38,8 +37,6 @@ export default async function StepPage({
}: PageArgs<LangParams & { step: StepEnum }, SelectRateSearchParams>) { }: PageArgs<LangParams & { step: StepEnum }, SelectRateSearchParams>) {
const { lang } = params const { lang } = params
void getBreakfastPackages(searchParams.hotel)
const intl = await getIntl() const intl = await getIntl()
const selectRoomParams = new URLSearchParams(searchParams) const selectRoomParams = new URLSearchParams(searchParams)
const { const {
@@ -52,10 +49,7 @@ export default async function StepPage({
toDate, toDate,
} = getQueryParamsForEnterDetails(selectRoomParams) } = getQueryParamsForEnterDetails(selectRoomParams)
if (!rateCode || !roomTypeCode) { void getBreakfastPackages(searchParams.hotel)
return notFound()
}
void getSelectedRoomAvailability({ void getSelectedRoomAvailability({
hotelId: parseInt(searchParams.hotel), hotelId: parseInt(searchParams.hotel),
adults, 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 // https://nextjs.org/docs/app/api-reference/next-config-js/redirects#header-cookie-and-query-matching
redirects() { 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 [ return [
// { {
// ---------------------------------------- // ----------------------------------------
// Uncomment when Team Explorer has deployed // hotel (hotelId) param missing
// the select room submission
// ---------------------------------------- // ----------------------------------------
// source: "/:lang/hotelreservation/(select-bed|breakfast|details|payment)", source:
// destination: "/:lang/hotelreservation/select-rate", "/:lang/hotelreservation/(select-bed|breakfast|details|payment)",
// missing: [ destination: "/:lang/hotelreservation/select-rate",
// { missing: [
// key: "hotel", {
// type: "query", key: "hotel",
// value: undefined, type: "query",
// }, value: undefined,
// { },
// key: "fromDate", ],
// type: "query", permanent: false,
// value: undefined, },
// }, {
// { // ----------------------------------------
// key: "toDate", // hotel (hotelId) param has to be an integer
// type: "query", // ----------------------------------------
// value: undefined, source:
// }, "/:lang/hotelreservation/(select-bed|breakfast|details|payment)",
// { destination: "/:lang/hotelreservation/select-rate",
// key: "room", missing: [
// type: "query", {
// value: undefined, key: "hotel",
// }, type: "query",
// ], value: "^[0-9]+$",
// permanent: false, },
// }, ],
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 { interface Room {
adults: number adults: number
roomtype?: string roomtype: string
ratecode?: string ratecode: string
counterratecode?: string counterratecode?: string
child?: Child[] child?: Child[]
} }