Use given locale input or user locale when translating updateProfile

pull/11421/merge^2
Alex van Andel 2023-09-27 10:53:17 +01:00
parent b95c884ddc
commit c30e867147
1 changed files with 4 additions and 2 deletions

View File

@ -33,6 +33,7 @@ type UpdateProfileOptions = {
export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions) => {
const { user } = ctx;
const userMetadata = handleUserMetadata({ ctx, input });
const locale = input.locale || user.locale;
const data: Prisma.UserUpdateInput = {
...input,
metadata: userMetadata,
@ -45,7 +46,7 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions)
const layoutError = validateBookerLayouts(input?.metadata?.defaultBookerLayouts || null);
if (layoutError) {
const t = await getTranslation("en", "common");
const t = await getTranslation(locale, "common");
throw new TRPCError({ code: "BAD_REQUEST", message: t(layoutError) });
}
@ -57,7 +58,8 @@ export const updateProfileHandler = async ({ ctx, input }: UpdateProfileOptions)
const response = await checkUsername(username);
isPremiumUsername = response.premium;
if (!response.available) {
throw new TRPCError({ code: "BAD_REQUEST", message: response.message });
const t = await getTranslation(locale, "common");
throw new TRPCError({ code: "BAD_REQUEST", message: t("username_already_taken") });
}
}
}