import { Box, DialogContent, FormControl, Grid2, Link } from "@mui/material"; import { useEffect, useRef, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { CustomProps } from "../../../../api/explorer"; import { DenseFilledTextField } from "../../../Common/StyledComponents"; import DraggableDialog from "../../../Dialogs/DraggableDialog"; import { getPropsContent } from "../../../FileManager/Sidebar/CustomProps/CustomPropsItem"; import SettingForm from "../../../Pages/Setting/SettingForm"; import { NoMarginHelperText } from "../../Settings/Settings"; import { FieldTypes } from "./DraggableCustomPropsRow"; interface EditPropsDialogProps { open: boolean; onClose: () => void; onSave: (props: CustomProps) => void; isNew: boolean; props?: CustomProps; } const EditPropsDialog = ({ open, onClose, onSave, isNew, props }: EditPropsDialogProps) => { const { t } = useTranslation("dashboard"); const formRef = useRef(null); const [editProps, setEditProps] = useState(props); const handleSave = () => { if (!formRef.current?.checkValidity()) { formRef.current?.reportValidity(); return; } onSave({ ...editProps } as CustomProps); onClose(); }; useEffect(() => { if (props) { setEditProps({ ...props }); } if (!open) { setTimeout(() => { setEditProps(undefined); }, 100); } }, [open, props]); if (!editProps || !editProps.type) return null; const fieldType = FieldTypes[editProps?.type]; return ( setEditProps({ ...editProps, id: e.target.value } as CustomProps)} /> {t("customProps.idDes")} setEditProps({ ...editProps, name: e.target.value, } as CustomProps) } required /> {t("settings.displayNameDes")} setEditProps({ ...editProps, icon: e.target.value } as CustomProps)} /> { ]} /> } {(fieldType.minTitle || fieldType.maxTitle) && ( {fieldType.minTitle && ( setEditProps({ ...editProps, min: e.target.value === "" ? undefined : parseInt(e.target.value) } as CustomProps)} /> {fieldType.minDes && {t(fieldType.minDes)}} )} {fieldType.maxTitle && ( setEditProps({ ...editProps, max: e.target.value === "" ? undefined : parseInt(e.target.value) } as CustomProps)} /> {fieldType.maxDes && {t(fieldType.maxDes)}} )} )} {fieldType.showOptions && ( setEditProps({ ...editProps, options: e.target.value.split("\n") } as CustomProps)} /> {t("customProps.optionsDes")} )} {getPropsContent( { props: editProps, id: editProps.id, value: editProps.default ?? "", }, (value) => { setEditProps({ ...editProps, default: value } as CustomProps); }, false, false, true, )} ); }; export default EditPropsDialog;