Merged in fix/LOY-206-add-missing-lang-input-transactions-query (pull request #1623)

fix(LOY-206): add missing lang input to friends transactions query, handles both server and client side

Approved-by: Michael Zetterberg
Approved-by: Chuma Mcphoy (We Ahead)
This commit is contained in:
Christian Andolf
2025-03-25 12:27:02 +00:00
5 changed files with 35 additions and 24 deletions

View File

@@ -7,17 +7,20 @@ import { trpc } from "@/lib/trpc/client"
import LoadingSpinner from "@/components/LoadingSpinner" import LoadingSpinner from "@/components/LoadingSpinner"
import Pagination from "@/components/MyPages/Pagination" import Pagination from "@/components/MyPages/Pagination"
import useLang from "@/hooks/useLang"
import ClientTable from "./ClientTable" import ClientTable from "./ClientTable"
export default function TransactionTable() { export default function TransactionTable() {
const limit = 5 const limit = 5
const [page, setPage] = useState(1) const [page, setPage] = useState(1)
const lang = useLang()
const { data, isFetching, isLoading } = const { data, isFetching, isLoading } =
trpc.user.transaction.friendTransactions.useQuery( trpc.user.transaction.friendTransactions.useQuery(
{ {
limit, limit,
page, page,
lang,
}, },
{ {
placeholderData: keepPreviousData, placeholderData: keepPreviousData,

View File

@@ -6,7 +6,7 @@ import { badRequestError } from "@/server/errors/trpc"
import { import {
contentStackBaseWithServiceProcedure, contentStackBaseWithServiceProcedure,
protectedProcedure, protectedProcedure,
protectedServcieProcedure, protectedServiceProcedure,
publicProcedure, publicProcedure,
router, router,
safeProtectedServiceProcedure, safeProtectedServiceProcedure,
@@ -862,7 +862,7 @@ export const hotelQueryRouter = router({
.query(async ({ input, ctx }) => { .query(async ({ input, ctx }) => {
return getRoomAvailability(input, ctx.lang, ctx.serviceToken) return getRoomAvailability(input, ctx.lang, ctx.serviceToken)
}), }),
roomWithRedemption: protectedServcieProcedure roomWithRedemption: protectedServiceProcedure
.input(selectedRoomAvailabilityInputSchema) .input(selectedRoomAvailabilityInputSchema)
.query(async ({ input, ctx }) => { .query(async ({ input, ctx }) => {
return getRoomAvailability( return getRoomAvailability(

View File

@@ -23,6 +23,7 @@ export const friendTransactionsInput = z
.object({ .object({
limit: z.number().int().positive(), limit: z.number().int().positive(),
page: z.number().int().positive(), page: z.number().int().positive(),
lang: z.nativeEnum(Lang).optional(),
}) })
.default({ limit: 5, page: 1 }) .default({ limit: 5, page: 1 })

View File

@@ -4,6 +4,7 @@ import { countries } from "@/constants/countries"
import * as api from "@/lib/api" import * as api from "@/lib/api"
import { dt } from "@/lib/dt" import { dt } from "@/lib/dt"
import { import {
languageProtectedProcedure,
protectedProcedure, protectedProcedure,
router, router,
safeProtectedProcedure, safeProtectedProcedure,
@@ -629,10 +630,11 @@ export const userQueryRouter = router({
}), }),
}), }),
transaction: router({ transaction: router({
friendTransactions: protectedProcedure friendTransactions: languageProtectedProcedure
.input(friendTransactionsInput) .input(friendTransactionsInput)
.query(async ({ ctx, input }) => { .query(async ({ ctx, input }) => {
const { limit, page } = input const { limit, page } = input
getFriendTransactionsCounter.add(1) getFriendTransactionsCounter.add(1)
console.info( console.info(
"api.transaction.friendTransactions start", "api.transaction.friendTransactions start",
@@ -699,6 +701,7 @@ export const userQueryRouter = router({
"api.transaction.friendTransactions success", "api.transaction.friendTransactions success",
JSON.stringify({}) JSON.stringify({})
) )
const updatedData = await updateStaysBookingUrl( const updatedData = await updateStaysBookingUrl(
verifiedData.data.data, verifiedData.data.data,
ctx.session.token.access_token, ctx.session.token.access_token,

View File

@@ -52,8 +52,7 @@ const baseProcedure = t.procedure.use(sentryMiddleware)
export const publicProcedure = baseProcedure export const publicProcedure = baseProcedure
export const contentstackBaseProcedure = baseProcedure.use( export const languageProcedure = baseProcedure.use(async function (opts) {
async function (opts) {
if (!opts.ctx.lang) { if (!opts.ctx.lang) {
// When fetching data client side with TRPC we don't pass through middlewares and therefore do not get the lang through headers // When fetching data client side with TRPC we don't pass through middlewares and therefore do not get the lang through headers
// We can then pass lang as an input in the request and set it to the context in the procedure // We can then pass lang as an input in the request and set it to the context in the procedure
@@ -76,8 +75,10 @@ export const contentstackBaseProcedure = baseProcedure.use(
lang: opts.ctx.lang, lang: opts.ctx.lang,
}, },
}) })
} })
)
export const contentstackBaseProcedure = languageProcedure
export const contentstackExtendedProcedureUID = contentstackBaseProcedure.use( export const contentstackExtendedProcedureUID = contentstackBaseProcedure.use(
async function (opts) { async function (opts) {
if (!opts.ctx.uid) { if (!opts.ctx.uid) {
@@ -207,5 +208,8 @@ export const contentStackBaseWithProtectedProcedure =
export const safeProtectedServiceProcedure = export const safeProtectedServiceProcedure =
safeProtectedProcedure.unstable_concat(serviceProcedure) safeProtectedProcedure.unstable_concat(serviceProcedure)
export const protectedServcieProcedure = export const protectedServiceProcedure =
protectedProcedure.unstable_concat(serviceProcedure) protectedProcedure.unstable_concat(serviceProcedure)
export const languageProtectedProcedure =
protectedProcedure.unstable_concat(languageProcedure)