diff --git a/src/js/routes/Ballot/Candidate.jsx b/src/js/routes/Ballot/Candidate.jsx
index 345a3bc91..d18a6a957 100644
--- a/src/js/routes/Ballot/Candidate.jsx
+++ b/src/js/routes/Ballot/Candidate.jsx
@@ -25,6 +25,7 @@ export default class Candidate extends Component {
componentDidMount(){
this.changeListener = this._onChange.bind(this);
+ BallotStore.initialize(function(){console.log("Initialized ballot in background")});
BallotStore.addChangeListener(this.changeListener);
var candidate = BallotStore.getOrFetchCandidateByWeVoteId(this.props.params.we_vote_id);
if (candidate) {
diff --git a/src/js/routes/Ballot/EmptyBallot.jsx b/src/js/routes/Ballot/EmptyBallot.jsx
new file mode 100644
index 000000000..cc340e411
--- /dev/null
+++ b/src/js/routes/Ballot/EmptyBallot.jsx
@@ -0,0 +1,27 @@
+import React, { Component, PropTypes } from 'react';
+import { Link } from 'react-router';
+
+export default class EmptyBallot extends Component {
+ static propTypes = {
+ };
+
+ constructor (props) {
+ super(props);
+ }
+
+ render () {
+ return (
+
+
+
+ Sorry
+
+
+ Our data providers don't have ballot data for your address yet.
+ Please check back 1-2 weeks before your election day
+
+
+
+ );
+ }
+}
diff --git a/src/js/routes/Settings/Location.jsx b/src/js/routes/Settings/Location.jsx
index 22bd6e3b4..32712d599 100644
--- a/src/js/routes/Settings/Location.jsx
+++ b/src/js/routes/Settings/Location.jsx
@@ -2,6 +2,7 @@ import React, { Component } from "react";
import { Button, ButtonToolbar } from "react-bootstrap";
import HeaderBackNavigation from "../../components/Navigation/HeaderBackNavigation";
import VoterStore from "../../stores/VoterStore";
+import BallotStore from "../../stores/BallotStore";
export default class Location extends Component {
constructor (props) {
@@ -23,10 +24,14 @@ export default class Location extends Component {
saveLocation () {
var { location } = this.state;
- VoterStore.saveLocation( location, (err) => {
- if (err) return console.error(err);
-
- window.location.href = "/ballot";
+ VoterStore.saveLocation( location, (res) => {
+ if (res){
+ this.props.history.push('/ballot');
+ } else {
+ BallotStore.initialize(function(){}); // reinitialize ballot in case old ballot items from old addresses are stored.
+ this.props.history.push('/ballot/empty');
+ }
+ }, (err) =>{
});
}
@@ -52,7 +57,7 @@ export default class Location extends Component {
name="address"
value={location}
className="form-control"
- defaultValue="Oakland, CA"
+ defaultValue="Oakland, CA"
/>
diff --git a/src/js/stores/VoterStore.js b/src/js/stores/VoterStore.js
index 2fbb1c169..272b9bc28 100644
--- a/src/js/stores/VoterStore.js
+++ b/src/js/stores/VoterStore.js
@@ -158,6 +158,7 @@ const VoterStore = createStore({
saveLocation: function (location, callback) {
if (typeof location !== "string") throw new Error("missing location to save");
if (callback instanceof Function === false) throw new Error("missing callback function");
+ var that = this;
$ajax({
type: "GET",
@@ -165,9 +166,14 @@ const VoterStore = createStore({
endpoint: "voterAddressSave",
success: (res) => {
var { text_for_map_search: savedLocation } = res;
-
- _setLocation(savedLocation);
- callback(null, savedLocation);
+ cookies.setItem('location', savedLocation);
+
+ if (res.success){ // Successfully saved address and found Google Civic Election ID
+ callback(true, savedLocation);
+ } else if (res.status.indexOf("GOOGLE_CIVIC_API_ERROR") != -1){ // Saved Address but couldn't find election ID
+ console.log("No election for the address");
+ callback(false, savedLocation);
+ }
},
error: (err) => callback(err, null)
});