mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
Merge branch '692-create-genericformdialog-component' into 689-refactor-languages-dialogs-add-edit-delete
This commit is contained in:
commit
c9822b1689
43
frontend/src/app-components/dialogs/GenericFormDialog.tsx
Normal file
43
frontend/src/app-components/dialogs/GenericFormDialog.tsx
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2025 Hexastack. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
import { FormDialog } from "@/app-components/dialogs";
|
||||||
|
import { useTranslate } from "@/hooks/useTranslate";
|
||||||
|
import { TTranslationKeys } from "@/i18n/i18n.types";
|
||||||
|
import { ComponentFormDialogProps } from "@/types/common/dialogs.types";
|
||||||
|
|
||||||
|
type GenericFormDialogProps<T> = ComponentFormDialogProps<T> & {
|
||||||
|
Form: React.ElementType;
|
||||||
|
addText?: TTranslationKeys;
|
||||||
|
editText?: TTranslationKeys;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GenericFormDialog = <T,>({
|
||||||
|
Form,
|
||||||
|
payload,
|
||||||
|
...rest
|
||||||
|
}: GenericFormDialogProps<T>) => {
|
||||||
|
const { t } = useTranslate();
|
||||||
|
const translationKey = payload ? rest.editText : rest.addText;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form
|
||||||
|
data={payload}
|
||||||
|
Wrapper={FormDialog}
|
||||||
|
onSuccess={() => {
|
||||||
|
rest.onClose(true);
|
||||||
|
}}
|
||||||
|
WrapperProps={{
|
||||||
|
title: translationKey && t(translationKey),
|
||||||
|
...rest,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
@ -11,5 +11,6 @@ export * from "./confirm/ConfirmDialogBody";
|
|||||||
export * from "./DeleteDialog";
|
export * from "./DeleteDialog";
|
||||||
export * from "./DialogTitle";
|
export * from "./DialogTitle";
|
||||||
export * from "./FormDialog";
|
export * from "./FormDialog";
|
||||||
|
export * from "./GenericFormDialog";
|
||||||
export * from "./layouts/ContentContainer";
|
export * from "./layouts/ContentContainer";
|
||||||
export * from "./layouts/ContentItem";
|
export * from "./layouts/ContentItem";
|
||||||
|
@ -6,32 +6,19 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { FC } from "react";
|
import { GenericFormDialog } from "@/app-components/dialogs";
|
||||||
|
|
||||||
import { FormDialog } from "@/app-components/dialogs";
|
|
||||||
import { useTranslate } from "@/hooks/useTranslate";
|
|
||||||
import { ICategory } from "@/types/category.types";
|
import { ICategory } from "@/types/category.types";
|
||||||
import { ComponentFormDialogProps } from "@/types/common/dialogs.types";
|
import { ComponentFormDialogProps } from "@/types/common/dialogs.types";
|
||||||
|
|
||||||
import { CategoryForm } from "./CategoryForm";
|
import { CategoryForm } from "./CategoryForm";
|
||||||
|
|
||||||
export const CategoryFormDialog: FC<ComponentFormDialogProps<ICategory>> = ({
|
export const CategoryFormDialog = <T extends ICategory = ICategory>(
|
||||||
payload,
|
props: ComponentFormDialogProps<T>,
|
||||||
...rest
|
) => (
|
||||||
}) => {
|
<GenericFormDialog<T>
|
||||||
const { t } = useTranslate();
|
Form={CategoryForm}
|
||||||
|
addText="title.new_category"
|
||||||
return (
|
editText="title.edit_category"
|
||||||
<CategoryForm
|
{...props}
|
||||||
data={payload}
|
|
||||||
onSuccess={() => {
|
|
||||||
rest.onClose(true);
|
|
||||||
}}
|
|
||||||
Wrapper={FormDialog}
|
|
||||||
WrapperProps={{
|
|
||||||
title: payload ? t("title.edit_category") : t("title.new_category"),
|
|
||||||
...rest,
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
@ -6,33 +6,19 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { FC } from "react";
|
import { GenericFormDialog } from "@/app-components/dialogs";
|
||||||
|
|
||||||
import { FormDialog } from "@/app-components/dialogs";
|
|
||||||
import { useTranslate } from "@/hooks/useTranslate";
|
|
||||||
import { ComponentFormDialogProps } from "@/types/common/dialogs.types";
|
import { ComponentFormDialogProps } from "@/types/common/dialogs.types";
|
||||||
import { IContextVar } from "@/types/context-var.types";
|
import { IContextVar } from "@/types/context-var.types";
|
||||||
|
|
||||||
import { ContextVarForm } from "./ContextVarForm";
|
import { ContextVarForm } from "./ContextVarForm";
|
||||||
|
|
||||||
export const ContextVarFormDialog: FC<
|
export const ContextVarFormDialog = <T extends IContextVar = IContextVar>(
|
||||||
ComponentFormDialogProps<IContextVar>
|
props: ComponentFormDialogProps<T>,
|
||||||
> = ({ payload, ...rest }) => {
|
) => (
|
||||||
const { t } = useTranslate();
|
<GenericFormDialog<T>
|
||||||
|
Form={ContextVarForm}
|
||||||
return (
|
addText="title.new_context_var"
|
||||||
<ContextVarForm
|
editText="title.edit_context_var"
|
||||||
data={payload}
|
{...props}
|
||||||
onSuccess={() => {
|
|
||||||
rest.onClose(true);
|
|
||||||
}}
|
|
||||||
Wrapper={FormDialog}
|
|
||||||
WrapperProps={{
|
|
||||||
title: payload
|
|
||||||
? t("title.edit_context_var")
|
|
||||||
: t("title.new_context_var"),
|
|
||||||
...rest,
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
@ -6,32 +6,19 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { FC } from "react";
|
import { GenericFormDialog } from "@/app-components/dialogs";
|
||||||
|
|
||||||
import { FormDialog } from "@/app-components/dialogs";
|
|
||||||
import { useTranslate } from "@/hooks/useTranslate";
|
|
||||||
import { ComponentFormDialogProps } from "@/types/common/dialogs.types";
|
import { ComponentFormDialogProps } from "@/types/common/dialogs.types";
|
||||||
import { ILabel } from "@/types/label.types";
|
import { ILabel } from "@/types/label.types";
|
||||||
|
|
||||||
import { LabelForm } from "./LabelForm";
|
import { LabelForm } from "./LabelForm";
|
||||||
|
|
||||||
export const LabelFormDialog: FC<ComponentFormDialogProps<ILabel>> = ({
|
export const LabelFormDialog = <T extends ILabel = ILabel>(
|
||||||
payload,
|
props: ComponentFormDialogProps<T>,
|
||||||
...rest
|
) => (
|
||||||
}) => {
|
<GenericFormDialog<T>
|
||||||
const { t } = useTranslate();
|
Form={LabelForm}
|
||||||
|
addText="title.new_label"
|
||||||
return (
|
editText="title.edit_label"
|
||||||
<LabelForm
|
{...props}
|
||||||
data={payload}
|
|
||||||
onSuccess={() => {
|
|
||||||
rest.onClose(true);
|
|
||||||
}}
|
|
||||||
Wrapper={FormDialog}
|
|
||||||
WrapperProps={{
|
|
||||||
title: payload ? t("title.edit_label") : t("title.new_label"),
|
|
||||||
...rest,
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
@ -6,31 +6,19 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { FC } from "react";
|
import { GenericFormDialog } from "@/app-components/dialogs";
|
||||||
|
|
||||||
import { FormDialog } from "@/app-components/dialogs";
|
|
||||||
import { useTranslate } from "@/hooks/useTranslate";
|
|
||||||
import { ComponentFormDialogProps } from "@/types/common/dialogs.types";
|
import { ComponentFormDialogProps } from "@/types/common/dialogs.types";
|
||||||
import { ITranslation } from "@/types/translation.types";
|
import { ITranslation } from "@/types/translation.types";
|
||||||
|
|
||||||
import { TranslationForm } from "./TranslationForm";
|
import { TranslationForm } from "./TranslationForm";
|
||||||
|
|
||||||
export const TranslationFormDialog: FC<
|
export const TranslationFormDialog = <T extends ITranslation = ITranslation>(
|
||||||
ComponentFormDialogProps<ITranslation>
|
props: ComponentFormDialogProps<T>,
|
||||||
> = ({ payload, ...rest }) => {
|
) => (
|
||||||
const { t } = useTranslate();
|
<GenericFormDialog<T>
|
||||||
|
Form={TranslationForm}
|
||||||
return (
|
addText="title.new_label"
|
||||||
<TranslationForm
|
editText="title.edit_label"
|
||||||
data={payload}
|
{...props}
|
||||||
onSuccess={() => {
|
|
||||||
rest.onClose(true);
|
|
||||||
}}
|
|
||||||
Wrapper={FormDialog}
|
|
||||||
WrapperProps={{
|
|
||||||
title: t("title.update_translation"),
|
|
||||||
...rest,
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user