diff --git a/app/[lang]/(live)/(protected)/my-pages/profile/@profile/page.tsx b/app/[lang]/(live)/(protected)/my-pages/profile/@profile/page.tsx index 4c1532cf1..ad6458704 100644 --- a/app/[lang]/(live)/(protected)/my-pages/profile/@profile/page.tsx +++ b/app/[lang]/(live)/(protected)/my-pages/profile/@profile/page.tsx @@ -1,4 +1,4 @@ -import { languageSelect } from "@/constants/languages" +import { languages, languageSelect } from "@/constants/languages" import { profileEdit } from "@/constants/routes/myPages" import { serverClient } from "@/lib/trpc/server" @@ -29,6 +29,8 @@ export default async function Profile({ params }: PageArgs) { if (!user || "error" in user) { return null } + + const defaultLanguage = languages[params.lang] const language = languageSelect.find((l) => l.value === user.language) return ( <> @@ -68,7 +70,7 @@ export default async function Profile({ params }: PageArgs) { {formatMessage({ id: "Language" })} - {language?.label ?? "N/A"} + {language?.label ?? defaultLanguage}
diff --git a/components/Forms/Edit/Profile/index.tsx b/components/Forms/Edit/Profile/index.tsx index faf69db57..acebe9f89 100644 --- a/components/Forms/Edit/Profile/index.tsx +++ b/components/Forms/Edit/Profile/index.tsx @@ -7,6 +7,7 @@ import { FormProvider, useForm } from "react-hook-form" import { usePhoneInput } from "react-international-phone" import { useIntl } from "react-intl" +import { type Lang, langToApiLang } from "@/constants/languages" import { profile } from "@/constants/routes/myPages" import { trpc } from "@/lib/trpc/client" @@ -25,7 +26,6 @@ import { type EditFormProps, Status, } from "@/types/components/myPages/myProfile/edit" -import type { Lang } from "@/constants/languages" const formId = "edit-profile" @@ -61,7 +61,7 @@ export default function Form({ user }: EditFormProps) { }, dateOfBirth: user.dateOfBirth, email: user.email, - language: user.language, + language: user.language ?? langToApiLang[lang], phoneNumber: phoneInput, password: "", newPassword: "", diff --git a/constants/languages.ts b/constants/languages.ts index 269ae2686..0605e1ce7 100644 --- a/constants/languages.ts +++ b/constants/languages.ts @@ -66,6 +66,17 @@ export enum ApiLang { Unknown = "Unknown", } +type ApiLangKey = keyof typeof ApiLang + +export const langToApiLang: Record = { + [Lang.da]: ApiLang.Da, + [Lang.de]: ApiLang.De, + [Lang.en]: ApiLang.En, + [Lang.fi]: ApiLang.Fi, + [Lang.no]: ApiLang.No, + [Lang.sv]: ApiLang.Sv, +} + export const languageSelect = [ { label: "Danish", value: ApiLang.Da }, { label: "German", value: ApiLang.De }, diff --git a/server/routers/user/output.ts b/server/routers/user/output.ts index e135ace77..a6bd88611 100644 --- a/server/routers/user/output.ts +++ b/server/routers/user/output.ts @@ -15,7 +15,7 @@ export const getUserSchema = z.object({ dateOfBirth: z.string().optional().default("N/A"), email: z.string().email(), firstName: z.string(), - language: z.string(), + language: z.string().optional(), lastName: z.string(), memberships: z.array( z.object({ diff --git a/server/routers/user/query.ts b/server/routers/user/query.ts index e50d024dd..e49bcb826 100644 --- a/server/routers/user/query.ts +++ b/server/routers/user/query.ts @@ -84,7 +84,12 @@ async function getVerifiedUser({ session }: { session: Session }) { const verifiedData = getUserSchema.safeParse(apiJson.data.attributes) if (!verifiedData.success) { - console.error("api.user.profile validation error", JSON.stringify({})) // not passing the data to avoid logging sensitive data + console.error( + "api.user.profile validation error", + JSON.stringify({ + errors: verifiedData.error, + }) + ) return null } console.info("api.user.profile success", JSON.stringify({}))