Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for editing an existing form #21

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 33 additions & 35 deletions src/components/FormBuilder/Preview/index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import React, { Component } from "react";
import { DropTarget } from "react-dnd";
import { connect } from "react-redux";
import { compose } from "redux";
import isEmpty from "lodash/isEmpty";
import React, { Component } from 'react'
import { DropTarget } from 'react-dnd'
import { connect } from 'react-redux'
import { compose } from 'redux'
import isEmpty from 'lodash/isEmpty'
import {
removeItem,
dragItem,
showEditor
} from "../../../actions/formBuilderActions";
import FormInputs from "./SortableFormInputs";
import FinalFormPreview from "./FinalFormPreview";
showEditor,
} from '../../../actions/formBuilderActions'
import FormInputs from './SortableFormInputs'
import FinalFormPreview from './FinalFormPreview'

// DropTarget parameters
const type = () => "items";
const type = () => 'items'

const collect = (connect, monitor) => ({
connectDropTarget: connect.dropTarget(),
hovered: monitor.isOver(),
item: monitor.getItem()
});
item: monitor.getItem(),
})

class Preview extends Component {
constructor(props) {
super(props);
super(props)
this.state = {
showFinalPreview: false
};
showFinalPreview: false,
}
}

hideFinalPreview = () => {
this.setState({ showFinalPreview: false });
};
this.setState({ showFinalPreview: false })
}

render() {
const {
Expand All @@ -40,27 +40,25 @@ class Preview extends Component {
removeItem,
showEditor,
previewItems,
connectDropTarget
} = this.props;
connectDropTarget,
} = this.props

const border = hovered ? "1px solid green" : "1px solid #ccc";
const border = hovered ? '1px solid green' : '1px solid #ccc'

return connectDropTarget(
<div style={{ height: "100%" }} className="mt-3">
<div style={{ height: '100%' }} className="mt-3">
{this.state.showFinalPreview && (
<FinalFormPreview
data={previewItems}
hideFinalPreview={this.hideFinalPreview}
/>
)}
<div style={{ height: "100%" }}>
<div style={{ height: "50px" }}>
<div style={{ height: '100%' }}>
<div style={{ height: '50px' }}>
<h3 className="float-left">Form Builder</h3>
<button
className="btn btn-primary float-right ml-3"
onClick={() =>
this.setState({ showFinalPreview: true })
}
onClick={() => this.setState({ showFinalPreview: true })}
disabled={isEmpty(previewItems)}
>
Preview
Expand All @@ -75,7 +73,7 @@ class Preview extends Component {
</div>
<div
className="jumbotron bg-default"
style={{ border, minHeight: "80vh" }}
style={{ border, minHeight: '80vh' }}
>
{isEmpty(previewItems) && (
<h3 className="list-group-item bg-light text-center text-muted">
Expand All @@ -97,21 +95,21 @@ class Preview extends Component {
))}
</div>
</div>
</div>
);
</div>,
)
}
}

export default compose(
connect(
state => ({
previewItems: state.formBuilder.previewItems
(state, ownProps) => ({
previewItems: state.formBuilder.previewItems.length > 0 ? state.formBuilder.previewItems : ownProps.previewItems,
}),
{
removeItem,
dragItem,
showEditor
}
showEditor,
},
),
DropTarget(type, {}, collect)
)(Preview);
DropTarget(type, {}, collect),
)(Preview)
9 changes: 6 additions & 3 deletions src/components/FormBuilder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import defaultItems from "./Toolbar/defaultItems";
const Builder = ({
editorVisible,
onSubmit,
items
items,
previewItems
}) => {
return (
<React.Fragment>
Expand All @@ -23,7 +24,8 @@ const Builder = ({
<div className="container">
<div className="row mt-3">
<div className="col-md-8">
<Preview
<Preview
previewItems={previewItems}
onSubmit={onSubmit}
/>
</div>
Expand All @@ -40,7 +42,8 @@ const Builder = ({

Builder.propTypes = {
onSubmit: PropTypes.func.isRequired,
items: PropTypes.array
items: PropTypes.array,
previewItems: PropTypes.array
};

Builder.defaultProps = {
Expand Down