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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import { KeyboardDatePicker, MuiPickersUtilsProvider } from '@material-ui/pickers';
import MomentUtils from '@date-io/moment';
import { reduxForm, Field } from 'redux-form/immutable';
import { connect } from 'react-redux';
import css from 'ba-styles/Form.scss';
import { Button, Radio, RadioGroup, FormLabel, FormControlLabel } from '@material-ui/core';
import { TextFieldRedux } from '../Forms/ReduxFormMUI';
import styles from './calendar-jss';
// validation functions
const required = value => (value == null ? 'Required' : undefined);
const DateTimePickerRow = props => {
const {
showErrorsInline,
dispatch,
input: { onChange, value },
meta: { touched, error },
...other
} = props;
const showError = showErrorsInline || touched;
return (
<MuiPickersUtilsProvider utils={MomentUtils}>
<KeyboardDatePicker
error={!!(showError && error)}
helperText={showError && error}
value={value || new Date()}
onChange={onChange}
disablePast
label="DateTimePicker"
{...other}
/>
</MuiPickersUtilsProvider>
);
};
DateTimePickerRow.propTypes = {
showErrorsInline: PropTypes.bool,
dispatch: PropTypes.func,
input: PropTypes.object.isRequired,
meta: PropTypes.object.isRequired,
};
const renderRadioGroup = ({ input, ...rest }) => (
<RadioGroup
{...input}
{...rest}
valueselected={input.value}
onChange={(event, value) => input.onChange(value)}
/>
);
renderRadioGroup.propTypes = {
input: PropTypes.object.isRequired,
};
DateTimePickerRow.defaultProps = {
showErrorsInline: false,
dispatch: () => {},
};
class AddEventForm extends React.Component {
state = {
selectedDate: new Date(),
}
onChangeDate = date => {
this.setState({ selectedDate: date });
}
saveRef = ref => {
this.ref = ref;
return this.ref;
};
render() {
const {
classes,
reset,
pristine,
submitting,
handleSubmit,
} = this.props;
const { selectedDate } = this.state;
return (
<div>
<form onSubmit={handleSubmit}>
<section className={css.bodyForm}>
<div>
<Field
name="title"
component={TextFieldRedux}
placeholder="Event Name"
label="Event Name"
validate={required}
required
ref={this.saveRef}
className={classes.field}
/>
</div>
<div>
<Field
name="start"
component={DateTimePickerRow}
placeholder="Start Date"
value={selectedDate}
onChange={this.onChangeDate}
label="Start Date"
className={classes.field}
/>
</div>
<div>
<Field
name="end"
component={DateTimePickerRow}
placeholder="End Date"
value={selectedDate}
onChange={this.onChangeDate}
label="End Date"
className={classes.field}
/>
</div>
<div className={classes.fieldBasic}>
<FormLabel component="label">Label Color</FormLabel>
<Field name="hexColor" className={classes.inlineWrap} component={renderRadioGroup}>
<FormControlLabel value="F8BBD0" control={<Radio className={classes.redRadio} classes={{ root: classes.redRadio, checked: classes.checked }} />} label="Red" />
<FormControlLabel value="C8E6C9" control={<Radio className={classes.greenRadio} classes={{ root: classes.greenRadio, checked: classes.checked }} />} label="Green" />
<FormControlLabel value="B3E5FC" control={<Radio className={classes.blueRadio} classes={{ root: classes.blueRadio, checked: classes.checked }} />} label="Blue" />
<FormControlLabel value="D1C4E9" control={<Radio className={classes.violetRadio} classes={{ root: classes.violetRadio, checked: classes.checked }} />} label="Violet" />
<FormControlLabel value="FFECB3" control={<Radio className={classes.orangeRadio} classes={{ root: classes.orangeRadio, checked: classes.checked }} />} label="Orange" />
</Field>
</div>
</section>
<div className={css.buttonArea}>
<Button variant="contained" color="secondary" type="submit" disabled={submitting}>
Submit
</Button>
<Button
type="button"
disabled={pristine || submitting}
onClick={reset}
>
Reset
</Button>
</div>
</form>
</div>
);
}
}
AddEventForm.propTypes = {
classes: PropTypes.object.isRequired,
handleSubmit: PropTypes.func.isRequired,
reset: PropTypes.func.isRequired,
pristine: PropTypes.bool.isRequired,
submitting: PropTypes.bool.isRequired,
};
const AddEventFormRedux = reduxForm({
form: 'immutableAddCalendar',
enableReinitialize: true,
})(AddEventForm);
const reducer = 'calendar';
const AddEventInit = connect(
state => ({
force: state,
initialValues: state.getIn([reducer, 'formValues'])
}),
)(AddEventFormRedux);
export default withStyles(styles)(AddEventInit);
|