Skip to content

Commit

Permalink
Merge pull request #63 from bigcommerce/develop
Browse files Browse the repository at this point in the history
v1.4.0
  • Loading branch information
jorgemasta authored May 19, 2021
2 parents d88dc30 + 31260b6 commit b00e3a7
Show file tree
Hide file tree
Showing 20 changed files with 967 additions and 21 deletions.
61 changes: 51 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,71 @@
# 1.4.0
## Get `locale` with `useCommerce` instead of `useRouter`

Right now, in the `useAddItem`, we use `useRouter` to get locale. This requires `next` as peer dependency, which isn't optimal, and was introduced in version [v1.2.0](https://github.com/bigcommerce/storefront-data-hooks/releases/tag/v1.2.0) when adding locale support to the cart https://github.com/bigcommerce/storefront-data-hooks/pull/41.

Now the `locale` will be obtained from the `useCommerce` as is done in other hooks such as `usePrice`.
https://github.com/bigcommerce/storefront-data-hooks/blob/e6196b04ca86239987148878e305f61c05f58902/src/commerce/use-price.tsx#L54

## Add `useOrderProducts` hook

Add a new `useOrderProducts` hook. Right now the `useOrders` hook doesn't include the products for each order due to limitations in the BigCommerce API. Thanks to this new hook you can get the products of a specific order.

API Reference: https://developer.bigcommerce.com/api-reference/store-management/orders/order-products/getallorderproducts

### Usage

```
import useOrderProduct from "@bigcommerce/storefront-data-hooks/use-order-products"
const { data } = useOrderProduct({ orderId: 20015 })
```

## Add Customer Address Hooks

Allow getting, adding, modifying and deleting customer addresses with hooks.

All hooks require the user to be authenticated, if not, they will return an error.

- New `useAddresses` hook to get all the customer addresses (includes pagination)
- New `useAddAddress` hook to create a new address
- New `useRemoveAddress` hook to remove a specific address by id.
- New `useUpdateAddress` hook to update a existing address
- Update de Readme to include examples of how to use the new hooks

## Set prototype to BigCommerce Error

Programmatically set the prototype to be able to check if a thrown Error is a BigCommerce Error. This is necessary because our compile target is ES5. Related issue: https://github.com/microsoft/TypeScript/issues/22585

Resolves a bug where the user couldn't add new products to the cart because the current cart was invalid but never deleted.

Resolves [49](#49)
# 1.3.1
### Troubleshoot login cookie problem

- The Bigcommerce API has changed the cookies it returns after login, now we specifically select the cookie we are interested in returning to the customer: `SHOP_TOKEN`

# 1.3.0
### Login SSO Documentation
## Login SSO Documentation

- Fix a bug in the Login SSO sample code: The `url` param must be passed inside the `options` object.

### Add pagination to `useSearch`
## Add pagination to `useSearch`

- Update `README.me`
- Add a new param to the `useSearch` hook: `page`
- Get the results based on the provided `page`.

*Resolves [#38](https://github.com/bigcommerce/storefront-data-hooks/issues/38)*

### Return `basePrice` in the product query
## Return `basePrice` in the product query

- Return `basePrice` in the product query
- Update GraphQL schema to generate the updated types (also includes updated types from the latest [Storefront GraphQL API](https://developer.bigcommerce.com/changelog#labels/storefront-api) updates)

*Related to [#37](https://github.com/bigcommerce/storefront-data-hooks/issues/37)*

# 1.2.0
### Embedded checkout
## Embedded checkout

- Now the `SHOP_TOKEN` is set at TLD (Top Level Domain) so the subdomain (where the embedded checkout iframe lives) can access the token
- Added a new section in the readme with some notes about how to make the checkout work
Expand All @@ -33,7 +74,7 @@
*Resolves [#36](https://github.com/bigcommerce/storefront-data-hooks/issues/36)*
*Resolves [#6](https://github.com/bigcommerce/storefront-data-hooks/issues/6)*

### Create `useOrders` hooks
## Create `useOrders` hooks

Allow to fetch the orders using a new `useOrders` hook.

Expand All @@ -43,7 +84,7 @@ Allow to fetch the orders using a new `useOrders` hook.

*Resolves [#25](https://github.com/bigcommerce/storefront-data-hooks/issues/25)*

### Add locale to cart
## Add locale to cart

When creating the carts, you can specify the locale. By default it's **en**, now the package checks the locale of the app to add it to the request.

Expand All @@ -53,21 +94,21 @@ When creating the carts, you can specify the locale. By default it's **en**, now

# 1.1.0

### Fix `useUpdateItem`
## Fix `useUpdateItem`

- Fix typo in https://github.com/bigcommerce/storefront-data-hooks/blob/034be1e4c7fa363f4b1362fd1a6d50e25b2632ea/src/cart/use-update-item.tsx#L54
- Add missing types to the `Cart` body

*Resolves [#22](https://github.com/bigcommerce/storefront-data-hooks/issues/22)*

### Login SSO
## Login SSO

- Accept `options` in the `useLogin` hook to allow Login SSO
- Update Readme with a quick guide of using Login SSO

*Resolves [#11](https://github.com/bigcommerce/storefront-data-hooks/issues/11) and [#13](https://github.com/bigcommerce/storefront-data-hooks/issues/13)*

### Allow to get products of different categories
## Allow to get products of different categories

- Add a new key to `useSearch`: `categoryIds`
- Stringify `categoryIds` to use as a key in SWR
Expand All @@ -76,7 +117,7 @@ When creating the carts, you can specify the locale. By default it's **en**, now
*Resolves [#9](https://github.com/bigcommerce/storefront-data-hooks/issues/9)*


### Fix `useAddItem` types
## Fix `useAddItem` types
- Set `variantId` as optional

*Resolves [#21](https://github.com/bigcommerce/storefront-data-hooks/issues/21)*
Expand Down
40 changes: 34 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
# Contributing to Storefront Data Hooks

## Pull Requests
## Reporting Issues

First ensure that your feature isn't already being developed or considered (see open PRs and issues).
If it is, please consider contributing to those initiatives.

## Issues / Bugs

* Please include a clear, specific title and replicable description.

* Please include your environment, OS, and any exceptions/backtraces that occur. The more
information that is given, the more likely we can debug and fix the issue.

## Suggesting new features

If you are here to suggest a feature, first create an issue if it does not already exist. From there, we will discuss use-cases for the feature and then finally discuss how it could be implemented.

## Development

First ensure that your feature isn't already being developed or considered (see open PRs and issues). If it is, please consider contributing to those initiatives.

Steps to get started:

- Fork this repository
- Install dependencies by running `$ yarn`
- Link `@bigcommerce/storefront-data-hooks` locally by running `$ yarn link`
- Auto-build files as you edit by running `$ yarn start`
- Implement your changes and tests to files in the `src/` directory and corresponding test files
- Run a project that uses this package
- To run a project using your local build, link to the local `@bigcommerce/storefront-data-hooks` by running `$ yarn link @bigcommerce/storefront-data-hooks` from the project directory
- Document your changes in the appropriate doc page
- Git stage your required changes and commit (we recommend following [Angular Commit Message Conventions](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines))
- Submit PR for review pointing to `develop`

## Pull requests

Maintainers merge pull requests by squashing all commits and editing the commit message if necessary using the GitHub user interface.

Use an appropriate commit type. Be especially careful with breaking changes. We recommend following [Angular Commit Message Conventions](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines)

## Releases

When it is decided that a new version is needed, the maintainers will create a PR with all the changes from `develop` to `master`. Once accepted and merged, a new release will be generated on GitHub and a GitHub Action will be triggered to publish the package to **npm**.

<!-- TODO: Consider to integrate semantic-release -->

## Other Ways to Contribute

* Consider contributing to documentation, reporting bugs, or helping spread the word about `storefront-data-hooks`.
Expand Down
125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Last version](https://img.shields.io/github/tag/bigcommerce/storefront-data-hooks.svg?style=flat-square)
[![NPM Status](https://img.shields.io/npm/dm/@bigcommerce/storefront-data-hooks.svg?style=flat-square)](https://www.npmjs.org/package/@bigcommerce/storefront-data-hooks)

Table of Contents
=================
Expand All @@ -21,6 +23,11 @@ Table of Contents
* [useSearch](#usesearch)
* [getAllProducts](#getallproducts)
* [getProduct](#getproduct)
* [Customer Addresses Hooks](#customer-addresses-hooks)
* [useAddresses](#useaddresses)
* [useAddAddress](#useaddaddress)
* [useUpdateAddress](#useupdateaddress)
* [useRemoveAddress](#useremoveaddress)
* [Checkout](#checkout)
* [Troubleshooting](#troubleshooting)
* [More](#more)
Expand Down Expand Up @@ -398,6 +405,120 @@ const { product } = await getProduct({
})
```
## Customer Addresses Hooks
### useAddresses
Hook for returning the current users addresses
```javascript
import useAddresses from '@bigcommerce/storefront-data-hooks/address/use-addresses'

const AddressPage = () => {
const { data } = useAddresses()

return (
<div>
<pre>{JSON.stringify(data?.addresses, null, 2)}</pre>
</div>
)
}

```
### useAddAddress
Hook for adding customer address
```javascript
import useAddAddress from '@bigcommerce/storefront-data-hooks/address/use-add-address'

const AddressPage = () => {
const addAddress = useAddAddress()

const handleAddAddress = async () => {
await addAddress({
first_name: "Rod",
last_name: "Hull",
address1: "Waffle Road",
city: "Bristol",
state_or_province: "Bristol",
postal_code: "WAF FLE",
country_code: "GB",
phone: "01234567890",
address_type: "residential",
})
}

return (
<form onSubmit={handleAddAddress}>
{children}
</form>
)
}

```
### useUpdateAddress
Hook for updating a customer address
```javascript
import useUpdateAddress from '@bigcommerce/storefront-data-hooks/address/use-update-address'

const AddressPage = () => {
const updateAddress = useUpdateAddress()

const handleUpdateAddress = async () => {
await updateAddress({
id: 4,
first_name: "Rod",
last_name: "Hull",
address1: "Waffle Road",
city: "Bristol",
state_or_province: "Bristol",
postal_code: "WAF FLE",
country_code: "GB",
phone: "01234567890",
address_type: "residential",
id: 12
})
}

return (
<form onSubmit={handleUpdateAddress}>
{children}
</form>
)
}

```
### useRemoveAddress
Hook for removing a customers address
```javascript
import useRemoveAddress from '@bigcommerce/storefront-data-hooks/address/use-remove-address'

const AddressPage = () => {
const removeAddress = useRemoveAddress()

const handleUpdateAddress = async () => {
await removeAddress({
id: 4,
})
}

return (
<form onSubmit={handleUpdateAddress}>
{children}
</form>
)
}

```
## Checkout
> The checkout only works on **production** and with a custom domain
Expand All @@ -421,6 +542,10 @@ The recommended method is the [Embedded Checkout](https://developer.bigcommerce.
Thanks @Strapazzon 🚀
</details>
## Contributing
Pull requests, issues and comments are welcome! See [Contributing](CONTRIBUTING.md) for more details.
Many thanks to all [contributors](https://github.com/bigcommerce/storefront-data-hooks/contributors)!
## More
Feel free to read through the source for more usage, and check the commerce vercel demo and commerce repo for usage examples: ([demo.vercel.store](https://demo.vercel.store/)) ([repo](https://github.com/vercel/commerce))
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bigcommerce/storefront-data-hooks",
"version": "1.3.1",
"version": "1.4.0",
"main": "index.js",
"repository": "[email protected]:bigcommerce/storefront-data-hooks.git",
"license": "MIT",
Expand All @@ -16,6 +16,7 @@
"scripts": {
"clean": "rimraf *.js *.d.ts api cart commerce products scripts wishlist",
"build": "npm run clean && tsc && cp src/schema.d.ts schema.d.ts",
"start": "npm run clean && tsc -w",
"prepublish": "npm run build",
"generate": "graphql-codegen",
"generate:definitions": "node src/scripts/generate-definitions.js"
Expand Down Expand Up @@ -51,7 +52,6 @@
"typescript": "^4.0.3"
},
"peerDependencies": {
"next": ">=10",
"react": ">=17"
}
}
Loading

0 comments on commit b00e3a7

Please sign in to comment.