diff --git a/.changeset/thick-adults-love.md b/.changeset/thick-adults-love.md new file mode 100644 index 000000000..b72e5eda1 --- /dev/null +++ b/.changeset/thick-adults-love.md @@ -0,0 +1,5 @@ +--- +"@bigcommerce/catalyst-core": patch +--- + +add get customer query diff --git a/apps/core/client/queries/get-customer.ts b/apps/core/client/queries/get-customer.ts new file mode 100644 index 000000000..b094ef80d --- /dev/null +++ b/apps/core/client/queries/get-customer.ts @@ -0,0 +1,60 @@ +import { cache } from 'react'; + +import { client } from '..'; +import { graphql } from '../graphql'; + +const GET_CUSTOMER_QUERY = graphql(` + query getCustomer { + customer { + entityId + company + email + firstName + lastName + phone + formFields { + entityId + name + __typename + ... on CheckboxesFormFieldValue { + valueEntityIds + values + } + ... on DateFormFieldValue { + date { + utc + } + } + ... on MultipleChoiceFormFieldValue { + valueEntityId + value + } + ... on NumberFormFieldValue { + number + } + ... on PasswordFormFieldValue { + password + } + ... on TextFormFieldValue { + text + } + } + } + } +`); + +export const getCustomer = cache(async (customerId: string) => { + const response = await client.fetch({ + document: GET_CUSTOMER_QUERY, + fetchOptions: { cache: 'no-store' }, + customerId, + }); + + const customer = response.data.customer; + + if (!customer) { + return null; + } + + return customer; +});