From 123f9bf1a9276117e91fe1753f530efb38e3a655 Mon Sep 17 00:00:00 2001 From: Mohamed Marrouchi Date: Sun, 6 Oct 2024 21:01:00 +0100 Subject: [PATCH] fix: i18n custom blocks settings --- api/src/setting/schemas/setting.schema.ts | 8 ++++++++ frontend/src/components/settings/SettingInput.tsx | 8 +++++--- frontend/src/types/setting.types.ts | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/api/src/setting/schemas/setting.schema.ts b/api/src/setting/schemas/setting.schema.ts index 3296b500..082778eb 100644 --- a/api/src/setting/schemas/setting.schema.ts +++ b/api/src/setting/schemas/setting.schema.ts @@ -7,6 +7,7 @@ */ import { Prop, Schema, SchemaFactory, ModelDefinition } from '@nestjs/mongoose'; +import { Transform } from 'class-transformer'; import { IsArray, IsIn } from 'class-validator'; import { BaseSchema } from '@/utils/generics/base-schema'; @@ -45,6 +46,13 @@ export class Setting extends BaseSchema { @Prop({ type: JSON, default: {} }) config?: Record; + @Prop({ + type: String, + default: '', + }) + @Transform(({ obj }) => obj.help || undefined) + help?: string; + @Prop({ type: Number, default: 0, diff --git a/frontend/src/components/settings/SettingInput.tsx b/frontend/src/components/settings/SettingInput.tsx index bd14e7da..d59c58a0 100644 --- a/frontend/src/components/settings/SettingInput.tsx +++ b/frontend/src/components/settings/SettingInput.tsx @@ -36,9 +36,11 @@ const SettingInput: React.FC = ({ }) => { const { t } = useTranslate(); const nestedLabel = setting.label as TNestedTranslation<"label">; - const nestedHelp = setting.label as TNestedTranslation<"help">; - const label = t("label", nestedLabel); - const helperText = t("help", nestedHelp); + const nestedHelp = setting.help as TNestedTranslation<"help">; + const label = t("label", nestedLabel, { defaultValue: nestedLabel }); + const helperText = nestedHelp + ? t("help", nestedHelp, { defaultValue: nestedHelp }) + : ""; switch (setting.type) { case "text": diff --git a/frontend/src/types/setting.types.ts b/frontend/src/types/setting.types.ts index 663d428e..6d9b9021 100644 --- a/frontend/src/types/setting.types.ts +++ b/frontend/src/types/setting.types.ts @@ -93,6 +93,7 @@ export interface ISettingAttributes { config?: Record; weight?: number; title?: string; + help?: string; } export interface ISettingStub extends IBaseSchema, ISettingAttributes {}