import React, {Component} from 'react'; import classes from "../seller.css"; type Props = { onDiscountChange: (val: any) => void; onCheckout: () => void; totalCash: number; } type State = { inputValue: 0; } class Checkout extends Component { constructor(props: Props) { super(props); this.state = { inputValue: 0 } } onDiscountChange = (e: any) => { const value = e.target.value; if (!isNaN(value)) { this.setState({inputValue: value}); this.props.onDiscountChange(value) } else { this.setState({inputValue: 0}); this.props.onDiscountChange(value) } }; renderButton = () => { return (
{ this.props.onCheckout(); this.setState({inputValue: 0}) }}>
CHECKOUT
{this.props.totalCash > 0 ? (this.props.totalCash - this.state.inputValue).toFixed(2): 0}
) }; render() { return (

CHECKOUT

this.onDiscountChange(e)} id="discount" type="text" className="form-control" style={{paddingTop: "10px", paddingBottom: "10px", background: "#fff"}} placeholder="DISCOUNT" />
DISCOUNT TOTAL
{this.state.inputValue}
{this.renderButton()}
); } } export default Checkout;