Skip to content

Commit

Permalink
Merge pull request #2175 from graphcommerce-org/feature/autofill-coun…
Browse files Browse the repository at this point in the history
…try-code

feat: autofill countryCode field with shop country
  • Loading branch information
paales authored Jan 29, 2024
2 parents fa50102 + a6bcb87 commit f707609
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/soft-pumpkins-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphcommerce/magento-customer": minor
---

Autofill country dropdown in CreateCustomerAddressForm so AddPostcodeNLAddressFields plugin works by default
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useQuery } from '@graphcommerce/graphql'
import { CountryRegionsDocument } from '@graphcommerce/magento-store'
import { CountryCodeEnum } from '@graphcommerce/graphql-mesh'
import { CountryRegionsDocument, StoreConfigDocument } from '@graphcommerce/magento-store'
import {
Form,
FormActions,
Expand All @@ -22,12 +23,18 @@ import { CreateCustomerAddressDocument } from './CreateCustomerAddress.gql'

export function CreateCustomerAddressForm() {
const countryQuery = useQuery(CountryRegionsDocument, { fetchPolicy: 'cache-and-network' })
const { data: config } = useQuery(StoreConfigDocument)
const countries = countryQuery.data?.countries ?? countryQuery.previousData?.countries
const router = useRouter()

const shopCountry = config?.storeConfig?.locale?.split('_')?.[1].toUpperCase() as CountryCodeEnum

const form = useFormGqlMutation(
CreateCustomerAddressDocument,
{
defaultValues: {
countryCode: shopCountry,
},
onBeforeSubmit: (formData) => {
const region = countries
?.find((country) => country?.two_letter_abbreviation === formData.countryCode)
Expand Down

0 comments on commit f707609

Please sign in to comment.