import { type FC, useEffect } from "react"; import { DialogTitle, DialogContent, Dialog, DialogHeader, Form, FormItem, FormControl, FormMessage, FormLabel, Input, FormField, Button, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, FormDescription, HStack, } from "@marzneshin/components"; import { useTranslation } from "react-i18next"; import { NodeSchema, useNodesCreationMutation, useNodesUpdateMutation, } from "../.."; import type { NodeType } from "../.."; import { useMutationDialog } from "@marzneshin/hooks"; interface MutationDialogProps { entity: NodeType | null; open: boolean; onOpenChange: (state: boolean) => void; onClose: () => void; } const getDefaultValue = (): NodeType => ({ name: "", address: "", status: "none", port: 62050, usage_coefficient: 1, connection_backend: "grpclib", }); export const MutationDialog: FC = ({ entity, open, onOpenChange, onClose, }) => { const updateMutation = useNodesUpdateMutation(); const createMutation = useNodesCreationMutation(); const { t } = useTranslation(); const { form, handleSubmit } = useMutationDialog({ onOpenChange, entity, schema: NodeSchema, createMutation, updateMutation, getDefaultValue, }); useEffect(() => { if (!open) onClose(); }, [open, onClose]); return ( {entity ? t("page.nodes.dialogs.edition.title") : t("page.nodes.dialogs.creation.title")}
( {t("name")} )} />
( {t("address")} )} /> ( {t("port")} )} />
( {t("page.nodes.connection_backend")} {t("page.nodes.connection_backend_desc")} )} /> ( {t("page.nodes.usage_coefficient")} )} />
); };