Commit Graph

7 Commits

Author SHA1 Message Date
Darren Ethier 80f692404f Refactor Cart to include shippingAddress (https://github.com/woocommerce/woocommerce-blocks/pull/1960)
* Include shipping and billing address data in cart schema

* update cart hook (and data api) with new properties from endpoint

* add use-shipping-address hook and implement in use-shipping-rates

* update usages of useShippingRates through code

* update tests for use-shipping-rates

* update use-payment-method-interface and typedef to remove country field

This is provided reliably via the shippingAddress now.

* restore pluck comparison to effect.

Also added some clarification docs for why `iniitalAddress` is not included in the effect dependencies.

* remove billingAddress from cart schema

* clear city and postcode when changing country

* Update REST Api schemas aftere rebase

- CustomerSchema no longer exists
- Added ShippingAddressSchema implemented by Cart and Order schemas
- fix broken js because of bad merge conflict resolution.

* remove duplicate keys
2020-03-13 15:04:03 -04:00
Albert Juhé Lluveras 2147e8a22a Add checkout sidebar (https://github.com/woocommerce/woocommerce-blocks/pull/1921) 2020-03-12 10:41:35 +01:00
Darren Ethier 02b3f2fccc add defaults for cart data totals object (https://github.com/woocommerce/woocommerce-blocks/pull/1896) 2020-03-09 08:52:25 -04:00
Seghir Nadir 2c8388f0a8 Update and select shipping rates dynamically (https://github.com/woocommerce/woocommerce-blocks/pull/1794)
* add select shipping endpoint to router

* add select shipping method

* add selected rates to cart

* better select rates

* move schema function to seperate function

* move validation to Cart Controller

* fix wrong session key

* Update shipping/cart endpoints (https://github.com/woocommerce/woocommerce-blocks/pull/1833)

* Items should not have keys in API response

* Include package ID in response (this is just a basic index)

* /cart/select-shipping-rate/package_id

* Add package_id to package array

* Update responses and add shipping-rates to main cart endpoint

* update-shipping endpoint

* Add querying selected shipping rate to the store (https://github.com/woocommerce/woocommerce-blocks/pull/1829)

* add selecting shipping to store

* directly call useSelectShippingRate

* refactor cart keys transformation to reducer

* remove selecting first result and accept selecting

* move update shipping to new endpoint

* pass selected rates down

* select shipping right directly and fix editor issues

* fix some broken prop types

* key -> package id

* Update and fix cart/shipping-rate tests

* fix case for when rates are set

* Update useShippingRates test

* add args to rest endpoint

* move selecting shipping rate logic to hook

* fix some naming issues

* update propTypes

* update action call

* fully watch cart state

* address review issues

* fix prop type issues

* fix issue with rates not loading in checkout

* remove extra package for shipping

* move ShippingCalculatorOptions to outside

Co-authored-by: Mike Jolley <mike.jolley@me.com>
Co-authored-by: Albert Juhé Lluveras <aljullu@gmail.com>
2020-03-05 20:54:05 +01:00
Rua Haszard 201cb4ff50 Support updating quantity of cart items & sold_individually product option (https://github.com/woocommerce/woocommerce-blocks/pull/1824)
* first cut - removing an item from cart:
- add actions to cart store for removing an item and keeping track of
pending removal API call
- add reducer logic for storing pending state on an item, and removing
an item
- expose removeCartItem on new useStoreCartItems hook
- hook it up to remove link / trashcan icon in row item

* disable cart quantity picker/remove link while API request in progress:
- expose cart item pending status from store using selector
- use selector to disable quantity related components in line item row

* add typedef for cart items store object provided by hook

* allow user to change quantity of cart items (first cut):
- add action for replacing a cart item in the store
- add generator action for changing quantity
- expose change quantity action on useStoreCartItems hook
- hook up to quantity UI in cart block
(work in progress)

* post-rebase fixes & fix broken typedef:
- rework cart item change quantity callback - now supplies item key like
remove callback
- fix hook StoreCartItem return value typedef - single item with
specified key, was array of all items
- add quantity JSDoc for changeCartItemQuantity action
- remove changeQuantity callback from UI (currently infinite looping)

* fix bug in recieveCartItem reducer - check keys for equality:
- was key === object

* fix invalid url in POST cart/items/quantity request

* hook up cart line item quantity to API:
- remove internal state/ref for QuantitySelector, is now a controlled
component
- call changeQuantity action from QuantitySelector change callback

* QuantitySelector no longer needs a ref to wrangle number input value

* hoist quantity state out of QuantitySelector into story (fix storybook)

* add product sold_individually option to cart item API response

* limit sold_individually items to 1 per cart/order:
- support optional max value in QuantitySelector
- set maximum dependent on sold_individually API field

* prevent user from requesting zero x cart item (API 500 errors):
- add minimum limit to QuantitySelector
- default limit to 1
+ fix bug with limiting to maximum value in number input change handler

* remove useStoreCartItems, zombie hook coming back from rebase 🧟‍♂️

* address various review feedback:
- inline undefined check, don't use lodash
- quantityInputOnKeyDown callback hook depends on canIncrease/canDecrease
- also removed undefined check for minimum, as minimum has default 0

* use safer typeof check for presence of maximum prop
2020-03-03 14:08:19 +13:00
Rua Haszard 69ea94378b support removing cart items (https://github.com/woocommerce/woocommerce-blocks/pull/1813)
* first cut - removing an item from cart:
- add actions to cart store for removing an item and keeping track of
pending removal API call
- add reducer logic for storing pending state on an item, and removing
an item
- expose removeCartItem on new useStoreCartItems hook
- hook it up to remove link / trashcan icon in row item

* disable cart quantity picker/remove link while API request in progress:
- expose cart item pending status from store using selector
- use selector to disable quantity related components in line item row

* fix jsdoc - getCartItem returns undefined if not found

* add typedef for cart items store object provided by hook

* fix rebase error - key prop went awol

* orient useStoreCartItem hook to single cart item:
- simplify interface for client component
  - isPending bool (was callback)
  - removeItem callback no need to specify item key
+ reinstate disabled prop on remove link when updating (lost in rebase)

* move cart item pending state out of cartItems, preserve API state shape:
- pending is now stored as array of keys
- fix isItemQuantityPending selector (now much simpler)

* ensure react knows that our useSelect depends on cartItemKey
2020-02-28 15:05:10 +13:00
Mike Jolley 6d7fdf50e0 Allow coupons to be applied and removed from the cart (https://github.com/woocommerce/woocommerce-blocks/pull/1790)
* useStoreCartCoupons hook

* Apply coupon w/ basic error handling for the fetch

* Basic store specifically for cart data

* Working on error states

* Show error on coupon fail

* removeCoupon action

* Added extra endpoints for more efficient cart queries

* Apply/remove coupons working

* Track applying/removing state

* StoreCartCoupon typedef

* Use coupon code on index

* Remove custom controls definition

* Adjust storecartcoupons mapper and remove ref

* Move cartData defaults and remove ref

* Call API directly, avoid schema lookup

* Improved selectors

* StoreCart typedef

* Split up cart state data and add more typedefs

* Add API tests for apply/remove coupon

* Jest tests

* Move default cart data to constant

* Comment indentation
2020-02-25 11:36:53 +00:00