Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: autofill countryCode field with shop country #2175

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading