-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
CommentForm.tsx
46 lines (42 loc) · 1.14 KB
/
CommentForm.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
import { Form, Button, Input, Space } from 'antd';
import { useLoading } from '@rest-hooks/hooks';
import { memo } from 'react';
const { TextArea } = Input;
function CommentForm({
onFinish,
label = 'Comment',
initialValues,
onCancel,
}: {
onFinish: (data: { body: string }) => Promise<unknown>;
onCancel?: () => void;
label: string;
initialValues?: any;
}) {
const [handleSubmit, loading] = useLoading(onFinish, [onFinish]);
return (
<Form
name="basic"
onFinish={handleSubmit}
onFinishFailed={() => {}}
autoComplete="off"
initialValues={initialValues}
>
<Form.Item
name="body"
rules={[{ required: true, message: 'Content is required' }]}
>
<TextArea rows={4} autoSize={{ minRows: 3, maxRows: 20 }} />
</Form.Item>
<Form.Item style={{ textAlign: 'right', marginBottom: 0 }}>
<Space>
{onCancel ? <Button onClick={onCancel}>Cancel</Button> : null}
<Button type="primary" htmlType="submit" loading={loading}>
{label}
</Button>
</Space>
</Form.Item>
</Form>
);
}
export default memo(CommentForm);