Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | 22x 22x 22x 22x 1x 1x 1x 1x | import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import { useParams } from "react-router";
import { useBackend, useBackendMutation } from "main/utils/useBackend";
import ReviewForm from "main/components/MyReviews/ReviewForm";
import { toast } from "react-toastify";
import { useNavigate } from "react-router";
export default function EditReviewPage() {
const { id } = useParams();
const navigate = useNavigate();
const { data: review } = useBackend(
// Stryker disable next-line ArrayDeclaration,StringLiteral
[`/api/reviews/${id}`],
// Stryker disable next-line StringLiteral
{ method: "GET", url: `/api/reviews/${id}` },
);
const mutation = useBackendMutation(
(updatedReview) => ({
method: "PUT",
url: `/api/reviews/reviewer`,
params: { id },
data: {
reviewerComments: updatedReview.reviewerComments,
itemStars: updatedReview.itemsStars,
dateItemServed: updatedReview.dateItemServed,
},
}),
{
onSuccess: () => {
toast("Review updated!");
navigate("/myreviews");
},
},
// Stryker disable next-line ArrayDeclaration,StringLiteral
[`/api/reviews/${id}`],
);
return (
<BasicLayout>
<div className="pt-2">
<h1>Edit Review</h1>
{review && (
<ReviewForm
initialContents={{
...review,
itemStars: review.itemsStars,
itemName: review.item?.name,
}}
initialItemName={review.item?.name}
submitAction={(data) => mutation.mutate(data)}
buttonLabel="Update Review"
/>
)}
</div>
</BasicLayout>
);
}
|