Skip to content
This repository was archived by the owner on Dec 9, 2021. It is now read-only.

Commit d4529ae

Browse files
committed
finish redux form
1 parent 37aca26 commit d4529ae

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

src/server-side/controllers/ReactController.jsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import rootSaga from '../../store/rootSaga';
88

99
class ReactController {
1010

11-
mapRoutes(server) {
11+
async mapRoutes(server) {
12+
const baseMarkup = await fse.readFile(path.resolve(__dirname, '../../public/index.html'), 'utf8');
13+
1214
server.route({
1315
method: 'GET',
1416
path: '/{route*}',
@@ -34,7 +36,7 @@ class ReactController {
3436
}
3537
};
3638

37-
let html = await fse.readFile(path.resolve(__dirname, '../../public/index.html'), 'utf8');
39+
let html = baseMarkup.slice();
3840
html = html.replace('{title}', state.metaReducer.title);
3941
html = html.replace('{description}', state.metaReducer.description);
4042
html = html.replace('{content}', renderedHtml);

src/views/Contact.jsx

+30-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Contact extends React.Component {
1818
}
1919

2020
render() {
21-
const { handleSubmit } = this.props;
21+
const {handleSubmit, reset} = this.props;
2222

2323
return (
2424
<div>
@@ -48,13 +48,17 @@ class Contact extends React.Component {
4848
</div>
4949
<div className="form-group">
5050
<label htmlFor="exampleSelect1">{'Example select'}</label>
51-
<select className="form-control" id="exampleSelect1">
51+
<Field
52+
name="exampleSelect1"
53+
className="form-control"
54+
component="select"
55+
>
5256
<option>1</option>
5357
<option>2</option>
5458
<option>3</option>
5559
<option>4</option>
5660
<option>5</option>
57-
</select>
61+
</Field>
5862
</div>
5963
<div className="form-group">
6064
<Field
@@ -72,6 +76,7 @@ class Contact extends React.Component {
7276
label="This code is awesome!"
7377
name="codeQualityRadio"
7478
option="1"
79+
checked={true}
7580
/>
7681
<Field
7782
component={this._renderRadio}
@@ -84,6 +89,7 @@ class Contact extends React.Component {
8489
label="This code is bad."
8590
name="codeQualityRadio"
8691
option="3"
92+
disabled={true}
8793
/>
8894
</fieldset>
8995
<div className="form-check">
@@ -94,14 +100,27 @@ class Contact extends React.Component {
94100
type="checkbox"
95101
/>
96102
</div>
97-
<button type="submit" className="btn btn-primary">{'Submit'}</button>
103+
<button
104+
type="submit"
105+
className="btn btn-primary"
106+
>
107+
{'Submit'}
108+
</button>
109+
<button
110+
type="submit"
111+
className="btn btn-primary"
112+
onClick={reset}
113+
>
114+
{'Reset'}
115+
</button>
98116
</form>
99117
</div>
100118
);
101119
}
102120

103121
_onFormSubmit(formData){
104122
// TODO: Can an acton with the form data.
123+
alert(formData);
105124
console.log(formData);
106125
}
107126

@@ -151,6 +170,8 @@ class Contact extends React.Component {
151170
className="form-check-input"
152171
name={field.input.name}
153172
value={field.option}
173+
disabled={field.disabled}
174+
checked={field.checked}
154175
/>
155176
{field.label}
156177
</label>
@@ -186,13 +207,14 @@ export default reduxForm({
186207
form: 'contactForm',
187208
validate: (formData) => {
188209
const errors = {};
210+
const validEmailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
189211

190-
if (!formData.name) {
191-
errors.name = 'Required';
212+
if (!validEmailRegex.test(formData.email)) {
213+
errors.email = 'Invalid email address';
192214
}
193215

194-
if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(formData.email)) {
195-
errors.email = 'Invalid email address';
216+
if (!formData.name) {
217+
errors.name = 'Required';
196218
}
197219

198220
if (!formData.message) {

src/views/landmarks/Header.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Header extends React.Component {
3838
</li>
3939
</ul>
4040
</nav>
41-
<h3 className="text-muted">{'Star My Repo On Github'}</h3>
41+
<h3 className="text-muted">{'Star My Github Repo!'}</h3>
4242
</div>
4343
);
4444
}

0 commit comments

Comments
 (0)