import React, { useRef, useState } from 'react'; import { Form, Input } from 'UI'; import styles from './customFieldForm.module.css'; import { useStore } from 'App/mstore'; import { useModal } from 'Components/Modal'; import { toast } from 'react-toastify'; import { Button, Modal } from 'antd'; import { Trash } from 'UI/Icons'; import { observer } from 'mobx-react-lite'; interface CustomFieldFormProps { siteId: string; } const CustomFieldForm: React.FC = ({ siteId }) => { const focusElementRef = useRef(null); const { customFieldStore: store } = useStore(); const field = store.instance; const { hideModal } = useModal(); const [loading, setLoading] = useState(false); const write = ({ target: { value, name } }: any) => store.edit({ [name]: value }); const exists = field?.exists(); const onDelete = async () => { Modal.confirm({ title: 'Metadata', content: `Are you sure you want to remove?`, onOk: async () => { await store.remove(siteId, field?.index!); hideModal(); } }); }; const onSave = (field: any) => { setLoading(true); store.save(siteId, field).then((response) => { if (!response || !response.errors || response.errors.size === 0) { hideModal(); toast.success('Metadata added successfully!'); } else { toast.error(response.errors[0]); } }).catch(() => { toast.error('An error occurred while saving metadata.'); }).finally(() => { setLoading(false); }); }; return (

{exists ? 'Update' : 'Add'} Metadata Field

); }; export default observer(CustomFieldForm);