async addProductToCart()

in TailwindTraders.Website/Source/Tailwind.Traders.Web/ClientApp/src/pages/detail/detailContainer.js [43:71]


    async addProductToCart() {

        const profile = await UserService.getProfileData(this.props.userInfo.token);
        const { profile: { email } } = profile;
        this.state.detailProduct.email = email

        const productToCart = await CartService.postProductToCart(this.props.userInfo.token, this.state.detailProduct)

        if (productToCart.errMessage) {
            return this.showErrorMessage(productToCart)
        } else {
            this.showSuccesMessage(productToCart)
        }

        this.setState({ loadingRelated: true });

        setTimeout(async () => {
            let relatedDetailProducts = await CartService
                .getRelatedDetailProducts(this.props.userInfo.token, this.state.detailProduct.type.id);

            if (relatedDetailProducts) {
                relatedDetailProducts = relatedDetailProducts.recommendations.slice(0, 3);
            }

            this.setState({ relatedDetailProducts, loadingRelated: false });
        }, 2000);

        this.props.sumProductInState();
    }