/
edit.tsx
50 lines (43 loc) · 1.31 KB
/
edit.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
/* eslint-disable no-unused-expressions */
import React, { FC, memo } from 'react'
import {
FormGroup,
Label,
FormMessage,
RichText,
QuillOptions,
DefaultQuillToolbarOptions,
} from '@admin-bro/design-system'
import { EditPropertyProps } from '../base-property-props'
import { recordPropertyIsEqual } from '../record-property-is-equal'
const Edit: FC<EditPropertyProps> = (props) => {
const { property, record, onChange } = props
const value = record.params?.[property.name] ?? ''
const error = record.errors && record.errors[property.name]
const { custom } = property
const quill = custom as QuillOptions || {}
quill.theme = quill.theme || 'snow'
quill.modules = {
toolbar: DefaultQuillToolbarOptions,
...(quill.modules || {}),
}
return (
<FormGroup error={Boolean(error)}>
<Label
htmlFor={property.name}
required={property.isRequired}
>
{property.label}
</Label>
<RichText
value={value}
onChange={content => onChange(property.name, content)}
quill={quill}
/>
<FormMessage>{error?.message}</FormMessage>
</FormGroup>
)
}
export default memo(Edit, recordPropertyIsEqual)