Fix/mypages clientside menu * feat: move mypages menu to client side * Merge branch 'master' of bitbucket.org:scandic-swap/web into fix/mypages-clientside-menu * wip * wip * wip * refactor: reorganize MyPages navigation logic and improve type definitions * refactor: enhance MyPagesMobileDropdown with loading states and skeletons * refactor: clean up header component and improve myPagesNavigation query structure * Merge branch 'master' of bitbucket.org:scandic-swap/web into fix/mypages-clientside-menu Approved-by: Linus Flood
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { TRPCError } from "@trpc/server"
|
|
import { z } from "zod"
|
|
|
|
import { Lang } from "@/constants/languages"
|
|
import { safeProtectedProcedure } from "@/server/trpc"
|
|
|
|
import { getPrimaryLinks } from "./getPrimaryLinks"
|
|
import { getSecondaryLinks } from "./getSecondaryLinks"
|
|
|
|
import type { MyPagesLink } from "./MyPagesLink"
|
|
|
|
export const myPagesNavigation = safeProtectedProcedure
|
|
.input(
|
|
z.object({
|
|
lang: z.nativeEnum(Lang).optional(),
|
|
})
|
|
)
|
|
.query(
|
|
async ({
|
|
ctx,
|
|
input,
|
|
}): Promise<{
|
|
primaryLinks: MyPagesLink[]
|
|
secondaryLinks: MyPagesLink[]
|
|
} | null> => {
|
|
if (!ctx.session) {
|
|
return null
|
|
}
|
|
|
|
const lang = input.lang || ctx.lang
|
|
|
|
if (!lang) {
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message: "Language must be provided.",
|
|
})
|
|
}
|
|
|
|
const [primaryLinks, secondaryLinks] = await Promise.all([
|
|
getPrimaryLinks({ lang }),
|
|
getSecondaryLinks({ lang }),
|
|
])
|
|
|
|
return {
|
|
primaryLinks,
|
|
secondaryLinks,
|
|
}
|
|
}
|
|
)
|