- {imageSources.map((src) => (
+ {imageSources.slice(0, 6).map((src) => (
diff --git a/src/components/offer/offer-host.tsx b/src/components/offer/offer-host.tsx
index e4c288b..18b0e14 100644
--- a/src/components/offer/offer-host.tsx
+++ b/src/components/offer/offer-host.tsx
@@ -11,7 +11,17 @@ export function OfferHost({ host }: OfferHostProps): React.JSX.Element {
<>
Meet the host
-
+ {host.isPro ? (
+
+
+
+ ) : (
-
+ )}
{getFirstName(host.name)}
{host.isPro &&
Pro}
diff --git a/src/components/rating.tsx b/src/components/rating.tsx
index 7db3415..621be8d 100644
--- a/src/components/rating.tsx
+++ b/src/components/rating.tsx
@@ -3,21 +3,21 @@ import React from 'react';
interface RatingProps {
rating: number;
usePlace: string;
- isInOffer?: boolean;
+ showRatingValue?: boolean;
}
export function Rating({
rating,
- isInOffer,
+ showRatingValue,
usePlace,
}: RatingProps): React.JSX.Element {
return (
-
+
Rating
- {isInOffer && (
+ {showRatingValue && (
{rating}
)}
diff --git a/src/components/reviews/review-form.tsx b/src/components/reviews/review-form.tsx
index e9a25ba..143535a 100644
--- a/src/components/reviews/review-form.tsx
+++ b/src/components/reviews/review-form.tsx
@@ -1,4 +1,10 @@
import { useState } from 'react';
+import { store, useAppSelector } from '../../store/store.ts';
+import { postReview } from '../../store/actions.ts';
+import {
+ MAX_COMMENT_LENGTH,
+ MIN_COMMENT_LENGTH,
+} from '../../consts/reviews.ts';
type UserReview = {
comment?: string;
@@ -7,16 +13,32 @@ type UserReview = {
export function ReviewForm(): React.JSX.Element {
const [review, setReview] = useState
();
+ const offerId = useAppSelector((state) => state.currentOffer)!.id;
const onRatingChange: React.ChangeEventHandler = (
event,
): void => setReview({ ...review, rating: +event.target.value });
const onCommentChange: React.ChangeEventHandler = (
event,
): void => setReview({ ...review, comment: event.target.value });
+ const handleSubmit: React.MouseEventHandler = (
+ event,
+ ): void => {
+ event.preventDefault();
+ store.dispatch(
+ postReview({
+ offerId: offerId,
+ rating: review?.rating || 5,
+ comment: review?.comment || '',
+ }),
+ );
+ };
const isValid =
- review?.comment && review?.comment?.length >= 50 && review?.rating;
+ review?.comment &&
+ review?.comment?.length >= MIN_COMMENT_LENGTH &&
+ review?.comment?.length <= MAX_COMMENT_LENGTH &&
+ review?.rating;
return (
-