woocommerce/plugins/woocommerce-blocks/assets/js/data/checkout/default-state.ts

65 lines
2.7 KiB
TypeScript
Raw Normal View History

Convert checkout context to data store - part 1 (https://github.com/woocommerce/woocommerce-blocks/pull/6232) * Add checkout data store * wip on checkout data store * CheckoutContext now uses the checkout store * Investigated and removed setting the redirectUrl on the default state * update extension and address hooks to use checkout data store * use checkout data store in checkout-processor and use-checkout-button * trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity * Remove useCheckoutContext from shipping provider * Remove isCalculating from state * Removed useCheckoutContext from lots of places * Remove useCheckoutContext from checkout-payment-block * Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block * add isCart selector and action and update the checkoutstate context * Fixed redirectUrl bug by using thunks * Remove dispatchActions from checkout-state * Change SET_HAS_ERROR action to be neater * Thomas' feedback * Tidy up * Oops, deleted things I shouldn't have * Typescript * Fix types * Fix tests * Remove isCart * Update docs and remove unecessary getRedirectUrl() selector * set correct type for preloadedCheckoutData * Remove duplicate Address type * Fix missing addresses from type-defs index * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Revert feedback changes * REvert feedback formatting * Update docs formatting * Delete empty types.ts file * remove merge conflict from docs * Correct linting in docs Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2022-06-10 16:33:15 +00:00
/**
* External dependencies
*/
import { isSameAddress } from '@woocommerce/base-utils';
import { AdditionalValues } from '@woocommerce/settings';
Convert checkout context to data store - part 1 (https://github.com/woocommerce/woocommerce-blocks/pull/6232) * Add checkout data store * wip on checkout data store * CheckoutContext now uses the checkout store * Investigated and removed setting the redirectUrl on the default state * update extension and address hooks to use checkout data store * use checkout data store in checkout-processor and use-checkout-button * trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity * Remove useCheckoutContext from shipping provider * Remove isCalculating from state * Removed useCheckoutContext from lots of places * Remove useCheckoutContext from checkout-payment-block * Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block * add isCart selector and action and update the checkoutstate context * Fixed redirectUrl bug by using thunks * Remove dispatchActions from checkout-state * Change SET_HAS_ERROR action to be neater * Thomas' feedback * Tidy up * Oops, deleted things I shouldn't have * Typescript * Fix types * Fix tests * Remove isCart * Update docs and remove unecessary getRedirectUrl() selector * set correct type for preloadedCheckoutData * Remove duplicate Address type * Fix missing addresses from type-defs index * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Revert feedback changes * REvert feedback formatting * Update docs formatting * Delete empty types.ts file * remove merge conflict from docs * Correct linting in docs Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2022-06-10 16:33:15 +00:00
/**
* Internal dependencies
*/
import { STATUS, checkoutData } from './constants';
export type CheckoutState = {
Checkout: Add password field to create account form (#48985) * Add site title to account checkbox * Add customer_password support to Store API * Hide password nag if defining own password * Add woocommerce_registration_generate_password option to block assets * Change login prompt to just "log in" * Add default styling to password inputs * Reset line height for checkbox inputs * Add customer password to store * Add password field to contact information block * Handle customer password in checkout processor * Styling for new elements * Update tests so they match new create account label * Update log in link in tests * Add e2e tests for password field * Add validation message and fix rendering when account is required * Changelog * Add missing api to tests * Remove console log * rerender checkout * Update log in link in test * Adjust validation so we can change the label in messages with custom callback * Use queryByText in test * Make sure password generation is on in tests * Create password if provided password is empty * Skip "Place order" button translation test * Revert "Skip "Place order" button translation test" This reverts commit 7aed6137e88cdb3577f74f6f0c05258b531ed534. * Update plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-contact-information-block/block.tsx Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update plugins/woocommerce-blocks/assets/js/data/checkout/reducers.ts Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Comment empty condition * Update CSS classnames * Return null in CreateAccountUI if nothing to display * Linting: Return return param * Document $password param --------- Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com> Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2024-07-15 10:43:02 +00:00
additionalFields: AdditionalValues; // Additional fields values that are collected on Checkout.
calculatingCount: number; // If any of the totals, taxes, shipping, etc need to be calculated, the count will be increased here
customerId: number; // This is the ID of the customer the draft order belongs to.
customerPassword: string; // Customer password for account creation, if applicable.
extensionData: Record< string, Record< string, unknown > >; // Custom checkout data passed to the store API on processing.
hasError: boolean; // True when the checkout is in an error state. Whatever caused the error (validation/payment method) will likely have triggered a notice.
orderId: number; // This is the ID for the draft order if one exists.
orderNotes: string; // Order notes introduced by the user in the checkout form.
prefersCollection?: boolean | undefined; // If customer wants to checkout with a local pickup option.
redirectUrl: string; // This is the url that checkout will redirect to when it's ready.
shouldCreateAccount: boolean; // Should a user account be created?
status: STATUS; // Status of the checkout
useShippingAsBilling: boolean; // Should the billing form be hidden and inherit the shipping address?
editingBillingAddress: boolean; // Is the billing address being edited?
editingShippingAddress: boolean; // Is the shipping address being edited?
Convert checkout context to data store - part 1 (https://github.com/woocommerce/woocommerce-blocks/pull/6232) * Add checkout data store * wip on checkout data store * CheckoutContext now uses the checkout store * Investigated and removed setting the redirectUrl on the default state * update extension and address hooks to use checkout data store * use checkout data store in checkout-processor and use-checkout-button * trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity * Remove useCheckoutContext from shipping provider * Remove isCalculating from state * Removed useCheckoutContext from lots of places * Remove useCheckoutContext from checkout-payment-block * Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block * add isCart selector and action and update the checkoutstate context * Fixed redirectUrl bug by using thunks * Remove dispatchActions from checkout-state * Change SET_HAS_ERROR action to be neater * Thomas' feedback * Tidy up * Oops, deleted things I shouldn't have * Typescript * Fix types * Fix tests * Remove isCart * Update docs and remove unecessary getRedirectUrl() selector * set correct type for preloadedCheckoutData * Remove duplicate Address type * Fix missing addresses from type-defs index * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Revert feedback changes * REvert feedback formatting * Update docs formatting * Delete empty types.ts file * remove merge conflict from docs * Correct linting in docs Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2022-06-10 16:33:15 +00:00
};
// Default editing state for CustomerAddress component comes from the current address and whether or not we're in the editor.
const hasBillingAddress = !! (
checkoutData.billing_address.address_1 &&
( checkoutData.billing_address.first_name ||
checkoutData.billing_address.last_name )
);
const hasShippingAddress = !! (
checkoutData.shipping_address.address_1 &&
( checkoutData.shipping_address.first_name ||
checkoutData.shipping_address.last_name )
);
const billingMatchesShipping = isSameAddress(
checkoutData.billing_address,
checkoutData.shipping_address
);
Convert checkout context to data store - part 1 (https://github.com/woocommerce/woocommerce-blocks/pull/6232) * Add checkout data store * wip on checkout data store * CheckoutContext now uses the checkout store * Investigated and removed setting the redirectUrl on the default state * update extension and address hooks to use checkout data store * use checkout data store in checkout-processor and use-checkout-button * trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity * Remove useCheckoutContext from shipping provider * Remove isCalculating from state * Removed useCheckoutContext from lots of places * Remove useCheckoutContext from checkout-payment-block * Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block * add isCart selector and action and update the checkoutstate context * Fixed redirectUrl bug by using thunks * Remove dispatchActions from checkout-state * Change SET_HAS_ERROR action to be neater * Thomas' feedback * Tidy up * Oops, deleted things I shouldn't have * Typescript * Fix types * Fix tests * Remove isCart * Update docs and remove unecessary getRedirectUrl() selector * set correct type for preloadedCheckoutData * Remove duplicate Address type * Fix missing addresses from type-defs index * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Revert feedback changes * REvert feedback formatting * Update docs formatting * Delete empty types.ts file * remove merge conflict from docs * Correct linting in docs Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2022-06-10 16:33:15 +00:00
export const defaultState: CheckoutState = {
Checkout: Add password field to create account form (#48985) * Add site title to account checkbox * Add customer_password support to Store API * Hide password nag if defining own password * Add woocommerce_registration_generate_password option to block assets * Change login prompt to just "log in" * Add default styling to password inputs * Reset line height for checkbox inputs * Add customer password to store * Add password field to contact information block * Handle customer password in checkout processor * Styling for new elements * Update tests so they match new create account label * Update log in link in tests * Add e2e tests for password field * Add validation message and fix rendering when account is required * Changelog * Add missing api to tests * Remove console log * rerender checkout * Update log in link in test * Adjust validation so we can change the label in messages with custom callback * Use queryByText in test * Make sure password generation is on in tests * Create password if provided password is empty * Skip "Place order" button translation test * Revert "Skip "Place order" button translation test" This reverts commit 7aed6137e88cdb3577f74f6f0c05258b531ed534. * Update plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-contact-information-block/block.tsx Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update plugins/woocommerce-blocks/assets/js/data/checkout/reducers.ts Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Comment empty condition * Update CSS classnames * Return null in CreateAccountUI if nothing to display * Linting: Return return param * Document $password param --------- Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com> Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2024-07-15 10:43:02 +00:00
additionalFields: checkoutData.additional_fields || {},
calculatingCount: 0,
customerId: checkoutData.customer_id,
customerPassword: '',
extensionData: {},
Convert checkout context to data store - part 1 (https://github.com/woocommerce/woocommerce-blocks/pull/6232) * Add checkout data store * wip on checkout data store * CheckoutContext now uses the checkout store * Investigated and removed setting the redirectUrl on the default state * update extension and address hooks to use checkout data store * use checkout data store in checkout-processor and use-checkout-button * trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity * Remove useCheckoutContext from shipping provider * Remove isCalculating from state * Removed useCheckoutContext from lots of places * Remove useCheckoutContext from checkout-payment-block * Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block * add isCart selector and action and update the checkoutstate context * Fixed redirectUrl bug by using thunks * Remove dispatchActions from checkout-state * Change SET_HAS_ERROR action to be neater * Thomas' feedback * Tidy up * Oops, deleted things I shouldn't have * Typescript * Fix types * Fix tests * Remove isCart * Update docs and remove unecessary getRedirectUrl() selector * set correct type for preloadedCheckoutData * Remove duplicate Address type * Fix missing addresses from type-defs index * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Revert feedback changes * REvert feedback formatting * Update docs formatting * Delete empty types.ts file * remove merge conflict from docs * Correct linting in docs Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2022-06-10 16:33:15 +00:00
hasError: false,
orderId: checkoutData.order_id,
orderNotes: '',
Checkout: Add password field to create account form (#48985) * Add site title to account checkbox * Add customer_password support to Store API * Hide password nag if defining own password * Add woocommerce_registration_generate_password option to block assets * Change login prompt to just "log in" * Add default styling to password inputs * Reset line height for checkbox inputs * Add customer password to store * Add password field to contact information block * Handle customer password in checkout processor * Styling for new elements * Update tests so they match new create account label * Update log in link in tests * Add e2e tests for password field * Add validation message and fix rendering when account is required * Changelog * Add missing api to tests * Remove console log * rerender checkout * Update log in link in test * Adjust validation so we can change the label in messages with custom callback * Use queryByText in test * Make sure password generation is on in tests * Create password if provided password is empty * Skip "Place order" button translation test * Revert "Skip "Place order" button translation test" This reverts commit 7aed6137e88cdb3577f74f6f0c05258b531ed534. * Update plugins/woocommerce-blocks/assets/js/blocks/checkout/inner-blocks/checkout-contact-information-block/block.tsx Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update plugins/woocommerce-blocks/assets/js/data/checkout/reducers.ts Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Comment empty condition * Update CSS classnames * Return null in CreateAccountUI if nothing to display * Linting: Return return param * Document $password param --------- Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com> Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2024-07-15 10:43:02 +00:00
prefersCollection: undefined,
redirectUrl: '',
shouldCreateAccount: false,
status: STATUS.IDLE,
useShippingAsBilling: billingMatchesShipping,
editingBillingAddress: ! hasBillingAddress,
editingShippingAddress: ! hasShippingAddress,
Convert checkout context to data store - part 1 (https://github.com/woocommerce/woocommerce-blocks/pull/6232) * Add checkout data store * wip on checkout data store * CheckoutContext now uses the checkout store * Investigated and removed setting the redirectUrl on the default state * update extension and address hooks to use checkout data store * use checkout data store in checkout-processor and use-checkout-button * trim useCheckoutContext from use-payment-method-interface && use-store-cart-item-quantity * Remove useCheckoutContext from shipping provider * Remove isCalculating from state * Removed useCheckoutContext from lots of places * Remove useCheckoutContext from checkout-payment-block * Remove useCheckoutContext in checkout-shipping-methods-block and checkout-shipping-address-block * add isCart selector and action and update the checkoutstate context * Fixed redirectUrl bug by using thunks * Remove dispatchActions from checkout-state * Change SET_HAS_ERROR action to be neater * Thomas' feedback * Tidy up * Oops, deleted things I shouldn't have * Typescript * Fix types * Fix tests * Remove isCart * Update docs and remove unecessary getRedirectUrl() selector * set correct type for preloadedCheckoutData * Remove duplicate Address type * Fix missing addresses from type-defs index * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Update docs/block-client-apis/checkout/checkout-api.md Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com> * Revert feedback changes * REvert feedback formatting * Update docs formatting * Delete empty types.ts file * remove merge conflict from docs * Correct linting in docs Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
2022-06-10 16:33:15 +00:00
};