fix: default language if missing in profile
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 { profileEdit } from "@/constants/routes/myPages"
|
||||||
import { serverClient } from "@/lib/trpc/server"
|
import { serverClient } from "@/lib/trpc/server"
|
||||||
|
|
||||||
@@ -29,6 +29,8 @@ export default async function Profile({ params }: PageArgs<LangParams>) {
|
|||||||
if (!user || "error" in user) {
|
if (!user || "error" in user) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultLanguage = languages[params.lang]
|
||||||
const language = languageSelect.find((l) => l.value === user.language)
|
const language = languageSelect.find((l) => l.value === user.language)
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -68,7 +70,7 @@ export default async function Profile({ params }: PageArgs<LangParams>) {
|
|||||||
<Body color="burgundy" textTransform="bold">
|
<Body color="burgundy" textTransform="bold">
|
||||||
{formatMessage({ id: "Language" })}
|
{formatMessage({ id: "Language" })}
|
||||||
</Body>
|
</Body>
|
||||||
<Body color="burgundy">{language?.label ?? "N/A"}</Body>
|
<Body color="burgundy">{language?.label ?? defaultLanguage}</Body>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.item}>
|
<div className={styles.item}>
|
||||||
<EmailIcon color="burgundy" />
|
<EmailIcon color="burgundy" />
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { FormProvider, useForm } from "react-hook-form"
|
|||||||
import { usePhoneInput } from "react-international-phone"
|
import { usePhoneInput } from "react-international-phone"
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
|
import { type Lang, langToApiLang } from "@/constants/languages"
|
||||||
import { profile } from "@/constants/routes/myPages"
|
import { profile } from "@/constants/routes/myPages"
|
||||||
import { trpc } from "@/lib/trpc/client"
|
import { trpc } from "@/lib/trpc/client"
|
||||||
|
|
||||||
@@ -25,7 +26,6 @@ import {
|
|||||||
type EditFormProps,
|
type EditFormProps,
|
||||||
Status,
|
Status,
|
||||||
} from "@/types/components/myPages/myProfile/edit"
|
} from "@/types/components/myPages/myProfile/edit"
|
||||||
import type { Lang } from "@/constants/languages"
|
|
||||||
|
|
||||||
const formId = "edit-profile"
|
const formId = "edit-profile"
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ export default function Form({ user }: EditFormProps) {
|
|||||||
},
|
},
|
||||||
dateOfBirth: user.dateOfBirth,
|
dateOfBirth: user.dateOfBirth,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
language: user.language,
|
language: user.language ?? langToApiLang[lang],
|
||||||
phoneNumber: phoneInput,
|
phoneNumber: phoneInput,
|
||||||
password: "",
|
password: "",
|
||||||
newPassword: "",
|
newPassword: "",
|
||||||
|
|||||||
@@ -66,6 +66,17 @@ export enum ApiLang {
|
|||||||
Unknown = "Unknown",
|
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 = [
|
export const languageSelect = [
|
||||||
{ label: "Danish", value: ApiLang.Da },
|
{ label: "Danish", value: ApiLang.Da },
|
||||||
{ label: "German", value: ApiLang.De },
|
{ label: "German", value: ApiLang.De },
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export const getUserSchema = z.object({
|
|||||||
dateOfBirth: z.string().optional().default("N/A"),
|
dateOfBirth: z.string().optional().default("N/A"),
|
||||||
email: z.string().email(),
|
email: z.string().email(),
|
||||||
firstName: z.string(),
|
firstName: z.string(),
|
||||||
language: z.string(),
|
language: z.string().optional(),
|
||||||
lastName: z.string(),
|
lastName: z.string(),
|
||||||
memberships: z.array(
|
memberships: z.array(
|
||||||
z.object({
|
z.object({
|
||||||
|
|||||||
@@ -84,7 +84,12 @@ async function getVerifiedUser({ session }: { session: Session }) {
|
|||||||
|
|
||||||
const verifiedData = getUserSchema.safeParse(apiJson.data.attributes)
|
const verifiedData = getUserSchema.safeParse(apiJson.data.attributes)
|
||||||
if (!verifiedData.success) {
|
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
|
return null
|
||||||
}
|
}
|
||||||
console.info("api.user.profile success", JSON.stringify({}))
|
console.info("api.user.profile success", JSON.stringify({}))
|
||||||
|
|||||||
Reference in New Issue
Block a user