Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,52 @@ import {
import ArchiveLocationForm from './LocationForm';
import ArchiveDateTimeForm from './DateTimeForm';

class ArchiveAddressDateEditForm extends React.Component {
class ArchiveEditForm extends React.Component {
constructor(props) {
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
this.checkData = this.checkData.bind(this);
this.setAddressConfirm = this.setAddressConfirm.bind(this);
this.state = {
addressConfirm: true,
}
}

setAddressConfirm(val) {
this.setState({
addressConfirm: val,
});
}

handleSubmit(e) {
const {
townHall,
moc,
updateEvent,
tempAddress,
clearTempAddress,
handleClose,
defaultUsState,
} = this.props;
e.preventDefault();
if (tempAddress.address) {
if (!this.state.addressConfirm) {
console.log('still have address')
return;
}
this.props.form.validateFieldsAndScroll((err, vals) => {
if (!err) {
clearTempAddress();
const updateObj = {};
console.log(vals);
if (vals.location) {
updateObj.location = vals.location;
}
if (vals.presidential) {
updateObj.chamber = 'nationwide';
updateObj.state = defaultUsState;
} else {
updateObj.chamber = moc.chamber;
updateObj.state = moc.state;
}
if (vals.address) {
updateObj.address = vals.address;
}
Expand Down Expand Up @@ -91,13 +112,14 @@ class ArchiveAddressDateEditForm extends React.Component {
townHall,
tempAddress,
setTempAddress,
clearTempAddress,
updateEvent,
handleClose,
} = this.props;
const {
getFieldDecorator,
resetFields,
setFieldsValue,
getFieldValue,
} = this.props.form;
return (
<Form
Expand All @@ -114,12 +136,14 @@ class ArchiveAddressDateEditForm extends React.Component {
geoCodeLocation={setTempAddress}
tempAddress={tempAddress.address}
tempAddressFullData={tempAddress}
clearTempAddress={clearTempAddress}
tempLat={tempAddress.lat}
tempLng={tempAddress.lng}
getFieldDecorator={getFieldDecorator}
setFieldsValue={setFieldsValue}
getFieldValue={getFieldValue}
resetFields={resetFields}
updateEvent={updateEvent}
setAddressConfirm={this.setAddressConfirm}
/>
<Row>
<Col style={{ textAlign: 'right' }}>
Expand All @@ -138,6 +162,6 @@ class ArchiveAddressDateEditForm extends React.Component {

const WrappedArchiveAddressDateEditForm = Form.create({
name: 'address-date-form'
})(ArchiveAddressDateEditForm);
})(ArchiveEditForm);

export default WrappedArchiveAddressDateEditForm;
59 changes: 32 additions & 27 deletions src/components/ArchiveEventsEditModal/LocationForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Switch,
Button,
} from 'antd';
import { includes, debounce } from 'lodash';
import { includes } from 'lodash';


const { Search } = Input;
Expand All @@ -16,6 +16,8 @@ const initialState = {
showResponse: false,
validating: '',
value: undefined,
eventState: undefined,
includeState: false,
};

class ArchiveLocationForm extends React.Component {
Expand All @@ -31,6 +33,14 @@ class ArchiveLocationForm extends React.Component {
this.discardTempAddress = this.discardTempAddress.bind(this);
}

componentDidMount() {
const {
geoCodeLocation,
getFieldValue,
} = this.props;
geoCodeLocation(getFieldValue('address'));
}

componentDidUpdate(prevProps) {
const { tempAddress } = this.props;
if (!prevProps.tempAddress && tempAddress) {
Expand All @@ -48,46 +58,34 @@ class ArchiveLocationForm extends React.Component {
clearAddressTimeout() {
clearTimeout(this.confirmingTime);
const {
updateEvent,
tempAddressFullData,
tempAddress,
tempLat,
tempLng,
clearTempAddress,
currentTownHall,
setFieldsValue,
setAddressConfirm,
} = this.props;

if (this.state.includeState && tempAddressFullData.state && tempAddressFullData.stateName) {
updateEvent({
...currentTownHall,
...tempAddressFullData,
})
}
updateEvent({
...currentTownHall,
lat: tempLat,
lng: tempLng,
address: tempAddress
this.setState({
showResponse: false,
});
clearTempAddress();
setFieldsValue({'address': tempAddress});
setAddressConfirm(true);
}

discardTempAddress() {
const {
clearTempAddress,
resetFields,
setAddressConfirm,
} = this.props;
this.setState({
showResponse: false,
});
clearTempAddress();
setAddressConfirm(true);
resetFields(['address']);
}

handleSearch() {
const {
geoCodeLocation,
currentTownHall,
setAddressConfirm,
} = this.props;
const {
value,
Expand All @@ -96,6 +94,7 @@ class ArchiveLocationForm extends React.Component {
return;
}
geoCodeLocation(value);
setAddressConfirm(false);
this.setState({
showResponse: true,
validating: 'validating',
Expand All @@ -118,7 +117,6 @@ class ArchiveLocationForm extends React.Component {
}

toggleIncludeState(value) {
console.log(value)
this.setState({
includeState: value,
})
Expand Down Expand Up @@ -150,7 +148,10 @@ class ArchiveLocationForm extends React.Component {
} = this.state;
return (
<React.Fragment>
<FormItem class="general-inputs">
<FormItem
class="general-inputs"
label="Location"
>
{getFieldDecorator('location', {
initialValue: currentTownHall.location,
})(
Expand All @@ -165,8 +166,13 @@ class ArchiveLocationForm extends React.Component {
<FormItem
label="is a presidental event"
help="switch on if the event should be stored by the event location and not the MOC state/district"
>
<Switch onChange={this.toggleIncludeState} />
>
{getFieldDecorator('presidential', {
valuePropName: 'checked',
initialValue: currentTownHall.chamber === 'nationwide' ? true : false,
})(
<Switch onChange={this.toggleIncludeState} />
)}
</FormItem>
{currentTownHall.meetingType === 'Tele-Town Hall' ? this.renderTeleInputs()
: (
Expand Down Expand Up @@ -214,7 +220,6 @@ class ArchiveLocationForm extends React.Component {

ArchiveLocationForm.propTypes = {
address: PropTypes.string,
clearTempAddress: PropTypes.func.isRequired,
geoCodeLocation: PropTypes.func.isRequired,
getFieldDecorator: PropTypes.func.isRequired,
style: PropTypes.shape({}),
Expand Down
7 changes: 6 additions & 1 deletion src/components/ArchiveEventsEditModal/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { connect } from 'react-redux';
import { Modal } from 'antd';
import ArchiveEditForm from './forms';
import ArchiveEditForm from './ArchiveEditForm';
import selectionStateBranch from '../../state/selections';

class ArchiveEventsEditModal extends React.Component {
Expand All @@ -24,11 +24,13 @@ class ArchiveEventsEditModal extends React.Component {
visible,
handleClose,
townHall,
moc,
tempAddress,
setTempAddress,
clearTempAddress,
updateEvent,
setTimeZone,
defaultUsState,
} = this.props;
return (
<Modal
Expand All @@ -40,12 +42,14 @@ class ArchiveEventsEditModal extends React.Component {
>
<ArchiveEditForm
townHall={townHall}
moc={moc}
tempAddress={tempAddress}
setTempAddress={setTempAddress}
clearTempAddress={clearTempAddress}
setTimeZone={setTimeZone}
updateEvent={updateEvent}
handleClose={handleClose}
defaultUsState={defaultUsState}
/>
</Modal>
)
Expand All @@ -55,6 +59,7 @@ class ArchiveEventsEditModal extends React.Component {
const mapStateToProps = state => ({
pathForEvents: selectionStateBranch.selectors.getEventsToShowUrl(state),
tempAddress: selectionStateBranch.selectors.getTempAddress(state),
defaultUsState: selectionStateBranch.selectors.getDefaultUsState(state),
});

const mapDispatchToProps = dispatch => ({
Expand Down
15 changes: 14 additions & 1 deletion src/containers/LookupOldEvents/achivedResultsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import EditableCell from './editableCell';
import eventsStateBranch from '../../state/events';
import researcherStateBranch from '../../state/researchers';
import selectionStateBranch from '../../state/selections';
import mocsStateBranch from '../../state/mocs';

import activism from '../../assets/img/icon-flags/activism.svg';
import campaign from '../../assets/img/icon-flags/campaign.svg';
Expand Down Expand Up @@ -54,13 +55,22 @@ class ResultsTable extends React.Component {
this.handleSave = this.handleSave.bind(this);
}

componentDidMount() {
const {
requestAllMocData,
} = this.props;
requestAllMocData();
}

handleSave = (eventData) => {
const { validateAndSaveOldEvent } = this.props;
validateAndSaveOldEvent(eventData);
};

render() {
const {
const {
showErrors,
allMocs,
showErrors,
allResearchers,
researchersEmailById,
Expand Down Expand Up @@ -176,6 +186,7 @@ class ResultsTable extends React.Component {
...col,
onCell: record => ({
record,
moc: allMocs[record.govtrack_id],
editable: col.editable && record.editable,
className: `${record.editable}-editable-cell`,
inputType: col.key,
Expand Down Expand Up @@ -212,11 +223,13 @@ function mapStateToProps(state) {
filteredOldEvents: selectionStateBranch.selectors.getFilteredEvents(state),
allResearchers: researcherStateBranch.selectors.getAllResearchers(state),
researchersEmailById: researcherStateBranch.selectors.getResearchersEmailById(state),
allMocs: mocsStateBranch.selectors.getAllMocs(state),
};
}

const mapDispatchToProps = dispatch => ({
validateAndSaveOldEvent: (data) => dispatch(eventsStateBranch.actions.validateAndSaveOldEvent(data)),
requestAllMocData: () => dispatch(mocsStateBranch.actions.requestAllMocData()),
});

export default connect(mapStateToProps, mapDispatchToProps)(ResultsTable);
2 changes: 2 additions & 0 deletions src/containers/LookupOldEvents/editableCell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default class EditableCell extends React.Component {
inputType,
handleSave,
record,
moc,
} = this.props;
switch (inputType) {
case 'displayName':
Expand Down Expand Up @@ -115,6 +116,7 @@ export default class EditableCell extends React.Component {
visible={this.state.modalVisible}
handleClose={this.handleCloseOnSubmit}
townHall={record}
moc={moc}
updateEvent={handleSave}
/>
)
Expand Down
1 change: 0 additions & 1 deletion src/containers/LookupOldEvents/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
DatePicker,
Select,
Row,
Progress,
Statistic,
AutoComplete,
} from 'antd';
Expand Down
5 changes: 5 additions & 0 deletions src/state/mocs/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import {
UPDATE_IN_OFFICE_SUCCESS,
UPDATE_DISPLAY_NAME,
UPDATE_DISPLAY_NAME_SUCCESS,
GET_ALL_MOC_DATA
} from './constants';

export const requestAllMocData = () => ({
type: GET_ALL_MOC_DATA
});

export const requestMocIds = () => ({
type: GET_MOCS
});
Expand Down
4 changes: 3 additions & 1 deletion src/state/mocs/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ export const UPDATE_DISPLAY_NAME_SUCCESS = makeConstant(STATE_BRANCH, 'UPDATE_DI
export const UPDATE_DISPLAY_NAME_FAIL = makeConstant(STATE_BRANCH, 'UPDATE_DISPLAY_NAME_FAIL');
export const ADD_STATE_LEG = 'ADD_STATE_LEG';
export const ADD_STATE_LEG_SUCCESS = 'ADD_STATE_LEG_SUCCESS';
export const ADD_STATE_LEG_FAILURE = 'ADD_STATE_LEG_FAILURE';
export const ADD_STATE_LEG_FAILURE = 'ADD_STATE_LEG_FAILURE';
export const GET_ALL_MOC_DATA = 'GET_ALL_MOC_DATA';
export const GET_ALL_MOC_DATA_SUCCESS = 'GET_ALL_MOC_DATA_SUCCESS';
Loading