mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
Merge pull request #10 from Hexastack/fix/translations-display
Fix/translations display
This commit is contained in:
commit
b01e998ed0
@ -134,7 +134,7 @@ export const config: Config = {
|
|||||||
},
|
},
|
||||||
chatbot: {
|
chatbot: {
|
||||||
lang: {
|
lang: {
|
||||||
default: 'fr',
|
default: 'en',
|
||||||
available: ['en', 'fr', 'ar', 'tn'],
|
available: ['en', 'fr', 'ar', 'tn'],
|
||||||
},
|
},
|
||||||
messages: {
|
messages: {
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
|
* 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { config } from '@/config';
|
||||||
|
|
||||||
import { SettingCreateDto } from '../dto/setting.dto';
|
import { SettingCreateDto } from '../dto/setting.dto';
|
||||||
import { SettingType } from '../schemas/types';
|
import { SettingType } from '../schemas/types';
|
||||||
|
|
||||||
@ -80,7 +82,7 @@ export const settingModels: SettingCreateDto[] = [
|
|||||||
{
|
{
|
||||||
group: 'nlp_settings',
|
group: 'nlp_settings',
|
||||||
label: 'default_lang',
|
label: 'default_lang',
|
||||||
value: '',
|
value: config.chatbot.lang.default,
|
||||||
options: [], // NOTE : will be set onBeforeCreate from config
|
options: [], // NOTE : will be set onBeforeCreate from config
|
||||||
type: SettingType.select,
|
type: SettingType.select,
|
||||||
weight: 5,
|
weight: 5,
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Dialog, DialogActions, DialogContent } from "@mui/material";
|
import { Dialog, DialogActions, DialogContent } from "@mui/material";
|
||||||
import { useEffect, FC } from "react";
|
import { useEffect, FC, useMemo } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
@ -22,14 +22,14 @@ import { useSetting } from "@/hooks/useSetting";
|
|||||||
import { useToast } from "@/hooks/useToast";
|
import { useToast } from "@/hooks/useToast";
|
||||||
import { EntityType } from "@/services/types";
|
import { EntityType } from "@/services/types";
|
||||||
import {
|
import {
|
||||||
ITranslationFull,
|
|
||||||
ITranslationAttributes,
|
ITranslationAttributes,
|
||||||
ITranslations,
|
ITranslations,
|
||||||
|
ITranslation,
|
||||||
} from "@/types/translation.types";
|
} from "@/types/translation.types";
|
||||||
|
|
||||||
import TranslationInput from "./TranslationInput";
|
import TranslationInput from "./TranslationInput";
|
||||||
|
|
||||||
export type EditTranslationDialogProps = DialogControlProps<ITranslationFull>;
|
export type EditTranslationDialogProps = DialogControlProps<ITranslation>;
|
||||||
export const EditTranslationDialog: FC<EditTranslationDialogProps> = ({
|
export const EditTranslationDialog: FC<EditTranslationDialogProps> = ({
|
||||||
open,
|
open,
|
||||||
data,
|
data,
|
||||||
@ -39,6 +39,7 @@ export const EditTranslationDialog: FC<EditTranslationDialogProps> = ({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const availableLanguages = useSetting("nlp_settings", "languages");
|
const availableLanguages = useSetting("nlp_settings", "languages");
|
||||||
|
const defaultLanguage = useSetting("nlp_settings", "default_lang");
|
||||||
const { mutateAsync: updateTranslation } = useUpdate(EntityType.TRANSLATION, {
|
const { mutateAsync: updateTranslation } = useUpdate(EntityType.TRANSLATION, {
|
||||||
onError: () => {
|
onError: () => {
|
||||||
toast.error(t("message.internal_server_error"));
|
toast.error(t("message.internal_server_error"));
|
||||||
@ -48,16 +49,29 @@ export const EditTranslationDialog: FC<EditTranslationDialogProps> = ({
|
|||||||
toast.success(t("message.success_save"));
|
toast.success(t("message.success_save"));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const defaultValues: ITranslation | undefined = useMemo(
|
||||||
|
() =>
|
||||||
|
data
|
||||||
|
? {
|
||||||
|
...data,
|
||||||
|
translations: {
|
||||||
|
...data?.translations,
|
||||||
|
[defaultLanguage]: data?.str,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
[defaultLanguage, data],
|
||||||
|
);
|
||||||
const { reset, control, handleSubmit } = useForm<ITranslationAttributes>({
|
const { reset, control, handleSubmit } = useForm<ITranslationAttributes>({
|
||||||
defaultValues: data,
|
defaultValues,
|
||||||
});
|
});
|
||||||
const onSubmitForm = async (params: ITranslationAttributes) => {
|
const onSubmitForm = async (params: ITranslationAttributes) => {
|
||||||
if (data?.id) updateTranslation({ id: data.id, params });
|
if (data?.id) updateTranslation({ id: data.id, params });
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open) reset(data);
|
if (open) reset(defaultValues);
|
||||||
}, [open, reset, data]);
|
}, [open, reset, defaultValues]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} fullWidth onClose={closeDialog} {...rest}>
|
<Dialog open={open} fullWidth onClose={closeDialog} {...rest}>
|
||||||
|
@ -30,7 +30,7 @@ import { useToast } from "@/hooks/useToast";
|
|||||||
import { PageHeader } from "@/layout/content/PageHeader";
|
import { PageHeader } from "@/layout/content/PageHeader";
|
||||||
import { EntityType } from "@/services/types";
|
import { EntityType } from "@/services/types";
|
||||||
import { PermissionAction } from "@/types/permission.types";
|
import { PermissionAction } from "@/types/permission.types";
|
||||||
import { ITranslation, ITranslationFull } from "@/types/translation.types";
|
import { ITranslation } from "@/types/translation.types";
|
||||||
import { getDateTimeFormatter } from "@/utils/date";
|
import { getDateTimeFormatter } from "@/utils/date";
|
||||||
|
|
||||||
import { EditTranslationDialog } from "./EditTranslationDialog";
|
import { EditTranslationDialog } from "./EditTranslationDialog";
|
||||||
@ -39,7 +39,7 @@ export const Translations = () => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const availableLanguages = useSetting("nlp_settings", "languages");
|
const availableLanguages = useSetting("nlp_settings", "languages");
|
||||||
const editDialogCtl = useDialog<ITranslationFull>(false);
|
const editDialogCtl = useDialog<ITranslation>(false);
|
||||||
const deleteDialogCtl = useDialog<string>(false);
|
const deleteDialogCtl = useDialog<string>(false);
|
||||||
const { onSearch, searchPayload } = useSearch<ITranslation>({
|
const { onSearch, searchPayload } = useSearch<ITranslation>({
|
||||||
$iLike: ["str"],
|
$iLike: ["str"],
|
||||||
@ -69,7 +69,7 @@ export const Translations = () => {
|
|||||||
toast.success(t("message.success_translation_refresh"));
|
toast.success(t("message.success_translation_refresh"));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const actionColumns = useActionColumns<ITranslationFull>(
|
const actionColumns = useActionColumns<ITranslation>(
|
||||||
EntityType.TRANSLATION,
|
EntityType.TRANSLATION,
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@ -85,9 +85,8 @@ export const Translations = () => {
|
|||||||
],
|
],
|
||||||
t("label.operations"),
|
t("label.operations"),
|
||||||
);
|
);
|
||||||
const columns: GridColDef<ITranslationFull>[] = [
|
const columns: GridColDef<ITranslation>[] = [
|
||||||
{ flex: 1, field: "str", headerName: t("label.str") },
|
{ flex: 1, field: "str", headerName: t("label.str") },
|
||||||
|
|
||||||
{
|
{
|
||||||
maxWidth: 300,
|
maxWidth: 300,
|
||||||
field: "translations",
|
field: "translations",
|
||||||
|
@ -27,6 +27,3 @@ export interface ITranslationStub extends IBaseSchema {
|
|||||||
|
|
||||||
export interface ITranslation extends ITranslationStub, IFormat<Format.BASIC> {}
|
export interface ITranslation extends ITranslationStub, IFormat<Format.BASIC> {}
|
||||||
|
|
||||||
export interface ITranslationFull
|
|
||||||
extends ITranslationStub,
|
|
||||||
IFormat<Format.FULL> {}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user