Skip to content

Commit

Permalink
refactor(common): CHECKOUT-4338 Stop importing internal modules
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchin committed Aug 19, 2019
1 parent a27769e commit ef9d34c
Show file tree
Hide file tree
Showing 181 changed files with 408 additions and 454 deletions.
17 changes: 14 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"extends": [
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript"
"plugin:import/react",
"plugin:import/typescript",
"plugin:import/warnings"
],
"env": {
"browser": true
Expand Down Expand Up @@ -30,6 +31,16 @@
}
],
"react-hooks/exhaustive-deps": "error",
"react-hooks/rules-of-hooks": "error"
"react-hooks/rules-of-hooks": "error",
"import/no-internal-modules": [
"error",
{
"allow": [
"react-dom/test-utils",
"**/*.{mock,scss}",
"**/index.ts"
]
}
]
}
}
2 changes: 1 addition & 1 deletion src/app/address/AddressSelect.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { getCustomer } from '../customer/customers.mock';
import { createLocaleContext, LocaleContext, LocaleContextType } from '../locale';

import { getAddress } from './address.mock';
import StaticAddress from './staticAddress/StaticAddress';
import AddressSelect from './AddressSelect';
import StaticAddress from './StaticAddress';

describe('AddressSelect Component', () => {
let checkoutService: CheckoutService;
Expand Down
6 changes: 3 additions & 3 deletions src/app/address/AddressSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Address, CustomerAddress } from '@bigcommerce/checkout-sdk';
import React, { Component, FunctionComponent, ReactNode } from 'react';

import { preventDefault } from '../common/dom';
import { TranslatedString } from '../language';
import { TranslatedString } from '../locale';
import { DropdownTrigger } from '../ui/dropdown';

import StaticAddress from './staticAddress/StaticAddress';
import isEqualAddress from './util/isEqualAddress';
import isEqualAddress from './isEqualAddress';
import StaticAddress from './StaticAddress';

export interface AddressSelectProps {
addresses: CustomerAddress[];
Expand Down
2 changes: 1 addition & 1 deletion src/app/address/DynamicFormField.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mount, shallow } from 'enzyme';
import { Formik } from 'formik';
import React from 'react';

import { TranslatedString } from '../language';
import { TranslatedString } from '../locale';
import { FormField } from '../ui/form';

import { getFormFields } from './formField.mock';
Expand Down
4 changes: 2 additions & 2 deletions src/app/address/DynamicFormField.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { FormField as FormFieldType } from '@bigcommerce/checkout-sdk';
import React, { FunctionComponent } from 'react';

import { TranslatedString } from '../language';
import { TranslatedString } from '../locale';
import { FormField, Label } from '../ui/form';

import { getFormFieldInputId, getFormFieldLegacyName } from './util/getFormFieldInputId';
import { getFormFieldInputId, getFormFieldLegacyName } from './getFormFieldInputId';
import CheckboxGroupFormField from './CheckboxGroupFormField';
import DynamicFormFieldType from './DynamicFormFieldType';
import DynamicInput from './DynamicInput';
Expand Down
2 changes: 1 addition & 1 deletion src/app/address/MultiCheckboxControl.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FunctionComponent } from 'react';

import { TranslatedString } from '../language';
import { TranslatedString } from '../locale';

export interface MultiCheckboxControlProps {
testId?: string;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { createCheckoutService, CheckoutService } from '@bigcommerce/checkout-sd
import { mount } from 'enzyme';
import React from 'react';

import { CheckoutProvider } from '../../checkout';
import { getCountries } from '../../geography/countries.mock';
import { getAddress } from '../address.mock';
import { CheckoutProvider } from '../checkout';
import { getCountries } from '../geography/countries.mock';

import { getAddress } from './address.mock';
import StaticAddress from './StaticAddress';

describe('StaticAddress Component', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Address } from '@bigcommerce/checkout-sdk';
import React from 'react';

import { withCheckout, CheckoutContextProps } from '../../checkout';
import { LocalizedGeography } from '../../geography';
import localizeAddress from '../util/localizeAddress';
import { withCheckout, CheckoutContextProps } from '../checkout';
import { LocalizedGeography } from '../geography';

import localizeAddress from './localizeAddress';
import './StaticAddress.scss';

interface StaticAddressProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AddressKeyMap } from '../DynamicFormField';
import { AddressKeyMap } from './DynamicFormField';

export const ADDRESS_FIELD_IDS: AddressKeyMap = {
address1: 'addressLine1',
Expand Down
2 changes: 1 addition & 1 deletion src/app/address/googleAutocomplete/AddressSelector.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getGoogleAutocompletePlaceMock } from './__mocks__/googleAutocompleteResult';
import { getGoogleAutocompletePlaceMock } from './googleAutocompleteResult.mock';
import AddressSelector from './AddressSelector';

describe('AddressSelector', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { FormField as FormFieldType } from '@bigcommerce/checkout-sdk';
import React, { FunctionComponent } from 'react';

import { TranslatedString } from '../../language';
import { TranslatedString } from '../../locale';
import { AutocompleteItem } from '../../ui/autocomplete';
import { FormField } from '../../ui/form';
import { getFormFieldInputId } from '../util/getFormFieldInputId';
import { getFormFieldInputId } from '../getFormFieldInputId';

import GoogleAutocomplete from './GoogleAutocomplete';

Expand Down
2 changes: 1 addition & 1 deletion src/app/address/googleAutocomplete/mapToAddress.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getCountries } from '../../geography/countries.mock';

import { getGoogleAutocompletePlaceMock } from './googleAutocompleteResult.mock';
import mapToAddress from './mapToAddress';
import { getGoogleAutocompletePlaceMock } from './__mocks__/googleAutocompleteResult';

describe('mapToAddress()', () => {
it('returns a partial address with hydrated province', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/app/address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export { default as mapAddressFromFormValues } from './mapAddressFromFormValues'
export { default as AddressForm } from './AddressForm';
export { default as AddressSelect } from './AddressSelect';
export { default as getAddressValidationSchema } from './getAddressValidationSchema';
export { default as StaticAddress } from './staticAddress/StaticAddress';
export { default as localizeAddress } from './util/localizeAddress';
export { default as isValidAddress } from './util/isValidAddress';
export { default as isValidCustomerAddress } from './util/isValidCustomerAddress';
export { default as isEqualAddress } from './util/isEqualAddress';
export { default as StaticAddress } from './StaticAddress';
export { default as localizeAddress } from './localizeAddress';
export { default as isValidAddress } from './isValidAddress';
export { default as isValidCustomerAddress } from './isValidCustomerAddress';
export { default as isEqualAddress } from './isEqualAddress';
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { getAddress } from '../address.mock';
import { getAddressFormFields } from '../formField.mock';
import mapAddressFromFormValues from '../mapAddressFromFormValues';
import mapAddressToFormValues from '../mapAddressToFormValues';

import { getAddress } from './address.mock';
import { getAddressFormFields } from './formField.mock';
import isEqualAddress from './isEqualAddress';
import mapAddressFromFormValues from './mapAddressFromFormValues';
import mapAddressToFormValues from './mapAddressToFormValues';

describe('isEqualAddress', () => {
it('returns true when ignored values are different', () => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getAddress } from '../address.mock';
import { getFormFields } from '../formField.mock';

import { getAddress } from './address.mock';
import { getFormFields } from './formField.mock';
import isValidAddress from './isValidAddress';

describe('isValidAddress()', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address, FormField } from '@bigcommerce/checkout-sdk';

import getAddressValidationSchema from '../getAddressValidationSchema';
import mapAddressToFormValues from '../mapAddressToFormValues';
import getAddressValidationSchema from './getAddressValidationSchema';
import mapAddressToFormValues from './mapAddressToFormValues';

export default function isValidAddress(address: Address, formFields: FormField[]): boolean {
const addressSchema = getAddressValidationSchema({ formFields });
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Address } from '@bigcommerce/checkout-sdk';

import { getCountries } from '../../geography/countries.mock';
import { getAddress } from '../address.mock';
import { getCountries } from '../geography/countries.mock';

import { getAddress } from './address.mock';
import localizeAddress from './localizeAddress';

describe('localizeAddress', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Address } from '@bigcommerce/checkout-sdk';
import { find, isEmpty } from 'lodash';

import { memoize } from '../../common/utility';
import { Country, LocalizedGeography } from '../../geography';
import { memoize } from '../common/utility';
import { Country, LocalizedGeography } from '../geography';

const localizeAddress = <T1 extends Address>(
address: T1,
Expand Down
2 changes: 1 addition & 1 deletion src/app/billing/Billing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, { Component, ReactNode } from 'react';
import { isEqualAddress, mapAddressFromFormValues } from '../address';
import { withCheckout, CheckoutContextProps } from '../checkout';
import { EMPTY_ARRAY } from '../common/utility';
import { TranslatedString } from '../language';
import { TranslatedString } from '../locale';
import { getShippableItemsCount } from '../shipping';
import { Legend } from '../ui/form';
import { LoadingOverlay } from '../ui/loading';
Expand Down
3 changes: 1 addition & 2 deletions src/app/billing/BillingForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import React, { createRef, Component, ReactNode, RefObject } from 'react';
import { lazy } from 'yup';

import { getAddressValidationSchema, isValidCustomerAddress, mapAddressToFormValues, AddressForm, AddressFormValues, AddressSelect } from '../address';
import { TranslatedString } from '../language';
import { withLanguage, WithLanguageProps } from '../locale';
import { withLanguage, TranslatedString, WithLanguageProps } from '../locale';
import { OrderComments } from '../orderComments';
import { Button, ButtonVariant } from '../ui/button';
import { Fieldset, Form } from '../ui/form';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mount, ReactWrapper } from 'enzyme';
import React from 'react';

import { getStoreConfig } from '../../config/config.mock';
import { createLocaleContext, LocaleContext } from '../../locale';
import { getStoreConfig } from '../config/config.mock';
import { createLocaleContext, LocaleContext } from '../locale';

import AppliedRedeemable from './AppliedRedeemable';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import classNames from 'classnames';
import React, { FunctionComponent } from 'react';

import { TranslatedString } from '../../language';
import { IconRemove } from '../../ui/icon';
import { TranslatedString } from '../locale';
import { IconRemove } from '../ui/icon';

export interface AppliedRedeemableProps {
isRemoving: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Coupon, GiftCertificate } from '@bigcommerce/checkout-sdk';
import React, { FunctionComponent } from 'react';

import { AppliedCoupon } from '../../coupon';
import { AppliedGiftCertificate } from '../../giftCertificate';
import { AppliedCoupon } from '../coupon';
import { AppliedGiftCertificate } from '../giftCertificate';

import AppliedRedeemable from './AppliedRedeemable';

Expand Down
2 changes: 1 addition & 1 deletion src/app/cart/EditLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FunctionComponent } from 'react';

import { TranslatedString } from '../language';
import { TranslatedString } from '../locale';

export interface EditLinkProps {
className?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/app/cart/EmptyCartMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component, ReactNode } from 'react';

import { TranslatedHtml } from '../language';
import { TranslatedHtml } from '../locale';
import { LoadingOverlay } from '../ui/loading';

export interface EmptyCartMessageProps {
Expand Down
9 changes: 4 additions & 5 deletions src/app/cart/Redeemable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import React, { Fragment, FunctionComponent } from 'react';
import { object, string } from 'yup';

import { preventDefault } from '../common/dom';
import { TranslatedString } from '../language';
import { withLanguage, WithLanguageProps } from '../locale';
import AppliedRedeemables, { AppliedRedeemablesProps } from '../payment/redeemable/AppliedRedeemables';
import { withLanguage, TranslatedString, WithLanguageProps } from '../locale';
import { Alert, AlertType } from '../ui/alert';
import { Button, ButtonVariant } from '../ui/button';
import { FormField, Label, TextInput } from '../ui/form';
import FormProvider from '../ui/form/FormProvider';
import { FormField, FormProvider, Label, TextInput } from '../ui/form';
import { Toggle } from '../ui/toggle';

import AppliedRedeemables, { AppliedRedeemablesProps } from './AppliedRedeemables';

export interface RedeemableFormValues {
redeemableCode: string;
}
Expand Down
4 changes: 4 additions & 0 deletions src/app/cart/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { CartSummaryProps } from './CartSummary';
import { EmptyCartMessageProps } from './EmptyCartMessage';
import { RedeemableProps } from './Redeemable';

export type EmptyCartMessageProps = EmptyCartMessageProps;
export type CartSummaryProps = CartSummaryProps;
export type RedeemableProps = RedeemableProps;

export { default as CartSummaryDrawer } from './CartSummaryDrawer';
export { default as CartSummary } from './CartSummary';
export { default as Redeemable } from './Redeemable';
export { default as EmptyCartMessage } from './EmptyCartMessage';
export { default as mapToRedeemableProps } from './mapToRedeemableProps';
3 changes: 1 addition & 2 deletions src/app/cart/withRedeemable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { ComponentType, FunctionComponent } from 'react';

import { OrderSummarySubtotalsProps } from '../order';
import { OrderSummaryProps } from '../order/OrderSummary';
import { OrderSummaryProps, OrderSummarySubtotalsProps } from '../order';

import mapToOrderSummarySubtotalsProps from './mapToOrderSummarySubtotalsProps';
import { CartSummaryProps, WithCheckoutCartSummaryProps } from './CartSummary';
Expand Down
1 change: 0 additions & 1 deletion src/app/checkout/Checkout.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ describe('Checkout', () => {
.toMatchObject({
cart: getCart(),
compactView: true,
showShippingMethod: true,
consignment,
});
});
Expand Down
4 changes: 1 addition & 3 deletions src/app/checkout/Checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { CartSummary, CartSummaryDrawer, EmptyCartMessage } from '../cart';
import { ErrorLogger, ErrorModal } from '../common/error';
import { Customer, CustomerInfo, CustomerSignOutEvent, CustomerViewType } from '../customer';
import { isEmbedded, EmbeddedCheckoutStylesheet } from '../embeddedCheckout';
import { TranslatedString } from '../language';
import { withLanguage, WithLanguageProps } from '../locale';
import { withLanguage, TranslatedString, WithLanguageProps } from '../locale';
import { Payment } from '../payment';
import { PromotionBannerList } from '../promotion';
import { isUsingMultiShipping, Shipping, StaticConsignment } from '../shipping';
Expand Down Expand Up @@ -276,7 +275,6 @@ class Checkout extends Component<CheckoutProps & WithCheckoutProps & WithLanguag
summary={ consignments.map(consignment =>
<div key={ consignment.id } className="staticConsignmentContainer">
<StaticConsignment
showShippingMethod
cart={ cart }
consignment={ consignment }
compactView={ consignments.length < 2 }
Expand Down
2 changes: 1 addition & 1 deletion src/app/checkout/CheckoutStepHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { noop } from 'lodash';
import React, { FunctionComponent, ReactNode } from 'react';

import { preventDefault } from '../common/dom';
import { TranslatedString } from '../language';
import { TranslatedString } from '../locale';
import { Button, ButtonSize, ButtonVariant } from '../ui/button';
import { IconCheck } from '../ui/icon';

Expand Down
2 changes: 1 addition & 1 deletion src/app/checkout/getCheckoutStepStatuses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createSelector } from 'reselect';

import { isValidAddress } from '../address';
import { EMPTY_ARRAY } from '../common/utility';
import { SUPPORTED_METHODS } from '../customer/CheckoutButtonList';
import { SUPPORTED_METHODS } from '../customer';
import { hasSelectedShippingOptions, hasUnassignedLineItems } from '../shipping';

import CheckoutStepType from './CheckoutStepType';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '../../../../../node_modules/@bigcommerce/citadel/src/settings/global/global';
@import '../../../../node_modules/@bigcommerce/citadel/src/settings/global/global';

.errorCode {
font-size: fontSize("tiny");
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import React, { FunctionComponent } from 'react';

import { TranslatedString } from '../../../language';
import { TranslatedString } from '../../locale';

import './ErrorCode.scss';

const ErrorCode: React.SFC<{code: string}> = ({ code }) => {
const ErrorCode: FunctionComponent<{code: string}> = ({ code }) => {
return (
<div className="errorCode">
<span className="errorCode-label">
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ef9d34c

Please sign in to comment.