From a6bcb8785d54ef735d82154a775822d84f2b2b80 Mon Sep 17 00:00:00 2001 From: Giovanni Schroevers Date: Wed, 24 Jan 2024 17:30:50 +0100 Subject: [PATCH] feat: autofill countryCode field with shop country --- .changeset/soft-pumpkins-dress.md | 5 +++++ .../CreateCustomerAddressForm.tsx | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/soft-pumpkins-dress.md diff --git a/.changeset/soft-pumpkins-dress.md b/.changeset/soft-pumpkins-dress.md new file mode 100644 index 0000000000..fd939ca80c --- /dev/null +++ b/.changeset/soft-pumpkins-dress.md @@ -0,0 +1,5 @@ +--- +"@graphcommerce/magento-customer": minor +--- + +Autofill country dropdown in CreateCustomerAddressForm so AddPostcodeNLAddressFields plugin works by default diff --git a/packages/magento-customer/components/CreateCustomerAddressForm/CreateCustomerAddressForm.tsx b/packages/magento-customer/components/CreateCustomerAddressForm/CreateCustomerAddressForm.tsx index aa55f90327..4a9e2f7565 100644 --- a/packages/magento-customer/components/CreateCustomerAddressForm/CreateCustomerAddressForm.tsx +++ b/packages/magento-customer/components/CreateCustomerAddressForm/CreateCustomerAddressForm.tsx @@ -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, @@ -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)