Skip to content

Commit

Permalink
Merge branch 'feature/improve-form-type' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
gocreating committed Nov 9, 2016
2 parents c6a4172 + 5b5c031 commit 2bbf17d
Show file tree
Hide file tree
Showing 17 changed files with 1,096 additions and 8 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@
"passport-linkedin-oauth2": "^1.4.1",
"pm2": "^2.0.18",
"react": "^15.3.2",
"react-addons-shallow-compare": "^15.3.2",
"react-bootstrap": "^0.30.5",
"react-dates": "^4.0.0",
"react-dom": "^15.0.2",
"react-ga": "^2.1.2",
"react-google-recaptcha": "^0.5.4",
Expand All @@ -125,6 +127,7 @@
"react-router": "^2.3.0",
"react-router-active-component": "^4.0.0",
"react-router-redux": "^4.0.6",
"react-slider": "^0.7.0",
"redux": "^3.5.2",
"redux-form": "^6.1.0",
"redux-thunk": "^2.1.0",
Expand Down
240 changes: 240 additions & 0 deletions src/common/components/forms/DemoForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router';
import { Field, reduxForm } from 'redux-form';
import Alert from 'react-bootstrap/lib/Alert';
import Button from 'react-bootstrap/lib/Button';
import FormNames from '../../constants/FormNames';
import { Form, FormField, FormFooter } from '../utils/BsForm';
import Head from '../widgets/Head';

class DemoForm extends Component {
constructor() {
super();
this.handleSubmit = this._handleSubmit.bind(this);
}

_handleSubmit(formData) {
console.log('formData', formData);
// let { dispatch, apiEngine } = this.props;
//
// return someAPI(apiEngine)
// .doSomething(formData)
// .catch((err) => {
// dispatch(pushErrors(err));
// throw err;
// })
// .then((json) => {
// console.log('json', json);
// });
}

render() {
let {
handleSubmit,
submitFailed,
error,
pristine,
submitting,
invalid,
demoForm: { values },
} = this.props;

return (
<Form horizontal onSubmit={handleSubmit(this.handleSubmit)}>
<Head
links={[
'/css/react-dates.css',
]}
/>
{submitFailed && error && (<Alert bsStyle="danger">{error}</Alert>)}
<Alert bsStyle="info">
File object is not going to show here.
Please submit the form and check the console.
</Alert>
<pre>{JSON.stringify(values, null, 2)}</pre>
<Field
label="Text"
name="someText"
component={FormField}
type="text"
placeholder="Text"
/>
<Field
label="Password"
name="somePassword"
component={FormField}
type="password"
placeholder="Password"
/>
<Field
label="Number"
name="someNumber"
component={FormField}
type="number"
placeholder="Number"
/>
<Field
label="Date"
name="someDate"
component={FormField}
type="date"
placeholder="Date"
/>
<Field
label="Time"
name="someTime"
component={FormField}
type="time"
placeholder="Time"
/>
<Field
label="File"
name="someFile"
component={FormField}
type="file"
/>
<Field
label="Textarea"
name="someTextarea"
component={FormField}
type="textarea"
rows="6"
/>
<Field
label=" "
name="somePlainText"
component={FormField}
type="plaintext"
text="Plain Text"
/>
<Field
label="Range Slider"
name="someRangeSlider"
component={FormField}
type="rangeSlider"
min={0}
max={100}
step={5}
/>
<Field
label=" "
name="_"
component={FormField}
type="plaintext"
text={
'range slider value is ' +
`${values.someRangeSlider.min} ~ ${values.someRangeSlider.max}`
}
/>
<Field
label="Airbnb Single Date"
name="someAirSingleDate"
component={FormField}
type="airSingleDate"
displayFormat="YYYY/MM/DD"
showClearDate
/>
<Field
label="Airbnb Date Range"
name="someAirDateRange"
component={FormField}
type="airDateRange"
displayFormat="YYYY/MM/DD"
showClearDates
/>
<Field
label="Select"
name="someSelect"
component={FormField}
type="select"
options={[{
label: 'Taiwan',
value: 'TW',
}, {
label: 'Japan',
value: 'JP',
}, {
label: 'United States',
value: 'US',
}]}
/>
<Field
label="Checkbox"
name="someCheckbox"
component={FormField}
type="checkbox"
text="This is a checkbox"
/>
<Field
label="Checkboxes"
name="someInlineCheckboxes"
component={FormField}
type="checkboxes"
style={{float: 'left', paddingRight: 20}}
options={[{
label: 'There',
value: 'VALUE1',
}, {
label: 'are',
value: 'VALUE2',
}, {
label: 'many',
value: 'VALUE3',
}, {
label: 'inline',
value: 'VALUE4',
}, {
label: 'checkboxes',
value: 'VALUE5',
}]}
/>
<Field
label="Radio Button"
name="someRadiobutton"
component={FormField}
type="radiobutton"
options={[{
label: 'some',
value: 'VALUE1',
}, {
label: 'radio',
value: 'VALUE2',
disabled: true,
}, {
label: 'buttons',
value: 'VALUE3',
}]}
/>
<Field
label="Recaptcha"
name="someRecaptcha"
component={FormField}
type="recaptcha"
/>
<FormFooter>
<Button type="submit" disabled={pristine || submitting || invalid}>
Submit
</Button>
<Link to="#">
<Button bsStyle="link">Some link</Button>
</Link>
</FormFooter>
</Form>
);
}
};

export default reduxForm({
form: FormNames.DEMO,
initialValues: {
somePassword: 'xxxxxxxxxx',
someRangeSlider: {
min: 10,
max: 30,
},
},
})(connect(state => ({
apiEngine: state.apiEngine,
demoForm: state.form[FormNames.DEMO],
}))(DemoForm));
7 changes: 7 additions & 0 deletions src/common/components/forms/user/AvatarForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import userAPI from '../../../api/user';
import { pushErrors } from '../../../actions/errorActions';
import { setCookies } from '../../../actions/cookieActions';
import { Form, FormField, FormFooter } from '../../utils/BsForm';
import Head from '../../widgets/Head';
import toRefreshURL from '../../../utils/toRefreshURL';

const initialValues = {
Expand Down Expand Up @@ -196,6 +197,11 @@ class AvatarForm extends Component {

return (
<Form onSubmit={handleSubmit(this.handleSubmit)}>
<Head
scripts={[
'https://www.gstatic.com/firebasejs/live/3.0/firebase.js',
]}
/>
{avatarURL && <Image thumbnail src={avatarURL} />}
<Field
name="avatar"
Expand All @@ -206,6 +212,7 @@ class AvatarForm extends Component {
label="Store avatar into"
name="storage"
component={FormField}
type="radiobutton"
options={[{
label: 'Firebase',
value: 'firebase',
Expand Down
19 changes: 19 additions & 0 deletions src/common/components/forms/user/RegisterForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const validate = (values) => {
errors.password = 'Required';
}

if (!values.isAgreeTerms) {
errors.isAgreeTerms = 'Required';
}

if (configs.recaptcha && !values.recaptcha) {
errors.recaptcha = 'Required';
}
Expand Down Expand Up @@ -74,6 +78,7 @@ class RegisterForm extends Component {
asyncValidating,
submitting,
invalid,
registerForm: { values },
} = this.props;

return (
Expand All @@ -100,6 +105,13 @@ class RegisterForm extends Component {
type="password"
placeholder="Password"
/>
<Field
label=" "
name="isAgreeTerms"
component={FormField}
type="checkbox"
text={<span>I agree the <a href="#">terms</a></span>}
/>
<Field
label=" "
name="recaptcha"
Expand All @@ -121,9 +133,16 @@ class RegisterForm extends Component {

export default reduxForm({
form: FormNames.USER_REGISTER,
initialValues: {
slide: {
min: 30,
max: 40,
},
},
validate,
asyncValidate,
asyncBlurFields: ['email'],
})(connect(state => ({
apiEngine: state.apiEngine,
registerForm: state.form[FormNames.USER_REGISTER],
}))(RegisterForm));
17 changes: 17 additions & 0 deletions src/common/components/pages/demo/FormElementPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import PageHeader from 'react-bootstrap/lib/PageHeader';
import PageLayout from '../../layouts/PageLayout';
import DemoForm from '../../forms/DemoForm';

let FormElementPage = (props) => (
<PageLayout>
<PageHeader>Form Elements</PageHeader>
<p>
There are a rich amount of field types built inside the boilerplate.
You can reuse them to prototype your custom form.
</p>
<DemoForm />
</PageLayout>
);

export default FormElementPage;
6 changes: 0 additions & 6 deletions src/common/components/pages/user/ShowPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Button from 'react-bootstrap/lib/Button';
import Image from 'react-bootstrap/lib/Image';
import userAPI from '../../../api/user';
import { pushErrors } from '../../../actions/errorActions';
import Head from '../../widgets/Head';
import PageLayout from '../../layouts/PageLayout';
import Time from '../../widgets/Time';
import VerifyEmailForm from '../../forms/user/VerifyEmailForm';
Expand Down Expand Up @@ -76,11 +75,6 @@ class ShowPage extends Component {
const { user } = this.state;
return (
<PageLayout>
<Head
scripts={[
'https://www.gstatic.com/firebasejs/live/3.0/firebase.js',
]}
/>
{this.renderModal()}
<Row>
<Col md={12}>
Expand Down
Loading

0 comments on commit 2bbf17d

Please sign in to comment.