import React, {Component} from 'react'; import {History, LocationState} from 'history' import Modal from "../../ui/Modal"; type Props = { auth: any; products: any; getProducts: (id: string) => void; deleteProduct: (id: string) => void; history: History; match: any; } interface State { fadeStyle: string; show: boolean; item: any } class ProductDelete extends Component { constructor(props: Props) { super(props); this.state = { fadeStyle: "modalFadein", show: true, item: {} } } componentDidMount() { if(this.props.auth.authenticateUser) { this.props.getProducts(this.props.auth.authenticateUser.UsersId); this.setState({item: this.props.products[this.props.match.params.id]}) } } onDismiss () { this.setState({fadeStyle: "modalFadeout"}); this.setState({show: false}); setTimeout(() => { this.props.history.push("/logged/products"); }, 500) } deleteItem = () => { this.props.deleteProduct(this.props.match.params.id); this.onDismiss() }; renderFooter() { return ( <> ) } renderTitle() { return(
Delete item
) } renderBody = () => { if(this.props.products[this.props.match.params.id]) { const item = this.props.products[this.props.match.params.id]; return (

Are you sure you want to delete {item.trade_name} - {item.scientific_name} ?

) } else { return

loading

} }; render() { return ( this.deleteItem()} show={this.state.show} fadeStyle={this.state.fadeStyle} onDismiss={() => this.onDismiss()} renderTitle={this.renderTitle} renderBody={this.renderBody} renderFooter={this.renderFooter} /> ) } } export default ProductDelete;