Skip to content

Commit

Permalink
Merge branch 'main' into delete-address-mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-alexsaiannyi authored Apr 16, 2024
2 parents 03f4565 + 30c7624 commit 2d36737
Show file tree
Hide file tree
Showing 12 changed files with 526 additions and 1,266 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-flowers-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Add customer addresses query
73 changes: 73 additions & 0 deletions apps/core/client/queries/get-customer-addresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { removeEdgesAndNodes } from '@bigcommerce/catalyst-client';
import { cache } from 'react';

import { getSessionCustomerId } from '~/auth';

import { client } from '..';
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
}
}
}
}
}
`);

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 }),
};
},
);
4 changes: 2 additions & 2 deletions apps/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
"@bigcommerce/eslint-config-catalyst": "workspace:^",
"@gql.tada/cli-utils": "^0.3.3",
"@tailwindcss/container-queries": "^0.1.1",
"@testing-library/react": "^14.3.0",
"@testing-library/react": "^15.0.2",
"@types/lodash.debounce": "^4.0.7",
"@types/node": "^20.12.7",
"@types/react": "^18.2.74",
"@types/react": "^18.2.78",
"@types/react-dom": "^18.2.24",
"@types/react-google-recaptcha": "^2.1.9",
"autoprefixer": "^10.4.19",
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@storybook/react": "^7.6.17",
"@storybook/react-vite": "^7.6.17",
"@types/node": "^20.12.7",
"@types/react": "^18.2.74",
"@types/react": "^18.2.78",
"@types/react-dom": "^18.2.24",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.19",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@inquirer/prompts": "^4.3.2",
"@inquirer/prompts": "^5.0.0",
"dotenv-cli": "^7.4.1",
"turbo": "^1.13.2",
"typescript": "^5.4.4"
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"graphql": "^16.0.0"
},
"devDependencies": {
"@bigcommerce/eslint-config": "^2.8.0",
"@bigcommerce/eslint-config": "^2.8.1",
"@bigcommerce/eslint-config-catalyst": "workspace:^",
"@types/node": "^20.12.7",
"dotenv-cli": "^7.4.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
},
"devDependencies": {
"@bigcommerce/eslint-config-catalyst": "workspace:^",
"@testing-library/react": "^14.3.0",
"@types/react": "^18.2.74",
"@testing-library/react": "^15.0.2",
"@types/react": "^18.2.78",
"@types/react-dom": "^18.2.24",
"autoprefixer": "^10.4.19",
"eslint": "^8.57.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/create-catalyst/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"dependencies": {
"@commander-js/extra-typings": "^12.0.1",
"@inquirer/prompts": "^4.3.2",
"@inquirer/prompts": "^5.0.0",
"chalk": "^5.3.0",
"commander": "^12.0.0",
"fs-extra": "^11.2.0",
Expand All @@ -32,7 +32,7 @@
"zod-validation-error": "^3.1.0"
},
"devDependencies": {
"@bigcommerce/eslint-config": "^2.8.0",
"@bigcommerce/eslint-config": "^2.8.1",
"@bigcommerce/eslint-config-catalyst": "workspace:^",
"@swc/core": "^1.4.12",
"@swc/jest": "^0.2.36",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-catalyst/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"./react.js"
],
"dependencies": {
"@bigcommerce/eslint-config": "^2.8.0",
"@bigcommerce/eslint-config": "^2.8.1",
"@next/eslint-plugin-next": "^14.1.4",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-check-file": "^2.7.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/functional/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "eslint . --ext .ts,.js,.cjs --max-warnings 0"
},
"devDependencies": {
"@bigcommerce/eslint-config": "^2.8.0",
"@bigcommerce/eslint-config": "^2.8.1",
"@bigcommerce/eslint-config-catalyst": "workspace:^",
"@faker-js/faker": "^8.4.1",
"@playwright/test": "^1.43.0",
Expand Down
Loading

0 comments on commit 2d36737

Please sign in to comment.