diff --git a/src/components/ArchiveEventsEditModal/forms.js b/src/components/ArchiveEventsEditModal/ArchiveEditForm.js
similarity index 80%
rename from src/components/ArchiveEventsEditModal/forms.js
rename to src/components/ArchiveEventsEditModal/ArchiveEditForm.js
index f8c2cac..d97d728 100644
--- a/src/components/ArchiveEventsEditModal/forms.js
+++ b/src/components/ArchiveEventsEditModal/ArchiveEditForm.js
@@ -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;
}
@@ -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 (
@@ -138,6 +162,6 @@ class ArchiveAddressDateEditForm extends React.Component {
const WrappedArchiveAddressDateEditForm = Form.create({
name: 'address-date-form'
-})(ArchiveAddressDateEditForm);
+})(ArchiveEditForm);
export default WrappedArchiveAddressDateEditForm;
\ No newline at end of file
diff --git a/src/components/ArchiveEventsEditModal/LocationForm.js b/src/components/ArchiveEventsEditModal/LocationForm.js
index 9539934..c81c570 100644
--- a/src/components/ArchiveEventsEditModal/LocationForm.js
+++ b/src/components/ArchiveEventsEditModal/LocationForm.js
@@ -6,7 +6,7 @@ import {
Switch,
Button,
} from 'antd';
-import { includes, debounce } from 'lodash';
+import { includes } from 'lodash';
const { Search } = Input;
@@ -16,6 +16,8 @@ const initialState = {
showResponse: false,
validating: '',
value: undefined,
+ eventState: undefined,
+ includeState: false,
};
class ArchiveLocationForm extends React.Component {
@@ -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) {
@@ -48,39 +58,26 @@ 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']);
}
@@ -88,6 +85,7 @@ class ArchiveLocationForm extends React.Component {
const {
geoCodeLocation,
currentTownHall,
+ setAddressConfirm,
} = this.props;
const {
value,
@@ -96,6 +94,7 @@ class ArchiveLocationForm extends React.Component {
return;
}
geoCodeLocation(value);
+ setAddressConfirm(false);
this.setState({
showResponse: true,
validating: 'validating',
@@ -118,7 +117,6 @@ class ArchiveLocationForm extends React.Component {
}
toggleIncludeState(value) {
- console.log(value)
this.setState({
includeState: value,
})
@@ -150,7 +148,10 @@ class ArchiveLocationForm extends React.Component {
} = this.state;
return (
-
+
{getFieldDecorator('location', {
initialValue: currentTownHall.location,
})(
@@ -165,8 +166,13 @@ class ArchiveLocationForm extends React.Component {
-
+ >
+ {getFieldDecorator('presidential', {
+ valuePropName: 'checked',
+ initialValue: currentTownHall.chamber === 'nationwide' ? true : false,
+ })(
+
+ )}
{currentTownHall.meetingType === 'Tele-Town Hall' ? this.renderTeleInputs()
: (
@@ -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({}),
diff --git a/src/components/ArchiveEventsEditModal/index.js b/src/components/ArchiveEventsEditModal/index.js
index 08522e5..f687430 100644
--- a/src/components/ArchiveEventsEditModal/index.js
+++ b/src/components/ArchiveEventsEditModal/index.js
@@ -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 {
@@ -24,11 +24,13 @@ class ArchiveEventsEditModal extends React.Component {
visible,
handleClose,
townHall,
+ moc,
tempAddress,
setTempAddress,
clearTempAddress,
updateEvent,
setTimeZone,
+ defaultUsState,
} = this.props;
return (
)
@@ -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 => ({
diff --git a/src/containers/LookupOldEvents/achivedResultsTable.jsx b/src/containers/LookupOldEvents/achivedResultsTable.jsx
index fc2d6d0..5a99e84 100644
--- a/src/containers/LookupOldEvents/achivedResultsTable.jsx
+++ b/src/containers/LookupOldEvents/achivedResultsTable.jsx
@@ -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';
@@ -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,
@@ -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,
@@ -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);
\ No newline at end of file
diff --git a/src/containers/LookupOldEvents/editableCell.jsx b/src/containers/LookupOldEvents/editableCell.jsx
index 81d495b..5549f73 100644
--- a/src/containers/LookupOldEvents/editableCell.jsx
+++ b/src/containers/LookupOldEvents/editableCell.jsx
@@ -55,6 +55,7 @@ export default class EditableCell extends React.Component {
inputType,
handleSave,
record,
+ moc,
} = this.props;
switch (inputType) {
case 'displayName':
@@ -115,6 +116,7 @@ export default class EditableCell extends React.Component {
visible={this.state.modalVisible}
handleClose={this.handleCloseOnSubmit}
townHall={record}
+ moc={moc}
updateEvent={handleSave}
/>
)
diff --git a/src/containers/LookupOldEvents/index.jsx b/src/containers/LookupOldEvents/index.jsx
index e5831d0..1616891 100644
--- a/src/containers/LookupOldEvents/index.jsx
+++ b/src/containers/LookupOldEvents/index.jsx
@@ -10,7 +10,6 @@ import {
DatePicker,
Select,
Row,
- Progress,
Statistic,
AutoComplete,
} from 'antd';
diff --git a/src/state/mocs/actions.js b/src/state/mocs/actions.js
index 27f208c..11d1390 100644
--- a/src/state/mocs/actions.js
+++ b/src/state/mocs/actions.js
@@ -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
});
diff --git a/src/state/mocs/constants.js b/src/state/mocs/constants.js
index 425a79d..a1fabd2 100644
--- a/src/state/mocs/constants.js
+++ b/src/state/mocs/constants.js
@@ -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';
\ No newline at end of file
+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';
\ No newline at end of file
diff --git a/src/state/mocs/logic.js b/src/state/mocs/logic.js
index d2e1dd7..7f78088 100644
--- a/src/state/mocs/logic.js
+++ b/src/state/mocs/logic.js
@@ -18,6 +18,8 @@ import {
UPDATE_DISPLAY_NAME_FAIL,
ADD_STATE_LEG,
ADD_STATE_LEG_SUCCESS,
+ GET_ALL_MOC_DATA,
+ GET_ALL_MOC_DATA_SUCCESS,
} from "./constants";
import {
updateInOfficeSuccess,
@@ -27,6 +29,24 @@ import Candidate from './candidate-model';
import { map } from "lodash";
import StateLeg from "./state-leg-model";
+const fetchAllMocData = createLogic({
+ type: GET_ALL_MOC_DATA,
+ processOptions: {
+ successType: GET_ALL_MOC_DATA_SUCCESS,
+ failType: GET_MOCS_FAILED,
+ },
+ process(deps) {
+ const {
+ action,
+ firebasedb,
+ } = deps;
+ return firebasedb.ref('mocData').once('value')
+ .then((snapshot) => {
+ return snapshot.val();
+ })
+ }
+});
+
const fetchMocs = createLogic({
type: GET_MOCS,
processOptions: {
@@ -180,6 +200,7 @@ const updateDisplayNameLogic = createLogic({
export default [
addStateLegLogic,
+ fetchAllMocData,
fetchMocs,
addCandidateLogic,
requestCongressLogic,
diff --git a/src/state/mocs/reducers.js b/src/state/mocs/reducers.js
index ab63570..a672873 100644
--- a/src/state/mocs/reducers.js
+++ b/src/state/mocs/reducers.js
@@ -9,11 +9,13 @@ import {
UPDATE_IN_OFFICE_FAIL,
UPDATE_DISPLAY_NAME_SUCCESS,
UPDATE_DISPLAY_NAME_FAIL,
+ GET_ALL_MOC_DATA_SUCCESS,
} from "./constants";
import { map } from 'lodash';
const initialState = {
allMocIds: [],
+ allMocData: [],
116: [],
115: [],
error: null,
@@ -89,6 +91,11 @@ const mocReducer = (state = initialState, action) => {
...state,
error: action.payload,
}
+ case GET_ALL_MOC_DATA_SUCCESS:
+ return {
+ ...state,
+ allMocData: action.payload,
+ }
default:
return state;
}
diff --git a/src/state/mocs/selectors.js b/src/state/mocs/selectors.js
index b4ab361..523847a 100644
--- a/src/state/mocs/selectors.js
+++ b/src/state/mocs/selectors.js
@@ -4,7 +4,7 @@ import { map } from 'lodash';
export const getAllMocsIds = state => state.mocs.allMocIds;
export const get116thCongress = state => state.mocs[116];
export const get115thCongress = state => state.mocs[115];
-
+export const getAllMocs = state => state.mocs.allMocData;
export const getAllMocNames = createSelector([getAllMocsIds], (mocIdObjs) => {
return map(mocIdObjs, 'nameEntered');
diff --git a/src/state/selections/logic.js b/src/state/selections/logic.js
index 30983a0..10315fb 100644
--- a/src/state/selections/logic.js
+++ b/src/state/selections/logic.js
@@ -61,7 +61,6 @@ const requestLatLngLogic = createLogic({
address: payload,
})
.then((r) => {
- console.log(r.body.results[0]);
const {
results,
} = r.body;
diff --git a/src/state/selections/reducers.js b/src/state/selections/reducers.js
index 398a196..a8c96f3 100644
--- a/src/state/selections/reducers.js
+++ b/src/state/selections/reducers.js
@@ -129,6 +129,7 @@ const selectionReducer = (state = initialState, action) => {
lat: action.payload.lat,
lng: action.payload.lng,
address: action.payload.address,
+ usState: action.payload.state,
}
};
case CLEAR_ADDRESS:
diff --git a/src/state/selections/selectors.js b/src/state/selections/selectors.js
index 7cecca3..cfd1450 100644
--- a/src/state/selections/selectors.js
+++ b/src/state/selections/selectors.js
@@ -50,6 +50,10 @@ export const getResearcherFilter = state => state.selections.filterByResearcher;
export const getErrorFilter = state => state.selections.filterByError;
export const getDateLookupType = state => state.selections.dateLookupType;
+export const getDefaultUsState = createSelector([getTempAddress], (tempAddress) => {
+ return tempAddress.usState;
+});
+
export const getLiveEventUrl = createSelector([getActiveFederalOrState], (federalOrState) => {
if (federalOrState !== FEDERAL_RADIO_BUTTON) {
return `state_townhalls/${federalOrState}`;