fix: auto navigate to new flow after creation

This commit is contained in:
hexastack 2025-04-23 16:43:35 +01:00
parent 5b2bfd0f46
commit a11d1952c6

View File

@ -6,6 +6,7 @@
* 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 { useRouter } from "next/router";
import { FC, Fragment, useEffect } from "react"; import { FC, Fragment, useEffect } from "react";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
@ -15,7 +16,7 @@ import { useCreate } from "@/hooks/crud/useCreate";
import { useUpdate } from "@/hooks/crud/useUpdate"; import { useUpdate } from "@/hooks/crud/useUpdate";
import { useToast } from "@/hooks/useToast"; import { useToast } from "@/hooks/useToast";
import { useTranslate } from "@/hooks/useTranslate"; import { useTranslate } from "@/hooks/useTranslate";
import { EntityType } from "@/services/types"; import { EntityType, RouterType } from "@/services/types";
import { ICategory, ICategoryAttributes } from "@/types/category.types"; import { ICategory, ICategoryAttributes } from "@/types/category.types";
import { ComponentFormProps } from "@/types/common/dialogs.types"; import { ComponentFormProps } from "@/types/common/dialogs.types";
@ -27,14 +28,16 @@ export const CategoryForm: FC<ComponentFormProps<ICategory>> = ({
}) => { }) => {
const { t } = useTranslate(); const { t } = useTranslate();
const { toast } = useToast(); const { toast } = useToast();
const router = useRouter();
const options = { const options = {
onError: (error: Error) => { onError: (error: Error) => {
rest.onError?.(); rest.onError?.();
toast.error(error || t("message.internal_server_error")); toast.error(error || t("message.internal_server_error"));
}, },
onSuccess: () => { onSuccess: (response: ICategory) => {
rest.onSuccess?.(); rest.onSuccess?.();
toast.success(t("message.success_save")); toast.success(t("message.success_save"));
router.push(`/${RouterType.VISUAL_EDITOR}/flows/${response.id}`);
}, },
}; };
const { mutate: createCategory } = useCreate(EntityType.CATEGORY, options); const { mutate: createCategory } = useCreate(EntityType.CATEGORY, options);