Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
optometrists
/
cache
/
cache
/
cache
/
cache
/
cache
/
.wp-cli
/
wp-content
/
plugins
/
woocommerce
/
packages
/
woocommerce-blocks
/
assets
/
js
/
base
/
components
/
cart-checkout
/
totals
/
coupon
/
stories
:
index.js
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
/** * External dependencies */ import { text, boolean } from '@storybook/addon-knobs'; import { useValidationContext, ValidationContextProvider, } from '@woocommerce/base-context'; /** * Internal dependencies */ import TotalsCoupon from '../'; export default { title: 'WooCommerce Blocks/@base-components/cart-checkout/totals/TotalsCoupon', component: TotalsCoupon, }; const StoryComponent = ( { validCoupon, isLoading, invalidCouponText } ) => { const { setValidationErrors } = useValidationContext(); const onSubmit = ( coupon ) => { if ( coupon !== validCoupon ) { setValidationErrors( { coupon: invalidCouponText } ); } }; return <TotalsCoupon isLoading={ isLoading } onSubmit={ onSubmit } />; }; export const Default = () => { const validCoupon = text( 'A valid coupon code', 'validcoupon' ); const invalidCouponText = text( 'Error message for invalid code', 'Invalid coupon code.' ); const isLoading = boolean( 'Toggle isLoading state', false ); return ( <ValidationContextProvider> <StoryComponent validCoupon={ validCoupon } isLoading={ isLoading } invalidCouponText={ invalidCouponText } /> </ValidationContextProvider> ); };