Skip to content

@W-18762700: Implemented address autocomplete dropdown using mock addresses#2614

Merged
dannyphan2000 merged 9 commits intoSalesforceCommerceCloud:harshini-magesh.main-address-autocompletionfrom
harshini-magesh:W-18698963.harshini-magesh.create_address_suggestion_dropdown
Jul 9, 2025
Merged

@W-18762700: Implemented address autocomplete dropdown using mock addresses#2614
dannyphan2000 merged 9 commits intoSalesforceCommerceCloud:harshini-magesh.main-address-autocompletionfrom
harshini-magesh:W-18698963.harshini-magesh.create_address_suggestion_dropdown

Conversation

@harshini-magesh
Copy link

Description

This PR implements Address Autocomplete functionality for checkout in the PWA Kit storefront.The implementation includes a mock address service that simulates the Google Places API, which can then be replaced with the actual API integration in the future.

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • Added AddressSuggestionDropdown component for displaying address suggestions
  • Created mockAddressService.js as a placeholder for Google Places API with country filtering
  • Modified useAddressFields hook to implement address autocomplete logic and debouncing
  • Updated SHIPPING_COUNTRY_CODES in constants.js to include all countries (hardcoded)

How to Test-Drive This PR

  • Go to checkout
  • Click on the address input field and type at least 3 characters
  • Verify that address suggestions appear in a dropdown
  • Select a country from the country dropdown and check that only addresses from that country appear
  • Edge cases: clicking outside the dropdown to close it, keyboard navigation, cut/paste operations

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

@harshini-magesh harshini-magesh requested a review from a team as a code owner June 20, 2025 18:55
@cc-prodsec
Copy link
Collaborator

cc-prodsec commented Jun 20, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

Copy link
Contributor

@dannyphan2000 dannyphan2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments in the earlier PR: #2589

Copy link
Contributor

@dannyphan2000 dannyphan2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testing is needed

@harshini-magesh
Copy link
Author

Test Results
Screenshot 2025-07-01 at 9 48 10 AM
Screenshot 2025-07-01 at 9 48 21 AM

@@ -0,0 +1,289 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file should be under the same folder as useAddressFields.jsx

@@ -0,0 +1,200 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file name = index.jsx, same with test file

/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not need this file for this PR, out of scope

* @param {string} countryCode - Country code to filter addresses (e.g., 'US', 'UK', 'AU')
* @returns {Promise<Array>} Array of address suggestions
*/
export const getAddressSuggestions = async (input, countryCode) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is these functions in the mock

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explore using hook/function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or helper/util

address: '147 Broadway, New York, NY 10038, USA',
mainText: '147 Broadway',
secondaryText: 'New York, NY 10038, USA',
country: 'US'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename the file name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

address-suggestions

Copy link
Contributor

@dannyphan2000 dannyphan2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run: npm run lint:fix at project root

@@ -0,0 +1,289 @@
/*
* Copyright (c) 2021, salesforce.com, inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename test file useAddressFields.test.js

return parsedFields
}

// Parse secondary text to extract city, state, and postal code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use multi-line comment

provinceOptions
} from '@salesforce/retail-react-app/app/components/forms/state-province-options'
import {SHIPPING_COUNTRY_CODES} from '@salesforce/retail-react-app/app/constants'
import {getAddressSuggestions} from '@salesforce/retail-react-app/app/utils/address-suggestions' // TODO: replace with the actual API call to the address service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From same file, why 2 lines are needed here for the import?

*/
export const getAddressSuggestions = async (input, countryCode) => {
// Simulate API delay
await simulateDelay(300)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put 300 as a CONSTANT in this file?

* Simulates API delay similar to real Google Places API
* @param {number} delay - Delay in milliseconds
*/
const simulateDelay = (delay = 200) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do 300 as DEFAULT instead

@harshini-magesh harshini-magesh force-pushed the W-18698963.harshini-magesh.create_address_suggestion_dropdown branch from 3b45f3f to 47ef052 Compare July 9, 2025 18:25
Copy link
Contributor

@dannyphan2000 dannyphan2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QA is done, verifying that it is working as intended. Great job :)

Screenshot 2025-07-09 at 12 34 11 PM

@dannyphan2000 dannyphan2000 merged commit 01ff2dc into SalesforceCommerceCloud:harshini-magesh.main-address-autocompletion Jul 9, 2025
16 checks passed
dannyphan2000 pushed a commit that referenced this pull request Aug 12, 2025
…resses (#2614)

This PR implements Address Autocomplete functionality for checkout in the PWA Kit storefront.The implementation includes a mock address service that simulates the Google Places API, which can then be replaced with the actual API integration in the future.
dannyphan2000 pushed a commit that referenced this pull request Nov 20, 2025
…resses (#2614)

This PR implements Address Autocomplete functionality for checkout in the PWA Kit storefront.The implementation includes a mock address service that simulates the Google Places API, which can then be replaced with the actual API integration in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants