Merged in feat/SW-1281-ancillaries-add-flow (pull request #1399)
Feat/SW-1281 ancillaries add flow * feat(SW-1546): update design * feat(SW-1546): show points only if logged in * feat(SW-1546): always show points * feat(SW-1281): ancillary add flow initial * feat(SW-1546): add api call * feat(SW-1281): refactor naming and break out components * feat(SW-1281): handle back button * feat(SW-1281): make mobile cards clickable * feat(SW-1281): refactor spread ancillaries * feat(SW-1281): add deliverytimes * feat(SW-1281): rebase master * feat(SW-1281): add design for logged in or not * feat(SW-1281): add design * feat(SW-1281): add mobile design * feat(SW-1281): fix carousel * feat(SW-1281): show deliverytime only if ancillary has not been added * feat(SW-1281): add design * feat(SW-1281): add translations * feat(SW-1281): add translations * feat(SW-1281): add translations * feat(SW-1281): base dates on check in date only * feat(SW-1281): fix show correct toast when no valid data * feat(SW-1281): hande logic if deliverytime is not required * feat(SW-1281): fix max width for mobile * feat(SW-1281): refactor after pr comment Approved-by: Niclas Edenvin Approved-by: Linus Flood
This commit is contained in:
committed by
Linus Flood
parent
341f0c54ed
commit
541b91e34c
@@ -85,6 +85,20 @@ export const createBookingInput = z.object({
|
||||
language: z.nativeEnum(Lang).transform((val) => langToApiLang[val]),
|
||||
})
|
||||
|
||||
export const addPackageInput = z.object({
|
||||
confirmationNumber: z.string(),
|
||||
ancillaryComment: z.string(),
|
||||
ancillaryDeliveryTime: z.string().optional(),
|
||||
packages: z.array(
|
||||
z.object({
|
||||
code: z.string(),
|
||||
quantity: z.number(),
|
||||
comment: z.string().optional(),
|
||||
})
|
||||
),
|
||||
language: z.nativeEnum(Lang).transform((val) => langToApiLang[val]),
|
||||
})
|
||||
|
||||
export const priceChangeInput = z.object({
|
||||
confirmationNumber: z.string(),
|
||||
})
|
||||
|
||||
@@ -8,6 +8,7 @@ import { getMembership } from "@/utils/user"
|
||||
|
||||
import {
|
||||
cancelBookingInput,
|
||||
addPackageInput,
|
||||
createBookingInput,
|
||||
priceChangeInput,
|
||||
} from "./input"
|
||||
@@ -39,6 +40,14 @@ const cancelBookingFailCounter = meter.createCounter(
|
||||
"trpc.bookings.cancel-fail"
|
||||
)
|
||||
|
||||
const addPackageCounter = meter.createCounter("trpc.bookings.add-package")
|
||||
const addPackageSuccessCounter = meter.createCounter(
|
||||
"trpc.bookings.add-package-success"
|
||||
)
|
||||
const addPackageFailCounter = meter.createCounter(
|
||||
"trpc.bookings.add-package-fail"
|
||||
)
|
||||
|
||||
async function getMembershipNumber(
|
||||
session: Session | null
|
||||
): Promise<string | undefined> {
|
||||
@@ -304,6 +313,70 @@ export const bookingMutationRouter = router({
|
||||
})
|
||||
)
|
||||
|
||||
return verifiedData.data
|
||||
}),
|
||||
packages: safeProtectedServiceProcedure
|
||||
.input(addPackageInput)
|
||||
.mutation(async function ({ ctx, input }) {
|
||||
const accessToken = ctx.session?.token.access_token ?? ctx.serviceToken
|
||||
const { confirmationNumber, ...body } = input
|
||||
|
||||
addPackageCounter.add(1, { confirmationNumber })
|
||||
|
||||
const headers = {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
}
|
||||
|
||||
const apiResponse = await api.post(
|
||||
api.endpoints.v1.Booking.packages(confirmationNumber),
|
||||
{
|
||||
headers,
|
||||
body: body,
|
||||
}
|
||||
)
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
const text = await apiResponse.text()
|
||||
addPackageFailCounter.add(1, {
|
||||
confirmationNumber,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"api.booking.addPackage error",
|
||||
JSON.stringify({
|
||||
query: { confirmationNumber },
|
||||
error: {
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
error: text,
|
||||
},
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
const apiJson = await apiResponse.json()
|
||||
const verifiedData = createBookingSchema.safeParse(apiJson)
|
||||
if (!verifiedData.success) {
|
||||
addPackageFailCounter.add(1, {
|
||||
confirmationNumber,
|
||||
error_type: "validation_error",
|
||||
})
|
||||
console.error(
|
||||
"api.booking.addPackage validation error",
|
||||
JSON.stringify({
|
||||
query: { confirmationNumber },
|
||||
error: verifiedData.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
addPackageSuccessCounter.add(1, { confirmationNumber })
|
||||
|
||||
return verifiedData.data
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -11,7 +11,7 @@ export const createBookingSchema = z
|
||||
data: z.object({
|
||||
attributes: z.object({
|
||||
reservationStatus: z.string(),
|
||||
paymentUrl: z.string().nullable(),
|
||||
paymentUrl: z.string().nullable().optional(),
|
||||
rooms: z
|
||||
.array(
|
||||
z.object({
|
||||
@@ -81,6 +81,7 @@ const guestSchema = z.object({
|
||||
const packageSchema = z
|
||||
.object({
|
||||
description: z.string().nullable().default(""),
|
||||
type: z.string().nullable().default(""),
|
||||
code: z.string().nullable().default(""),
|
||||
price: z.object({
|
||||
unit: z.number().int().nullable(),
|
||||
@@ -94,6 +95,7 @@ const packageSchema = z
|
||||
.transform((packageData) => ({
|
||||
description: packageData.description,
|
||||
code: packageData.code,
|
||||
type: packageData.type,
|
||||
currency: packageData.price.currency,
|
||||
points: packageData.price.points,
|
||||
totalPrice: packageData.price.totalPrice ?? 0,
|
||||
@@ -195,7 +197,7 @@ export const bookingConfirmationSchema = z
|
||||
createDateTime: z.date({ coerce: true }),
|
||||
currencyCode: z.string(),
|
||||
guest: guestSchema,
|
||||
isGuaranteedForLateArrival: z.boolean(),
|
||||
isGuaranteedForLateArrival: z.boolean().optional(),
|
||||
linkedReservations: z.array(linkedReservationsSchema).default([]),
|
||||
hotelId: z.string(),
|
||||
packages: z.array(packageSchema).default([]),
|
||||
|
||||
Reference in New Issue
Block a user