From e6fa7db87b5f879de71bfc9e4f8afea9d722ab95 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Fri, 26 May 2023 18:57:36 -0600 Subject: Añade creación de reseñas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/products/product.tsx | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/routes') diff --git a/src/routes/products/product.tsx b/src/routes/products/product.tsx index cca4073..fb883a8 100644 --- a/src/routes/products/product.tsx +++ b/src/routes/products/product.tsx @@ -2,17 +2,20 @@ import { useLoaderData, Form, useActionData } from "react-router-dom"; import { CartPlusFill } from "react-bootstrap-icons" import { InfoModal } from "../../components/info_modal"; import { Modal } from "flowbite"; +import { isUserAuthenticated } from "../../lib/session"; import ProductListing from "../../components/product_listing"; import MainContentLayout from "../../components/main_content_layout"; import Review from "../../components/review"; +import ReviewForm from "../../components/forms/review_form"; import "../../components/stylesheets/shared.css" import { useEffect } from "react"; export default function Product() { let quantity_field; + let review_form_error_messages; const response = useLoaderData(); - const response_status = useActionData(); + const action_response = useActionData(); const product = response[0].data; const reviews = response[1].data.data.map(review =>
  • @@ -33,12 +36,22 @@ export default function Product() { modal.hide(); }); - if(response_status == 200) + if(action_response == 200) modal.show(); - }, [response_status]); + }, [action_response]); + let review_form; - if(response_status == 422) { + if(isUserAuthenticated()) { + if(action_response?.status == 422) + review_form_error_messages = action_response.data.errors; + review_form = ; + } + else { + review_form = null; + } + + if(action_response == 422) { quantity_field = (
    {quantity_field} -
    +
    + {review_form} +
      {reviews}
    -- cgit v1.2.3