fix: markdown editor not accepting input due to Form.Item prop injection conflict #6
@@ -21,6 +21,7 @@ function Inventory() {
|
|||||||
const [editingItem, setEditingItem] = useState<Item | null>(null);
|
const [editingItem, setEditingItem] = useState<Item | null>(null);
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [fileList, setFileList] = useState<UploadFile[]>([]);
|
const [fileList, setFileList] = useState<UploadFile[]>([]);
|
||||||
|
const [description, setDescription] = useState<string>('');
|
||||||
const { mode } = useThemeMode();
|
const { mode } = useThemeMode();
|
||||||
|
|
||||||
const load = () => fetchAdminItems().then(setItems);
|
const load = () => fetchAdminItems().then(setItems);
|
||||||
@@ -30,6 +31,7 @@ function Inventory() {
|
|||||||
setEditingItem(null);
|
setEditingItem(null);
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
setFileList([]);
|
setFileList([]);
|
||||||
|
setDescription('');
|
||||||
setModalOpen(true);
|
setModalOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,10 +39,10 @@ function Inventory() {
|
|||||||
setEditingItem(item);
|
setEditingItem(item);
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
name: item.name,
|
name: item.name,
|
||||||
description: item.description,
|
|
||||||
price: item.price_cents / 100
|
price: item.price_cents / 100
|
||||||
});
|
});
|
||||||
setFileList([]);
|
setFileList([]);
|
||||||
|
setDescription(item.description || '');
|
||||||
setModalOpen(true);
|
setModalOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +50,7 @@ function Inventory() {
|
|||||||
const values = await form.validateFields();
|
const values = await form.validateFields();
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
fd.append('name', values.name);
|
fd.append('name', values.name);
|
||||||
fd.append('description', values.description || '');
|
fd.append('description', description);
|
||||||
fd.append('price', String(values.price));
|
fd.append('price', String(values.price));
|
||||||
fileList.forEach(f => {
|
fileList.forEach(f => {
|
||||||
if (f.originFileObj) fd.append('images', f.originFileObj as File);
|
if (f.originFileObj) fd.append('images', f.originFileObj as File);
|
||||||
@@ -135,19 +137,21 @@ function Inventory() {
|
|||||||
destroyOnClose
|
destroyOnClose
|
||||||
width={720}
|
width={720}
|
||||||
>
|
>
|
||||||
|
<div data-color-mode={mode}>
|
||||||
<Form form={form} layout="vertical">
|
<Form form={form} layout="vertical">
|
||||||
<Form.Item name="name" label="Name" rules={[{ required: true }]}>
|
<Form.Item name="name" label="Name" rules={[{ required: true }]}>
|
||||||
<Input />
|
<Input />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
|
||||||
name="description"
|
<Form.Item label="Description (Markdown supported)">
|
||||||
label="Description (Markdown supported)"
|
<MDEditor
|
||||||
getValueFromEvent={(value) => value}
|
value={description}
|
||||||
>
|
onChange={(val) => setDescription(val || '')}
|
||||||
<div data-color-mode={mode}>
|
height={220}
|
||||||
<MDEditor height={220} preview="live" />
|
preview="live"
|
||||||
</div>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item name="price" label="Price (USD)" rules={[{ required: true }]}>
|
<Form.Item name="price" label="Price (USD)" rules={[{ required: true }]}>
|
||||||
<InputNumber min={0} step={0.01} style={{ width: '100%' }} />
|
<InputNumber min={0} step={0.01} style={{ width: '100%' }} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -184,6 +188,7 @@ function Inventory() {
|
|||||||
</Upload>
|
</Upload>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user