debeerify in account as user profile can have dots (#26680)

fixes: #26635

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
Erik Jan de Wit 2024-02-12 19:32:53 +01:00 committed by GitHub
parent 750bc2c09c
commit 8d3d94f904
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 2 deletions

View file

@ -14,6 +14,7 @@ import { ErrorOption, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { import {
UserProfileFields, UserProfileFields,
debeerify,
setUserProfileServerError, setUserProfileServerError,
useAlerts, useAlerts,
} from "ui-shared"; } from "ui-shared";
@ -58,8 +59,14 @@ export const PersonalInfo = () => {
const onSubmit = async (user: UserRepresentation) => { const onSubmit = async (user: UserRepresentation) => {
try { try {
await savePersonalInfo(context, user); const attributes = Object.fromEntries(
const locale = user.attributes?.["locale"]?.toString(); Object.entries(user.attributes || {}).map(([k, v]) => [
debeerify(k),
v,
]),
);
await savePersonalInfo(context, { ...user, attributes });
const locale = attributes["locale"]?.toString();
i18n.changeLanguage(locale, (error) => { i18n.changeLanguage(locale, (error) => {
if (error) { if (error) {
console.warn("Error(s) loading locale", locale, error); console.warn("Error(s) loading locale", locale, error);

View file

@ -20,6 +20,7 @@ export {
setUserProfileServerError, setUserProfileServerError,
isUserProfileError, isUserProfileError,
label, label,
debeerify,
} from "./user-profile/utils"; } from "./user-profile/utils";
export type { UserFormFields } from "./user-profile/utils"; export type { UserFormFields } from "./user-profile/utils";
export { ScrollForm, mainPageContentId } from "./scroll-form/ScrollForm"; export { ScrollForm, mainPageContentId } from "./scroll-form/ScrollForm";

View file

@ -49,6 +49,9 @@ export const fieldName = (name?: string) =>
"🍺", "🍺",
)}` as FieldPath<UserFormFields>; )}` as FieldPath<UserFormFields>;
export const debeerify = <T extends string>(name: T) =>
name.replaceAll("🍺", ".");
export function setUserProfileServerError<T>( export function setUserProfileServerError<T>(
error: UserProfileError, error: UserProfileError,
setError: (field: keyof T, params: object) => void, setError: (field: keyof T, params: object) => void,