diff --git a/app/lib/judgeme.ts b/app/lib/judgeme.ts index ecddf938..87721e3a 100644 --- a/app/lib/judgeme.ts +++ b/app/lib/judgeme.ts @@ -30,7 +30,9 @@ type JudgemeReviewType = { }[]; }; -type JudgemeReviewsData = { +export type JudgemeReviewsData = { + rating: number; + reviewNumber: number; reviews: JudgemeReviewType[]; }; diff --git a/app/sections/judgeme-reviews/review-form.tsx b/app/sections/judgeme-reviews/review-form.tsx index a904dc50..e1df6367 100644 --- a/app/sections/judgeme-reviews/review-form.tsx +++ b/app/sections/judgeme-reviews/review-form.tsx @@ -1,12 +1,18 @@ import { useFetcher, useLoaderData } from "@remix-run/react"; +import clsx from "clsx"; import { FormEvent, useEffect, useRef, useState } from "react"; import Button from "~/components/button"; import { IconStar, IconStarFilled } from "~/components/icons"; +import { JudgemeReviewsData } from "~/lib/judgeme"; import { StarRating } from "~/modules/star-rating"; import { ProductLoaderType } from "~/routes/($locale).products.$productHandle"; -export function ReviewForm() { - const { product, judgemeReviews } = useLoaderData(); +export function ReviewForm({ + judgemeReviews, +}: { + judgemeReviews: JudgemeReviewsData; +}) { + const { product } = useLoaderData(); const [rating, setRating] = useState(0); const [hover, setHover] = useState(0); const [isFormVisible, setIsFormVisible] = useState(false); @@ -39,150 +45,208 @@ export function ReviewForm() { }; return ( -
-
-

- product reviews ({judgemeReviews.reviewNumber}) -

-
-

{judgemeReviews.rating.toFixed(1)}

- -
- -
- {isFormVisible && ( -
-
- Rating -
- {[...Array(5)].map((_, index) => { - const ratingValue = index + 1; - return ( -
handleRatingClick(ratingValue)} - onMouseEnter={() => setHover(ratingValue)} - onMouseLeave={() => setHover(0)} - aria-label={`Rate ${ratingValue} out of 5 stars`} - role="button" - > - {ratingValue <= (hover || rating) ? ( - - ) : ( - - )} -
- ); - })} - {rating} out of 5 -
+

+ product reviews ({judgemeReviews.reviewNumber}) +

+
+ {judgemeReviews && judgemeReviews.rating ? ( + <> +

+ {judgemeReviews.rating.toFixed(1)} +

+
+ +
+ + ) : ( +

+ We'd love to hear from you. Provide a review for this product. +

+ )}
- {/* Review Form */} - setIsFormVisible(true)} // Show form + disabled={isFormVisible || isPopupVisible} + variant={"outline"} > - - -
- - -
-
- - -
-
- - -
-
- - -
- {message && ( -
-

ERROR:

-

{message}

-
+ WRITE A REVIEW + +
+ ) : null} + {isFormVisible && ( +
+
- - + WRITE YOUR REVIEW + +
+ Rating +
+ {[...Array(5)].map((_, index) => { + const ratingValue = index + 1; + return ( +
handleRatingClick(ratingValue)} + onMouseEnter={() => setHover(ratingValue)} + onMouseLeave={() => setHover(0)} + aria-label={`Rate ${ratingValue} out of 5 stars`} + role="button" + > + {ratingValue <= (hover || rating) ? ( + + ) : ( + + )} +
+ ); + })} +
+
- + {/* Review Form */} + + + +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ {message && ( +
+

ERROR:

+

{message}

+
+ )} +
+ + +
+
+
)} {isPopupVisible && ( -
+

REVIEW SUBMITTED

Thanks for leaving your review!

-
+