/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { useState, useEffect, useRef } from '@wordpress/element'; import { PanelBody, PanelRow } from 'wordpress-components'; import Button from '@woocommerce/base-components/button'; import TextInput from '@woocommerce/base-components/text-input'; import Label from '@woocommerce/base-components/label'; import PropTypes from 'prop-types'; import withComponentId from '@woocommerce/base-hocs/with-component-id'; /** * Internal dependencies */ import './style.scss'; import LoadingMask from '../../loading-mask'; const TotalsCouponCodeInput = ( { componentId, isLoading = false, onSubmit = () => {}, } ) => { const [ couponValue, setCouponValue ] = useState( '' ); const currentIsLoading = useRef( false ); useEffect( () => { if ( currentIsLoading.current !== isLoading ) { if ( ! isLoading && couponValue ) { setCouponValue( '' ); } currentIsLoading.current = isLoading; } }, [ isLoading, couponValue ] ); return ( } initialOpen={ true } > setCouponValue( newCouponValue ) } /> ); }; TotalsCouponCodeInput.propTypes = { onSubmit: PropTypes.func, isLoading: PropTypes.bool, }; export default withComponentId( TotalsCouponCodeInput );