Skip to content

Commit

Permalink
Allow undefined address components, and fix weird path issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vontell committed Sep 24, 2024
1 parent defaee7 commit fe27d42
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
24 changes: 14 additions & 10 deletions src/components/AddResourceModal/AddResourceModalV2.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,18 @@ export default function AddResourceModalV2(props) {
const geocodedAddresses = await geocodeByAddress(values.address);
const geocodedAddress = geocodedAddresses[0];
const placeId = geocodedAddress.place_id;
const city = geocodedAddress.address_components.find(component =>
component.types.includes('locality')
).long_name;
const state = geocodedAddress.address_components.find(component =>
component.types.includes('administrative_area_level_1')
).long_name;
const postalCode = geocodedAddress.address_components.find(component =>
component.types.includes('postal_code')
).long_name;
const city =
geocodedAddress.address_components.find(component =>
component.types.includes('locality')
)?.long_name || null;
const state =
geocodedAddress.address_components.find(component =>
component.types.includes('administrative_area_level_1')
)?.long_name || null;
const postalCode =
geocodedAddress.address_components.find(component =>
component.types.includes('postal_code')
)?.long_name || null;

/**
*
Expand Down Expand Up @@ -355,7 +358,8 @@ export default function AddResourceModalV2(props) {
const app = initializeApp(resourcesConfig);
const database = getDatabase(app);
push(ref(database, '/'), newResource).then(result => {
const id = result._path.pieces[0];
const pieces = result._path.pieces || result._path.pieces_;
const id = pieces[0];
newResource.id = id;
dispatch(pushNewResource(newResource));
});
Expand Down
6 changes: 3 additions & 3 deletions src/types/ResourceEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
* @property {Verification} verification The verification details of this resource.
* @property {"WATER" | "FOOD" | "FORAGE" | "BATHROOM"} resource_type The type of resource.
* @property {string | undefined} address The street address of the resource (not including city, state, or zip). May include the secondary address.
* @property {string} city The city of the resource.
* @property {string} state The 2-letter abbreviation for the state of the resource.
* @property {string} zip_code The zip code of the resource.
* @property {string | undefined} city The city of the resource.
* @property {string | undefined} state The 2-letter abbreviation for the state of the resource.
* @property {string | undefined} zip_code The zip code of the resource.
* @property {number} latitude The latitude of the resource.
* @property {number} longitude The longitude of the resource.
* @property {string | undefined} gp_id The Google Places ID of the resource.
Expand Down

0 comments on commit fe27d42

Please sign in to comment.