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 action_response = useActionData(); const product = response[0].data; const reviews = response[1].data.data.map(review =>
  • ); useEffect(() => { const target = document.getElementById("info-modal"); const options = { placement: 'center-center', backdrop: 'dynamic', backdropClasses: 'bg-gray-900 bg-opacity-50 dark:bg-opacity-80 fixed inset-0 z-40', closable: true }; const modal = new Modal(target, options); document.getElementById('modal-button')?.addEventListener("click", () => { modal.hide(); }); if(action_response == 200) modal.show(); }, [action_response]); let review_form; 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 = (
    ); } else { quantity_field = (
    ); } return ( <>
    {quantity_field}
    {review_form}
      {reviews}
    ); }