Skip to content

Instantly share code, notes, and snippets.

@dams
Created June 7, 2021 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dams/bb84bdd7d97a5bce6a9a0e2d43d73fe1 to your computer and use it in GitHub Desktop.
Save dams/bb84bdd7d97a5bce6a9a0e2d43d73fe1 to your computer and use it in GitHub Desktop.
try {
let homeAddress: string | null = null;
let homeSearchCenter: Coordinates | null = null;
let workAddress: string | null = null;
let workSearchCenter: Coordinates | null = null;
const response = await api.get(`/users/${userId}/geolocate`);
if (!_.isNil(response.user)) {
homeAddress = capitalizeProperNoun(response.user.address);
homeSearchCenter = response.user.geoloc;
}
if (!_.isNil(response.company)) {
workAddress = capitalizeProperNoun(response.company.address);
workSearchCenter = response.company.geoloc;
}
const updateAction = {
address: homeAddress || workAddress,
homeAddress,
homeSearchCenter,
searchCenter: homeSearchCenter || workSearchCenter,
workAddress,
workSearchCenter,
};
dispatch(alanMapLocationsUpdateAction(updateAction));
} catch (error) {
logWarning(`Failed to geolocate user ${userId}`, { error });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment