Skip to content

Commit 12c55da

Browse files
author
Luis Sanchez
committed
feat(shipping): CHECKOUT-3243 Support tracking loading and error states per consignment
1 parent 62c0dc3 commit 12c55da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+729
-368
lines changed

src/address/address.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ export default interface Address extends AddressRequestBody {
22
country: string;
33
}
44

5-
export interface AddressRequestBody {
6-
id?: string;
5+
export interface BillingAddress extends Address {
6+
id: string;
77
email?: string;
8+
}
9+
10+
export interface CustomerAddress extends Address {
11+
id: string;
12+
}
13+
14+
export interface AddressRequestBody {
815
firstName: string;
916
lastName: string;
1017
company: string;
@@ -21,3 +28,8 @@ export interface AddressRequestBody {
2128
fieldValue: string;
2229
}>;
2330
}
31+
32+
export interface BillingAddressUpdateRequestBody extends AddressRequestBody {
33+
id: string;
34+
email?: string;
35+
}
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { getShippingAddress as getInternalShippingAddress } from '../shipping/internal-shipping-addresses.mock';
2-
import { getShippingAddress } from '../shipping/shipping-addresses.mock';
1+
import { omit } from 'lodash';
2+
3+
import { getBillingAddress } from '../billing/billing-addresses.mock';
4+
import { getBillingAddress as getInternalBillingAddress } from '../billing/internal-billing-addresses.mock';
35

46
import mapFromInternalAddress from './map-from-internal-address';
57

68
describe('mapFromInternalAddress()', () => {
79
it('maps from internal address', () => {
8-
expect(mapFromInternalAddress(getInternalShippingAddress()))
9-
.toEqual(getShippingAddress());
10+
expect(mapFromInternalAddress(getInternalBillingAddress()))
11+
.toEqual(omit(getBillingAddress(), 'email'));
1012
});
1113
});

src/address/map-from-internal-address.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Address from './address';
1+
import Address, { BillingAddress } from './address';
22
import InternalAddress from './internal-address';
33

4-
export default function mapFromInternalAddress(address: InternalAddress): Address {
4+
export default function mapFromInternalAddress(address: InternalAddress): Address | BillingAddress {
55
return {
66
id: address.id,
77
firstName: address.firstName,
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
import { getBillingAddress } from '../billing/billing-addresses.mock';
2+
import { getBillingAddress as getInternalBillingAddress } from '../billing/internal-billing-addresses.mock';
3+
import { getConsignment } from '../shipping/consignments.mock';
14
import { getShippingAddress as getInternalShippingAddress } from '../shipping/internal-shipping-addresses.mock';
25
import { getShippingAddress } from '../shipping/shipping-addresses.mock';
36

47
import mapToInternalAddress from './map-to-internal-address';
58

69
describe('mapToInternalAddress()', () => {
710
it('maps to internal address', () => {
8-
expect(mapToInternalAddress(getShippingAddress()))
11+
expect(mapToInternalAddress(getBillingAddress()))
12+
.toEqual(getInternalBillingAddress());
13+
});
14+
15+
it('maps to internal shipping address when consignments are passed', () => {
16+
expect(mapToInternalAddress(getShippingAddress(), [getConsignment()]))
917
.toEqual(getInternalShippingAddress());
1018
});
1119
});

src/address/map-to-internal-address.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
1-
import Address from './address';
1+
import { Consignment } from '../shipping';
2+
3+
import Address, { BillingAddress } from './address';
24
import InternalAddress from './internal-address';
35

4-
export default function mapToInternalAddress(address: Address, id?: string): InternalAddress {
6+
export default function mapToInternalAddress(address: Address | BillingAddress, consignments?: Consignment[]): InternalAddress {
7+
let addressId;
8+
9+
if ((address as BillingAddress).id) {
10+
addressId = (address as BillingAddress).id;
11+
} else if (consignments && consignments.length) {
12+
addressId = consignments[0].id;
13+
}
14+
515
return {
6-
id: id ? id : address.id,
16+
id: addressId,
717
firstName: address.firstName,
818
lastName: address.lastName,
919
company: address.company,

src/billing/billing-address-action-creator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Response } from '@bigcommerce/request-sender';
33
import { Observable } from 'rxjs/Observable';
44
import { Observer } from 'rxjs/Observer';
55

6-
import { AddressRequestBody } from '../address';
6+
import { BillingAddressUpdateRequestBody } from '../address/address';
77
import { Checkout, CheckoutClient, InternalCheckoutSelectors, ReadableCheckoutStore } from '../checkout';
88
import { MissingDataError, MissingDataErrorType } from '../common/error/errors';
99
import { RequestOptions } from '../common/http-request';
@@ -15,7 +15,7 @@ export default class BillingAddressActionCreator {
1515
private _checkoutClient: CheckoutClient
1616
) {}
1717

18-
updateAddress(address: Partial<AddressRequestBody>, options?: RequestOptions): ThunkAction<UpdateBillingAddressAction, InternalCheckoutSelectors> {
18+
updateAddress(address: Partial<BillingAddressUpdateRequestBody>, options?: RequestOptions): ThunkAction<UpdateBillingAddressAction, InternalCheckoutSelectors> {
1919
return store => Observable.create((observer: Observer<UpdateBillingAddressAction>) => {
2020
observer.next(createAction(BillingAddressActionType.UpdateBillingAddressRequested));
2121

@@ -30,7 +30,7 @@ export default class BillingAddressActionCreator {
3030
});
3131
}
3232

33-
private _requestBillingAddressUpdate(store: ReadableCheckoutStore, address: Partial<AddressRequestBody>, options?: RequestOptions): Promise<Response<Checkout>> {
33+
private _requestBillingAddressUpdate(store: ReadableCheckoutStore, address: Partial<BillingAddressUpdateRequestBody>, options?: RequestOptions): Promise<Response<Checkout>> {
3434
const state = store.getState();
3535
const checkout = state.checkout.getCheckout();
3636

src/billing/billing-address-reducer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { combineReducers } from '@bigcommerce/data-store';
22

3-
import { Address } from '../address';
3+
import { BillingAddress } from '../address/address';
44
import { CheckoutAction, CheckoutActionType } from '../checkout';
55
import { OrderAction, OrderActionType } from '../order';
66

@@ -26,9 +26,9 @@ export default function billingAddressReducer(
2626
}
2727

2828
function dataReducer(
29-
data: Address | undefined,
29+
data: BillingAddress | undefined,
3030
action: CheckoutAction | BillingAddressAction | OrderAction
31-
): Address | undefined {
31+
): BillingAddress | undefined {
3232
switch (action.type) {
3333
case BillingAddressActionType.UpdateBillingAddressSucceeded:
3434
case CheckoutActionType.LoadCheckoutSucceeded:

src/billing/billing-address-request-sender.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { RequestSender, Response } from '@bigcommerce/request-sender';
22

33
import { AddressRequestBody } from '../address';
4+
import { BillingAddressUpdateRequestBody } from '../address/address';
45
import { Checkout } from '../checkout';
56
import { ContentType, RequestOptions } from '../common/http-request';
67

@@ -25,7 +26,7 @@ export default class BillingAddressRequestSender {
2526
return this._requestSender.post(url, { body: address, params: DEFAULT_PARAMS, headers, timeout });
2627
}
2728

28-
updateAddress(checkoutId: string, address: Partial<AddressRequestBody>, { timeout }: RequestOptions = {}): Promise<Response<Checkout>> {
29+
updateAddress(checkoutId: string, address: Partial<BillingAddressUpdateRequestBody>, { timeout }: RequestOptions = {}): Promise<Response<Checkout>> {
2930
const { id, ...body } = address;
3031
const url = `/api/storefront/checkouts/${checkoutId}/billing-address/${id}`;
3132
const headers = { Accept: ContentType.JsonV1 };

src/billing/billing-address-selector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Address } from '../address';
1+
import { BillingAddress } from '../address/address';
22
import { selector } from '../common/selector';
33

44
import BillingAddressState from './billing-address-state';
@@ -9,7 +9,7 @@ export default class BillingAddressSelector {
99
private _billingAddress: BillingAddressState
1010
) {}
1111

12-
getBillingAddress(): Address | undefined {
12+
getBillingAddress(): BillingAddress | undefined {
1313
return this._billingAddress.data;
1414
}
1515

src/billing/billing-address-state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Address } from '../address';
1+
import { BillingAddress } from '../address/address';
22

33
export default interface BillingAddressState {
4-
data?: Address;
4+
data?: BillingAddress;
55
errors: BillingAddressErrorsState;
66
statuses: BillingAddressStatusesState;
77
}

0 commit comments

Comments
 (0)