Skip to content

fix: default address not persisting when creating new address - #208

Open
eltonleaocadastra wants to merge 1 commit into
vtex-apps:masterfrom
Cadastra-Next-Gen-Company:fix/default-address-new-address
Open

fix: default address not persisting when creating new address#208
eltonleaocadastra wants to merge 1 commit into
vtex-apps:masterfrom
Cadastra-Next-Gen-Company:fix/default-address-new-address

Conversation

@eltonleaocadastra

@eltonleaocadastra eltonleaocadastra commented Jan 16, 2026

Copy link
Copy Markdown

What problem is this solving?

When creating a new address in the cost center details storefront page (/account#/cost-center/{id}) with the "default address" checkbox enabled, the new address is not being set as default after saving.

Root Cause: The new address was being appended to the end of the addresses array:

const newAddresses = [...addresses, newAddress]

Since the backend considers the first address in the array as the default, the previously existing address remained as default.

How to test it?

1. Go to /account#/cost-center/{id}
2. Click "Add new address"
3. Fill in address details and enable "Default address" checkbox
4. Save
5. Reload the page
6.  The new address should remain as default

Screenshots or example usage

Video Evidence: https://jam.dev/c/53f653f9-5d69-4a55-a9c2-7faa92b03f8b

Describe alternatives you've considered, if any

N/A - This is a straightforward bug fix.

Related to / Depends on

Related to VTEX Support Ticket opened for account klabinb2b.

Solution

Place the new address at the beginning of the array when the "default" checkbox is enabled:
const newAddresses = address.checked
  ? [newAddress, ...addresses]
  : [...addresses, newAddress]

When creating a new address in the cost center details page with the
'default address' checkbox enabled, the new address was being appended
to the end of the addresses array. Since the backend considers the first
address in the array as the default, the previously existing address
remained as default.

This fix places the new address at the beginning of the array when the
'default' checkbox is enabled, ensuring the backend correctly persists
it as the default address.
@vtex-io-ci-cd

vtex-io-ci-cd Bot commented Jan 16, 2026

Copy link
Copy Markdown

Hi! I'm VTEX IO CI/CD Bot and I'll be helping you to publish your app! 🤖

Please select which version do you want to release:

  • Patch (backwards-compatible bug fixes)

  • Minor (backwards-compatible functionality)

  • Major (incompatible API changes)

And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.

  • No thanks, I would rather do it manually 😞

@vtex-io-docs-bot

Copy link
Copy Markdown

Beep boop 🤖

I noticed you didn't make any changes at the docs/ folder

  • There's nothing new to document 🤔
  • I'll do it later 😞

In order to keep track, I'll create an issue if you decide now is not a good time

  • I just updated 🎉🎉

@eltonleaocadastra

Copy link
Copy Markdown
Author

Patch

@eltonleaocadastra

Copy link
Copy Markdown
Author

There's nothing new to document 🤔

@eltonleaocadastra

Copy link
Copy Markdown
Author

@vtex-apps/b2b Could someone please check the boxes for Patch version and "There's nothing new to document"? As an external contributor I don't have permission to edit the bot comments. Thanks!

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.

1 participant