-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
FormBase.js
103 lines (78 loc) · 2.23 KB
/
FormBase.js
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
import { Component } from 'react';
import PropTypes from 'prop-types';
import { Alert } from 'modules/common/utils';
const propTypes = {
brands: PropTypes.array,
users: PropTypes.array,
save: PropTypes.func,
kind: PropTypes.string,
message: PropTypes.object
};
class FormBase extends Component {
constructor(props) {
super(props);
this.save = this.save.bind(this);
this.changeState = this.changeState.bind(this);
}
save(type, e) {
const { __ } = this.context;
const doc = this.generateDoc(e);
if (!doc.title) {
return Alert.error(__('Write title'));
}
if (!doc.fromUserId) {
return Alert.error(__('Choose from who'));
}
if (doc.messenger && !doc.messenger.brandId) {
return Alert.error(__('Choose brand'));
}
if (doc.messenger && !doc.messenger.sentAs) {
return Alert.error(__('Choose from sent as'));
}
if (doc.scheduleDate) {
const { time, type, day, month } = doc.scheduleDate;
if (!type && time) {
return Alert.error(__('Choose schedule type'));
}
if (type && (!time || time.length === 0)) {
return Alert.error(__('Choose schedule time'));
}
if ((type === 'year' || type === 'month') && !day) {
return Alert.error(__('Choose schedule day'));
}
if (type === 'year' && !month) {
return Alert.error(__('Choose schedule month'));
}
}
if (type === 'live') {
return this.props.save({ isLive: true, isDraft: false, ...doc });
}
if (type === 'draft ') {
return this.props.save({ isLive: false, isDraft: true, ...doc });
}
this.props.save(doc);
}
changeState(key, value) {
this.setState({ [key]: value });
}
renderTitle() {
const { __ } = this.context;
const { kind } = this.props;
let title = __('Show statistics');
if (kind === 'auto') {
title = __('Auto message');
}
if (kind === 'manual') {
title = __('Manual message');
}
if (kind === 'visitorAuto') {
title = __('Visitor auto message');
}
return [{ title: __('Engage'), link: '/engage' }, { title: title }];
}
}
FormBase.propTypes = propTypes;
FormBase.contextTypes = {
__: PropTypes.func
};
export default FormBase;