Skip to content

Commit

Permalink
Merge pull request Expensify#55996 from Krishna2323/krishna2323/issue…
Browse files Browse the repository at this point in the history
…/55295

fix: Workflows - Street doesn't get automatically filled out for a specific address.
  • Loading branch information
mjasikowski authored Feb 3, 2025
2 parents 7ef3254 + 5b774a8 commit f60c647
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/components/AddressSearch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,21 @@ function AddressSearch(

// Make sure that the order of keys remains such that the country is always set above the state.
// Refer to https://github.com/Expensify/App/issues/15633 for more information.
const {country: countryFallbackLongName = '', state: stateAutoCompleteFallback = '', city: cityAutocompleteFallback = ''} = getPlaceAutocompleteTerms(autocompleteData?.terms ?? []);
const {
country: countryFallbackLongName = '',
state: stateAutoCompleteFallback = '',
city: cityAutocompleteFallback = '',
street: streetAutocompleteFallback = '',
streetNumber: streetNumberAutocompleteFallback = '',
} = getPlaceAutocompleteTerms(autocompleteData?.terms ?? []);

const countryFallback = Object.keys(CONST.ALL_COUNTRIES).find((country) => country === countryFallbackLongName);

// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const country = countryPrimary || countryFallback || '';

const values = {
street: `${streetNumber} ${streetName}`.trim(),
street: `${streetNumber || streetNumberAutocompleteFallback} ${streetName || streetAutocompleteFallback}`.trim(),
name: details.name ?? '',
// Autocomplete returns any additional valid address fragments (e.g. Apt #) as subpremise.
street2: subpremise,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/GooglePlacesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ function getAddressComponents(addressComponents: AddressComponent[], fieldsToExt
}

type AddressTerm = {value: string};
type GetPlaceAutocompleteTermsResultKey = 'country' | 'state' | 'city' | 'street';
type GetPlaceAutocompleteTermsResultKey = 'country' | 'state' | 'city' | 'street' | 'streetNumber';
type GetPlaceAutocompleteTermsResult = Partial<Record<GetPlaceAutocompleteTermsResultKey, string>>;

/**
* Finds an address term by type, and returns the value associated to key. Note that each term in the address must
* conform to the following ORDER: <street, city, state, country>
*/
function getPlaceAutocompleteTerms(addressTerms: AddressTerm[]): GetPlaceAutocompleteTermsResult {
const fieldsToExtract: GetPlaceAutocompleteTermsResultKey[] = ['country', 'state', 'city', 'street'];
const fieldsToExtract: GetPlaceAutocompleteTermsResultKey[] = ['country', 'state', 'city', 'street', 'streetNumber'];
const result: GetPlaceAutocompleteTermsResult = {};
fieldsToExtract.forEach((fieldToExtract, index) => {
const fieldTermIndex = addressTerms.length - (index + 1);
Expand Down
1 change: 1 addition & 0 deletions tests/unit/GooglePlacesUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe('GooglePlacesUtilsTest', () => {
state: 'Bangladesh Border Road',
city: '',
street: '',
streetNumber: '',
});
});
});
Expand Down

0 comments on commit f60c647

Please sign in to comment.