-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathCollectionDialog.tsx
More file actions
106 lines (94 loc) · 3.25 KB
/
CollectionDialog.tsx
File metadata and controls
106 lines (94 loc) · 3.25 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import React from 'react';
import {Dialog, TextArea, TextInput} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';
import {I18n} from 'i18n';
import './CollectionDialog.scss';
const i18n = I18n.keyset('component.collections-structure');
const b = block('dl-collection-dialog');
export type CollectionDialogValues = {
title: string;
description: string;
};
type CollectionDialogErrors = Partial<Record<keyof CollectionDialogValues, string>>;
export type Props = {
title: string;
textButtonApply: string;
open: boolean;
isLoading: boolean;
titleAutoFocus?: boolean;
onChange: (values: CollectionDialogValues) => void;
onApply: (values: CollectionDialogValues, onClose: () => void) => Promise<unknown>;
onClose: () => void;
} & {values: CollectionDialogValues} & {errors?: CollectionDialogErrors};
export const CollectionDialog = React.memo<Props>(
({
values,
errors,
title,
textButtonApply,
open,
isLoading,
titleAutoFocus = false,
onApply,
onChange,
onClose,
}) => {
const handleChange = React.useCallback(
(params) => {
const {target} = params;
onChange({
...values,
[target.name]: target.value,
});
},
[onChange, values],
);
const handleApply = React.useCallback(() => {
onApply(values, onClose);
}, [onApply, values, onClose]);
return (
<Dialog
className={b()}
size="s"
open={open}
onClose={onClose}
onEnterKeyDown={handleApply}
>
<Dialog.Header caption={title} />
<Dialog.Body>
<div className={b('field')}>
<div className={b('title')}>{i18n('label_title')}</div>
<TextInput
name="title"
value={values.title}
error={errors?.title}
onChange={handleChange}
autoFocus={titleAutoFocus}
/>
</div>
<div className={b('field')}>
<div className={b('title')}>{i18n('label_description')}</div>
<TextArea
name="description"
value={values.description}
error={errors?.description}
onChange={handleChange}
minRows={2}
/>
</div>
</Dialog.Body>
<Dialog.Footer
onClickButtonCancel={onClose}
onClickButtonApply={handleApply}
textButtonApply={textButtonApply}
propsButtonApply={{
disabled: !values.title,
}}
textButtonCancel={i18n('action_cancel')}
loading={isLoading}
/>
</Dialog>
);
},
);
CollectionDialog.displayName = 'CollectionDialog';