Fixing bug with comments/reviews

This commit is contained in:
Vladislav Khorev 2024-02-24 13:00:24 +00:00
parent 67b935b47f
commit 566c4d4473
2 changed files with 5 additions and 10 deletions

View File

@ -12,7 +12,3 @@ export interface IReview {
review: string; review: string;
created_at: string; created_at: string;
} }
export interface IReviewList extends IList {
results: IReview[];
}

View File

@ -2,7 +2,7 @@
import "./ReviewSection.scss"; import "./ReviewSection.scss";
import { apiInstance } from "@/shared/config/apiConfig"; import { apiInstance } from "@/shared/config/apiConfig";
import { IReviewList } from "@/shared/types/review-type"; import { IReview } from "@/shared/types/review-type";
import { useSession } from "next-auth/react"; import { useSession } from "next-auth/react";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import calendar from "./icons/calendar.svg"; import calendar from "./icons/calendar.svg";
@ -17,7 +17,7 @@ const ReviewSection: React.FC<IReviewsSectionProps> = ({
endpoint, endpoint,
id, id,
}: IReviewsSectionProps) => { }: IReviewsSectionProps) => {
const [reviews, setReviews] = useState<IReviewList>(); const [reviews, setReviews] = useState<IReview[]>();
const session = useSession(); const session = useSession();
const handleSubmit: React.MouseEventHandler< const handleSubmit: React.MouseEventHandler<
HTMLFormElement HTMLFormElement
@ -52,11 +52,10 @@ const ReviewSection: React.FC<IReviewsSectionProps> = ({
}; };
const getReviews = async () => { const getReviews = async () => {
const response = await apiInstance.get<IReviewList>( const response = await apiInstance.get<IReview[]>(
`/${endpoint}/${id}/reviews/` `/${endpoint}/${id}/reviews/`
); );
setReviews(response?.data);
setReviews(response.data);
}; };
useEffect(() => { useEffect(() => {
@ -94,7 +93,7 @@ const ReviewSection: React.FC<IReviewsSectionProps> = ({
</h3> </h3>
<ul> <ul>
{reviews?.results.map((review) => ( {reviews?.map((review) => (
<li key={review.id} className="review"> <li key={review.id} className="review">
<div className="review__author"> <div className="review__author">
<img <img