Merged in fix/profile-validation (pull request #488)
fix: default language if missing in profile Approved-by: Michael Zetterberg Approved-by: Tobias Johansson Approved-by: Arvid Norlin Approved-by: Matilda Landström
This commit is contained in:
@@ -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<LangParams>) {
|
||||
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<LangParams>) {
|
||||
<Body color="burgundy" textTransform="bold">
|
||||
{formatMessage({ id: "Language" })}
|
||||
</Body>
|
||||
<Body color="burgundy">{language?.label ?? "N/A"}</Body>
|
||||
<Body color="burgundy">{language?.label ?? defaultLanguage}</Body>
|
||||
</div>
|
||||
<div className={styles.item}>
|
||||
<EmailIcon color="burgundy" />
|
||||
|
||||
@@ -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: "",
|
||||
|
||||
@@ -66,6 +66,17 @@ export enum ApiLang {
|
||||
Unknown = "Unknown",
|
||||
}
|
||||
|
||||
type ApiLangKey = keyof typeof ApiLang
|
||||
|
||||
export const langToApiLang: Record<Lang, ApiLangKey> = {
|
||||
[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 },
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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({}))
|
||||
|
||||
Reference in New Issue
Block a user