diff --git a/.changeset/witty-falcons-marry.md b/.changeset/witty-falcons-marry.md new file mode 100644 index 000000000..60a681551 --- /dev/null +++ b/.changeset/witty-falcons-marry.md @@ -0,0 +1,5 @@ +--- +"@bigcommerce/catalyst-core": patch +--- + +Remove updateCustomer and getCustomerAddresses queries since they are defined now where they are used. diff --git a/core/client/mutations/update-customer.ts b/core/client/mutations/update-customer.ts deleted file mode 100644 index 03c9179de..000000000 --- a/core/client/mutations/update-customer.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { getSessionCustomerId } from '~/auth'; - -import { client } from '..'; -import { graphql, VariablesOf } from '../graphql'; - -const UPDATE_CUSTOMER_MUTATION = graphql(` - mutation updateCustomer($input: UpdateCustomerInput!, $reCaptchaV2: ReCaptchaV2Input) { - customer { - updateCustomer(input: $input, reCaptchaV2: $reCaptchaV2) { - customer { - firstName - lastName - } - errors { - __typename - ... on UnexpectedUpdateCustomerError { - message - } - ... on EmailAlreadyInUseError { - message - } - ... on ValidationError { - message - } - ... on CustomerDoesNotExistError { - message - } - ... on CustomerNotLoggedInError { - message - } - } - } - } - } -`); - -type Variables = VariablesOf; -export type Input = Variables['input']; - -interface UpdateCustomer { - formFields: Input; - reCaptchaToken?: string; -} - -export const updateCustomer = async ({ formFields, reCaptchaToken }: UpdateCustomer) => { - const customerId = await getSessionCustomerId(); - - const response = await client.fetch({ - document: UPDATE_CUSTOMER_MUTATION, - customerId, - fetchOptions: { cache: 'no-store' }, - variables: { - input: formFields, - ...(reCaptchaToken && { reCaptchaV2: { token: reCaptchaToken } }), - }, - }); - - return response.data.customer.updateCustomer; -}; diff --git a/core/client/queries/get-customer-addresses.ts b/core/client/queries/get-customer-addresses.ts deleted file mode 100644 index 6e8573c74..000000000 --- a/core/client/queries/get-customer-addresses.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { removeEdgesAndNodes } from '@bigcommerce/catalyst-client'; -import { cache } from 'react'; - -import { getSessionCustomerId } from '~/auth'; - -import { client } from '..'; -import { FormFieldValuesFragment } from '../fragments/form-fields-values'; -import { graphql } from '../graphql'; - -const GET_CUSTOMER_ADDRESSES_QUERY = graphql( - ` - query getCustomerAddresses($after: String, $before: String, $first: Int, $last: Int) { - customer { - entityId - addresses(before: $before, after: $after, first: $first, last: $last) { - pageInfo { - hasNextPage - hasPreviousPage - startCursor - endCursor - } - collectionInfo { - totalItems - } - edges { - node { - entityId - firstName - lastName - address1 - address2 - city - stateOrProvince - countryCode - phone - postalCode - company - formFields { - ...FormFieldValuesFragment - } - } - } - } - } - } - `, - [FormFieldValuesFragment], -); - -export interface CustomerAddressesArgs { - after?: string; - before?: string; - limit?: number; -} - -export const getCustomerAddresses = cache( - async ({ before = '', after = '', limit = 9 }: CustomerAddressesArgs) => { - const customerId = await getSessionCustomerId(); - const paginationArgs = before ? { last: limit, before } : { first: limit, after }; - - const response = await client.fetch({ - document: GET_CUSTOMER_ADDRESSES_QUERY, - variables: { ...paginationArgs }, - customerId, - fetchOptions: { cache: 'no-store' }, - }); - - const addresses = response.data.customer?.addresses; - - if (!addresses) { - return undefined; - } - - return { - pageInfo: addresses.pageInfo, - addressesCount: addresses.collectionInfo?.totalItems ?? 0, - addresses: removeEdgesAndNodes({ edges: addresses.edges }), - }; - }, -);