Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev]: Refactor Checkout #1309

Merged
merged 33 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
acce583
Refactor addressForm:
sirugh Jun 6, 2019
5f7f320
Refactor checkoutButton and cart components.
sirugh Jun 6, 2019
868b667
Refactor Label component and update one implementation to use id refe…
sirugh Jun 6, 2019
7cfb4bf
Remove unused resetButton component
sirugh Jun 6, 2019
f95f509
Refactor section component
sirugh Jun 7, 2019
9418b49
Remove submitButton component
sirugh Jun 7, 2019
9f024dd
Refactor wrapper/container
sirugh Jun 7, 2019
eb334ee
Refactor shippingForm
sirugh Jun 7, 2019
29f2161
Refactor paymentsForm and fix but in billing address reducer
sirugh Jun 7, 2019
1666745
Refactor Flow to function component
sirugh Jun 7, 2019
8253a4b
Refactor Form to function component
sirugh Jun 7, 2019
ff3107f
Refactor braintreedropin component
sirugh Jun 10, 2019
d6e829b
Remove unused type value from submit actions
sirugh Jun 12, 2019
0ddacf0
Refactor flow container to just connect and assign props.
sirugh Jun 13, 2019
3452dc1
Add jsdoc
sirugh Jun 13, 2019
511dbce
Update packages/venia-concept/src/components/Checkout/flow.js
sirugh Jun 13, 2019
a7ffa68
Merge branch 'develop' into refactor/checkout
sirugh Jun 18, 2019
93835bd
First pass at feedback.
sirugh Jun 18, 2019
e551d43
Break form into separate files
sirugh Jun 18, 2019
b5e5906
fix hook in dropin
sirugh Jun 18, 2019
30c72d5
alphabetize props
sirugh Jun 18, 2019
95fede4
Merge branch 'develop' into refactor/checkout
sirugh Jun 18, 2019
c6d4cf3
Merge branch 'develop' into refactor/checkout
sirugh Jun 24, 2019
6ee067f
fix footer from merge
sirugh Jun 24, 2019
ae5a6f7
Remove unnecessary useCallback
sirugh Jun 24, 2019
0b4b17c
Remove another unnecessary useCallback
sirugh Jun 24, 2019
f59a85e
Merge branch 'develop' into refactor/checkout
sirugh Jun 25, 2019
6ca1a26
Update verbage to invalid/valid vs incorrect/correct
sirugh Jun 25, 2019
f1a77d4
Refactor payments form items into separate component
sirugh Jun 25, 2019
ce48a4f
Merge branch 'develop' into refactor/checkout
sirugh Jun 26, 2019
2e2a6b5
Merge branch 'develop' into refactor/checkout
dpatil-magento Jun 27, 2019
0717bbf
Merge branch 'develop' into refactor/checkout
dpatil-magento Jun 27, 2019
4b0647e
Merge branch 'develop' into refactor/checkout
dpatil-magento Jun 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/venia-concept/src/components/Checkout/addressForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const AddressForm = props => {
acc[key] = initialValues[key];
return acc;
}, {}),
[fields, initialValues]
[initialValues]
);

const handleCancel = useCallback(() => {
Expand Down Expand Up @@ -174,12 +174,13 @@ AddressForm.propTypes = {
email: string,
firstname: string,
footer: string,
heading: string,
lastname: string,
postcode: string,
root: string,
region_code: string,
street0: string,
telephone: string,
textInput: string,
validation: string
}),
countries: array,
Expand Down
120 changes: 120 additions & 0 deletions packages/venia-concept/src/components/Checkout/editableForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import React, { useCallback } from 'react';
import { array, bool, func, object, oneOf, shape, string } from 'prop-types';

import AddressForm from './addressForm';
import PaymentsForm from './paymentsForm';
import ShippingForm from './shippingForm';

/**
* The EditableForm component renders the actual edit forms for the sections
* within the form.
*/
const EditableForm = props => {
const {
editing,
editOrder,
submitShippingAddress,
submitShippingMethod,
submitPaymentMethodAndBillingAddress,
submitting,
isAddressIncorrect,
incorrectAddressMessage,
sirugh marked this conversation as resolved.
Show resolved Hide resolved
directory: { countries }
} = props;

const handleCancel = useCallback(() => {
editOrder(null);
}, [editOrder]);

const handleSubmitAddressForm = useCallback(
formValues => {
submitShippingAddress({
formValues
});
},
[submitShippingAddress]
);

const handleSubmitPaymentsForm = useCallback(
formValues => {
submitPaymentMethodAndBillingAddress({
formValues
});
},
[submitPaymentMethodAndBillingAddress]
);

const handleSubmitShippingForm = useCallback(
formValues => {
submitShippingMethod({
formValues
});
},
[submitShippingMethod]
);

switch (editing) {
case 'address': {
const { shippingAddress } = props;

return (
<AddressForm
cancel={handleCancel}
countries={countries}
isAddressIncorrect={isAddressIncorrect}
incorrectAddressMessage={incorrectAddressMessage}
initialValues={shippingAddress}
submit={handleSubmitAddressForm}
submitting={submitting}
/>
);
}
case 'paymentMethod': {
const { billingAddress } = props;

return (
<PaymentsForm
cancel={handleCancel}
countries={countries}
initialValues={billingAddress}
submit={handleSubmitPaymentsForm}
submitting={submitting}
/>
);
}
case 'shippingMethod': {
const { availableShippingMethods, shippingMethod } = props;
return (
<ShippingForm
availableShippingMethods={availableShippingMethods}
cancel={handleCancel}
shippingMethod={shippingMethod}
submit={handleSubmitShippingForm}
submitting={submitting}
/>
);
}
default: {
return null;
}
}
};

EditableForm.propTypes = {
availableShippingMethods: array,
editing: oneOf(['address', 'paymentMethod', 'shippingMethod']),
editOrder: func.isRequired,
shippingAddress: object,
shippingMethod: string,
submitShippingAddress: func.isRequired,
submitShippingMethod: func.isRequired,
submitPaymentMethodAndBillingAddress: func.isRequired,
submitting: bool,
isAddressIncorrect: bool,
incorrectAddressMessage: string,
directory: shape({
countries: array
})
};

export default EditableForm;
Loading