Merged in feat/loy-291-new-claim-points-flow (pull request #3508)

feat(LOY-291): New claim points flow for logged in users

* wip new flow

* More wip

* More wip

* Wip styling

* wip with a mutation

* Actually fetch booking data

* More styling wip

* Fix toast duration

* fix loading a11y maybe

* More stuff

* Add feature flag

* Add invalid state

* Clean up

* Add fields for missing user info

* Restructure files

* Add todos

* Disable warning

* Fix icon and border radius


Approved-by: Emma Zettervall
Approved-by: Matilda Landström
This commit is contained in:
Anton Gunnarsson
2026-02-03 13:27:24 +00:00
parent 310ad7bc7f
commit c2cf6b03a7
13 changed files with 775 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import { router } from "../.."
import { findBookingForCurrentUserRoute } from "./query/findBookingForCurrentUserRoute"
import { findBookingRoute } from "./query/findBookingRoute"
import { getBookingRoute } from "./query/getBookingRoute"
import { getBookingStatusRoute } from "./query/getBookingStatusRoute"
@@ -7,6 +8,7 @@ import { getLinkedReservationsRoute } from "./query/getLinkedReservationsRoute"
export const bookingQueryRouter = router({
get: getBookingRoute,
findBooking: findBookingRoute,
findBookingForCurrentUser: findBookingForCurrentUserRoute,
linkedReservations: getLinkedReservationsRoute,
status: getBookingStatusRoute,
})

View File

@@ -0,0 +1,86 @@
import { createCounter } from "@scandic-hotels/common/telemetry"
import { notFoundError } from "../../../errors"
import { safeProtectedServiceProcedure } from "../../../procedures"
import { findBooking } from "../../../services/booking/findBooking"
import { getHotel } from "../../hotels/services/getHotel"
import { findBookingInput } from "../input"
export const findBookingForCurrentUserRoute = safeProtectedServiceProcedure
.input(
findBookingInput.omit({ lastName: true, firstName: true, email: true })
)
.query(async function ({ ctx, input }) {
const lang = input.lang ?? ctx.lang
const { confirmationNumber } = input
const user = await ctx.getScandicUser()
const token = await ctx.getScandicUserToken()
const findBookingCounter = createCounter(
"trpc.booking.findBookingForCurrentUser"
)
const metricsFindBooking = findBookingCounter.init({
confirmationNumber,
})
metricsFindBooking.start()
if (!user || !token) {
metricsFindBooking.dataError(
`Fail to find user when finding booking for ${confirmationNumber}`,
{ confirmationNumber }
)
return null
}
const booking = await findBooking(
{
confirmationNumber,
lang,
lastName: user.lastName,
firstName: user.firstName,
email: user.email,
},
token
)
if (!booking) {
metricsFindBooking.dataError(
`Fail to find booking data for ${confirmationNumber}`,
{ confirmationNumber }
)
return null
}
const hotelData = await getHotel(
{
hotelId: booking.hotelId,
isCardOnlyPayment: false,
language: lang,
},
ctx.serviceToken
)
if (!hotelData) {
metricsFindBooking.dataError(
`Failed to find hotel data for ${booking.hotelId}`,
{
hotelId: booking.hotelId,
}
)
throw notFoundError({
message: "Hotel data not found",
errorDetails: { hotelId: booking.hotelId },
})
}
metricsFindBooking.success()
return {
hotel: {
name: hotelData.hotel.name,
cityName: hotelData.hotel.cityName,
},
booking,
}
})

View File

@@ -1,3 +1,5 @@
import z from "zod"
import { signupVerify } from "@scandic-hotels/common/constants/routes/signup"
import { createLogger } from "@scandic-hotels/common/logger/createLogger"
import { createCounter } from "@scandic-hotels/common/telemetry"
@@ -318,4 +320,33 @@ export const userMutationRouter = router({
return true
}),
}),
claimPoints: protectedProcedure
.input(
z.object({
from: z.string(),
to: z.string(),
city: z.string(),
hotel: z.string(),
firstName: z.string(),
lastName: z.string(),
email: z.string().email(),
phone: z.string(),
})
)
.mutation(async function ({ input, ctx }) {
userMutationLogger.info("api.user.claimPoints start")
const user = await ctx.getScandicUser()
if (!user) {
throw "error"
}
// eslint-disable-next-line no-console
console.log("Claiming points", input, user.membershipNumber)
// TODO Waiting for API endpoint, simulating delay
await new Promise((resolve) => setTimeout(resolve, 2_000))
userMutationLogger.info("api.user.claimPoints success")
return true
}),
})